From 681c8374ac7caf872a863ad8923df72b47495b02 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 6 Jan 2009 03:04:54 +0100 Subject: [PATCH] Add support for device priority setting --- doc/device-api.txt | 5 +++++ src/device.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/list-connections | 2 +- test/list-networks | 4 ++-- test/monitor-connman | 2 +- test/test-manager | 2 +- 6 files changed, 54 insertions(+), 5 deletions(-) diff --git a/doc/device-api.txt b/doc/device-api.txt index 6d8f348..b0cf440 100644 --- a/doc/device-api.txt +++ b/doc/device-api.txt @@ -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 diff --git a/src/device.c b/src/device.c index 1d888e9..f07128f 100644 --- a/src/device.c +++ b/src/device.c @@ -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); diff --git a/test/list-connections b/test/list-connections index a656e96..655e50a 100755 --- a/test/list-connections +++ b/test/list-connections @@ -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]) diff --git a/test/list-networks b/test/list-networks index f4d5075..e8fb00a 100755 --- a/test/list-networks +++ b/test/list-networks @@ -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]) diff --git a/test/monitor-connman b/test/monitor-connman index 97d3a6b..886373a 100755 --- a/test/monitor-connman +++ b/test/monitor-connman @@ -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) diff --git a/test/test-manager b/test/test-manager index ea976ca..e9f1231 100755 --- a/test/test-manager +++ b/test/test-manager @@ -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]) -- 1.7.9.5