summaryrefslogtreecommitdiffstats
path: root/mono/Connection.cs
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-06-23 02:12:19 +0000
committerHavoc Pennington <hp@redhat.com>2003-06-23 02:12:19 +0000
commitcef11442f69e9a649731f3b2a12b655996da265b (patch)
tree63968e3cc34dc13820515bd415adb58ebe14d221 /mono/Connection.cs
parent1cc184b4a849619b56bed2be0e752fbc0fb75a29 (diff)
2003-06-22 Havoc Pennington <hp@pobox.com>
* mono/Connection.cs: add more bindings * dbus/dbus-threads.c (dbus_threads_init): allow calling this more than once.
Diffstat (limited to 'mono/Connection.cs')
-rw-r--r--mono/Connection.cs84
1 files changed, 76 insertions, 8 deletions
diff --git a/mono/Connection.cs b/mono/Connection.cs
index f0d34eec..ff983d5a 100644
--- a/mono/Connection.cs
+++ b/mono/Connection.cs
@@ -20,6 +20,49 @@ namespace DBus {
}
}
+ // Keep in sync with C
+ public enum BusType {
+ Session = 0,
+ System = 1,
+ Activation = 2
+ }
+
+ public static Connection GetBus (BusType bus) {
+ Error error = new Error ();
+
+ error.Init ();
+
+ IntPtr ptr = dbus_bus_get ((int) bus, ref error);
+ if (ptr != (IntPtr) 0) {
+ Connection c = Wrap (ptr);
+ dbus_connection_unref (ptr);
+ return c;
+ } else {
+ Exception e = new Exception (ref error);
+ error.Free ();
+ throw e;
+ }
+ }
+
+ public void Send (Message m,
+ ref int serial) {
+ if (!dbus_connection_send (raw, m.raw, ref serial))
+ throw new OutOfMemoryException ();
+ }
+
+ public void Send (Message m) {
+ int ignored = 0;
+ Send (m, ref ignored);
+ }
+
+ public void Flush () {
+ dbus_connection_flush (raw);
+ }
+
+ public void Disconnect () {
+ dbus_connection_disconnect (raw);
+ }
+
public static Connection Wrap (IntPtr ptr) {
IntPtr gch_ptr;
@@ -34,7 +77,7 @@ namespace DBus {
// surely there's a convention for this pattern with the property
// and the real member
IntPtr raw_;
- IntPtr raw {
+ internal IntPtr raw {
get {
return raw_;
}
@@ -74,6 +117,9 @@ namespace DBus {
}
~Connection () {
+ if (raw != (IntPtr) 0) {
+ Disconnect ();
+ }
raw = (IntPtr) 0; // free the native object
}
@@ -83,6 +129,8 @@ namespace DBus {
// static constructor runs before any methods
static Connection () {
+ DBus.Internals.Init ();
+
Debug.Assert (wrapper_slot == -1);
if (!dbus_connection_allocate_data_slot (ref wrapper_slot))
@@ -94,30 +142,50 @@ namespace DBus {
// slot used to store the C# object on the C object
static int wrapper_slot = -1;
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_open")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_open")]
private extern static IntPtr dbus_connection_open (string address,
ref Error error);
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_unref")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_unref")]
private extern static void dbus_connection_unref (IntPtr ptr);
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_ref")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_ref")]
private extern static void dbus_connection_ref (IntPtr ptr);
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_allocate_data_slot")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_allocate_data_slot")]
private extern static bool dbus_connection_allocate_data_slot (ref int slot);
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_free_data_slot")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_free_data_slot")]
private extern static void dbus_connection_free_data_slot (ref int slot);
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_set_data")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_set_data")]
private extern static bool dbus_connection_set_data (IntPtr ptr,
int slot,
IntPtr data,
IntPtr free_data_func);
- [DllImport (DBus.Internals.Libname, EntryPoint="dbus_connection_get_data")]
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_send")]
+ private extern static bool dbus_connection_send (IntPtr ptr,
+ IntPtr message,
+ ref int client_serial);
+
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_flush")]
+ private extern static void dbus_connection_flush (IntPtr ptr);
+
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_bus_get")]
+ private extern static IntPtr dbus_bus_get (int which,
+ ref Error error);
+
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_get_data")]
private extern static IntPtr dbus_connection_get_data (IntPtr ptr,
int slot);
+
+ [DllImport (DBus.Internals.DBusLibname, EntryPoint="dbus_connection_disconnect")]
+ private extern static void dbus_connection_disconnect (IntPtr ptr);
+
+ [DllImport (DBus.Internals.DBusGLibname, EntryPoint="dbus_connection_setup_with_g_main")]
+ private extern static void dbus_connection_setup_with_g_main (IntPtr ptr,
+ IntPtr context);
+
}
}