From: Marcel Holtmann Date: Wed, 11 Mar 2009 20:52:10 +0000 (+0100) Subject: Add implementation for notifier hooks X-Git-Tag: 0.13~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76ca29341f8c68a7345c0b09f7097debf759d585;p=platform%2Fupstream%2Fconnman.git Add implementation for notifier hooks --- 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)