From: Pekka Pessi <[email protected]>

The Modem Online property is tied with the cellular device Powered property.
---
 plugins/ofono.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index 1a4b8e6..43d2410 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -65,6 +65,8 @@ struct modem_data {
        char *path;
        struct connman_device *device;
        gboolean available;
+       dbus_bool_t online;
+       gboolean online_is_valid;
 };
 
 static int modem_probe(struct connman_device *device)
@@ -159,13 +161,61 @@ static int set_property(const char *path,
        return -EINPROGRESS;
 }
 
-static int gprs_change_powered(const char *path, dbus_bool_t powered)
+static void update_online(struct modem_data *modem, connman_bool_t online)
 {
-       DBG("path %s powered %d", path, powered);
+       DBG("modem %p, path %s, online %d", modem, modem->path, online);
 
-       return set_property(path, OFONO_GPRS_INTERFACE, "Powered",
-                               DBUS_TYPE_BOOLEAN, &powered,
-                               NULL, NULL, NULL);
+       modem->online = online;
+       modem->online_is_valid = TRUE;
+
+       if (modem->device)
+               connman_device_set_powered(modem->device, online);
+}
+
+static void set_online_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply;
+       DBusError error;
+       struct modem_data *modem;
+
+       DBG("");
+
+       dbus_error_init(&error);
+
+       reply = dbus_pending_call_steal_reply(call);
+
+       if (dbus_set_error_from_message(&error, reply)) {
+               connman_error("%s(\"%s\"): %s: %s",
+                               "SetProperty", "Online",
+                               error.name, error.message);
+               dbus_error_free(&error);
+               modem = g_hash_table_lookup(modem_hash, user_data);
+               if (modem && modem->device)
+                       connman_device_set_powered(modem->device,
+                                                       modem->online);
+       }
+
+       dbus_message_unref(reply);
+
+       dbus_pending_call_unref(call);
+}
+
+static int modem_change_online(const char *path, dbus_bool_t online)
+{
+       struct modem_data *modem = g_hash_table_lookup(modem_hash, path);
+
+       DBG("path %s, modem %p", path, modem);
+
+       if (!modem)
+               return -ENODEV;
+
+       if (modem->online == online && modem->online_is_valid)
+               return 0;
+
+       return set_property(path, OFONO_MODEM_INTERFACE, "Online",
+                                       DBUS_TYPE_BOOLEAN, &online,
+                                       set_online_reply,
+                                       g_strdup(path), g_free);
 }
 
 static int modem_enable(struct connman_device *device)
@@ -174,7 +224,7 @@ static int modem_enable(struct connman_device *device)
 
        DBG("device %p, path, %s", device, path);
 
-       return gprs_change_powered(path, TRUE);
+       return modem_change_online(path, TRUE);
 }
 
 static int modem_disable(struct connman_device *device)
@@ -183,7 +233,7 @@ static int modem_disable(struct connman_device *device)
 
        DBG("device %p, path %s", device, path);
 
-       return gprs_change_powered(path, FALSE);
+       return modem_change_online(path, FALSE);
 }
 
 static struct connman_device_driver modem_driver = {
@@ -839,12 +889,6 @@ static void check_networks_reply(DBusPendingCall *call, 
void *user_data)
                        contexts = value;
                        add_default_context(&contexts, path,
                                        CONTEXT_NAME, CONTEXT_TYPE);
-               } else if (g_str_equal(key, "Powered") == TRUE) {
-                       dbus_bool_t powered;
-
-                       dbus_message_iter_get_basic(&value, &powered);
-
-                       connman_device_set_powered(device, powered);
                }
 
                dbus_message_iter_next(&dict);
@@ -1112,6 +1156,8 @@ static void modem_properties_reply(DBusPendingCall *call, 
void *user_data)
        DBusMessageIter array, dict;
        const char *path = user_data;
        dbus_bool_t powered = FALSE;
+       /* Online default is TRUE for backward compatibility reasons */
+       dbus_bool_t online = TRUE;
        gboolean has_sim = FALSE;
        struct modem_data *new_modem;
 
@@ -1149,6 +1195,8 @@ static void modem_properties_reply(DBusPendingCall *call, 
void *user_data)
 
                if (g_str_equal(key, "Powered") == TRUE)
                        dbus_message_iter_get_basic(&value, &powered);
+               else if (g_str_equal(key, "Online") == TRUE)
+                       dbus_message_iter_get_basic(&value, &online);
                else if (g_str_equal(key, "Interfaces") == TRUE)
                        has_sim = modem_has_sim(&value);
 
@@ -1162,6 +1210,8 @@ static void modem_properties_reply(DBusPendingCall *call, 
void *user_data)
        if (!powered)
                modem_change_powered(path, TRUE);
 
+       update_online(new_modem, online);
+
        if (has_sim)
                get_imsi(path);
 
@@ -1389,6 +1439,12 @@ static gboolean modem_changed(DBusConnection 
*connection, DBusMessage *message,
                dbus_message_iter_get_basic(&value, &powered);
                if (powered == FALSE)
                        modem_remove_device(modem);
+       } else if (g_str_equal(key, "Online") == TRUE) {
+               dbus_bool_t online;
+
+               dbus_message_iter_get_basic(&value, &online);
+
+               update_online(modem, online);
        } else if (g_str_equal(key, "Interfaces") == TRUE) {
                if (modem_has_sim(&value)) {
                        if (modem->device == NULL)
-- 
1.7.0.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to