diff options
Diffstat (limited to 'binding')
-rw-r--r-- | binding/gdbus/ofono_manager.c | 86 |
1 files changed, 42 insertions, 44 deletions
diff --git a/binding/gdbus/ofono_manager.c b/binding/gdbus/ofono_manager.c index 98d8c5b..8db5df3 100644 --- a/binding/gdbus/ofono_manager.c +++ b/binding/gdbus/ofono_manager.c @@ -48,56 +48,54 @@ int ofono_manager_set_default_modem(const char *address) const gchar *name = NULL, *type = NULL, *serial = NULL; gboolean powered = FALSE, online = FALSE; GVariantIter *iter, *iter2 = NULL; - int ret = 0; /* Fetch all visible modems */ org_ofono_manager_call_get_modems_sync(manager, &out_arg, NULL, &error); - if (error == NULL) { - g_variant_get(out_arg, "a(oa{sv})", &iter); - /* Iterate over each modem */ - while ((next = g_variant_iter_next_value(iter))) { - g_variant_get(next, "(oa{sv})", &path, &iter2); - while (g_variant_iter_loop(iter2, "{sv}", &key, &value)) { - if (!strcmp(key, "Name")) - name = g_variant_get_string(value, NULL); - else if (!strcmp(key, "Online")) - online = g_variant_get_boolean(value); - else if (!strcmp(key, "Powered")) - powered = g_variant_get_boolean(value); - else if (!strcmp(key, "Serial")) - serial = g_variant_get_string(value, NULL); - else if (!strcmp(key, "Type")) - type = g_variant_get_string(value, NULL); - } - - /* If not a HFP modem then continue */ - if (g_strcmp0(type, "hfp")) - continue; - - /* If address is NULL then use the first modem as default, - * and if not then continue if doesn't match address. - */ - if (address && g_strcmp0(address, serial)) - continue; - - /* If powered, and online then set as default */ - if (powered && online) { - default_modem.address = serial; - default_modem.path = path; - default_modem.name = name; - default_modem.type = type; - default_modem.powered = powered; - default_modem.online = online; - default_modem.valid = TRUE; - AFB_NOTICE("New modem: %s (%s)", name, serial); - break; - } + if (error != NULL) + return -1; + + g_variant_get(out_arg, "a(oa{sv})", &iter); + /* Iterate over each modem */ + while ((next = g_variant_iter_next_value(iter))) { + g_variant_get(next, "(oa{sv})", &path, &iter2); + while (g_variant_iter_loop(iter2, "{sv}", &key, &value)) { + if (!strcmp(key, "Name")) + name = g_variant_get_string(value, NULL); + else if (!strcmp(key, "Online")) + online = g_variant_get_boolean(value); + else if (!strcmp(key, "Powered")) + powered = g_variant_get_boolean(value); + else if (!strcmp(key, "Serial")) + serial = g_variant_get_string(value, NULL); + else if (!strcmp(key, "Type")) + type = g_variant_get_string(value, NULL); + } + + /* If not a HFP modem then continue */ + if (g_strcmp0(type, "hfp")) + continue; + + /* If address is NULL then use the first modem as default, + * and if not then continue if doesn't match address. + */ + if (address && g_strcmp0(address, serial)) + continue; + + /* If powered, and online then set as default */ + if (powered && online) { + default_modem.address = serial; + default_modem.path = path; + default_modem.name = name; + default_modem.type = type; + default_modem.powered = powered; + default_modem.online = online; + default_modem.valid = TRUE; + AFB_NOTICE("New modem: %s (%s)", name, serial); + break; } - } else { - ret = -1; } - return ret; + return 0; } int ofono_manager_init() |