Add support for default service changed notifier
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 28 Nov 2009 14:32:09 +0000 (14:32 +0000)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 28 Nov 2009 14:32:09 +0000 (14:32 +0000)
include/notifier.h
include/service.h
src/connman.h
src/notifier.c
src/service.c

index 1addb55..8b299a5 100644 (file)
@@ -41,6 +41,7 @@ extern "C" {
 struct connman_notifier {
        const char *name;
        int priority;
+       void (*default_changed) (struct connman_service *service);
        void (*service_enabled) (enum connman_service_type type,
                                                connman_bool_t enabled);
        void (*offline_mode) (connman_bool_t enabled);
index ceaeeaf..3ab32db 100644 (file)
@@ -85,6 +85,8 @@ struct connman_service *connman_service_create(void);
 struct connman_service *connman_service_ref(struct connman_service *service);
 void connman_service_unref(struct connman_service *service);
 
+enum connman_service_type connman_service_get_type(struct connman_service *service);
+
 int connman_service_set_favorite(struct connman_service *service,
                                                connman_bool_t favorite);
 
index 1475d0a..c53f521 100644 (file)
@@ -379,6 +379,7 @@ void __connman_notifier_disable(enum connman_service_type type);
 void __connman_notifier_connect(enum connman_service_type type);
 void __connman_notifier_disconnect(enum connman_service_type type);
 void __connman_notifier_offlinemode(connman_bool_t enabled);
+void __connman_notifier_default_changed(struct connman_service *service);
 
 connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type);
 
index 303bc42..ec04d95 100644 (file)
@@ -343,6 +343,48 @@ void __connman_notifier_disconnect(enum connman_service_type type)
                technology_connected(type, FALSE);
 }
 
+static void technology_default(enum connman_service_type type)
+{
+       DBusMessage *signal;
+       DBusMessageIter entry, value;
+       const char *str, *key = "DefaultTechnology";
+
+       str = __connman_service_type2string(type);
+       if (str == NULL)
+               return;
+
+       signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
+                               CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
+       if (signal == NULL)
+               return;
+
+       dbus_message_iter_init_append(signal, &entry);
+
+       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+                                       DBUS_TYPE_STRING_AS_STRING, &value);
+       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &str);
+       dbus_message_iter_close_container(&entry, &value);
+
+       g_dbus_send_message(connection, signal);
+}
+
+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;
+
+               if (notifier->default_changed)
+                       notifier->default_changed(service);
+       }
+}
+
 static void offlinemode_changed(dbus_bool_t enabled)
 {
        DBusMessage *signal;
index b2f2029..88ce4bb 100644 (file)
@@ -226,7 +226,7 @@ static enum connman_service_error string2error(const char *error)
        return CONNMAN_SERVICE_ERROR_UNKNOWN;
 }
 
-const char *__connman_service_default(void)
+static struct connman_service *get_default(void)
 {
        struct connman_service *service;
        GSequenceIter *iter;
@@ -234,13 +234,29 @@ const char *__connman_service_default(void)
        iter = g_sequence_get_begin_iter(service_list);
 
        if (g_sequence_iter_is_end(iter) == TRUE)
-               return "";
+               return NULL;
 
        service = g_sequence_get(iter);
-       if (service == NULL)
-               return "";
 
        if (service->state != CONNMAN_SERVICE_STATE_READY)
+               return NULL;
+
+       return service;
+}
+
+static void default_changed(void)
+{
+       struct connman_service *service = get_default();
+
+       __connman_notifier_default_changed(service);
+}
+
+const char *__connman_service_default(void)
+{
+       struct connman_service *service;
+
+       service = get_default();
+       if (service == NULL)
                return "";
 
        return __connman_service_type2string(service->type);
@@ -1383,6 +1399,17 @@ static void favorite_changed(struct connman_service *service)
 }
 
 /**
+ * connman_service_get_type:
+ * @service: service structure
+ *
+ * Get the type of service
+ */
+enum connman_service_type connman_service_get_type(struct connman_service *service)
+{
+       return service->type;
+}
+
+/**
  * connman_service_set_favorite:
  * @service: service structure
  * @favorite: favorite value
@@ -1412,29 +1439,6 @@ int connman_service_set_favorite(struct connman_service *service,
        return 0;
 }
 
-static void default_changed(void)
-{
-       DBusMessage *signal;
-       DBusMessageIter entry, value;
-       const char *key = "DefaultTechnology";
-       const char *str = __connman_service_default();
-
-       signal = dbus_message_new_signal(CONNMAN_MANAGER_PATH,
-                               CONNMAN_MANAGER_INTERFACE, "PropertyChanged");
-       if (signal == NULL)
-               return;
-
-       dbus_message_iter_init_append(signal, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                       DBUS_TYPE_STRING_AS_STRING, &value);
-       dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &str);
-       dbus_message_iter_close_container(&entry, &value);
-
-       g_dbus_send_message(connection, signal);
-}
 
 int __connman_service_indicate_state(struct connman_service *service,
                                        enum connman_service_state state)