From: Pekka Pessi <[email protected]>
Create modem only after Modem.GetProperties succeeds, thus avoiding races
with Modem.PropertyChanged signal.
---
plugins/ofono.c | 59 +++++++++++++++++++++++++++++-------------------------
1 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/plugins/ofono.c b/plugins/ofono.c
index 82c7857..faf82b9 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -1031,15 +1031,11 @@ static struct modem_data *add_modem(const char *path)
{
struct modem_data *modem;
- if (path == NULL)
- return NULL;
+ DBG("path %s", path);
modem = g_hash_table_lookup(modem_hash, path);
- if (modem != NULL) {
- modem->available = TRUE;
-
- return modem;
- }
+ if (modem != NULL)
+ return NULL;
modem = g_try_new0(struct modem_data, 1);
if (modem == NULL)
@@ -1047,7 +1043,6 @@ static struct modem_data *add_modem(const char *path)
modem->path = g_strdup(path);
modem->device = NULL;
- modem->available = TRUE;
g_hash_table_insert(modem_hash, g_strdup(path), modem);
@@ -1080,6 +1075,9 @@ static void modem_properties_reply(DBusPendingCall *call,
void *user_data)
DBusError error;
DBusMessageIter array, dict;
const char *path = user_data;
+ dbus_bool_t powered = FALSE;
+ gboolean has_gprs = FALSE;
+ struct modem_data *new_modem;
DBG("path %s", path);
@@ -1106,7 +1104,6 @@ static void modem_properties_reply(DBusPendingCall *call,
void *user_data)
while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;
const char *key;
- dbus_bool_t powered;
dbus_message_iter_recurse(&dict, &entry);
dbus_message_iter_get_basic(&entry, &key);
@@ -1114,38 +1111,41 @@ static void modem_properties_reply(DBusPendingCall
*call, void *user_data)
dbus_message_iter_next(&entry);
dbus_message_iter_recurse(&entry, &value);
- if (g_str_equal(key, "Powered") == TRUE) {
+ if (g_str_equal(key, "Powered") == TRUE)
dbus_message_iter_get_basic(&value, &powered);
-
- if (powered == FALSE) {
- modem_change_powered(path, TRUE);
- break;
- }
- } else if (g_str_equal(key, "Interfaces") == TRUE) {
- if (modem_has_gprs(&value) == TRUE)
- get_imsi(path);
- }
+ else if (g_str_equal(key, "Interfaces") == TRUE)
+ has_gprs = modem_has_gprs(&value);
dbus_message_iter_next(&dict);
}
+ new_modem = add_modem(path);
+ if (new_modem == NULL)
+ goto done;
+
+ if (!powered)
+ modem_change_powered(path, TRUE);
+
+ if (has_gprs)
+ get_imsi(path);
+
done:
dbus_message_unref(reply);
dbus_pending_call_unref(call);
}
-static void get_modem_properties(struct modem_data *modem)
+static void get_modem_properties(const char *path)
{
DBusMessage *message;
DBusPendingCall *call;
- DBG("path %s", modem->path);
+ DBG("path %s", path);
- if (modem->path == NULL)
+ if (path == NULL)
return;
- message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
+ message = dbus_message_new_method_call(OFONO_SERVICE, path,
OFONO_MODEM_INTERFACE, GET_PROPERTIES);
if (message == NULL)
return;
@@ -1164,7 +1164,7 @@ static void get_modem_properties(struct modem_data *modem)
}
dbus_pending_call_set_notify(call, modem_properties_reply,
- (void *)g_strdup(modem->path), g_free);
+ (void *)g_strdup(path), g_free);
done:
dbus_message_unref(message);
@@ -1199,6 +1199,8 @@ static void update_modems(DBusMessageIter *array)
{
DBusMessageIter entry;
+ DBG("");
+
dbus_message_iter_recurse(array, &entry);
modems_set_unavailable();
@@ -1210,9 +1212,12 @@ static void update_modems(DBusMessageIter *array)
dbus_message_iter_get_basic(&entry, &path);
- modem = add_modem(path);
- if (modem != NULL)
- get_modem_properties(modem);
+ modem = g_hash_table_lookup(modem_hash, path);
+
+ if (modem)
+ modem->available = TRUE;
+ else
+ get_modem_properties(path);
dbus_message_iter_next(&entry);
}
--
1.7.0.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman