NetworkManager r3501 - in trunk: . libnm-glib



Author: dcbw
Date: Tue Mar 25 11:34:33 2008
New Revision: 3501
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3501&view=rev

Log:
2008-03-25  Dan Williams  <dcbw redhat com>

	* libnm-glib/nm-object.c
	  libnm-glib/nm-object-private.h
		- (nm_object_queue_notify): add helper to batch & postpone GObject notify
			signals to an idle handler
		- (nm_object_get_property): add a timeout to the D-Bus method call



Modified:
   trunk/ChangeLog
   trunk/libnm-glib/nm-object-private.h
   trunk/libnm-glib/nm-object.c

Modified: trunk/libnm-glib/nm-object-private.h
==============================================================================
--- trunk/libnm-glib/nm-object-private.h	(original)
+++ trunk/libnm-glib/nm-object-private.h	Tue Mar 25 11:34:33 2008
@@ -21,6 +21,7 @@
 
 gboolean nm_object_demarshal_generic (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field);
 
+void nm_object_queue_notify (NMObject *object, const char *property);
 
 /* DBus property accessors */
 

Modified: trunk/libnm-glib/nm-object.c
==============================================================================
--- trunk/libnm-glib/nm-object.c	(original)
+++ trunk/libnm-glib/nm-object.c	Tue Mar 25 11:34:33 2008
@@ -25,6 +25,8 @@
 	GSList *pcs;
 	NMObject *parent;
 
+	GSList *notify_props;
+	gulong notify_id;
 	gboolean disposed;
 } NMObjectPrivate;
 
@@ -85,6 +87,14 @@
 
 	priv->disposed = TRUE;
 
+	if (priv->notify_id) {
+		g_source_remove (priv->notify_id);
+		priv->notify_id = 0;
+	}
+
+	g_slist_foreach (priv->notify_props, (GFunc) g_free, NULL);
+	g_slist_free (priv->notify_props);
+
 	g_object_unref (priv->properties_proxy);
 	dbus_g_connection_unref (priv->connection);
 
@@ -191,6 +201,40 @@
 	return NM_OBJECT_GET_PRIVATE (object)->path;
 }
 
+static gboolean
+deferred_notify_cb (gpointer data)
+{
+	NMObject *object = NM_OBJECT (data);
+	NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
+	GSList *iter;
+
+	priv->notify_id = 0;
+
+	for (iter = priv->notify_props; iter; iter = g_slist_next (iter)) {
+		g_object_notify (G_OBJECT (object), (const char *) iter->data);
+		g_free (iter->data);
+	}
+	g_slist_free (priv->notify_props);
+	priv->notify_props = NULL;
+
+	return FALSE;
+}
+
+void
+nm_object_queue_notify (NMObject *object, const char *property)
+{
+	NMObjectPrivate *priv;
+
+	g_return_if_fail (NM_IS_OBJECT (object));
+	g_return_if_fail (property != NULL);
+
+	priv = NM_OBJECT_GET_PRIVATE (object);
+	if (!priv->notify_id)
+		priv->notify_id = g_idle_add_full (G_PRIORITY_LOW, deferred_notify_cb, object, NULL);
+
+	priv->notify_props = g_slist_append (priv->notify_props, g_strdup (property));
+}
+
 /* Stolen from dbus-glib */
 static char*
 wincaps_to_dash (const char *caps)
@@ -351,7 +395,7 @@
 
 done:
 	if (success) {
-		g_object_notify (G_OBJECT (object), pspec->name);
+		nm_object_queue_notify (object, pspec->name);
 	} else {
 		g_warning ("%s: %s/%s (type %s) couldn't be set with type %s.",
 		           __func__, G_OBJECT_TYPE_NAME (object), pspec->name,
@@ -373,8 +417,8 @@
 	g_return_val_if_fail (prop_name != NULL, FALSE);
 	g_return_val_if_fail (value != NULL, FALSE);
 
-	if (!dbus_g_proxy_call (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
-							"Get", &err,
+	if (!dbus_g_proxy_call_with_timeout (NM_OBJECT_GET_PRIVATE (object)->properties_proxy,
+							"Get", 15000, &err,
 							G_TYPE_STRING, interface,
 							G_TYPE_STRING, prop_name,
 							G_TYPE_INVALID,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]