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,
guint32 *ip_method)
{
DBusGProxy *proxy;
GValue value = { 0 };
GError *err = NULL;
GHashTable *props = NULL;
GHashTableIter iter;
const char *prop;
GValue *value;
proxy = dbus_g_proxy_new_for_name (connection,
MM_DBUS_SERVICE,
path,
"org.freedesktop.DBus.Properties");
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_STRING, "Type",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
*type = g_value_get_uint (&value);
g_value_unset (&value);
} else {
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);
MM_DBUS_SERVICE,
path,
"org.freedesktop.DBus.Properties");
if (!dbus_g_proxy_call_with_timeout (proxy, "GetAll", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_INVALID,
DBUS_TYPE_G_MAP_OF_VARIANT, &props,
G_TYPE_INVALID)) {
nm_log_warn (LOGD_MB, "could not get modem properties: %s %s",
err ? dbus_g_error_get_name (err) : "(none)",
err ? err->message : "(unknown)");
g_clear_error (&err);
goto out;
}
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
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);
if (!props) {
nm_log_warn (LOGD_MB, "no modem properties found");
goto out;
}
if (dbus_g_proxy_call_with_timeout (proxy, "Get", 15000, &err,
G_TYPE_STRING, MM_DBUS_INTERFACE_MODEM,
G_TYPE_STRING, "Driver",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
*driver = g_value_dup_string (&value);
g_value_unset (&value);
} else {
nm_log_warn (LOGD_MB, "could not get modem driver: %s", err->message);
goto out;
g_hash_table_iter_init (&iter, props);
while (g_hash_table_iter_next (&iter, (gpointer) &prop, (gpointer) &value)) {
if (g_strcmp0 (prop, "Type") == 0)
*type = g_value_get_uint (value);
else if (g_strcmp0 (prop, "MasterDevice") == 0)
*device = g_value_dup_string (value);
else if (g_strcmp0 (prop, "IpMethod") == 0)
*ip_method = g_value_get_uint (value);
else if (g_strcmp0 (prop, "Device") == 0)
*data_device = g_value_dup_string (value);
else if (g_strcmp0 (prop, "Driver") == 0)
*driver = g_value_dup_string (value);
}
g_hash_table_unref (props);
out:
if (err)
g_error_free (err);
g_object_unref (proxy);
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