4 using System.Runtime.InteropServices;
5 using System.Diagnostics;
17 public static Connection GetSessionBus()
19 return GetBus(BusType.Session);
22 public static Connection GetSystemBus()
24 return GetBus(BusType.System);
27 private static Connection GetBus(BusType busType)
29 Error error = new Error();
32 IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
34 if (rawConnection != IntPtr.Zero) {
35 Connection connection = Connection.Wrap(rawConnection);
36 connection.SetupWithMain();
37 dbus_connection_unref(rawConnection);
41 throw new DBusException(error);
45 [DllImport ("dbus-1")]
46 private extern static IntPtr dbus_bus_get (int which, ref Error error);
48 [DllImport ("dbus-1")]
49 private extern static void dbus_connection_unref (IntPtr ptr);