Add support for device priority setting
authorMarcel Holtmann <marcel@holtmann.org>
Tue, 6 Jan 2009 02:04:54 +0000 (03:04 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 6 Jan 2009 02:04:54 +0000 (03:04 +0100)
doc/device-api.txt
src/device.c
test/list-connections
test/list-networks
test/monitor-connman
test/test-manager

index 6d8f348..b0cf440 100644 (file)
@@ -87,6 +87,11 @@ Properties   string Name [readonly]
                        For simple devices like Ethernet cards, setting
                        the "manual" policy might fail.
 
+               uint8 Priority [readwrite]
+
+                       The device priority. Higher values indicate the
+                       preference for this device.
+
                boolean Powered [readwrite]
 
                        Switch a device on or off. This will also modify
index 1d888e9..f07128f 100644 (file)
@@ -36,6 +36,7 @@ struct connman_device {
        connman_bool_t powered;
        connman_bool_t carrier;
        connman_bool_t scanning;
+       connman_uint8_t priority;
        char *name;
        char *node;
        char *interface;
@@ -277,6 +278,10 @@ static DBusMessage *get_properties(DBusConnection *conn,
                connman_dbus_dict_append_variant(&dict, "Policy",
                                                DBUS_TYPE_STRING, &str);
 
+       if (device->priority > 0)
+               connman_dbus_dict_append_variant(&dict, "Priority",
+                                       DBUS_TYPE_BYTE, &device->priority);
+
        connman_dbus_dict_append_variant(&dict, "Powered",
                                        DBUS_TYPE_BOOLEAN, &device->powered);
 
@@ -346,6 +351,12 @@ static DBusMessage *set_property(DBusConnection *conn,
                err = set_policy(conn, device, policy);
                if (err < 0)
                        return __connman_error_failed(msg);
+       } else if (g_str_equal(name, "Priority") == TRUE) {
+               connman_uint8_t priority;
+
+               dbus_message_iter_get_basic(&value, &priority);
+
+               device->priority = priority;
        }
 
        __connman_storage_save_device(device);
@@ -710,6 +721,29 @@ struct connman_device *connman_device_create(const char *node,
        device->mode   = CONNMAN_DEVICE_MODE_UNKNOWN;
        device->policy = CONNMAN_DEVICE_POLICY_AUTO;
 
+       switch (type) {
+       case CONNMAN_DEVICE_TYPE_UNKNOWN:
+       case CONNMAN_DEVICE_TYPE_VENDOR:
+               device->priority = 0;
+               break;
+       case CONNMAN_DEVICE_TYPE_ETHERNET:
+       case CONNMAN_DEVICE_TYPE_WIFI:
+               device->priority = 100;
+               break;
+       case CONNMAN_DEVICE_TYPE_WIMAX:
+               device->priority = 20;
+               break;
+       case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+               device->priority = 50;
+               break;
+       case CONNMAN_DEVICE_TYPE_HSO:
+       case CONNMAN_DEVICE_TYPE_NOZOMI:
+       case CONNMAN_DEVICE_TYPE_HUAWEI:
+       case CONNMAN_DEVICE_TYPE_NOVATEL:
+               device->priority = 60;
+               break;
+       }
+
        device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                g_free, unregister_network);
 
@@ -1295,6 +1329,7 @@ static int device_load(struct connman_device *device)
        gchar *pathname, *data = NULL;
        gsize length;
        char *str;
+       int val;
 
        DBG("device %p", device);
 
@@ -1326,6 +1361,11 @@ static int device_load(struct connman_device *device)
                g_free(str);
        }
 
+       val = g_key_file_get_integer(keyfile, "Configuration",
+                                                       "Priority", NULL);
+       if (val > 0)
+               device->priority = val;
+
        g_key_file_free(keyfile);
 
        return 0;
@@ -1363,6 +1403,10 @@ update:
        if (str != NULL)
                g_key_file_set_string(keyfile, "Configuration", "Policy", str);
 
+       if (device->priority > 0)
+               g_key_file_set_integer(keyfile, "Configuration",
+                                               "Priority", device->priority);
+
        data = g_key_file_to_data(keyfile, &length, NULL);
 
        g_file_set_contents(pathname, data, length, NULL);
index a656e96..655e50a 100755 (executable)
@@ -18,7 +18,7 @@ for path in properties["Connections"]:
        print "[ %s ]" % (path)
 
        for key in properties.keys():
-               if key == "Strength":
+               if key in ["Strength", "Priority"]:
                        val = int(properties[key])
                else:
                        val = str(properties[key])
index f4d5075..e8fb00a 100755 (executable)
@@ -43,10 +43,10 @@ for path in properties["Devices"]:
                print "    [ %s ]" % (path)
 
                for key in properties.keys():
-                       if (key == "WiFi.SSID"):
+                       if key == "WiFi.SSID":
                                ssid = convert_ssid(properties[key])
                                print "        %s = [ %s ]" % (key, ssid)
-                       elif (key == "Strength"):
+                       elif key in ["Strength", "Priority"]:
                                print "        %s = %d" % (key, properties[key])
                        else:
                                print "        %s = %s" % (key, properties[key])
index 97d3a6b..886373a 100755 (executable)
@@ -7,7 +7,7 @@ import dbus.mainloop.glib
 
 def property_changed(name, value, path, interface):
        iface = interface[interface.rfind(".") + 1:]
-       if (name == "Strength"):
+       if name in ["Strength", "Priority"]:
                val = int(value)
        else:
                val = str(value)
index ea976ca..e9f1231 100755 (executable)
@@ -37,7 +37,7 @@ def print_properties(key, value):
                                        val = "true"
                                else:
                                        val = "false"
-                       elif key == "Strength":
+                       elif key in ["Strength", "Priority"]:
                                val = int(properties[key])
                        else:
                                val = str(properties[key])