dbus/mono Connection.cs,1.9,1.9.2.1 Service.cs,1.7.2.1,1.7.2.2
Joe Shaw
joe at freedesktop.org
Fri Feb 11 16:33:27 PST 2005
Update of /cvs/dbus/dbus/mono
In directory gabe:/tmp/cvs-serv16712/mono
Modified Files:
Tag: dbus-0-23
Connection.cs Service.cs
Log Message:
2005-02-11 Joe Shaw <joeshaw at novell.com>
* mono/Connection.cs: The unpredictability of finalizers in mono
prevents us from deterministically disconnecting the filters from
the Service class's finalizer, so move tracking of filters and
matches here. Add API for that.
* mono/Service.cs: Remove the code, add code which calls the
methods now on the Connection class.
Index: Connection.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/Connection.cs,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -d -r1.9 -r1.9.2.1
--- Connection.cs 31 Aug 2004 03:59:14 -0000 1.9
+++ Connection.cs 12 Feb 2005 00:33:25 -0000 1.9.2.1
@@ -8,6 +8,10 @@
using System.IO;
using System.Collections;
+ public delegate int DBusHandleMessageFunction (IntPtr rawConnection,
+ IntPtr rawMessage,
+ IntPtr userData);
+
public class Connection
{
/// <summary>
@@ -22,6 +26,9 @@
private int timeout = -1;
+ private ArrayList filters = new ArrayList (); // of DBusHandleMessageFunction
+ private ArrayList matches = new ArrayList (); // of string
+
internal Connection(IntPtr rawConnection)
{
RawConnection = rawConnection;
@@ -56,6 +63,12 @@
{
if (RawConnection != IntPtr.Zero)
{
+ foreach (DBusHandleMessageFunction func in this.filters)
+ RemoveFilter (func);
+
+ foreach (string match_rule in this.matches)
+ RemoveMatch (match_rule);
+
dbus_connection_disconnect(rawConnection);
}
RawConnection = IntPtr.Zero; // free the native object
@@ -76,6 +89,38 @@
return new Connection(rawConnection);
}
+ public void AddFilter (DBusHandleMessageFunction func)
+ {
+ if (!dbus_connection_add_filter (RawConnection,
+ func,
+ IntPtr.Zero,
+ IntPtr.Zero))
+ throw new OutOfMemoryException ();
+
+ this.filters.Add (func);
+ }
+
+ public void RemoveFilter (DBusHandleMessageFunction func)
+ {
+ dbus_connection_remove_filter (RawConnection, func, IntPtr.Zero);
+
+ this.filters.Remove (func);
+ }
+
+ public void AddMatch (string match_rule)
+ {
+ dbus_bus_add_match (RawConnection, match_rule, IntPtr.Zero);
+
+ this.matches.Add (match_rule);
+ }
+
+ public void RemoveMatch (string match_rule)
+ {
+ dbus_bus_remove_match (RawConnection, match_rule, IntPtr.Zero);
+
+ this.matches.Remove (match_rule);
+ }
+
public string BaseService
{
get
@@ -193,5 +238,26 @@
[DllImport ("dbus-1")]
private extern static IntPtr dbus_bus_get_base_service (IntPtr ptr);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_connection_add_filter(IntPtr rawConnection,
+ DBusHandleMessageFunction filter,
+ IntPtr userData,
+ 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);
}
}
Index: Service.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/Service.cs,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -d -r1.7.2.1 -r1.7.2.2
--- Service.cs 10 Feb 2005 23:22:11 -0000 1.7.2.1
+++ Service.cs 12 Feb 2005 00:33:25 -0000 1.7.2.2
@@ -14,18 +14,12 @@
private string name;
private bool local = false;
private Hashtable registeredHandlers = new Hashtable();
- private delegate int DBusHandleMessageFunction(IntPtr rawConnection,
- IntPtr rawMessage,
- IntPtr userData);
private DBusHandleMessageFunction filterCalled;
public delegate void SignalCalledHandler(Signal signal);
public event SignalCalledHandler SignalCalled;
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;
@@ -50,12 +44,6 @@
this.local = true;
}
- ~Service ()
- {
- if (this.filterCalled != null)
- RemoveFilter ();
- }
-
public static bool Exists(Connection connection, string name)
{
Error error = new Error();
@@ -116,23 +104,9 @@
{
// Setup the filter function
this.filterCalled = new DBusHandleMessageFunction(Service_FilterCalled);
- if (!dbus_connection_add_filter(Connection.RawConnection,
- this.filterCalled,
- IntPtr.Zero,
- IntPtr.Zero))
- throw new OutOfMemoryException();
-
- 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);
+ Connection.AddFilter (this.filterCalled);
+ // Add a match for signals. FIXME: Can we filter the service?
+ Connection.AddMatch ("type='signal'");
}
private int Service_FilterCalled(IntPtr rawConnection,
@@ -210,26 +184,6 @@
string serviceName,
ref Error error);
- [DllImport("dbus-1")]
- private extern static bool dbus_connection_add_filter(IntPtr rawConnection,
- DBusHandleMessageFunction filter,
- IntPtr userData,
- 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