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>
39 #include "dbus-common.h"
41 static DBusConnection *connection = NULL;
43 static void append_variant(DBusMessageIter *iter, int type, void *val)
45 DBusMessageIter value;
46 char sig[2] = { type, '\0' };
48 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, sig, &value);
50 dbus_message_iter_append_basic(&value, type, val);
52 dbus_message_iter_close_container(iter, &value);
55 static void append_array_variant(DBusMessageIter *iter, int type, void *val,
58 DBusMessageIter variant, array;
59 char type_sig[2] = { type, '\0' };
60 char array_sig[3] = { DBUS_TYPE_ARRAY, type, '\0' };
62 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
65 dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
68 if (dbus_type_is_fixed(type) == TRUE) {
69 dbus_message_iter_append_fixed_array(&array, type, val,
71 } else if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
72 const char ***str_array = val;
75 for (i = 0; i < n_elements; i++)
76 dbus_message_iter_append_basic(&array, type,
80 dbus_message_iter_close_container(&variant, &array);
82 dbus_message_iter_close_container(iter, &variant);
85 void dict_append_entry(DBusMessageIter *dict,
86 const char *key, int type, void *val)
88 DBusMessageIter entry;
90 if (type == DBUS_TYPE_STRING) {
91 const char *str = *((const char **) val);
96 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
99 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
101 append_variant(&entry, type, val);
103 dbus_message_iter_close_container(dict, &entry);
106 void dict_append_array(DBusMessageIter *dict, const char *key, int type,
107 void *val, int n_elements)
109 DBusMessageIter entry;
111 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
114 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
116 append_array_variant(&entry, type, val, n_elements);
118 dbus_message_iter_close_container(dict, &entry);
121 dbus_bool_t emit_property_changed(DBusConnection *conn,
123 const char *interface,
125 int type, void *value)
128 DBusMessageIter iter;
130 signal = dbus_message_new_signal(path, interface, "PropertyChanged");
133 error("Unable to allocate new %s.PropertyChanged signal",
138 dbus_message_iter_init_append(signal, &iter);
140 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
142 append_variant(&iter, type, value);
144 return g_dbus_send_message(conn, signal);
147 dbus_bool_t emit_array_property_changed(DBusConnection *conn,
149 const char *interface,
151 int type, void *value, int num)
154 DBusMessageIter iter;
156 signal = dbus_message_new_signal(path, interface, "PropertyChanged");
159 error("Unable to allocate new %s.PropertyChanged signal",
164 dbus_message_iter_init_append(signal, &iter);
166 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
168 append_array_variant(&iter, type, value, num);
170 return g_dbus_send_message(conn, signal);
173 void set_dbus_connection(DBusConnection *conn)
178 DBusConnection *get_dbus_connection(void)
183 const char *class_to_icon(uint32_t class)
185 switch ((class & 0x1f00) >> 8) {
189 switch ((class & 0xfc) >> 2) {
200 return "network-wireless";
202 switch ((class & 0xfc) >> 2) {
205 return "audio-card"; /* Headset */
207 return "audio-card"; /* Headphone */
209 case 0x0c: /* Video Camera */
210 case 0x0d: /* Camcorder */
211 return "camera-video";
213 return "audio-card"; /* Other audio device */
217 switch ((class & 0xc0) >> 6) {
219 switch ((class & 0x1e) >> 2) {
222 return "input-gaming";
226 return "input-keyboard";
228 switch ((class & 0x1e) >> 2) {
230 return "input-tablet";
232 return "input-mouse";
240 return "camera-photo";
247 const char *gap_appearance_to_icon(uint16_t appearance)
249 switch ((appearance & 0xffc0) >> 6) {
255 return "video-display";
257 return "multimedia-player";
260 case 0x0f: /* HID Generic */
261 switch (appearance & 0x3f) {
263 return "input-keyboard";
265 return "input-mouse";
268 return "input-gaming";
270 return "input-tablet";