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_entry(DBusMessageIter *dict,
87 const char *key, int type, void *val)
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, DBUS_TYPE_STRING, &key);
102 append_variant(&entry, type, val);
104 dbus_message_iter_close_container(dict, &entry);
107 void dict_append_array(DBusMessageIter *dict, const char *key, int type,
108 void *val, int n_elements)
110 DBusMessageIter entry;
112 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
115 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
117 append_array_variant(&entry, type, val, n_elements);
119 dbus_message_iter_close_container(dict, &entry);
122 void set_dbus_connection(DBusConnection *conn)
127 DBusConnection *btd_get_dbus_connection(void)
132 const char *class_to_icon(uint32_t class)
134 switch ((class & 0x1f00) >> 8) {
138 switch ((class & 0xfc) >> 2) {
149 return "network-wireless";
151 switch ((class & 0xfc) >> 2) {
154 return "audio-card"; /* Headset */
156 return "audio-card"; /* Headphone */
158 case 0x0c: /* Video Camera */
159 case 0x0d: /* Camcorder */
160 return "camera-video";
162 return "audio-card"; /* Other audio device */
166 switch ((class & 0xc0) >> 6) {
168 switch ((class & 0x1e) >> 2) {
171 return "input-gaming";
175 return "input-keyboard";
177 switch ((class & 0x1e) >> 2) {
179 return "input-tablet";
181 return "input-mouse";
189 return "camera-photo";
196 const char *gap_appearance_to_icon(uint16_t appearance)
198 switch ((appearance & 0xffc0) >> 6) {
206 return "video-display";
208 return "multimedia-player";
211 case 0x0f: /* HID Generic */
212 switch (appearance & 0x3f) {
214 return "input-keyboard";
216 return "input-mouse";
219 return "input-gaming";
221 return "input-tablet";