3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2006-2010 Nokia Corporation
6 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
7 * Copyright (C) 2005-2007 Johan Hedberg <johan.hedberg@nokia.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <dbus/dbus.h>
36 #include "gdbus/gdbus.h"
40 #include "dbus-common.h"
42 static DBusConnection *connection = NULL;
44 static void append_variant(DBusMessageIter *iter, int type, void *val)
46 DBusMessageIter value;
47 char sig[2] = { type, '\0' };
49 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value);
51 dbus_message_iter_append_basic(&value, type, val);
53 dbus_message_iter_close_container(iter, &value);
56 static void append_array_variant(DBusMessageIter *iter, int type, void *val,
59 DBusMessageIter variant, array;
60 char type_sig[2] = { type, '\0' };
61 char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
63 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
66 dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
69 if (dbus_type_is_fixed(type) == TRUE) {
70 dbus_message_iter_append_fixed_array(&array, type, val,
72 } else if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
73 const char ***str_array = val;
76 for (i = 0; i < n_elements; i++)
77 dbus_message_iter_append_basic(&array, type,
81 dbus_message_iter_close_container(&variant, &array);
83 dbus_message_iter_close_container(iter, &variant);
86 void dict_append_basic(DBusMessageIter *dict, int key_type, const void *key,
89 DBusMessageIter entry;
91 if (type == DBUS_TYPE_STRING) {
92 const char *str = *((const char **) val);
97 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
100 dbus_message_iter_append_basic(&entry, key_type, key);
102 append_variant(&entry, type, val);
104 dbus_message_iter_close_container(dict, &entry);
108 void dict_append_entry(DBusMessageIter *dict,
109 const char *key, int type, void *val)
111 dict_append_basic(dict, DBUS_TYPE_STRING, &key, type, val);
114 void dict_append_basic_array(DBusMessageIter *dict, int key_type,
115 const void *key, int type, void *val,
118 DBusMessageIter entry;
120 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
123 dbus_message_iter_append_basic(&entry, key_type, key);
125 append_array_variant(&entry, type, val, n_elements);
127 dbus_message_iter_close_container(dict, &entry);
130 void dict_append_array(DBusMessageIter *dict, const char *key, int type,
131 void *val, int n_elements)
133 dict_append_basic_array(dict, DBUS_TYPE_STRING, &key, type, val,
137 void set_dbus_connection(DBusConnection *conn)
142 DBusConnection *btd_get_dbus_connection(void)
147 const char *class_to_icon(uint32_t class)
149 switch ((class & 0x1f00) >> 8) {
153 switch ((class & 0xfc) >> 2) {
164 return "network-wireless";
166 switch ((class & 0xfc) >> 2) {
169 return "audio-card"; /* Headset */
171 return "audio-card"; /* Headphone */
173 case 0x0c: /* Video Camera */
174 case 0x0d: /* Camcorder */
175 return "camera-video";
177 return "audio-card"; /* Other audio device */
181 switch ((class & 0xc0) >> 6) {
183 switch ((class & 0x1e) >> 2) {
186 return "input-gaming";
190 return "input-keyboard";
192 switch ((class & 0x1e) >> 2) {
194 return "input-tablet";
196 return "input-mouse";
204 return "camera-photo";
211 const char *gap_appearance_to_icon(uint16_t appearance)
213 switch ((appearance & 0xffc0) >> 6) {
221 return "video-display";
223 return "multimedia-player";
226 case 0x0f: /* HID Generic */
227 switch (appearance & 0x3f) {
229 return "input-keyboard";
231 return "input-mouse";
234 return "input-gaming";
236 return "input-tablet";