Add support for Technologies and EnabledTechnologies properties
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 16 Jul 2009 13:54:16 +0000 (15:54 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 16 Jul 2009 13:54:16 +0000 (15:54 +0200)
doc/manager-api.txt
src/connman.h
src/device.c
src/manager.c
src/notifier.c
test/test-manager

index f6f2f9f2ee63802895f52c5422986755ba86ba19..08c59b8e3f3c15a372a7cfbe90192ca0e05266d0 100644 (file)
@@ -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
index a5614179580cdf06d5c7c8de6598eadbf5b56faf..d717664a48d830c26d47033a0dc82b964f1df763 100644 (file)
@@ -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);
index 6dadaa3a2068c6c2944403bec989b9b89db081b4..f50a98a26edd5f8099134eedb597fb294c7395fe 100644 (file)
@@ -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);
 }
 
index 85025b3652c41e9ba0969b5a60c8e8587745558f..69235b3c1cbddd675e1f0ec6906c68645f81325d 100644 (file)
@@ -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;
index 023b1eb4ba609023db47737337dbce3b6d3107ba..df6fd33ff6f9869fd2a29d05306602c220e3f426 100644 (file)
@@ -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(&registered[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(&registered[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(&registered[type]) == TRUE)
+                       device_registered(type, FALSE);
+               break;
+       }
+}
 
 void __connman_notifier_device_type_increase(enum connman_device_type type)
 {
index 28a20dee87bf3d98f3b5904ebdb7c8c647416dfd..c27ebedf6d6304e8ac3a42b7ccf1b0356e9f754a 100755 (executable)
@@ -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):