From 3e6995b377ef331e8e15267f6be357e7a958203a Mon Sep 17 00:00:00 2001 From: Forest Bond Date: Tue, 11 May 2010 20:56:06 -0400 Subject: [PATCH] Fail immediately enabling/disabling unregistered technology Previously, calling EnableTechnology or DisableTechnology with an unregistered technology type caused the call to fail silently and eventually timeout. With this patch, a "Not Registered" error is returned immediately instead. --- src/connman.h | 1 + src/manager.c | 6 ++++++ src/notifier.c | 27 ++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/connman.h b/src/connman.h index 16ded2d..f3a3050 100644 --- a/src/connman.h +++ b/src/connman.h @@ -464,6 +464,7 @@ 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_registered(enum connman_service_type type); connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type); unsigned int __connman_notifier_count_connected(void); const char *__connman_notifier_get_state(void); diff --git a/src/manager.c b/src/manager.c index da0ee53..6561a78 100644 --- a/src/manager.c +++ b/src/manager.c @@ -345,6 +345,9 @@ static DBusMessage *enable_technology(DBusConnection *conn, else return __connman_error_invalid_arguments(msg); + if (__connman_notifier_is_registered(type) == FALSE) + return __connman_error_not_registered(msg); + if (__connman_notifier_is_enabled(type) == TRUE) return __connman_error_already_enabled(msg); @@ -390,6 +393,9 @@ static DBusMessage *disable_technology(DBusConnection *conn, else return __connman_error_invalid_arguments(msg); + if (__connman_notifier_is_registered(type) == FALSE) + return __connman_error_not_registered(msg); + if (__connman_notifier_is_enabled(type) == FALSE) return __connman_error_already_disabled(msg); diff --git a/src/notifier.c b/src/notifier.c index 2777783..95794ac 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -401,10 +401,8 @@ void __connman_notifier_offlinemode(connman_bool_t enabled) } } -connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type) +static connman_bool_t technology_supported(enum connman_service_type type) { - DBG("type %d", type); - switch (type) { case CONNMAN_SERVICE_TYPE_UNKNOWN: case CONNMAN_SERVICE_TYPE_SYSTEM: @@ -419,6 +417,29 @@ connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type) break; } + return TRUE; +} + +connman_bool_t __connman_notifier_is_registered(enum connman_service_type type) +{ + DBG("type %d", type); + + if (technology_supported(type) == FALSE) + return FALSE; + + if (g_atomic_int_get(®istered[type]) > 0) + return TRUE; + + return FALSE; +} + +connman_bool_t __connman_notifier_is_enabled(enum connman_service_type type) +{ + DBG("type %d", type); + + if (technology_supported(type) == FALSE) + return FALSE; + if (g_atomic_int_get(&enabled[type]) > 0) return TRUE; -- 2.7.4