Commit 002155fb authored by Dan Williams's avatar Dan Williams
Browse files

modem: get modem properties using GetAll

More efficient and less error-prone; get all the properties
in one call instead of individually.
parent b574524d
...@@ -79,83 +79,50 @@ get_modem_properties (DBusGConnection *connection, ...@@ -79,83 +79,50 @@ get_modem_properties (DBusGConnection *connection,
guint32 *ip_method) guint32 *ip_method)
{ {
DBusGProxy *proxy; DBusGProxy *proxy;
GValue value = { 0 };
GError *err = NULL; GError *err = NULL;
GHashTable *props = NULL;
GHashTableIter iter;
const char *prop;
GValue *value;
proxy = dbus_g_proxy_new_for_name (connection, proxy = dbus_g_proxy_new_for_name (connection,
MM_DBUS_SERVICE, MM_DBUS_SERVICE,
path, path,
"org.freedesktop.DBus.Properties"); "org.freedesktop.DBus.Properties");
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err, if (!dbus_g_proxy_call_with_timeout (proxy, "GetAll", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM, G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_STRING, "Type", G_TYPE_INVALID,
G_TYPE_INVALID, DBUS_TYPE_G_MAP_OF_VARIANT, &props,
G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
G_TYPE_INVALID)) { nm_log_warn (LOGD_MB, "could not get modem properties: %s %s",
*type = g_value_get_uint (&value); err ? dbus_g_error_get_name (err) : "(none)",
g_value_unset (&value); err ? err->message : "(unknown)");
} else { g_clear_error (&err);
nm_log_warn (LOGD_MB, "could not get device type: %s", err->message);
goto out;
}
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_STRING, "MasterDevice",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
*device = g_value_dup_string (&value);
g_value_unset (&value);
} else {
nm_log_warn (LOGD_MB, "could not get device: %s", err->message);
goto out;
}
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_STRING, "IpMethod",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
*ip_method = g_value_get_uint (&value);
g_value_unset (&value);
} else {
nm_log_warn (LOGD_MB, "could not get IP method: %s", err->message);
goto out; goto out;
} }
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err, if (!props) {
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM, nm_log_warn (LOGD_MB, "no modem properties found");
G_TYPE_STRING, "Device",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
*data_device = g_value_dup_string (&value);
g_value_unset (&value);
} else {
nm_log_warn (LOGD_MB, "could not get modem data device: %s", err->message);
goto out; goto out;
} }
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err, g_hash_table_iter_init (&iter, props);
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM, while (g_hash_table_iter_next (&iter, (gpointer) &prop, (gpointer) &value)) {
G_TYPE_STRING, "Driver", if (g_strcmp0 (prop, "Type") == 0)
G_TYPE_INVALID, *type = g_value_get_uint (value);
G_TYPE_VALUE, &value, else if (g_strcmp0 (prop, "MasterDevice") == 0)
G_TYPE_INVALID)) { *device = g_value_dup_string (value);
*driver = g_value_dup_string (&value); else if (g_strcmp0 (prop, "IpMethod") == 0)
g_value_unset (&value); *ip_method = g_value_get_uint (value);
} else { else if (g_strcmp0 (prop, "Device") == 0)
nm_log_warn (LOGD_MB, "could not get modem driver: %s", err->message); *data_device = g_value_dup_string (value);
goto out; else if (g_strcmp0 (prop, "Driver") == 0)
*driver = g_value_dup_string (value);
} }
g_hash_table_unref (props);
out: out:
if (err)
g_error_free (err);
g_object_unref (proxy); g_object_unref (proxy);
return *data_device && *driver; return *data_device && *driver;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment