From 4a77a2dd972e817a08a4571220c8406709af8c48 Mon Sep 17 00:00:00 2001 From: Jon Trowbridge Date: Tue, 31 Aug 2004 03:59:14 +0000 Subject: [PATCH] 2004-08-30 Jon Trowbridge * mono/BusDriver.cs: Added. This is a class for interacting with the org.freedesktop.DBus service. * mono/Message.cs: Added a mechanism to expose the message that is currently being dispatched via the static Message.Current property. Added Message.Sender and Message.Destination properties. * mono/Handler.cs: Expose the dispatched message via Message.Current when handling method calls. * mono/Service.cs: Expose the dispatched message via Message.Current when handling signal emissions. * mono/Connection.cs: Bind dbus_bus_get_base_service via the Connection.BaseService property. --- ChangeLog | 19 +++++++++++++++++++ mono/BusDriver.cs | 39 +++++++++++++++++++++++++++++++++++++++ mono/Connection.cs | 11 +++++++++++ mono/Handler.cs | 4 ++++ mono/Makefile.am | 1 + mono/Message.cs | 38 ++++++++++++++++++++++++++++++++++++++ mono/Service.cs | 2 ++ 7 files changed, 114 insertions(+) create mode 100644 mono/BusDriver.cs diff --git a/ChangeLog b/ChangeLog index e47a0f3..89ebcf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2004-08-30 Jon Trowbridge + + * mono/BusDriver.cs: Added. This is a class for interacting with + the org.freedesktop.DBus service. + + * mono/Message.cs: Added a mechanism to expose the message that is + currently being dispatched via the static Message.Current + property. Added Message.Sender and Message.Destination + properties. + + * mono/Handler.cs: Expose the dispatched message via + Message.Current when handling method calls. + + * mono/Service.cs: Expose the dispatched message via + Message.Current when handling signal emissions. + + * mono/Connection.cs: Bind dbus_bus_get_base_service via the + Connection.BaseService property. + 2004-08-28 Havoc Pennington * dbus/dbus-userdb.c (_dbus_is_console_user): remove unused variable diff --git a/mono/BusDriver.cs b/mono/BusDriver.cs new file mode 100644 index 0000000..8b1fc68 --- /dev/null +++ b/mono/BusDriver.cs @@ -0,0 +1,39 @@ +namespace DBus +{ + + using System; + + public delegate void ServiceEventHandler (string serviceName); + + [Interface ("org.freedesktop.DBus")] + public abstract class BusDriver + { + [Method] + public abstract string[] ListServices (); + + [Method] + public abstract string GetServiceOwner (string serviceName); + + [Method] + public abstract UInt32 GetConnectionUnixUser (string connectionName); + + + [Signal] + public virtual event ServiceEventHandler ServiceCreated; + + [Signal] + public virtual event ServiceEventHandler ServiceDeleted; + + + static public BusDriver New (Connection connection) + { + Service service; + service = Service.Get (connection, "org.freedesktop.DBus"); + + BusDriver driver; + driver = (BusDriver) service.GetObject (typeof (BusDriver), "/org/freedesktop/DBus"); + + return driver; + } + } +} diff --git a/mono/Connection.cs b/mono/Connection.cs index fad0dc5..acc6ef6 100644 --- a/mono/Connection.cs +++ b/mono/Connection.cs @@ -76,6 +76,14 @@ namespace DBus return new Connection(rawConnection); } + public string BaseService + { + get + { + return Marshal.PtrToStringAnsi (dbus_bus_get_base_service (RawConnection)); + } + } + public int Timeout { get @@ -182,5 +190,8 @@ namespace DBus [DllImport ("dbus-1")] private extern static void dbus_connection_disconnect (IntPtr ptr); + + [DllImport ("dbus-1")] + private extern static IntPtr dbus_bus_get_base_service (IntPtr ptr); } } diff --git a/mono/Handler.cs b/mono/Handler.cs index 91569e9..9696a4d 100644 --- a/mono/Handler.cs +++ b/mono/Handler.cs @@ -177,11 +177,15 @@ namespace DBus } MethodInfo method = interfaceProxy.GetMethod(methodCall.Key); + + Message.Push (methodCall); // Now call the method. FIXME: Error handling object [] args = methodCall.Arguments.GetParameters(method); object retVal = method.Invoke(this.handledObject, args); + Message.Pop (); + // Create the reply and send it MethodReturn methodReturn = new MethodReturn(methodCall); methodReturn.Arguments.AppendResults(method, retVal, args); diff --git a/mono/Makefile.am b/mono/Makefile.am index 8bb25f5..1d19ec0 100644 --- a/mono/Makefile.am +++ b/mono/Makefile.am @@ -9,6 +9,7 @@ ASSEMBLY_NAME=dbus-sharp DBUS_SHARP_FILES= \ Arguments.cs \ Bus.cs \ + BusDriver.cs \ Connection.cs \ Custom.cs \ DBusException.cs \ diff --git a/mono/Message.cs b/mono/Message.cs index 54472d1..5aa3542 100644 --- a/mono/Message.cs +++ b/mono/Message.cs @@ -8,6 +8,25 @@ namespace DBus public class Message { + private static Stack stack = new Stack (); + + static public Message Current { + get + { + return stack.Count > 0 ? (Message) stack.Peek () : null; + } + } + + static internal void Push (Message message) + { + stack.Push (message); + } + + static internal void Pop () + { + stack.Pop (); + } + /// /// A pointer to the underlying Message structure @@ -294,6 +313,22 @@ namespace DBus } } + public string Sender + { + get + { + return Marshal.PtrToStringAnsi(dbus_message_get_sender(RawMessage)); + } + } + + public string Destination + { + get + { + return Marshal.PtrToStringAnsi(dbus_message_get_destination(RawMessage)); + } + } + protected int Slot { get @@ -373,5 +408,8 @@ namespace DBus [DllImport("dbus-1")] private extern static IntPtr dbus_message_get_destination(IntPtr rawMessage); + + [DllImport("dbus-1")] + private extern static IntPtr dbus_message_get_sender(IntPtr rawMessage); } } diff --git a/mono/Service.cs b/mono/Service.cs index 167cfc4..35a2584 100644 --- a/mono/Service.cs +++ b/mono/Service.cs @@ -128,7 +128,9 @@ namespace DBus // We're only interested in signals Signal signal = (Signal) message; if (SignalCalled != null) { + Message.Push (message); SignalCalled(signal); + Message.Pop (); } } -- 2.7.4