diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-11-28 14:32:09 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-11-28 14:32:09 +0000 |
commit | f425974003005b7587b59bba7cfeb8b1ac6aa7b0 (patch) | |
tree | 0f8f62063478c7cbfaa3b7e7d0295485be3806a1 | |
parent | 2b4c823115b9cf4db45227b6152b75170df10d48 (diff) | |
download | connman-f425974003005b7587b59bba7cfeb8b1ac6aa7b0.tar.gz connman-f425974003005b7587b59bba7cfeb8b1ac6aa7b0.tar.bz2 connman-f425974003005b7587b59bba7cfeb8b1ac6aa7b0.zip |
Add support for default service changed notifier
-rw-r--r-- | include/notifier.h | 1 | ||||
-rw-r--r-- | include/service.h | 2 | ||||
-rw-r--r-- | src/connman.h | 1 | ||||
-rw-r--r-- | src/notifier.c | 42 | ||||
-rw-r--r-- | src/service.c | 58 |
5 files changed, 77 insertions, 27 deletions
diff --git a/include/notifier.h b/include/notifier.h index 1addb556..8b299a59 100644 --- a/include/notifier.h +++ b/include/notifier.h @@ -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); diff --git a/include/service.h b/include/service.h index ceaeeaf8..3ab32dbb 100644 --- a/include/service.h +++ b/include/service.h @@ -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); diff --git a/src/connman.h b/src/connman.h index 1475d0a2..c53f521e 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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); diff --git a/src/notifier.c b/src/notifier.c index 303bc42d..ec04d954 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -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; diff --git a/src/service.c b/src/service.c index b2f20295..88ce4bb9 100644 --- a/src/service.c +++ b/src/service.c @@ -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) |