diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-07-16 15:54:16 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-07-16 15:54:16 +0200 |
commit | 0a0f473ced55dfdcfcfdc52a6a48d8db4b5d0500 (patch) | |
tree | ff1fdbf5aa545d92a04e7a37ed77076a7f59ba3a | |
parent | fa1d7b70dfa10b7af44909573e9c59f9c538850b (diff) | |
download | connman-0a0f473ced55dfdcfcfdc52a6a48d8db4b5d0500.tar.gz connman-0a0f473ced55dfdcfcfdc52a6a48d8db4b5d0500.tar.bz2 connman-0a0f473ced55dfdcfcfdc52a6a48d8db4b5d0500.zip |
Add support for Technologies and EnabledTechnologies properties
-rw-r--r-- | doc/manager-api.txt | 10 | ||||
-rw-r--r-- | src/connman.h | 4 | ||||
-rw-r--r-- | src/device.c | 4 | ||||
-rw-r--r-- | src/manager.c | 32 | ||||
-rw-r--r-- | src/notifier.c | 107 | ||||
-rwxr-xr-x | test/test-manager | 11 |
6 files changed, 167 insertions, 1 deletions
diff --git a/doc/manager-api.txt b/doc/manager-api.txt index f6f2f9f2..08c59b8e 100644 --- a/doc/manager-api.txt +++ b/doc/manager-api.txt @@ -108,6 +108,16 @@ Properties string State [readonly] the value "connected". This can only be seen if previously no connection was present. + array{string} Technologies [readonly] + + The list of available technologies. The strings + are the same as the ones from the service types. + + array{string} EnabledTechnologies [readonly] + + The list of enabled technologies. The strings + are the same as the ones from the service types. + boolean OfflineMode [readwrite] The offline mode indicates the global setting for diff --git a/src/connman.h b/src/connman.h index a5614179..d717664a 100644 --- a/src/connman.h +++ b/src/connman.h @@ -276,6 +276,10 @@ 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_offline_mode(connman_bool_t enabled); diff --git a/src/device.c b/src/device.c index 6dadaa3a..f50a98a2 100644 --- a/src/device.c +++ b/src/device.c @@ -1798,6 +1798,8 @@ int connman_device_register(struct connman_device *device) break; } + __connman_notifier_device_type_register(device->type); + return connman_element_register(&device->element, NULL); } @@ -1811,6 +1813,8 @@ void connman_device_unregister(struct connman_device *device) { __connman_storage_save_device(device); + __connman_notifier_device_type_unregister(device->type); + connman_element_unregister(&device->element); } diff --git a/src/manager.c b/src/manager.c index 85025b36..69235b3c 100644 --- a/src/manager.c +++ b/src/manager.c @@ -125,6 +125,35 @@ static void append_connections(DBusMessageIter *dict) dbus_message_iter_close_container(dict, &entry); } +static void append_technologies(gboolean powered, DBusMessageIter *dict) +{ + DBusMessageIter entry, value, iter; + const char *key; + + if (powered) + key = "EnabledTechnologies"; + else + key = "Technologies"; + + dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, + NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + &value); + + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &iter); + __connman_notifier_device_type_list(powered, &iter); + dbus_message_iter_close_container(&value, &iter); + + dbus_message_iter_close_container(&entry, &value); + + dbus_message_iter_close_container(dict, &entry); +} + static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -171,6 +200,9 @@ static DBusMessage *get_properties(DBusConnection *conn, connman_dbus_dict_append_variant(&dict, "OfflineMode", DBUS_TYPE_BOOLEAN, &global_offlinemode); + append_technologies(FALSE, &dict); + append_technologies(TRUE, &dict); + dbus_message_iter_close_container(&array, &dict); return reply; diff --git a/src/notifier.c b/src/notifier.c index 023b1eb4..df6fd33f 100644 --- a/src/notifier.c +++ b/src/notifier.c @@ -71,16 +71,121 @@ static void device_enabled(enum connman_device_type type, { GSList *list; + DBG("type %d enabled %d", type, enabled); + for (list = notifier_list; list; list = list->next) { struct connman_notifier *notifier = list->data; if (notifier->device_enabled) notifier->device_enabled(type, enabled); } +} + +static void device_registered(enum connman_device_type type, + connman_bool_t registered) +{ + DBG("type %d registered %d", type, registered); +} + +static const char *type2string(enum connman_device_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: + break; + case CONNMAN_DEVICE_TYPE_ETHERNET: + return "ethernet"; + case CONNMAN_DEVICE_TYPE_WIFI: + return "wifi"; + case CONNMAN_DEVICE_TYPE_WIMAX: + return "wimax"; + case CONNMAN_DEVICE_TYPE_BLUETOOTH: + return "bluetooth"; + case CONNMAN_DEVICE_TYPE_GPS: + return "gps"; + } + + return NULL; +} + +static volatile gint registered[20]; +static volatile gint enabled[20]; + +void __connman_notifier_device_type_list(gboolean powered, + DBusMessageIter *iter) +{ + int i; + + for (i = 0; i < 10; i++) { + const char *type = type2string(i); + gint count; + + if (type == NULL) + continue; + + if (powered == TRUE) + count = g_atomic_int_get(&enabled[i]); + else + count = g_atomic_int_get(®istered[i]); + + if (count > 0) + dbus_message_iter_append_basic(iter, + DBUS_TYPE_STRING, &type); + } +} + +void __connman_notifier_device_type_register(enum connman_device_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: + 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); + break; + } } -static volatile gint enabled[10]; +void __connman_notifier_device_type_unregister(enum connman_device_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: + 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); + break; + } +} void __connman_notifier_device_type_increase(enum connman_device_type type) { diff --git a/test/test-manager b/test/test-manager index 28a20dee..c27ebedf 100755 --- a/test/test-manager +++ b/test/test-manager @@ -58,10 +58,21 @@ def print_properties(key, value): val = str(path) list = list + val[val.rfind("/") + 1:] + " " print " Services = [ %s]" % (list) + if "Technologies" in properties.keys(): + list = "" + for val in properties["Technologies"]: + list = list + val + " " + print " Technologies = [ %s]" % (list) for key in properties.keys(): if key in ["Profiles", "Devices", "Connections", "Services"]: print_properties(key, properties[key]) + elif key in ["Technologies", "EnabledTechnologies"]: + print "%s" % (key) + list = "" + for val in properties[key]: + list = list + val + " " + print " [ %s]" % (list) elif key in ["OfflineMode"]: print "%s" % (key) if properties[key] == dbus.Boolean(1): |