5 * Copyright (C) 2007-2009 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
30 static DBusConnection *connection = NULL;
32 static GSList *notifier_list = NULL;
34 static gint compare_priority(gconstpointer a, gconstpointer b)
36 const struct connman_notifier *notifier1 = a;
37 const struct connman_notifier *notifier2 = b;
39 return notifier2->priority - notifier1->priority;
43 * connman_notifier_register:
44 * @notifier: notifier module
46 * Register a new notifier module
48 * Returns: %0 on success
50 int connman_notifier_register(struct connman_notifier *notifier)
52 DBG("notifier %p name %s", notifier, notifier->name);
54 notifier_list = g_slist_insert_sorted(notifier_list, notifier,
61 * connman_notifier_unregister:
62 * @notifier: notifier module
64 * Remove a previously registered notifier module
66 void connman_notifier_unregister(struct connman_notifier *notifier)
68 DBG("notifier %p name %s", notifier, notifier->name);
70 notifier_list = g_slist_remove(notifier_list, notifier);
73 static void device_enabled(enum connman_device_type type,
74 connman_bool_t enabled)
78 DBusMessageIter entry, value, iter;
79 const char *key = "EnabledTechnologies";
81 DBG("type %d enabled %d", type, enabled);
83 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
84 CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
88 dbus_message_iter_init_append(signal, &entry);
90 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
92 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
93 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
96 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
97 DBUS_TYPE_STRING_AS_STRING, &iter);
98 __connman_notifier_device_type_list(TRUE, &iter);
99 dbus_message_iter_close_container(&value, &iter);
101 dbus_message_iter_close_container(&entry, &value);
103 g_dbus_send_message(connection, signal);
106 for (list = notifier_list; list; list = list->next) {
107 struct connman_notifier *notifier = list->data;
109 if (notifier->device_enabled)
110 notifier->device_enabled(type, enabled);
114 static void device_registered(enum connman_device_type type,
115 connman_bool_t registered)
118 DBusMessageIter entry, value, iter;
119 const char *key = "Technologies";
121 DBG("type %d registered %d", type, registered);
123 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
124 CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
128 dbus_message_iter_init_append(signal, &entry);
130 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
132 dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
133 DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
136 dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
137 DBUS_TYPE_STRING_AS_STRING, &iter);
138 __connman_notifier_device_type_list(FALSE, &iter);
139 dbus_message_iter_close_container(&value, &iter);
141 dbus_message_iter_close_container(&entry, &value);
143 g_dbus_send_message(connection, signal);
146 static const char *type2string(enum connman_device_type type)
149 case CONNMAN_DEVICE_TYPE_UNKNOWN:
150 case CONNMAN_DEVICE_TYPE_MBM:
151 case CONNMAN_DEVICE_TYPE_HSO:
152 case CONNMAN_DEVICE_TYPE_NOZOMI:
153 case CONNMAN_DEVICE_TYPE_HUAWEI:
154 case CONNMAN_DEVICE_TYPE_NOVATEL:
155 case CONNMAN_DEVICE_TYPE_VENDOR:
157 case CONNMAN_DEVICE_TYPE_ETHERNET:
159 case CONNMAN_DEVICE_TYPE_WIFI:
161 case CONNMAN_DEVICE_TYPE_WIMAX:
163 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
165 case CONNMAN_DEVICE_TYPE_GPS:
172 static volatile gint registered[20];
173 static volatile gint enabled[20];
175 void __connman_notifier_device_type_list(gboolean powered,
176 DBusMessageIter *iter)
180 for (i = 0; i < 10; i++) {
181 const char *type = type2string(i);
188 count = g_atomic_int_get(&enabled[i]);
190 count = g_atomic_int_get(®istered[i]);
193 dbus_message_iter_append_basic(iter,
194 DBUS_TYPE_STRING, &type);
198 void __connman_notifier_device_type_register(enum connman_device_type type)
200 DBG("type %d", type);
203 case CONNMAN_DEVICE_TYPE_UNKNOWN:
204 case CONNMAN_DEVICE_TYPE_MBM:
205 case CONNMAN_DEVICE_TYPE_HSO:
206 case CONNMAN_DEVICE_TYPE_NOZOMI:
207 case CONNMAN_DEVICE_TYPE_HUAWEI:
208 case CONNMAN_DEVICE_TYPE_NOVATEL:
209 case CONNMAN_DEVICE_TYPE_VENDOR:
211 case CONNMAN_DEVICE_TYPE_ETHERNET:
212 case CONNMAN_DEVICE_TYPE_WIFI:
213 case CONNMAN_DEVICE_TYPE_WIMAX:
214 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
215 case CONNMAN_DEVICE_TYPE_GPS:
216 if (g_atomic_int_exchange_and_add(®istered[type], 1) == 0)
217 device_registered(type, TRUE);
222 void __connman_notifier_device_type_unregister(enum connman_device_type type)
224 DBG("type %d", type);
227 case CONNMAN_DEVICE_TYPE_UNKNOWN:
228 case CONNMAN_DEVICE_TYPE_MBM:
229 case CONNMAN_DEVICE_TYPE_HSO:
230 case CONNMAN_DEVICE_TYPE_NOZOMI:
231 case CONNMAN_DEVICE_TYPE_HUAWEI:
232 case CONNMAN_DEVICE_TYPE_NOVATEL:
233 case CONNMAN_DEVICE_TYPE_VENDOR:
235 case CONNMAN_DEVICE_TYPE_ETHERNET:
236 case CONNMAN_DEVICE_TYPE_WIFI:
237 case CONNMAN_DEVICE_TYPE_WIMAX:
238 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
239 case CONNMAN_DEVICE_TYPE_GPS:
240 if (g_atomic_int_dec_and_test(®istered[type]) == TRUE)
241 device_registered(type, FALSE);
246 void __connman_notifier_device_type_increase(enum connman_device_type type)
248 DBG("type %d", type);
251 case CONNMAN_DEVICE_TYPE_UNKNOWN:
252 case CONNMAN_DEVICE_TYPE_MBM:
253 case CONNMAN_DEVICE_TYPE_HSO:
254 case CONNMAN_DEVICE_TYPE_NOZOMI:
255 case CONNMAN_DEVICE_TYPE_HUAWEI:
256 case CONNMAN_DEVICE_TYPE_NOVATEL:
257 case CONNMAN_DEVICE_TYPE_VENDOR:
259 case CONNMAN_DEVICE_TYPE_ETHERNET:
260 case CONNMAN_DEVICE_TYPE_WIFI:
261 case CONNMAN_DEVICE_TYPE_WIMAX:
262 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
263 case CONNMAN_DEVICE_TYPE_GPS:
264 if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0)
265 device_enabled(type, TRUE);
270 void __connman_notifier_device_type_decrease(enum connman_device_type type)
272 DBG("type %d", type);
275 case CONNMAN_DEVICE_TYPE_UNKNOWN:
276 case CONNMAN_DEVICE_TYPE_MBM:
277 case CONNMAN_DEVICE_TYPE_HSO:
278 case CONNMAN_DEVICE_TYPE_NOZOMI:
279 case CONNMAN_DEVICE_TYPE_HUAWEI:
280 case CONNMAN_DEVICE_TYPE_NOVATEL:
281 case CONNMAN_DEVICE_TYPE_VENDOR:
283 case CONNMAN_DEVICE_TYPE_ETHERNET:
284 case CONNMAN_DEVICE_TYPE_WIFI:
285 case CONNMAN_DEVICE_TYPE_WIMAX:
286 case CONNMAN_DEVICE_TYPE_BLUETOOTH:
287 case CONNMAN_DEVICE_TYPE_GPS:
288 if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE)
289 device_enabled(type, FALSE);
294 void __connman_notifier_offline_mode(connman_bool_t enabled)
298 DBG("enabled %d", enabled);
300 __connman_profile_changed(FALSE);
302 for (list = notifier_list; list; list = list->next) {
303 struct connman_notifier *notifier = list->data;
305 if (notifier->offline_mode)
306 notifier->offline_mode(enabled);
310 int __connman_notifier_init(void)
314 connection = connman_dbus_get_connection();
319 void __connman_notifier_cleanup(void)
323 dbus_connection_unref(connection);