00001 namespace DBus
00002 {
00003 using System;
00004 using System.Runtime.InteropServices;
00005 using System.Diagnostics;
00006
00007 public class Bus
00008 {
00009
00010 private enum BusType
00011 {
00012 Session = 0,
00013 System = 1,
00014 Activation = 2
00015 }
00016
00017
00018 private Bus () { }
00019
00020 public static Connection GetSessionBus()
00021 {
00022 return GetBus(BusType.Session);
00023 }
00024
00025 public static Connection GetSystemBus()
00026 {
00027 return GetBus(BusType.System);
00028 }
00029
00030 private static Connection GetBus(BusType busType)
00031 {
00032 Error error = new Error();
00033 error.Init();
00034
00035 IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
00036
00037 if (rawConnection != IntPtr.Zero) {
00038 Connection connection = Connection.Wrap(rawConnection);
00039 connection.SetupWithMain();
00040 dbus_connection_unref(rawConnection);
00041
00042 return connection;
00043 } else {
00044 throw new DBusException(error);
00045 }
00046 }
00047
00048 [DllImport ("dbus-1")]
00049 private extern static IntPtr dbus_bus_get (int which, ref Error error);
00050
00051 [DllImport ("dbus-1")]
00052 private extern static void dbus_connection_unref (IntPtr ptr);
00053 }
00054 }