* qt/Makfile.am:
[platform/upstream/dbus.git] / mono / Bus.cs
1 namespace DBus
2 {
3   using System;
4   using System.Runtime.InteropServices;
5   using System.Diagnostics;
6   
7   public class Bus
8   {
9     // Keep in sync with C
10     private enum BusType 
11     {
12       Session = 0,
13       System = 1,
14       Activation = 2
15     }
16
17     // Don't allow instantiation
18     private Bus () { }
19
20     public static Connection GetSessionBus() 
21     {
22       return GetBus(BusType.Session);
23     }
24
25     public static Connection GetSystemBus()
26     {
27       return GetBus(BusType.System);
28     }
29
30     private static Connection GetBus(BusType busType) 
31     {
32       Error error = new Error();
33       error.Init();
34       
35       IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
36       
37       if (rawConnection != IntPtr.Zero) {
38         Connection connection = Connection.Wrap(rawConnection);
39         connection.SetupWithMain();
40         dbus_connection_unref(rawConnection);
41
42         return connection;
43       } else {
44         throw new DBusException(error);
45       }
46     }
47
48     [DllImport ("dbus-1")]
49     private extern static IntPtr dbus_bus_get (int which, ref Error error);
50
51     [DllImport ("dbus-1")]
52     private extern static void dbus_connection_unref (IntPtr ptr);
53   }
54 }