• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include "cras_dbus_util.h"
7 
append_key_value(DBusMessageIter * iter,const char * key,int type,const char * type_string,void * value)8 dbus_bool_t append_key_value(DBusMessageIter *iter, const char *key,
9 			     int type, const char *type_string,
10 			     void *value)
11 {
12        DBusMessageIter entry, variant;
13 
14        if (!dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
15                                              &entry))
16                return FALSE;
17        if (!dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key))
18                return FALSE;
19        if (!dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
20                                              type_string, &variant))
21                return FALSE;
22        if (!dbus_message_iter_append_basic(&variant, type, value))
23                return FALSE;
24        if (!dbus_message_iter_close_container(&entry, &variant))
25                return FALSE;
26        if (!dbus_message_iter_close_container(iter, &entry))
27                return FALSE;
28 
29        return TRUE;
30 }
31