From f425974003005b7587b59bba7cfeb8b1ac6aa7b0 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 28 Nov 2009 14:32:09 +0000 Subject: [PATCH] Add support for default service changed notifier --- include/notifier.h | 1 + include/service.h | 2 ++ src/connman.h | 1 + src/notifier.c | 42 +++++++++++++++++++++++++++++++++++++++ src/service.c | 58 +++++++++++++++++++++++++++++------------------------- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/include/notifier.h b/include/notifier.h index 1addb55..8b299a5 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 ceaeeaf..3ab32db 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 1475d0a..c53f521 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 303bc42..ec04d95 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 b2f2029..88ce4bb 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) -- 2.7.4