From: Pekka Pessi <[email protected]>

"Online" property is tied with 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 7cb1a00..91c2f61 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -64,7 +64,10 @@ static GHashTable *modem_hash = NULL;
 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)
@@ -156,13 +159,61 @@ static int set_ofono_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_ofono_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;
+       char const *name = user_data;
+       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("SetProperty(\"%s\"): %s: %s", name,
+                               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_ofono_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)
@@ -171,7 +222,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)
@@ -180,7 +231,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 = {
@@ -834,12 +885,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);
@@ -1111,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;
        dbus_bool_t has_sim = FALSE;
        struct modem_data *new_modem;
 
@@ -1148,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) {
                        if (modem_has_interface(&value, OFONO_SIM_INTERFACE))
                                has_sim = TRUE;
@@ -1160,6 +1209,7 @@ static void modem_properties_reply(DBusPendingCall *call, 
void *user_data)
        if (new_modem) {
                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,
 
                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_interface(&value, OFONO_SIM_INTERFACE)) {
                        if (modem->device == NULL)
-- 
1.7.0.4

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

Reply via email to