summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2011-11-25 11:30:50 +0100
committerJiří Klimeš <jklimes@redhat.com>2011-11-25 11:30:50 +0100
commit50a131da8f6e5426e2bb742313c67359903ae28e (patch)
treebbd5a2116ade529287a18f8780d2162db9e95ff0
parent19cc03b6a31ab78c00628902667c297ca006f021 (diff)
downloadNetworkManager-50a131da8f6e5426e2bb742313c67359903ae28e.tar.gz
libnm-glib: get devices and their properties in constructor (NMClient, NMDevice)
NMClient and NMDevice used a 'lazy' approach for getting stuff from D-Bus, i.e. requesting data from NM when they are asked for. However, for some cases, like removing devices it is not optimal. libnm-glib will never see a device that was removed, but not added during NMClient's lifetime. So let's get devices list in NMClient's constructor and device properties in NMDevice constructor to have the data from the beginning.
-rw-r--r--libnm-glib/nm-client.c8
-rw-r--r--libnm-glib/nm-device.c63
2 files changed, 70 insertions, 1 deletions
diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c
index 1de7b863c4..cffce38246 100644
--- a/libnm-glib/nm-client.c
+++ b/libnm-glib/nm-client.c
@@ -495,6 +495,14 @@ constructor (GType type,
g_signal_connect (G_OBJECT (object), "notify::" NM_CLIENT_WIRELESS_ENABLED,
G_CALLBACK (wireless_enabled_cb), NULL);
+ /* Get initial devices from NM. It is important to do it early. Else,
+ * a 'lazy' call won't find removed device.
+ * Solves this case: DeviceRemoved signal is received, we get devices
+ * from NM, but the removed object path is not there any more, and
+ * NMClient doesn't have the device either.
+ */
+ nm_client_get_devices (NM_CLIENT (object));
+
return G_OBJECT (object);
}
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c
index bb4b820912..b5793ab8db 100644
--- a/libnm-glib/nm-device.c
+++ b/libnm-glib/nm-device.c
@@ -18,7 +18,7 @@
* Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
- * Copyright (C) 2007 - 2010 Red Hat, Inc.
+ * Copyright (C) 2007 - 2011 Red Hat, Inc.
*/
#include <string.h>
@@ -37,6 +37,7 @@
#include "nm-object-private.h"
#include "nm-object-cache.h"
#include "nm-marshal.h"
+#include "nm-dbus-glib-types.h"
#include "nm-device-bindings.h"
@@ -300,6 +301,60 @@ device_state_changed (DBusGProxy *proxy,
}
}
+static void
+get_all_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
+{
+ NMObject *self = NM_OBJECT (user_data);
+ GHashTable *props = NULL;
+ GError *error = NULL;
+
+ if (!dbus_g_proxy_end_call (proxy, call, &error,
+ DBUS_TYPE_G_MAP_OF_VARIANT, &props,
+ G_TYPE_INVALID)) {
+ if (!(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NO_REPLY)) {
+ g_warning ("%s: couldn't retrieve device properties: (%d) %s.",
+ __func__,
+ error ? error->code : -1,
+ (error && error->message) ? error->message : "(unknown)");
+ }
+ g_clear_error (&error);
+ g_object_unref (proxy);
+ return;
+ }
+ g_object_unref (proxy);
+
+ /* Hack: libnm-glib's NMDevice doesn't have ip4-address property. Remove
+ * it from the hash to prevent warnings.
+ */
+ g_hash_table_remove (props, "Ip4Address");
+
+ _nm_object_process_properties_changed (NM_OBJECT (self), props);
+ g_hash_table_destroy (props);
+
+}
+
+static void
+initialize_properties (NMObject *object)
+{
+ DBusGProxy *props_proxy;
+
+ /* D-Bus properties proxy */
+ props_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object),
+ NM_DBUS_SERVICE,
+ nm_object_get_path (object),
+ "org.freedesktop.DBus.Properties");
+ g_assert (props_proxy);
+
+ /* Get properties */
+ dbus_g_proxy_begin_call (props_proxy, "GetAll",
+ get_all_cb,
+ object,
+ NULL,
+ G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
+ G_TYPE_INVALID);
+
+}
+
static GObject*
constructor (GType type,
guint n_construct_params,
@@ -323,6 +378,12 @@ constructor (GType type,
register_for_property_changed (NM_DEVICE (object));
+ /* Get initial properties, so that we have all properties set even if
+ * no PropertiesChanged signal is received.
+ * It has to be called after register_for_property_changed().
+ */
+ initialize_properties (object);
+
dbus_g_object_register_marshaller (_nm_marshal_VOID__UINT_UINT_UINT,
G_TYPE_NONE,
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT,