Modified to support char type.
[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     public static Connection GetSessionBus() 
18     {
19       return GetBus(BusType.Session);
20     }
21
22     public static Connection GetSystemBus()
23     {
24       return GetBus(BusType.System);
25     }
26
27     private static Connection GetBus(BusType busType) 
28     {
29       Error error = new Error();
30       error.Init();
31       
32       IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
33       
34       if (rawConnection != IntPtr.Zero) {
35         Connection connection = Connection.Wrap(rawConnection);
36         connection.SetupWithMain();
37         dbus_connection_unref(rawConnection);
38
39         return connection;
40       } else {
41         throw new DBusException(error);
42       }
43     }
44
45     [DllImport ("dbus-1")]
46     private extern static IntPtr dbus_bus_get (int which, ref Error error);
47
48     [DllImport ("dbus-1")]
49     private extern static void dbus_connection_unref (IntPtr ptr);
50   }
51 }