4 using System.Runtime.InteropServices;
5 using System.Diagnostics;
6 using System.Collections;
7 using System.Reflection;
8 using System.Reflection.Emit;
12 private Connection connection;
14 private bool local = false;
15 private Hashtable registeredHandlers = new Hashtable();
16 internal ModuleBuilder module = null;
18 internal Service(string name, Connection connection)
21 this.connection = connection;
24 public Service(Connection connection, string name)
26 Error error = new Error();
29 // This isn't used for now
32 if (dbus_bus_acquire_service(connection.RawConnection, name, flags, ref error) == -1) {
33 throw new DBusException(error);
36 this.connection = connection;
41 public static bool Exists(Connection connection, string name)
43 Error error = new Error();
46 if (dbus_bus_service_exists(connection.RawConnection,
52 throw new DBusException(error);
58 public static Service Get(Connection connection, string name)
60 if (Exists(connection, name)) {
61 return new Service(name, connection);
63 throw new ApplicationException("Service '" + name + "' does not exist.");
67 public void RegisterObject(object handledObject,
70 Handler handler = new Handler(handledObject,
73 registeredHandlers.Add(handledObject, handler);
76 internal Handler GetHandler(object handledObject)
78 if (!registeredHandlers.Contains(handledObject)) {
79 throw new ArgumentException("No handler registered for object: " + handledObject);
82 return (Handler) registeredHandlers[handledObject];
85 public object GetObject(Type type, string pathName)
87 ProxyBuilder builder = new ProxyBuilder(this, type, pathName);
88 object proxy = builder.GetProxy();
100 public Connection Connection
109 this.connection = value;
113 [DllImport ("dbus-1")]
114 private extern static int dbus_bus_acquire_service (IntPtr rawConnection, string serviceName, uint flags, ref Error error);
116 [DllImport ("dbus-1")]
117 private extern static bool dbus_bus_service_exists (IntPtr rawConnection, string serviceName, ref Error error);