5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 dbus_bool_t connman_dbus_validate_ident(const char *ident)
38 for (i = 0; i < strlen(ident); i++) {
39 if (ident[i] >= '0' && ident[i] <= '9')
41 if (ident[i] >= 'a' && ident[i] <= 'z')
43 if (ident[i] >= 'A' && ident[i] <= 'Z')
51 char *connman_dbus_encode_string(const char *value)
61 str = g_string_new(NULL);
65 for (i = 0; i < size; i++) {
66 const char tmp = value[i];
67 if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') &&
68 (tmp < 'a' || tmp > 'z'))
69 g_string_append_printf(str, "_%02x", tmp);
71 str = g_string_append_c(str, tmp);
74 return g_string_free(str, FALSE);
77 void connman_dbus_property_append_basic(DBusMessageIter *iter,
78 const char *key, int type, void *val)
80 DBusMessageIter value;
81 const char *signature;
83 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
86 case DBUS_TYPE_BOOLEAN:
87 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
89 case DBUS_TYPE_STRING:
90 signature = DBUS_TYPE_STRING_AS_STRING;
93 signature = DBUS_TYPE_BYTE_AS_STRING;
95 case DBUS_TYPE_UINT16:
96 signature = DBUS_TYPE_UINT16_AS_STRING;
99 signature = DBUS_TYPE_INT16_AS_STRING;
101 case DBUS_TYPE_UINT32:
102 signature = DBUS_TYPE_UINT32_AS_STRING;
104 case DBUS_TYPE_INT32:
105 signature = DBUS_TYPE_INT32_AS_STRING;
107 case DBUS_TYPE_UINT64:
108 signature = DBUS_TYPE_UINT64_AS_STRING;
110 case DBUS_TYPE_INT64:
111 signature = DBUS_TYPE_INT64_AS_STRING;
113 case DBUS_TYPE_OBJECT_PATH:
114 signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
117 signature = DBUS_TYPE_VARIANT_AS_STRING;
121 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
123 dbus_message_iter_append_basic(&value, type, val);
124 dbus_message_iter_close_container(iter, &value);
127 void connman_dbus_property_append_dict(DBusMessageIter *iter, const char *key,
128 connman_dbus_append_cb_t function, void *user_data)
130 DBusMessageIter value, dict;
132 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
134 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
135 DBUS_TYPE_ARRAY_AS_STRING
136 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
137 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
138 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &value);
140 connman_dbus_dict_open(&value, &dict);
142 function(&dict, user_data);
143 connman_dbus_dict_close(&value, &dict);
145 dbus_message_iter_close_container(iter, &value);
148 void connman_dbus_property_append_fixed_array(DBusMessageIter *iter,
149 const char *key, int type, void *val, int len)
151 DBusMessageIter value, array;
152 const char *variant_sig, *array_sig;
156 variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
157 array_sig = DBUS_TYPE_BYTE_AS_STRING;
163 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
165 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
166 variant_sig, &value);
168 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
170 dbus_message_iter_append_fixed_array(&array, type, val, len);
171 dbus_message_iter_close_container(&value, &array);
173 dbus_message_iter_close_container(iter, &value);
176 void connman_dbus_property_append_array(DBusMessageIter *iter,
177 const char *key, int type,
178 connman_dbus_append_cb_t function, void *user_data)
180 DBusMessageIter value, array;
181 const char *variant_sig, *array_sig;
184 case DBUS_TYPE_STRING:
185 variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
186 array_sig = DBUS_TYPE_STRING_AS_STRING;
188 case DBUS_TYPE_OBJECT_PATH:
189 variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING;
190 array_sig = DBUS_TYPE_OBJECT_PATH_AS_STRING;
196 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
198 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
199 variant_sig, &value);
201 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
204 function(&array, user_data);
205 dbus_message_iter_close_container(&value, &array);
207 dbus_message_iter_close_container(iter, &value);
210 static DBusConnection *connection = NULL;
212 dbus_bool_t connman_dbus_property_changed_basic(const char *path,
213 const char *interface, const char *key,
217 DBusMessageIter iter;
222 signal = dbus_message_new_signal(path, interface, "PropertyChanged");
226 dbus_message_iter_init_append(signal, &iter);
227 connman_dbus_property_append_basic(&iter, key, type, val);
229 g_dbus_send_message(connection, signal);
234 #if defined TIZEN_EXT
236 * Description: Extends state_changed signal to notify service error cause
238 dbus_bool_t connman_dbus_service_property_changed_with_error_cause(const char *path,
239 const char *interface, const char *key1, int type1, void *val1,
240 const char *key2, int type2, void *val2)
243 DBusMessageIter iter;
248 signal = dbus_message_new_signal(path, interface, "PropertyChanged");
252 dbus_message_iter_init_append(signal, &iter);
253 connman_dbus_property_append_basic(&iter, key1, type1, val1);
254 connman_dbus_property_append_basic(&iter, key2, type2, val2);
256 g_dbus_send_message(connection, signal);
262 dbus_bool_t connman_dbus_property_changed_dict(const char *path,
263 const char *interface, const char *key,
264 connman_dbus_append_cb_t function, void *user_data)
267 DBusMessageIter iter;
272 signal = dbus_message_new_signal(path, interface, "PropertyChanged");
276 dbus_message_iter_init_append(signal, &iter);
277 connman_dbus_property_append_dict(&iter, key, function, user_data);
279 g_dbus_send_message(connection, signal);
284 dbus_bool_t connman_dbus_property_changed_array(const char *path,
285 const char *interface, const char *key, int type,
286 connman_dbus_append_cb_t function, void *user_data)
289 DBusMessageIter iter;
294 signal = dbus_message_new_signal(path, interface, "PropertyChanged");
298 dbus_message_iter_init_append(signal, &iter);
299 connman_dbus_property_append_array(&iter, key, type,
300 function, user_data);
302 g_dbus_send_message(connection, signal);
307 dbus_bool_t connman_dbus_setting_changed_basic(const char *owner,
308 const char *path, const char *key,
312 DBusMessageIter array, dict;
314 if (owner == NULL || path == NULL)
317 msg = dbus_message_new_method_call(owner, path,
318 CONNMAN_NOTIFICATION_INTERFACE,
323 dbus_message_iter_init_append(msg, &array);
324 connman_dbus_dict_open(&array, &dict);
326 connman_dbus_dict_append_basic(&dict, key, type, val);
328 connman_dbus_dict_close(&array, &dict);
330 g_dbus_send_message(connection, msg);
335 dbus_bool_t connman_dbus_setting_changed_dict(const char *owner,
336 const char *path, const char *key,
337 connman_dbus_append_cb_t function,
341 DBusMessageIter array, dict;
343 if (owner == NULL || path == NULL)
346 msg = dbus_message_new_method_call(owner, path,
347 CONNMAN_NOTIFICATION_INTERFACE,
352 dbus_message_iter_init_append(msg, &array);
353 connman_dbus_dict_open(&array, &dict);
355 connman_dbus_dict_append_dict(&dict, key, function, user_data);
357 connman_dbus_dict_close(&array, &dict);
359 g_dbus_send_message(connection, msg);
364 dbus_bool_t connman_dbus_setting_changed_array(const char *owner,
365 const char *path, const char *key, int type,
366 connman_dbus_append_cb_t function,
370 DBusMessageIter array, dict;
372 if (owner == NULL || path == NULL)
375 msg = dbus_message_new_method_call(owner, path,
376 CONNMAN_NOTIFICATION_INTERFACE,
381 dbus_message_iter_init_append(msg, &array);
382 connman_dbus_dict_open(&array, &dict);
384 connman_dbus_dict_append_array(&dict, key, type, function, user_data);
386 connman_dbus_dict_close(&array, &dict);
388 g_dbus_send_message(connection, msg);
393 #if defined TIZEN_EXT
395 * August 22nd, 2011. TIZEN
397 * This part is added to send a DBus signal which means scan is completed
398 * because scan UX of a Wi-Fi setting application has an active scan procedure
399 * and it needs scan complete signal whether success or not
402 dbus_bool_t connman_dbus_scan_completed_basic(const char *path,
403 const char *interface, int type, void *val)
406 DBusMessageIter iter;
411 signal = dbus_message_new_signal(path, interface, "ScanCompleted");
415 dbus_message_iter_init_append(signal, &iter);
417 dbus_message_iter_append_basic(&iter, type, val);
419 g_dbus_send_message(connection, signal);
425 DBusConnection *connman_dbus_get_connection(void)
427 if (connection == NULL)
430 return dbus_connection_ref(connection);
433 int __connman_dbus_init(DBusConnection *conn)
442 void __connman_dbus_cleanup(void)