Add Available and Remember properties for networks
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 10 Dec 2008 23:29:28 +0000 (00:29 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 10 Dec 2008 23:29:28 +0000 (00:29 +0100)
include/element.h
plugins/wifi.c
src/element.c
src/storage.c

index 85b9b06..aaf389d 100644 (file)
@@ -92,6 +92,8 @@ struct connman_element {
        enum connman_element_state state;
        enum connman_element_policy policy;
        gboolean enabled;
+       gboolean available;
+       gboolean remember;
        guint16 priority;
 
        struct connman_element *parent;
index 39f288d..b0ee4ae 100644 (file)
@@ -251,6 +251,8 @@ static void scan_result(struct connman_element *parent,
                connman_element_register(element, parent);
        }
 
+       element->available = TRUE;
+
        g_free(temp);
 }
 
index 6ad75b1..a8eee21 100644 (file)
@@ -529,6 +529,8 @@ static DBusMessage *device_create_network(DBusConnection *conn,
        network->type = CONNMAN_ELEMENT_TYPE_NETWORK;
        network->index = element->index;
 
+       network->remember = TRUE;
+
        connman_element_add_static_property(network, "Name",
                                                DBUS_TYPE_STRING, &ssid);
 
@@ -550,7 +552,7 @@ static DBusMessage *device_remove_network(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
-static DBusMessage *get_network_properties(DBusConnection *conn,
+static DBusMessage *network_get_properties(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
        struct connman_element *element = data;
@@ -576,9 +578,15 @@ static DBusMessage *get_network_properties(DBusConnection *conn,
                connman_dbus_dict_append_variant(&dict, "Policy",
                                                DBUS_TYPE_STRING, &str);
 
+       connman_dbus_dict_append_variant(&dict, "Available",
+                                       DBUS_TYPE_BOOLEAN, &element->available);
+
        connman_dbus_dict_append_variant(&dict, "Connected",
                                        DBUS_TYPE_BOOLEAN, &element->enabled);
 
+       connman_dbus_dict_append_variant(&dict, "Remember",
+                                       DBUS_TYPE_BOOLEAN, &element->remember);
+
        add_common_properties(element, &dict);
 
        dbus_message_iter_close_container(&array, &dict);
@@ -586,7 +594,7 @@ static DBusMessage *get_network_properties(DBusConnection *conn,
        return reply;
 }
 
-static DBusMessage *set_network_property(DBusConnection *conn,
+static DBusMessage *network_set_property(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
        struct connman_element *element = data;
@@ -606,7 +614,9 @@ static DBusMessage *set_network_property(DBusConnection *conn,
        if (__connman_security_check_privileges(msg) < 0)
                return __connman_error_permission_denied(msg);
 
-       if (g_str_equal(name, "WiFi.Passphrase") == TRUE) {
+       if (g_str_equal(name, "Remember") == TRUE) {
+               dbus_message_iter_get_basic(&value, &element->remember);
+       } else if (g_str_equal(name, "WiFi.Passphrase") == TRUE) {
                const char *str;
 
                dbus_message_iter_get_basic(&value, &str);
@@ -788,8 +798,8 @@ static GDBusMethodTable device_methods[] = {
 };
 
 static GDBusMethodTable network_methods[] = {
-       { "GetProperties", "",   "a{sv}", get_network_properties },
-       { "SetProperty",   "sv", "",      set_network_property   },
+       { "GetProperties", "",   "a{sv}", network_get_properties },
+       { "SetProperty",   "sv", "",      network_set_property   },
        { "Connect",       "",   "",      do_enable              },
        { "Disconnect",    "",   "",      do_disable             },
        { },
index bbd9417..e0e3dc5 100644 (file)
@@ -48,6 +48,10 @@ static int do_load(GKeyFile *keyfile, struct connman_element *element)
        if (value != NULL)
                element->policy = __connman_element_string2policy(value);
 
+       if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK)
+               element->remember = g_key_file_get_boolean(keyfile,
+                                       element->path, "Remember", NULL);
+
        value = g_key_file_get_string(keyfile, element->path,
                                                "WiFi.Security", NULL);
        if (value != NULL)
@@ -116,6 +120,10 @@ static void do_update(GKeyFile *keyfile, struct connman_element *element)
        //g_key_file_set_boolean(keyfile, element->path, "Enabled",
        //                                              element->enabled);
 
+       if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK)
+               g_key_file_set_boolean(keyfile, element->path, "Remember",
+                                                       element->remember);
+
        __connman_element_lock(element);
 
        for (list = element->properties; list; list = list->next) {
@@ -172,7 +180,7 @@ int __connman_element_store(struct connman_element *element)
 
        if (length > 0) {
                if (g_key_file_load_from_data(keyfile, data, length,
-                               G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
+                                                       0, NULL) == FALSE)
                        goto done;
        }