4 using System.Runtime.InteropServices;
5 using System.Diagnostics;
17 // Don't allow instantiation
20 public static Connection GetSessionBus()
22 return GetBus(BusType.Session);
25 public static Connection GetSystemBus()
27 return GetBus(BusType.System);
30 private static Connection GetBus(BusType busType)
32 Error error = new Error();
35 IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
37 if (rawConnection != IntPtr.Zero) {
38 Connection connection = Connection.Wrap(rawConnection);
39 connection.SetupWithMain();
40 dbus_connection_unref(rawConnection);
44 throw new DBusException(error);
48 [DllImport ("dbus-1")]
49 private extern static IntPtr dbus_bus_get (int which, ref Error error);
51 [DllImport ("dbus-1")]
52 private extern static void dbus_connection_unref (IntPtr ptr);