ofono: Connect when context activation is requested
authorHenri Bragge <henri.bragge@ixonos.com>
Wed, 2 Mar 2011 15:43:35 +0000 (16:43 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 2 Mar 2011 15:43:35 +0000 (16:43 +0100)
ConnMan should connect the corresponding network/service after a
successful response to context activation request. If the context was
already active, connecting has to happen this way instead of waiting for
active property going up (it already is up).

In case the context was inactive before activation, it will not have
network index yet and connecting will happen later when activation is
ready.

This patch removes the reply handler for context inactivation because
it would have no other use than logging.

plugins/ofono.c

index 02c6d9eba05b9d53d61767e6f0fe49e06c2ce00f..51997c8518ee781889a6e0dfc89d82a5714aaeec 100644 (file)
@@ -408,6 +408,9 @@ static gboolean pending_network_is_available(struct connman_network *network)
        return TRUE;
 }
 
+static void set_connected(struct network_info *info,
+                               connman_bool_t connected);
+
 static void set_active_reply(DBusPendingCall *call, void *user_data)
 {
        char const *path = user_data;
@@ -435,7 +438,8 @@ static void set_active_reply(DBusPendingCall *call, void *user_data)
                                CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
 
                dbus_error_free(&error);
-       }
+       } else if (connman_network_get_index(info->network) >= 0)
+               set_connected(info, TRUE);
 
 done:
        dbus_message_unref(reply);
@@ -443,23 +447,34 @@ done:
        dbus_pending_call_unref(call);
 }
 
-static int set_network_active(struct connman_network *network,
-                                               dbus_bool_t active)
+static int set_network_active(struct connman_network *network)
 {
-       int error;
-
+       dbus_bool_t value = TRUE;
        const char *path = connman_network_get_string(network, "Path");
 
-       DBG("network %p, path %s, active %d", network, path, active);
+       DBG("network %p, path %s", network, path);
 
-       error = set_property(path, OFONO_CONTEXT_INTERFACE,
-                               "Active", DBUS_TYPE_BOOLEAN, &active,
+       return set_property(path, OFONO_CONTEXT_INTERFACE,
+                               "Active", DBUS_TYPE_BOOLEAN, &value,
                                set_active_reply, g_strdup(path), g_free);
+}
+
+static int set_network_inactive(struct connman_network *network)
+{
+       int err;
+       dbus_bool_t value = FALSE;
+       const char *path = connman_network_get_string(network, "Path");
+
+       DBG("network %p, path %s", network, path);
 
-       if (active == FALSE && error == -EINPROGRESS)
-               error = 0;
+       err = set_property(path, OFONO_CONTEXT_INTERFACE,
+                               "Active", DBUS_TYPE_BOOLEAN, &value,
+                               NULL, NULL, NULL);
 
-       return error;
+       if (err == -EINPROGRESS)
+               err = 0;
+
+       return err;
 }
 
 static int network_connect(struct connman_network *network)
@@ -469,9 +484,6 @@ static int network_connect(struct connman_network *network)
 
        DBG("network %p", network);
 
-       if (connman_network_get_index(network) >= 0)
-               return -EISCONN;
-
        device = connman_network_get_device(network);
        if (device == NULL)
                return -ENODEV;
@@ -489,7 +501,7 @@ static int network_connect(struct connman_network *network)
        if (modem->roaming_allowed == FALSE && modem->roaming == TRUE)
                return -ENOLINK;
 
-       return set_network_active(network, TRUE);
+       return set_network_active(network);
 }
 
 static int network_disconnect(struct connman_network *network)
@@ -501,7 +513,7 @@ static int network_disconnect(struct connman_network *network)
 
        connman_network_set_associating(network, FALSE);
 
-       return set_network_active(network, FALSE);
+       return set_network_inactive(network);
 }
 
 static void network_remove(struct connman_network *network)
@@ -525,9 +537,6 @@ static struct connman_network_driver network_driver = {
 static void update_settings(DBusMessageIter *array,
                                struct network_info *info);
 
-static void set_connected(struct network_info *info,
-                               connman_bool_t connected);
-
 static int add_network(struct connman_device *device,
                        const char *path, DBusMessageIter *dict)
 {