From 15a9b7abf662910638662ffe11cf880f91baee12 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 7 Aug 2009 10:23:13 -0700 Subject: [PATCH 1/1] Add support for changing the AutoConnect value of services --- doc/service-api.txt | 6 +++++- src/service.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-connman | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/doc/service-api.txt b/doc/service-api.txt index 0cd4a25..0678c82 100644 --- a/doc/service-api.txt +++ b/doc/service-api.txt @@ -203,11 +203,15 @@ Properties string State [readonly] it back to false the Remove() method needs to be used. - boolean AutoConnect [readonly] + boolean AutoConnect [readwrite] If set to true, this service will auto-connect when not other connection is available. + For favorite services it is possible to change + this value to prevent or permit automatic + connection attempts. + string IPv4.Method [readwrite] The IPv4 configuration method. Possible values here diff --git a/src/service.c b/src/service.c index 639ade8..dfb2149 100644 --- a/src/service.c +++ b/src/service.c @@ -342,6 +342,33 @@ static void passphrase_changed(struct connman_service *service) g_dbus_send_message(connection, signal); } +static void autoconnect_changed(struct connman_service *service) +{ + DBusMessage *signal; + DBusMessageIter entry, value; + const char *key = "AutoConnect"; + + if (service->path == NULL) + return; + + signal = dbus_message_new_signal(service->path, + CONNMAN_SERVICE_INTERFACE, "PropertyChanged"); + if (signal == NULL) + return; + + dbus_message_iter_init_append(signal, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, + DBUS_TYPE_BOOLEAN_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, + &service->autoconnect); + dbus_message_iter_close_container(&entry, &value); + + g_dbus_send_message(connection, signal); +} + static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -492,6 +519,25 @@ static DBusMessage *set_property(DBusConnection *conn, "WiFi.Passphrase", service->passphrase); __connman_storage_save_service(service); + } else if (g_str_has_prefix(name, "AutoConnect") == TRUE) { + connman_bool_t autoconnect; + + if (type != DBUS_TYPE_BOOLEAN) + return __connman_error_invalid_arguments(msg); + + if (service->favorite == FALSE) + return __connman_error_invalid_service(msg); + + dbus_message_iter_get_basic(&value, &autoconnect); + + if (service->autoconnect == autoconnect) + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); + + service->autoconnect = autoconnect; + + autoconnect_changed(service); + + __connman_storage_save_service(service); } else if (g_str_has_prefix(name, "IPv4.") == TRUE) { int err; @@ -2015,6 +2061,9 @@ static int service_load(struct connman_service *service) service->favorite = g_key_file_get_boolean(keyfile, service->identifier, "Favorite", NULL); + service->autoconnect = g_key_file_get_boolean(keyfile, + service->identifier, "AutoConnect", NULL); + str = g_key_file_get_string(keyfile, service->identifier, "Failure", NULL); if (str != NULL) { @@ -2124,6 +2173,10 @@ update: g_key_file_set_boolean(keyfile, service->identifier, "Favorite", service->favorite); + if (service->favorite == TRUE) + g_key_file_set_boolean(keyfile, service->identifier, + "AutoConnect", service->autoconnect); + if (service->state == CONNMAN_SERVICE_STATE_FAILURE) { const char *failure = error2string(service->error); if (failure != NULL) diff --git a/test/test-connman b/test/test-connman index dff1a25..f82150f 100755 --- a/test/test-connman +++ b/test/test-connman @@ -14,6 +14,7 @@ if len(sys.argv) < 2: print " state" print " services" print " passphrase [passphrase]" + print " autoconnect [autoconnect]" print " connect " print " disconnect " print " remove " @@ -187,6 +188,37 @@ elif sys.argv[1] in ["passphrase", "pass"]: print "Passphrase for %s is %s" % (name, passphrase) +elif sys.argv[1] in ["autoconnect", "autoconn"]: + if (len(sys.argv) < 3): + print "Need at least service parameter" + sys.exit(1) + + path = "/profile/default/" + sys.argv[2] + + service = dbus.Interface(bus.get_object("org.moblin.connman", path), + "org.moblin.connman.Service") + + if (len(sys.argv) > 3): + autoconnect = dbus.Boolean(sys.argv[3]) + + service.SetProperty("AutoConnect", autoconnect); + + print "Auto connect %s for %s" % (autoconnect, sys.argv[2]) + else: + properties = service.GetProperties() + + if "Name" in properties.keys(): + name = properties["Name"] + else: + name = "{" + properties["Type"] + "}" + + if "AutoConnect" in properties.keys(): + autoconnect = properties["AutoConnect"] + else: + autoconnect = dbus.Boolean(0) + + print "Auto connect %s for %s" % (autoconnect, name) + elif sys.argv[1] in ["connect", "conn"]: if (len(sys.argv) < 3): print "Need at least service parameter" -- 2.7.4