dbus/mono Service.cs,1.8,1.9

Joe Shaw joe at freedesktop.org
Thu Feb 10 15:01:30 PST 2005


Update of /cvs/dbus/dbus/mono
In directory gabe:/tmp/cvs-serv17846/mono

Modified Files:
	Service.cs 
Log Message:
2005-02-10  Joe Shaw  <joeshaw at novell.com>

	* dbus/dbus-connection.c
	(_dbus_connection_queue_received_message_link,
	_dbus_connection_message_sent): Add the path to
	the verbose output.
	(_dbus_connection_send_preallocated_and_unlock): Added.  Calls
	_dbus_connection_send_preallocated_unlocked(), updated the
	dispatch status, and unlocks.  Fixes a bug where certain
	situations (like a broken pipe) could cause a Disconnect message
	to not be sent, tricking the bus into thinking a service was still
	there when the process had quit.
	(_dbus_connection_send_preallocated): Call
	_dbus_connection_send_preallocated_and_unlock().
	(_dbus_connection_send_and_unlock): Added.  Calls
	_dbus_connection_send_preallocated_and_unlock().
	(dbus_connection_send): Call _dbus_connection_send_and_unlock().
	(dbus_connection_send_with_reply): Update the dispatch status and
	unlock.

	* mono/Service.cs (~Service): Added.  Removes the filter so that
	we don't get unmanaged code calling back into a GCed delegate.
	(RemoveFilter); Added.

Index: Service.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/Service.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Service.cs	25 Jan 2005 19:47:13 -0000	1.8
+++ Service.cs	10 Feb 2005 23:01:28 -0000	1.9
@@ -23,6 +23,9 @@
     private static AssemblyBuilder proxyAssembly;
     private ModuleBuilder module = null;
 
+    // Add a match for signals. FIXME: Can we filter the service?
+    private const string MatchRule = "type='signal'";
+
     internal Service(string name, Connection connection)
     {
       this.name = name;
@@ -47,6 +50,12 @@
       this.local = true;
     }
 
+    ~Service ()
+    {
+      if (this.filterCalled != null)
+        RemoveFilter ();
+    }
+
     public static bool HasOwner(Connection connection, string name)
     {
       Error error = new Error();
@@ -113,9 +122,17 @@
 				      IntPtr.Zero))
 	throw new OutOfMemoryException();
 
-      // Add a match for signals. FIXME: Can we filter the service?
-      string rule = "type='signal'";
-      dbus_bus_add_match(connection.RawConnection, rule, IntPtr.Zero);
+      dbus_bus_add_match(connection.RawConnection, MatchRule, IntPtr.Zero);
+    }
+
+    private void RemoveFilter() 
+    {
+      dbus_connection_remove_filter (Connection.RawConnection,
+				     this.filterCalled,
+				     IntPtr.Zero);
+      this.filterCalled = null;
+
+      dbus_bus_remove_match (connection.RawConnection, MatchRule, IntPtr.Zero);
     }
 
     private int Service_FilterCalled(IntPtr rawConnection,
@@ -200,9 +217,19 @@
 							  IntPtr freeData);
 
     [DllImport("dbus-1")]
+    private extern static void dbus_connection_remove_filter(IntPtr rawConnection,
+							     DBusHandleMessageFunction filter,
+							     IntPtr userData);
+
+    [DllImport("dbus-1")]
     private extern static void dbus_bus_add_match(IntPtr rawConnection,
 						  string rule,
 						  IntPtr erro);
 
+    [DllImport("dbus-1")]
+    private extern static void dbus_bus_remove_match(IntPtr rawConnection,
+						     string rule,
+						     IntPtr erro);
+
   }
 }



More information about the dbus-commit mailing list