File: Bus.cs

package info (click to toggle)
dbus-sharp 0.63.git.20060719-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,244 kB
  • ctags: 636
  • sloc: sh: 8,433; xml: 4,036; cs: 3,293; makefile: 163
file content (54 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace DBus
{
  using System;
  using System.Runtime.InteropServices;
  using System.Diagnostics;
  
  public class Bus
  {
    // Keep in sync with C
    private enum BusType 
    {
      Session = 0,
      System = 1,
      Activation = 2
    }

    // Don't allow instantiation
    private Bus () { }

    public static Connection GetSessionBus() 
    {
      return GetBus(BusType.Session);
    }

    public static Connection GetSystemBus()
    {
      return GetBus(BusType.System);
    }

    private static Connection GetBus(BusType busType) 
    {
      Error error = new Error();
      error.Init();
      
      IntPtr rawConnection = dbus_bus_get((int) busType, ref error);
      
      if (rawConnection != IntPtr.Zero) {
	Connection connection = Connection.Wrap(rawConnection);
	connection.SetupWithMain();
	dbus_connection_unref(rawConnection);

	return connection;
      } else {
	throw new DBusException(error);
      }
    }

    [DllImport ("dbus-1")]
    private extern static IntPtr dbus_bus_get (int which, ref Error error);

    [DllImport ("dbus-1")]
    private extern static void dbus_connection_unref (IntPtr ptr);
  }
}