Add implementation for notifier hooks
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 11 Mar 2009 20:52:10 +0000 (21:52 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 11 Mar 2009 20:52:10 +0000 (21:52 +0100)
src/notifier.c

index c23a570..9092b24 100644 (file)
@@ -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)