From 98ac1b13a75a5dddb17d6d6f26e9365146083d7b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sun, 19 Jul 2009 19:36:27 +0200 Subject: [PATCH] Track service types and not device types for technologies listing --- src/connman.h | 14 +++--- src/device.c | 57 +++++++++++++++++++++--- src/manager.c | 2 +- src/notifier.c | 137 +++++++++++++++++++++++---------------------------------- src/service.c | 26 +---------- 5 files changed, 116 insertions(+), 120 deletions(-) diff --git a/src/connman.h b/src/connman.h index 85d6d3e..f9a7b27 100644 --- a/src/connman.h +++ b/src/connman.h @@ -203,6 +203,8 @@ char *__connman_udev_get_mbm_devnode(const char *ifname); int __connman_device_init(void); void __connman_device_cleanup(void); +enum connman_service_type __connman_device_get_service_type(struct connman_device *device); + void __connman_device_increase_connections(struct connman_device *device); void __connman_device_decrease_connections(struct connman_device *device); @@ -284,12 +286,12 @@ void __connman_service_auto_connect(void); int __connman_notifier_init(void); void __connman_notifier_cleanup(void); -void __connman_notifier_device_type_list(gboolean powered, - DBusMessageIter *iter); -void __connman_notifier_device_type_register(enum connman_device_type type); -void __connman_notifier_device_type_unregister(enum connman_device_type type); -void __connman_notifier_device_type_increase(enum connman_device_type type); -void __connman_notifier_device_type_decrease(enum connman_device_type type); +void __connman_notifier_list(gboolean powered, DBusMessageIter *iter); + +void __connman_notifier_register(enum connman_service_type type); +void __connman_notifier_unregister(enum connman_service_type type); +void __connman_notifier_enable(enum connman_service_type type); +void __connman_notifier_disable(enum connman_service_type type); void __connman_notifier_offline_mode(connman_bool_t enabled); #include diff --git a/src/device.c b/src/device.c index a7505a0..807c5c0 100644 --- a/src/device.c +++ b/src/device.c @@ -152,6 +152,34 @@ static const char *type2string(enum connman_device_type type) return NULL; } +enum connman_service_type __connman_device_get_service_type(struct connman_device *device) +{ + enum connman_device_type type = connman_device_get_type(device); + + switch (type) { + case CONNMAN_DEVICE_TYPE_UNKNOWN: + case CONNMAN_DEVICE_TYPE_VENDOR: + case CONNMAN_DEVICE_TYPE_GPS: + case CONNMAN_DEVICE_TYPE_NOZOMI: + case CONNMAN_DEVICE_TYPE_HUAWEI: + case CONNMAN_DEVICE_TYPE_NOVATEL: + break; + case CONNMAN_DEVICE_TYPE_ETHERNET: + return CONNMAN_SERVICE_TYPE_ETHERNET; + case CONNMAN_DEVICE_TYPE_WIFI: + return CONNMAN_SERVICE_TYPE_WIFI; + case CONNMAN_DEVICE_TYPE_WIMAX: + return CONNMAN_SERVICE_TYPE_WIMAX; + case CONNMAN_DEVICE_TYPE_BLUETOOTH: + return CONNMAN_SERVICE_TYPE_BLUETOOTH; + case CONNMAN_DEVICE_TYPE_MBM: + case CONNMAN_DEVICE_TYPE_HSO: + return CONNMAN_SERVICE_TYPE_CELLULAR; + } + + return CONNMAN_SERVICE_TYPE_UNKNOWN; +} + static int set_connected(struct connman_device *device, connman_bool_t connected) { @@ -249,6 +277,7 @@ static int powered_changed(struct connman_device *device) static int set_powered(struct connman_device *device, connman_bool_t powered) { struct connman_device_driver *driver = device->driver; + enum connman_service_type type; int err; DBG("device %p powered %d", device, powered); @@ -259,10 +288,12 @@ static int set_powered(struct connman_device *device, connman_bool_t powered) if (!driver) return -EINVAL; + type = __connman_device_get_service_type(device); + if (powered == TRUE) { if (driver->enable) { err = driver->enable(device); - __connman_notifier_device_type_increase(device->type); + __connman_notifier_enable(type); } else err = -EINVAL; } else { @@ -272,7 +303,7 @@ static int set_powered(struct connman_device *device, connman_bool_t powered) if (driver->disable) { err = driver->disable(device); - __connman_notifier_device_type_decrease(device->type); + __connman_notifier_disable(type); } else err = -EINVAL; } @@ -820,20 +851,26 @@ static void unregister_interface(struct connman_element *element) static void device_enable(struct connman_device *device) { + enum connman_service_type type; + DBG("device %p", device); if (device->powered == TRUE) return; + type = __connman_device_get_service_type(device); + if (device->driver->enable) { if (device->driver->enable(device) == 0) device->powered = TRUE; - __connman_notifier_device_type_increase(device->type); + __connman_notifier_enable(type); } } static void device_disable(struct connman_device *device) { + enum connman_service_type type; + DBG("device %p", device); if (device->powered == FALSE) @@ -841,10 +878,12 @@ static void device_disable(struct connman_device *device) g_hash_table_remove_all(device->networks); + type = __connman_device_get_service_type(device); + if (device->driver->disable) { if (device->driver->disable(device) == 0) device->powered = FALSE; - __connman_notifier_device_type_decrease(device->type); + __connman_notifier_disable(type); } } @@ -1809,6 +1848,8 @@ void __connman_device_set_network(struct connman_device *device, */ int connman_device_register(struct connman_device *device) { + enum connman_service_type type; + __connman_storage_load_device(device); switch (device->mode) { @@ -1821,7 +1862,8 @@ int connman_device_register(struct connman_device *device) break; } - __connman_notifier_device_type_register(device->type); + type = __connman_device_get_service_type(device); + __connman_notifier_register(type); return connman_element_register(&device->element, NULL); } @@ -1834,9 +1876,12 @@ int connman_device_register(struct connman_device *device) */ void connman_device_unregister(struct connman_device *device) { + enum connman_service_type type; + __connman_storage_save_device(device); - __connman_notifier_device_type_unregister(device->type); + type = __connman_device_get_service_type(device); + __connman_notifier_unregister(type); connman_element_unregister(&device->element); } diff --git a/src/manager.c b/src/manager.c index b92440d..762425a 100644 --- a/src/manager.c +++ b/src/manager.c @@ -146,7 +146,7 @@ static void append_technologies(gboolean powered, DBusMessageIter *dict) dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter); - __connman_notifier_device_type_list(powered, &iter); + __connman_notifier_list(powered, &iter); dbus_message_iter_close_container(&value, &iter); dbus_message_iter_close_container(&entry, &value); diff --git a/src/notifier.c b/src/notifier.c index 1ece8a1..3692303 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -70,7 +70,7 @@ void connman_notifier_unregister(struct connman_notifier *notifier) notifier_list = g_slist_remove(notifier_list, notifier); } -static void device_enabled(enum connman_device_type type, +static void technology_enabled(enum connman_device_type type, connman_bool_t enabled) { GSList *list; @@ -95,7 +95,7 @@ static void device_enabled(enum connman_device_type type, dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter); - __connman_notifier_device_type_list(TRUE, &iter); + __connman_notifier_list(TRUE, &iter); dbus_message_iter_close_container(&value, &iter); dbus_message_iter_close_container(&entry, &value); @@ -111,7 +111,7 @@ done: } } -static void device_registered(enum connman_device_type type, +static void technology_registered(enum connman_service_type type, connman_bool_t registered) { DBusMessage *signal; @@ -135,7 +135,7 @@ static void device_registered(enum connman_device_type type, dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &iter); - __connman_notifier_device_type_list(FALSE, &iter); + __connman_notifier_list(FALSE, &iter); dbus_message_iter_close_container(&value, &iter); dbus_message_iter_close_container(&entry, &value); @@ -143,37 +143,30 @@ static void device_registered(enum connman_device_type type, g_dbus_send_message(connection, signal); } -static const char *type2string(enum connman_device_type type) +static const char *type2string(enum connman_service_type type) { switch (type) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_MBM: - case CONNMAN_DEVICE_TYPE_HSO: - case CONNMAN_DEVICE_TYPE_NOZOMI: - case CONNMAN_DEVICE_TYPE_HUAWEI: - case CONNMAN_DEVICE_TYPE_NOVATEL: - case CONNMAN_DEVICE_TYPE_VENDOR: + case CONNMAN_SERVICE_TYPE_UNKNOWN: break; - case CONNMAN_DEVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_ETHERNET: return "ethernet"; - case CONNMAN_DEVICE_TYPE_WIFI: + case CONNMAN_SERVICE_TYPE_WIFI: return "wifi"; - case CONNMAN_DEVICE_TYPE_WIMAX: + case CONNMAN_SERVICE_TYPE_WIMAX: return "wimax"; - case CONNMAN_DEVICE_TYPE_BLUETOOTH: + case CONNMAN_SERVICE_TYPE_BLUETOOTH: return "bluetooth"; - case CONNMAN_DEVICE_TYPE_GPS: - return "gps"; + case CONNMAN_SERVICE_TYPE_CELLULAR: + return "cellular"; } return NULL; } -static volatile gint registered[20]; -static volatile gint enabled[20]; +static volatile gint registered[10]; +static volatile gint enabled[10]; -void __connman_notifier_device_type_list(gboolean powered, - DBusMessageIter *iter) +void __connman_notifier_list(gboolean powered, DBusMessageIter *iter) { int i; @@ -195,100 +188,80 @@ void __connman_notifier_device_type_list(gboolean powered, } } -void __connman_notifier_device_type_register(enum connman_device_type type) +void __connman_notifier_register(enum connman_service_type type) { DBG("type %d", type); switch (type) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_MBM: - case CONNMAN_DEVICE_TYPE_HSO: - case CONNMAN_DEVICE_TYPE_NOZOMI: - case CONNMAN_DEVICE_TYPE_HUAWEI: - case CONNMAN_DEVICE_TYPE_NOVATEL: - case CONNMAN_DEVICE_TYPE_VENDOR: + case CONNMAN_SERVICE_TYPE_UNKNOWN: return; - case CONNMAN_DEVICE_TYPE_ETHERNET: - case CONNMAN_DEVICE_TYPE_WIFI: - case CONNMAN_DEVICE_TYPE_WIMAX: - case CONNMAN_DEVICE_TYPE_BLUETOOTH: - case CONNMAN_DEVICE_TYPE_GPS: - if (g_atomic_int_exchange_and_add(®istered[type], 1) == 0) - device_registered(type, TRUE); + case CONNMAN_SERVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_WIFI: + case CONNMAN_SERVICE_TYPE_WIMAX: + case CONNMAN_SERVICE_TYPE_BLUETOOTH: + case CONNMAN_SERVICE_TYPE_CELLULAR: break; } + + if (g_atomic_int_exchange_and_add(®istered[type], 1) == 0) + technology_registered(type, TRUE); } -void __connman_notifier_device_type_unregister(enum connman_device_type type) +void __connman_notifier_unregister(enum connman_service_type type) { DBG("type %d", type); switch (type) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_MBM: - case CONNMAN_DEVICE_TYPE_HSO: - case CONNMAN_DEVICE_TYPE_NOZOMI: - case CONNMAN_DEVICE_TYPE_HUAWEI: - case CONNMAN_DEVICE_TYPE_NOVATEL: - case CONNMAN_DEVICE_TYPE_VENDOR: + case CONNMAN_SERVICE_TYPE_UNKNOWN: return; - case CONNMAN_DEVICE_TYPE_ETHERNET: - case CONNMAN_DEVICE_TYPE_WIFI: - case CONNMAN_DEVICE_TYPE_WIMAX: - case CONNMAN_DEVICE_TYPE_BLUETOOTH: - case CONNMAN_DEVICE_TYPE_GPS: - if (g_atomic_int_dec_and_test(®istered[type]) == TRUE) - device_registered(type, FALSE); + case CONNMAN_SERVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_WIFI: + case CONNMAN_SERVICE_TYPE_WIMAX: + case CONNMAN_SERVICE_TYPE_BLUETOOTH: + case CONNMAN_SERVICE_TYPE_CELLULAR: break; } + + if (g_atomic_int_dec_and_test(®istered[type]) == TRUE) + technology_registered(type, FALSE); } -void __connman_notifier_device_type_increase(enum connman_device_type type) +void __connman_notifier_enable(enum connman_service_type type) { DBG("type %d", type); switch (type) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_MBM: - case CONNMAN_DEVICE_TYPE_HSO: - case CONNMAN_DEVICE_TYPE_NOZOMI: - case CONNMAN_DEVICE_TYPE_HUAWEI: - case CONNMAN_DEVICE_TYPE_NOVATEL: - case CONNMAN_DEVICE_TYPE_VENDOR: + case CONNMAN_SERVICE_TYPE_UNKNOWN: return; - case CONNMAN_DEVICE_TYPE_ETHERNET: - case CONNMAN_DEVICE_TYPE_WIFI: - case CONNMAN_DEVICE_TYPE_WIMAX: - case CONNMAN_DEVICE_TYPE_BLUETOOTH: - case CONNMAN_DEVICE_TYPE_GPS: - if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0) - device_enabled(type, TRUE); + case CONNMAN_SERVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_WIFI: + case CONNMAN_SERVICE_TYPE_WIMAX: + case CONNMAN_SERVICE_TYPE_BLUETOOTH: + case CONNMAN_SERVICE_TYPE_CELLULAR: break; } + + if (g_atomic_int_exchange_and_add(&enabled[type], 1) == 0) + technology_enabled(type, TRUE); } -void __connman_notifier_device_type_decrease(enum connman_device_type type) +void __connman_notifier_disable(enum connman_service_type type) { DBG("type %d", type); switch (type) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_MBM: - case CONNMAN_DEVICE_TYPE_HSO: - case CONNMAN_DEVICE_TYPE_NOZOMI: - case CONNMAN_DEVICE_TYPE_HUAWEI: - case CONNMAN_DEVICE_TYPE_NOVATEL: - case CONNMAN_DEVICE_TYPE_VENDOR: + case CONNMAN_SERVICE_TYPE_UNKNOWN: return; - case CONNMAN_DEVICE_TYPE_ETHERNET: - case CONNMAN_DEVICE_TYPE_WIFI: - case CONNMAN_DEVICE_TYPE_WIMAX: - case CONNMAN_DEVICE_TYPE_BLUETOOTH: - case CONNMAN_DEVICE_TYPE_GPS: - if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE) - device_enabled(type, FALSE); + case CONNMAN_SERVICE_TYPE_ETHERNET: + case CONNMAN_SERVICE_TYPE_WIFI: + case CONNMAN_SERVICE_TYPE_WIMAX: + case CONNMAN_SERVICE_TYPE_BLUETOOTH: + case CONNMAN_SERVICE_TYPE_CELLULAR: break; } + + if (g_atomic_int_dec_and_test(&enabled[type]) == TRUE) + technology_enabled(type, FALSE); } void __connman_notifier_offline_mode(connman_bool_t enabled) diff --git a/src/service.c b/src/service.c index b59234f..557a968 100644 --- a/src/service.c +++ b/src/service.c @@ -1414,30 +1414,6 @@ struct connman_service *__connman_service_lookup_from_device(struct connman_devi return service; } -static enum connman_service_type convert_device_type(struct connman_device *device) -{ - enum connman_device_type type = connman_device_get_type(device); - - switch (type) { - case CONNMAN_DEVICE_TYPE_UNKNOWN: - case CONNMAN_DEVICE_TYPE_VENDOR: - case CONNMAN_DEVICE_TYPE_WIFI: - case CONNMAN_DEVICE_TYPE_WIMAX: - case CONNMAN_DEVICE_TYPE_BLUETOOTH: - case CONNMAN_DEVICE_TYPE_GPS: - case CONNMAN_DEVICE_TYPE_MBM: - case CONNMAN_DEVICE_TYPE_HSO: - case CONNMAN_DEVICE_TYPE_NOZOMI: - case CONNMAN_DEVICE_TYPE_HUAWEI: - case CONNMAN_DEVICE_TYPE_NOVATEL: - break; - case CONNMAN_DEVICE_TYPE_ETHERNET: - return CONNMAN_SERVICE_TYPE_ETHERNET; - } - - return CONNMAN_SERVICE_TYPE_UNKNOWN; -} - /** * __connman_service_create_from_device: * @device: device structure @@ -1467,7 +1443,7 @@ struct connman_service *__connman_service_create_from_device(struct connman_devi return service; } - service->type = convert_device_type(device); + service->type = __connman_device_get_service_type(device); service->device = device; -- 2.7.4