dbus/mono Handler.cs,1.4,1.5 Service.cs,1.5,1.6

Owen Fraser-Green ow3n at pdx.freedesktop.org
Sun May 23 14:33:16 PDT 2004


Update of /cvs/dbus/dbus/mono
In directory pdx:/tmp/cvs-serv4578/mono

Modified Files:
	Handler.cs Service.cs 
Log Message:
Added UnregisterObject method.


Index: Handler.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/Handler.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/Handler.cs	3 Apr 2004 22:00:40 -0000	1.4
+++ b/Handler.cs	23 May 2004 21:33:14 -0000	1.5
@@ -13,7 +13,7 @@
     NeedMemory = 2
   }
 
-  internal class Handler
+  internal class Handler : IDisposable
   {
     private string[] path = null;
     private string pathName = null;
@@ -22,6 +22,7 @@
     private DBusObjectPathVTable vTable;
     private Connection connection;
     private Service service;
+    private bool disposed = false;
     
     internal delegate void DBusObjectPathUnregisterFunction(IntPtr rawConnection,
 							    IntPtr userData);
@@ -52,12 +53,38 @@
       }
     }
 
+    public void Dispose() 
+    {
+      Dispose(true);
+      GC.SuppressFinalize(this);
+    }
+    
+    private void Dispose(bool disposing) 
+    {
+      if (!disposed) {	
+	if (disposing) {
+	  // Clean up managed resources
+	}
+
+	service = null;
+
+	// Clean up unmanaged resources
+	if (Connection != null && Connection.RawConnection != IntPtr.Zero && path != null) {
+	  dbus_connection_unregister_object_path(Connection.RawConnection,
+						 Path);
+	}	
+
+	connection = null;
+	introspector = null;
+	handledObject = null;
+      }
+      
+      disposed = true;    
+    }
+
     ~Handler() 
     {
-      if (Connection != null && Connection.RawConnection != IntPtr.Zero && path != null) {
-	dbus_connection_unregister_object_path(Connection.RawConnection,
-					       Path);
-      } 
+      Dispose(false);
     }
 
     public Handler(object handledObject, 
@@ -119,7 +146,11 @@
     public void Unregister_Called(IntPtr rawConnection, 
 				  IntPtr userData)
     {
-      System.Console.WriteLine("FIXME: Unregister called.");
+      if (service != null) {
+	service.UnregisterObject(HandledObject);
+      }
+
+      path = null;
     }
 
     private int Message_Called(IntPtr rawConnection, 

Index: Service.cs
===================================================================
RCS file: /cvs/dbus/dbus/mono/Service.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/Service.cs	3 Apr 2004 22:00:40 -0000	1.5
+++ b/Service.cs	23 May 2004 21:33:14 -0000	1.6
@@ -73,6 +73,13 @@
       }
     }
 
+    public void UnregisterObject(object handledObject) 
+    {
+      Handler handler = (Handler) registeredHandlers[handledObject];
+      registeredHandlers.Remove(handledObject);
+      handler.Dispose();
+    }
+
     public void RegisterObject(object handledObject, 
 			       string pathName) 
     {




More information about the dbus-commit mailing list