From 76ca29341f8c68a7345c0b09f7097debf759d585 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 11 Mar 2009 21:52:10 +0100 Subject: [PATCH] Add implementation for notifier hooks --- src/notifier.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/notifier.c b/src/notifier.c index c23a570..9092b24 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -66,19 +66,80 @@ void connman_notifier_unregister(struct connman_notifier *notifier) notifier_list = g_slist_remove(notifier_list, notifier); } +static void device_enabled(enum connman_device_type type, + connman_bool_t enabled) +{ + GSList *list; + + for (list = notifier_list; list; list = list->next) { + struct connman_notifier *notifier = list->data; + + if (notifier->device_enabled) + notifier->device_enabled(type, enabled); + } + +} + +static volatile gint enabled[10]; + void __connman_notifier_device_type_increase(enum connman_device_type type) { DBG("type %d", type); + + switch (type) { + case CONNMAN_DEVICE_TYPE_UNKNOWN: + case CONNMAN_DEVICE_TYPE_HSO: + case CONNMAN_DEVICE_TYPE_NOZOMI: + case CONNMAN_DEVICE_TYPE_HUAWEI: + case CONNMAN_DEVICE_TYPE_NOVATEL: + case CONNMAN_DEVICE_TYPE_VENDOR: + return; + case CONNMAN_DEVICE_TYPE_ETHERNET: + case CONNMAN_DEVICE_TYPE_WIFI: + case CONNMAN_DEVICE_TYPE_WIMAX: + case CONNMAN_DEVICE_TYPE_BLUETOOTH: + case CONNMAN_DEVICE_TYPE_GPS: + if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0) + device_enabled(type, TRUE); + break; + } } void __connman_notifier_device_type_decrease(enum connman_device_type type) { DBG("type %d", type); + + switch (type) { + case CONNMAN_DEVICE_TYPE_UNKNOWN: + case CONNMAN_DEVICE_TYPE_HSO: + case CONNMAN_DEVICE_TYPE_NOZOMI: + case CONNMAN_DEVICE_TYPE_HUAWEI: + case CONNMAN_DEVICE_TYPE_NOVATEL: + case CONNMAN_DEVICE_TYPE_VENDOR: + return; + case CONNMAN_DEVICE_TYPE_ETHERNET: + case CONNMAN_DEVICE_TYPE_WIFI: + case CONNMAN_DEVICE_TYPE_WIMAX: + case CONNMAN_DEVICE_TYPE_BLUETOOTH: + case CONNMAN_DEVICE_TYPE_GPS: + if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE) + device_enabled(type, FALSE); + break; + } } void __connman_notifier_offline_mode(connman_bool_t enabled) { + GSList *list; + DBG("enabled %d", enabled); + + for (list = notifier_list; list; list = list->next) { + struct connman_notifier *notifier = list->data; + + if (notifier->offline_mode) + notifier->offline_mode(enabled); + } } int __connman_notifier_init(void) -- 1.7.9.5