diff options
author | Owen Fraser-Green <owen@discobabe.net> | 2004-03-23 12:10:32 +0000 |
---|---|---|
committer | Owen Fraser-Green <owen@discobabe.net> | 2004-03-23 12:10:32 +0000 |
commit | c916037773d7d3d8d37ca2c5a8899b7b728e377d (patch) | |
tree | 21c37372ab9795583e724e8459578b7fe0be330b /mono/Bus.cs | |
parent | 2195cf0dbde2ae26b5a684c6d914c1711f44c28d (diff) |
First checkin of the Mono bindings.
Diffstat (limited to 'mono/Bus.cs')
-rw-r--r-- | mono/Bus.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/mono/Bus.cs b/mono/Bus.cs new file mode 100644 index 00000000..963e8195 --- /dev/null +++ b/mono/Bus.cs @@ -0,0 +1,51 @@ +namespace DBus +{ + using System; + using System.Runtime.InteropServices; + using System.Diagnostics; + + public class Bus + { + // Keep in sync with C + private enum BusType + { + Session = 0, + System = 1, + Activation = 2 + } + + public static Connection GetSessionBus() + { + return GetBus(BusType.Session); + } + + public static Connection GetSystemBus() + { + return GetBus(BusType.System); + } + + private static Connection GetBus(BusType busType) + { + Error error = new Error(); + error.Init(); + + IntPtr rawConnection = dbus_bus_get((int) busType, ref error); + + if (rawConnection != IntPtr.Zero) { + Connection connection = Connection.Wrap(rawConnection); + connection.SetupWithMain(); + dbus_connection_unref(rawConnection); + + return connection; + } else { + throw new DBusException(error); + } + } + + [DllImport ("dbus-1")] + private extern static IntPtr dbus_bus_get (int which, ref Error error); + + [DllImport ("dbus-1")] + private extern static void dbus_connection_unref (IntPtr ptr); + } +} |