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
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 #define MAX_TECHNOLOGIES 10
75 static volatile gint registered[MAX_TECHNOLOGIES];
76 static volatile gint enabled[MAX_TECHNOLOGIES];
77 static volatile gint connected[MAX_TECHNOLOGIES];
79 void __connman_notifier_list_registered(DBusMessageIter *iter, void *user_data)
83 for (i = 0; i < MAX_TECHNOLOGIES; i++) {
84 const char *type = __connman_service_type2string(i);
89 if (g_atomic_int_get(®istered[i]) > 0)
90 dbus_message_iter_append_basic(iter,
91 DBUS_TYPE_STRING, &type);
95 void __connman_notifier_list_enabled(DBusMessageIter *iter, void *user_data)
99 for (i = 0; i < MAX_TECHNOLOGIES; i++) {
100 const char *type = __connman_service_type2string(i);
105 if (g_atomic_int_get(&enabled[i]) > 0)
106 dbus_message_iter_append_basic(iter,
107 DBUS_TYPE_STRING, &type);
111 void __connman_notifier_list_connected(DBusMessageIter *iter, void *user_data)
115 for (i = 0; i < MAX_TECHNOLOGIES; i++) {
116 const char *type = __connman_service_type2string(i);
121 if (g_atomic_int_get(&connected[i]) > 0)
122 dbus_message_iter_append_basic(iter,
123 DBUS_TYPE_STRING, &type);
127 static void technology_registered(enum connman_service_type type,
128 connman_bool_t registered)
130 DBG("type %d registered %d", type, registered);
132 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
133 CONNMAN_MANAGER_INTERFACE, "AvailableTechnologies",
134 DBUS_TYPE_STRING, __connman_notifier_list_registered, NULL);
137 static void technology_enabled(enum connman_service_type type,
138 connman_bool_t enabled)
142 DBG("type %d enabled %d", type, enabled);
144 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
145 CONNMAN_MANAGER_INTERFACE, "EnabledTechnologies",
146 DBUS_TYPE_STRING, __connman_notifier_list_enabled, NULL);
148 for (list = notifier_list; list; list = list->next) {
149 struct connman_notifier *notifier = list->data;
151 if (notifier->service_enabled)
152 notifier->service_enabled(type, enabled);
156 unsigned int __connman_notifier_count_connected(void)
158 unsigned int i, count = 0;
160 for (i = 0; i < MAX_TECHNOLOGIES; i++) {
161 if (g_atomic_int_get(&connected[i]) > 0)
168 const char *__connman_notifier_get_state(void)
170 unsigned int count = __connman_notifier_count_connected();
178 static void state_changed(void)
180 unsigned int count = __connman_notifier_count_connected();
181 char *state = "offline";
190 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
191 CONNMAN_MANAGER_INTERFACE, "State",
192 DBUS_TYPE_STRING, &state);
194 signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
195 CONNMAN_MANAGER_INTERFACE, "StateChanged");
199 dbus_message_append_args(signal, DBUS_TYPE_STRING, &state,
202 g_dbus_send_message(connection, signal);
205 static void technology_connected(enum connman_service_type type,
206 connman_bool_t connected)
208 DBG("type %d connected %d", type, connected);
210 connman_dbus_property_changed_array(CONNMAN_MANAGER_PATH,
211 CONNMAN_MANAGER_INTERFACE, "ConnectedTechnologies",
212 DBUS_TYPE_STRING, __connman_notifier_list_connected, NULL);
217 void __connman_notifier_register(enum connman_service_type type)
219 DBG("type %d", type);
222 case CONNMAN_SERVICE_TYPE_UNKNOWN:
223 case CONNMAN_SERVICE_TYPE_SYSTEM:
224 case CONNMAN_SERVICE_TYPE_GPS:
225 case CONNMAN_SERVICE_TYPE_VPN:
226 case CONNMAN_SERVICE_TYPE_GADGET:
228 case CONNMAN_SERVICE_TYPE_ETHERNET:
229 case CONNMAN_SERVICE_TYPE_WIFI:
230 case CONNMAN_SERVICE_TYPE_WIMAX:
231 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
232 case CONNMAN_SERVICE_TYPE_CELLULAR:
236 if (g_atomic_int_exchange_and_add(®istered[type], 1) == 0)
237 technology_registered(type, TRUE);
240 void __connman_notifier_unregister(enum connman_service_type type)
242 DBG("type %d", type);
245 case CONNMAN_SERVICE_TYPE_UNKNOWN:
246 case CONNMAN_SERVICE_TYPE_SYSTEM:
247 case CONNMAN_SERVICE_TYPE_GPS:
248 case CONNMAN_SERVICE_TYPE_VPN:
249 case CONNMAN_SERVICE_TYPE_GADGET:
251 case CONNMAN_SERVICE_TYPE_ETHERNET:
252 case CONNMAN_SERVICE_TYPE_WIFI:
253 case CONNMAN_SERVICE_TYPE_WIMAX:
254 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
255 case CONNMAN_SERVICE_TYPE_CELLULAR:
259 if (g_atomic_int_dec_and_test(®istered[type]) == TRUE)
260 technology_registered(type, FALSE);
263 void __connman_notifier_enable(enum connman_service_type type)
265 DBG("type %d", type);
268 case CONNMAN_SERVICE_TYPE_UNKNOWN:
269 case CONNMAN_SERVICE_TYPE_SYSTEM:
270 case CONNMAN_SERVICE_TYPE_GPS:
271 case CONNMAN_SERVICE_TYPE_VPN:
272 case CONNMAN_SERVICE_TYPE_GADGET:
274 case CONNMAN_SERVICE_TYPE_ETHERNET:
275 case CONNMAN_SERVICE_TYPE_WIFI:
276 case CONNMAN_SERVICE_TYPE_WIMAX:
277 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
278 case CONNMAN_SERVICE_TYPE_CELLULAR:
282 if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0)
283 technology_enabled(type, TRUE);
286 void __connman_notifier_disable(enum connman_service_type type)
288 DBG("type %d", type);
291 case CONNMAN_SERVICE_TYPE_UNKNOWN:
292 case CONNMAN_SERVICE_TYPE_SYSTEM:
293 case CONNMAN_SERVICE_TYPE_GPS:
294 case CONNMAN_SERVICE_TYPE_VPN:
295 case CONNMAN_SERVICE_TYPE_GADGET:
297 case CONNMAN_SERVICE_TYPE_ETHERNET:
298 case CONNMAN_SERVICE_TYPE_WIFI:
299 case CONNMAN_SERVICE_TYPE_WIMAX:
300 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
301 case CONNMAN_SERVICE_TYPE_CELLULAR:
305 if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE)
306 technology_enabled(type, FALSE);
309 void __connman_notifier_connect(enum connman_service_type type)
311 DBG("type %d", type);
314 case CONNMAN_SERVICE_TYPE_UNKNOWN:
315 case CONNMAN_SERVICE_TYPE_SYSTEM:
316 case CONNMAN_SERVICE_TYPE_GPS:
317 case CONNMAN_SERVICE_TYPE_VPN:
318 case CONNMAN_SERVICE_TYPE_GADGET:
320 case CONNMAN_SERVICE_TYPE_ETHERNET:
321 case CONNMAN_SERVICE_TYPE_WIFI:
322 case CONNMAN_SERVICE_TYPE_WIMAX:
323 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
324 case CONNMAN_SERVICE_TYPE_CELLULAR:
328 if (g_atomic_int_exchange_and_add(&connected[type], 1) == 0)
329 technology_connected(type, TRUE);
332 void __connman_notifier_disconnect(enum connman_service_type type)
334 DBG("type %d", type);
337 case CONNMAN_SERVICE_TYPE_UNKNOWN:
338 case CONNMAN_SERVICE_TYPE_SYSTEM:
339 case CONNMAN_SERVICE_TYPE_GPS:
340 case CONNMAN_SERVICE_TYPE_VPN:
341 case CONNMAN_SERVICE_TYPE_GADGET:
343 case CONNMAN_SERVICE_TYPE_ETHERNET:
344 case CONNMAN_SERVICE_TYPE_WIFI:
345 case CONNMAN_SERVICE_TYPE_WIMAX:
346 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
347 case CONNMAN_SERVICE_TYPE_CELLULAR:
351 if (g_atomic_int_dec_and_test(&connected[type]) == TRUE)
352 technology_connected(type, FALSE);
355 static void technology_default(enum connman_service_type type)
359 str = __connman_service_type2string(type);
363 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
364 CONNMAN_MANAGER_INTERFACE, "DefaultTechnology",
365 DBUS_TYPE_STRING, &str);
368 void __connman_notifier_default_changed(struct connman_service *service)
370 enum connman_service_type type = connman_service_get_type(service);
374 technology_default(type);
376 interface = connman_service_get_interface(service);
377 __connman_tethering_update_interface(interface);
380 for (list = notifier_list; list; list = list->next) {
381 struct connman_notifier *notifier = list->data;
383 if (notifier->default_changed)
384 notifier->default_changed(service);
388 void __connman_notifier_proxy_changed(struct connman_service *service)
392 for (list = notifier_list; list; list = list->next) {
393 struct connman_notifier *notifier = list->data;
395 if (notifier->proxy_changed)
396 notifier->proxy_changed(service);
400 static void offlinemode_changed(dbus_bool_t enabled)
402 DBG("enabled %d", enabled);
404 connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
405 CONNMAN_MANAGER_INTERFACE, "OfflineMode",
406 DBUS_TYPE_BOOLEAN, &enabled);
409 void __connman_notifier_offlinemode(connman_bool_t enabled)
413 DBG("enabled %d", enabled);
415 __connman_profile_changed(FALSE);
417 offlinemode_changed(enabled);
419 for (list = notifier_list; list; list = list->next) {
420 struct connman_notifier *notifier = list->data;
422 if (notifier->offline_mode)
423 notifier->offline_mode(enabled);
427 void __connman_notifier_service_state_changed(struct connman_service *service,
428 enum connman_service_state state)
432 for (list = notifier_list; list; list = list->next) {
433 struct connman_notifier *notifier = list->data;
435 if (notifier->service_state_changed)
436 notifier->service_state_changed(service, state);
440 void __connman_notifier_ipconfig_changed(struct connman_service *service,
441 struct connman_ipconfig *ipconfig)
445 for (list = notifier_list; list; list = list->next) {
446 struct connman_notifier *notifier = list->data;
448 if (notifier->ipconfig_changed)
449 notifier->ipconfig_changed(service, ipconfig);
453 static connman_bool_t technology_supported(enum connman_service_type type)
456 case CONNMAN_SERVICE_TYPE_UNKNOWN:
457 case CONNMAN_SERVICE_TYPE_SYSTEM:
458 case CONNMAN_SERVICE_TYPE_GPS:
459 case CONNMAN_SERVICE_TYPE_VPN:
460 case CONNMAN_SERVICE_TYPE_GADGET:
462 case CONNMAN_SERVICE_TYPE_ETHERNET:
463 case CONNMAN_SERVICE_TYPE_WIFI:
464 case CONNMAN_SERVICE_TYPE_WIMAX:
465 case CONNMAN_SERVICE_TYPE_BLUETOOTH:
466 case CONNMAN_SERVICE_TYPE_CELLULAR:
473 connman_bool_t __connman_notifier_is_registered(enum connman_service_type type)
475 DBG("type %d", type);
477 if (technology_supported(type) == FALSE)
480 if (g_atomic_int_get(®istered[type]) > 0)
486 connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type)
488 DBG("type %d", type);
490 if (technology_supported(type) == FALSE)
493 if (g_atomic_int_get(&enabled[type]) > 0)
499 int __connman_notifier_init(void)
503 connection = connman_dbus_get_connection();
508 void __connman_notifier_cleanup(void)
512 dbus_connection_unref(connection);