service: Support function that saves service
[framework/connectivity/connman.git] / src / notifier.c
index 7d4b1e8..b328a2a 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -78,42 +78,38 @@ void connman_notifier_unregister(struct connman_notifier *notifier)
 static int connected[MAX_TECHNOLOGIES];
 static int online[MAX_TECHNOLOGIES];
 
-static unsigned int notifier_count_online(void)
+static connman_bool_t notifier_is_online(void)
 {
-       unsigned int i, count = 0;
+       unsigned int i;
 
        __sync_synchronize();
        for (i = 0; i < MAX_TECHNOLOGIES; i++) {
                if (online[i] > 0)
-                       count++;
+                       return TRUE;
        }
 
-       return count;
+       return FALSE;
 }
 
-unsigned int __connman_notifier_count_connected(void)
+connman_bool_t __connman_notifier_is_connected(void)
 {
-       unsigned int i, count = 0;
+       unsigned int i;
 
        __sync_synchronize();
        for (i = 0; i < MAX_TECHNOLOGIES; i++) {
                if (connected[i] > 0)
-                       count++;
+                       return TRUE;
        }
 
-       return count;
+       return FALSE;
 }
 
 static const char *evaluate_notifier_state(void)
 {
-       unsigned int count;
-
-       count = notifier_count_online();
-       if (count > 0)
+       if (notifier_is_online() == TRUE)
                return "online";
 
-       count = __connman_notifier_count_connected();
-       if (count > 0)
+       if (__connman_notifier_is_connected() == TRUE)
                return "ready";
 
        if ( __connman_technology_get_offlinemode() == TRUE)
@@ -140,7 +136,7 @@ static void state_changed(void)
 
        connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
                                CONNMAN_MANAGER_INTERFACE, "State",
-                                               DBUS_TYPE_STRING, &notifier_state);
+                                       DBUS_TYPE_STRING, &notifier_state);
 }
 
 static void technology_connected(enum connman_service_type type,
@@ -175,7 +171,7 @@ void __connman_notifier_connect(enum connman_service_type type)
                technology_connected(type, TRUE);
 }
 
-void __connman_notifier_online(enum connman_service_type type)
+void __connman_notifier_enter_online(enum connman_service_type type)
 {
        DBG("type %d", type);
 
@@ -183,8 +179,15 @@ void __connman_notifier_online(enum connman_service_type type)
                state_changed();
 }
 
-void __connman_notifier_disconnect(enum connman_service_type type,
-                                       enum connman_service_state old_state)
+void __connman_notifier_leave_online(enum connman_service_type type)
+{
+       DBG("type %d", type);
+
+       if (__sync_fetch_and_sub(&online[type], 1) == 1)
+               state_changed();
+}
+
+void __connman_notifier_disconnect(enum connman_service_type type)
 {
        DBG("type %d", type);
 
@@ -209,35 +212,16 @@ void __connman_notifier_disconnect(enum connman_service_type type,
                break;
        }
 
-       if (old_state == CONNMAN_SERVICE_STATE_ONLINE)
-               __sync_fetch_and_sub(&online[type], 1);
-
        if (__sync_fetch_and_sub(&connected[type], 1) != 1)
                return;
 
        technology_connected(type, FALSE);
 }
 
-static void technology_default(enum connman_service_type type)
-{
-       const char *str;
-
-       str = __connman_service_type2string(type);
-       if (str == NULL)
-               str = "";
-
-       connman_dbus_property_changed_basic(CONNMAN_MANAGER_PATH,
-                       CONNMAN_MANAGER_INTERFACE, "DefaultTechnology",
-                                               DBUS_TYPE_STRING, &str);
-}
-
 void __connman_notifier_default_changed(struct connman_service *service)
 {
-       enum connman_service_type type = connman_service_get_type(service);
        GSList *list;
 
-       technology_default(type);
-
        for (list = notifier_list; list; list = list->next) {
                struct connman_notifier *notifier = list->data;