* Land the mono binding changes to conform to the new APIs.
* mono/Makefile.am: Remove Custom.cs, DBusType/Custom.cs,
DBusType/Dict.cs, and DBusType/Nil.cs from the build.
* mono/Arguments.cs (GetCodeAsString): Added. Returns the dbus
type code as a string.
(InitAppending): Rename dbus_message_append_iter_init() to
dbus_message_iter_init_append().
* mono/BusDriver.cs: Rename ServiceEventHandler to
NameOwnerChangedHandler. Rename GetServiceOwner to GetOwner.
Rename ServiceOwnerChanged to NameOwnerChanged.
* mono/Connection.cs: Rename BaseService to UniqueName, and the
underlying C call.
* mono/Custom.cs: Removed. The CUSTOM type has been removed.
* mono/Service.cs: Rename Exists to HasOwner, internally rename
dbus_bus_acquire_service() to dbus_bus_request_name().
* mono/DBusType/Array.cs (ctor): Use Type.GetElementType() instead
of Type.UnderlyingSystemType to get the correct element type for
the array.
(ctor): Update code for new APIs: use dbus_message_iter_recurse(),
dbus_message_get_{element|arg}_type() instead of
dbus_message_iter_init_array_iterator().
(Append): Replace dbus_message_iter_append_array() with
dbus_message_iter_open_container() and
dbus_message_iter_close_container().
* mono/DBusType/Custom.cs, mono/DBusType/Nil.cs: Removed. These
types have been removed.
* mono/DBusType/*.cs: Replace calls of
dbus_message_iter_get_[type]() to dbus_message_iter_get_basic(),
but specify the type in the DllImport extern declaration. Ditto
for dbus_message_iter_append_[type]() ->
dbus_message_iter_append_basic().
* mono/example/BusListener.cs: Update for ServiceEventHandler ->
NameOwnerChangedHandler.
+2005-01-25 Joe Shaw <joeshaw@novell.com>
+
+ * Land the mono binding changes to conform to the new APIs.
+
+ * mono/Makefile.am: Remove Custom.cs, DBusType/Custom.cs,
+ DBusType/Dict.cs, and DBusType/Nil.cs from the build.
+
+ * mono/Arguments.cs (GetCodeAsString): Added. Returns the dbus
+ type code as a string.
+ (InitAppending): Rename dbus_message_append_iter_init() to
+ dbus_message_iter_init_append().
+
+ * mono/BusDriver.cs: Rename ServiceEventHandler to
+ NameOwnerChangedHandler. Rename GetServiceOwner to GetOwner.
+ Rename ServiceOwnerChanged to NameOwnerChanged.
+
+ * mono/Connection.cs: Rename BaseService to UniqueName, and the
+ underlying C call.
+
+ * mono/Custom.cs: Removed. The CUSTOM type has been removed.
+
+ * mono/Service.cs: Rename Exists to HasOwner, internally rename
+ dbus_bus_acquire_service() to dbus_bus_request_name().
+
+ * mono/DBusType/Array.cs (ctor): Use Type.GetElementType() instead
+ of Type.UnderlyingSystemType to get the correct element type for
+ the array.
+ (ctor): Update code for new APIs: use dbus_message_iter_recurse(),
+ dbus_message_get_{element|arg}_type() instead of
+ dbus_message_iter_init_array_iterator().
+ (Append): Replace dbus_message_iter_append_array() with
+ dbus_message_iter_open_container() and
+ dbus_message_iter_close_container().
+
+ * mono/DBusType/Custom.cs, mono/DBusType/Nil.cs: Removed. These
+ types have been removed.
+
+ * mono/DBusType/*.cs: Replace calls of
+ dbus_message_iter_get_[type]() to dbus_message_iter_get_basic(),
+ but specify the type in the DllImport extern declaration. Ditto
+ for dbus_message_iter_append_[type]() ->
+ dbus_message_iter_append_basic().
+
+ * mono/example/BusListener.cs: Update for ServiceEventHandler ->
+ NameOwnerChangedHandler.
+
2005-01-25 John (J5) Palmieri <johnp@redhat.com>
* python/dbus_bindings.pyx.in: Rename of methods and bindings
return (char) dbusType.InvokeMember("Code", BindingFlags.Static | BindingFlags.GetField, null, null, null);
}
+ // Get the type code for a given D-BUS type as a string
+ public static string GetCodeAsString (Type dbusType)
+ {
+ return GetCode (dbusType).ToString ();
+ }
+
// Get a complete method signature
public override string ToString()
{
key += code;
} while (dbus_message_iter_next(iter));
}
-
+
Marshal.FreeCoTaskMem(iter);
return key;
// Begin appending
public void InitAppending()
{
- dbus_message_append_iter_init(message.RawMessage, appenderIter);
+ dbus_message_iter_init_append(message.RawMessage, appenderIter);
}
// Get the enumerator
}
[DllImport("dbus-1")]
- private extern static void dbus_message_append_iter_init(IntPtr rawMessage, IntPtr iter);
+ private extern static void dbus_message_iter_init_append(IntPtr rawMessage, IntPtr iter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_has_next(IntPtr iter);
using System;
- public delegate void ServiceEventHandler (string serviceName,
- string oldOwner,
- string newOwner);
+ public delegate void NameOwnerChangedHandler (string name,
+ string oldOwner,
+ string newOwner);
[Interface ("org.freedesktop.DBus")]
public abstract class BusDriver
public abstract string[] ListServices ();
[Method]
- public abstract string GetServiceOwner (string serviceName);
+ public abstract string GetOwner (string name);
[Method]
public abstract UInt32 GetConnectionUnixUser (string connectionName);
[Signal]
- public virtual event ServiceEventHandler ServiceOwnerChanged;
+ public virtual event NameOwnerChangedHandler NameOwnerChanged;
static public BusDriver New (Connection connection)
{
return new Connection(rawConnection);
}
- public string BaseService
+ public string UniqueName
{
get
{
- return Marshal.PtrToStringAnsi (dbus_bus_get_base_service (RawConnection));
+ return Marshal.PtrToStringAnsi (dbus_bus_get_unique_name (RawConnection));
}
}
private extern static void dbus_connection_disconnect (IntPtr ptr);
[DllImport ("dbus-1")]
- private extern static IntPtr dbus_bus_get_base_service (IntPtr ptr);
+ private extern static IntPtr dbus_bus_get_unique_name (IntPtr ptr);
}
}
+++ /dev/null
-using System;
-
-using DBus;
-
-namespace DBus
-{
- public struct Custom
- {
- public string Name;
- public byte[] Data;
-
- public Custom(string name, byte[] data)
- {
- Name = name;
- Data = data;
- }
- }
-}
public Array(System.Array val, Service service)
{
this.val = val;
- this.elementType = Arguments.MatchType(val.GetType().UnderlyingSystemType);
+ this.elementType = Arguments.MatchType(val.GetType().GetElementType());
this.service = service;
}
this.service = service;
IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
-
- int elementTypeCode;
- bool notEmpty = dbus_message_iter_init_array_iterator(iter, arrayIter, out elementTypeCode);
- this.elementType = (Type) Arguments.DBusTypes[(char) elementTypeCode];
- elements = new ArrayList();
+ int elementTypeCode = dbus_message_iter_get_element_type (iter);
+ dbus_message_iter_recurse (iter, arrayIter);
+ this.elementType = (Type) Arguments.DBusTypes [(char) elementTypeCode];
+
+ elements = new ArrayList ();
- if (notEmpty) {
- do {
- object [] pars = new Object[2];
+ if (dbus_message_iter_get_arg_type (arrayIter) != 0) {
+ do {
+ object [] pars = new Object[2];
pars[0] = arrayIter;
- pars[1] = service;
+ pars[1] = service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
elements.Add(dbusType);
- } while (dbus_message_iter_next(arrayIter));
- }
-
+ } while (dbus_message_iter_next(arrayIter));
+ }
+
Marshal.FreeCoTaskMem(arrayIter);
}
public void Append(IntPtr iter)
{
- IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
+ IntPtr arrayIter = Marshal.AllocCoTaskMem (Arguments.DBusMessageIterSize);
- if (!dbus_message_iter_append_array(iter,
- arrayIter,
- (int) Arguments.GetCode(this.elementType))) {
- throw new ApplicationException("Failed to append INT32 argument:" + val);
+ if (!dbus_message_iter_open_container (iter,
+ (int) this.Code,
+ Arguments.GetCodeAsString (elementType),
+ arrayIter)) {
+ throw new ApplicationException("Failed to append array argument: " + val);
}
-
+
foreach (object element in this.val) {
object [] pars = new Object[2];
pars[0] = element;
dbusType.Append(arrayIter);
}
- Marshal.FreeCoTaskMem(arrayIter);
+ if (!dbus_message_iter_close_container (iter, arrayIter)) {
+ throw new ApplicationException ("Failed to append array argument: " + val);
+ }
+
+ Marshal.FreeCoTaskMem (arrayIter);
}
public static bool Suits(System.Type type)
public object Get(System.Type type)
{
if (type.IsArray)
- type = type.GetElementType ();
+ type = type.GetElementType ();
if (Arguments.Suits(elementType, type.UnderlyingSystemType)) {
this.val = System.Array.CreateInstance(type.UnderlyingSystemType, elements.Count);
}
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_init_array_iterator(IntPtr iter,
- IntPtr arrayIter,
- out int elementType);
+ private extern static bool dbus_message_iter_open_container (IntPtr iter,
+ int containerType,
+ string elementType,
+ IntPtr subIter);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_message_iter_close_container (IntPtr iter,
+ IntPtr subIter);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_array(IntPtr iter,
- IntPtr arrayIter,
- int elementType);
+ private extern static int dbus_message_iter_get_element_type(IntPtr iter);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_has_next(IntPtr iter);
+ private extern static int dbus_message_iter_get_arg_type(IntPtr iter);
+
+ [DllImport("dbus-1")]
+ private extern static void dbus_message_iter_recurse(IntPtr iter, IntPtr subIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_next(IntPtr iter);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_message_iter_has_next (IntPtr iter);
}
}
public Boolean(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_boolean(iter);
+ dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_boolean(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append BOOLEAN argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.Boolean dbus_message_iter_get_boolean(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out bool value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_boolean(IntPtr iter, System.Boolean value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref bool value);
}
}
public Byte(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_byte(iter);
- }
+ dbus_message_iter_get_basic (iter, out this.val);
+ }
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_byte(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append BYTE argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.Byte dbus_message_iter_get_byte(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out byte value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_byte(IntPtr iter, System.Byte value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref byte value);
}
}
+++ /dev/null
-using System;
-using System.Runtime.InteropServices;
-using System.Reflection.Emit;
-
-using DBus;
-
-namespace DBus.DBusType
-{
- /// <summary>
- /// A named byte array, used for custom types.
- /// </summary>
- public class Custom : IDBusType
- {
- public const char Code = 'c';
- private DBus.Custom val;
-
- private Custom()
- {
- }
-
- public Custom(DBus.Custom val, Service service)
- {
- this.val = val;
- }
-
- public Custom(IntPtr iter, Service service)
- {
- string name;
- IntPtr value;
- int len;
-
- if (!dbus_message_iter_get_custom(iter, out name, out value, out len)) {
- throw new ApplicationException("Failed to get CUSTOM argument.");
- }
-
- this.val.Name = name;
- this.val.Data = new byte[len];
- Marshal.Copy(value, this.val.Data, 0, len);
- }
-
- public void Append(IntPtr iter)
- {
- IntPtr data = Marshal.AllocCoTaskMem(this.val.Data.Length);
- try {
- Marshal.Copy(this.val.Data, 0, data, this.val.Data.Length);
- if (!dbus_message_iter_append_custom(iter, this.val.Name, data, this.val.Data.Length)) {
- throw new ApplicationException("Failed to append CUSTOM argument:" + val);
- }
- } finally {
- Marshal.FreeCoTaskMem(data);
- }
- }
-
- public static bool Suits(System.Type type)
- {
- switch (type.ToString()) {
- case "DBus.Custom":
- case "DBus.Custom&":
- return true;
- }
-
- return false;
- }
-
- public static void EmitMarshalIn(ILGenerator generator, Type type)
- {
- if (type.IsByRef) {
- generator.Emit(OpCodes.Ldobj, type);
- }
- }
-
- public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
- {
- generator.Emit(OpCodes.Unbox, type);
- generator.Emit(OpCodes.Ldobj, type);
- if (!isReturn) {
- generator.Emit(OpCodes.Stobj, type);
- }
- }
-
- public object Get()
- {
- return this.val;
- }
-
- public object Get(System.Type type)
- {
- switch (type.ToString()) {
- case "DBus.Custom":
- case "DBus.Custom&":
- return this.val;
- default:
- throw new ArgumentException("Cannot cast DBus.Type.Custom to type '" + type.ToString() + "'");
- }
- }
-
- [DllImport("dbus-1")]
- private extern static bool dbus_message_iter_get_custom(IntPtr iter,
- out string name,
- out IntPtr value,
- out int len);
-
- [DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_custom(IntPtr iter,
- string name,
- IntPtr data,
- int len);
- }
-}
public Double(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_double(iter);
+ dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_double(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append DOUBLE argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.Double dbus_message_iter_get_double(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out double value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_double(IntPtr iter, System.Double value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref double value);
}
}
public Int32(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_int32(iter);
+ dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_int32(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append INT32 argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.Int32 dbus_message_iter_get_int32(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int32 value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_int32(IntPtr iter, System.Int32 value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int32 value);
}
}
public Int64(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_int64(iter);
+ dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_int64(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append INT64 argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.Int64 dbus_message_iter_get_int64(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.Int64 value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_int64(IntPtr iter, System.Int64 value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.Int64 value);
}
}
+++ /dev/null
-using System;
-using System.Runtime.InteropServices;
-using System.Reflection.Emit;
-
-using DBus;
-
-namespace DBus.DBusType
-{
- /// <summary>
- /// Marks a "void"/"unset"/"nonexistent"/"null" argument.
- /// </summary>
- public class Nil : IDBusType
- {
- public const char Code = 'v';
-
- private Nil()
- {
- }
-
- public Nil(object nil, Service service)
- {
- }
-
- public Nil(IntPtr iter, Service service)
- {
- }
-
- public void Append(IntPtr iter)
- {
- if (!dbus_message_iter_append_nil(iter))
- throw new ApplicationException("Failed to append NIL argument");
- }
-
- public static bool Suits(System.Type type)
- {
- return false;
- }
-
- public static void EmitMarshalIn(ILGenerator generator, Type type)
- {
- if (type.IsByRef) {
- generator.Emit(OpCodes.Ldind_I1);
- }
- }
-
- public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
- {
- generator.Emit(OpCodes.Unbox, type);
- generator.Emit(OpCodes.Ldind_I1);
- if (!isReturn) {
- generator.Emit(OpCodes.Stind_I1);
- }
- }
-
- public object Get()
- {
- return null;
- }
-
- public object Get(System.Type type)
- {
- throw new ArgumentException("Cannot cast DBus.Type.Nil to type '" + type.ToString() + "'");
- }
-
- [DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_nil(IntPtr iter);
- }
-}
public ObjectPath(IntPtr iter, Service service)
{
-
- this.path = Marshal.PtrToStringAnsi(dbus_message_iter_get_object_path(iter));
+ IntPtr raw;
+
+ dbus_message_iter_get_basic (iter, out raw);
+
+ this.path = Marshal.PtrToStringAnsi (raw);
this.service = service;
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_object_path(iter, Marshal.StringToHGlobalAnsi(Path)))
+ IntPtr marshalVal = Marshal.StringToHGlobalAnsi (Path);
+
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal))
throw new ApplicationException("Failed to append OBJECT_PATH argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static IntPtr dbus_message_iter_get_object_path(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr path);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_object_path(IntPtr iter, IntPtr path);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr path);
}
}
public String(IntPtr iter, Service service)
{
- this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter));
+ IntPtr raw;
+
+ dbus_message_iter_get_basic (iter, out raw);
+
+ this.val = Marshal.PtrToStringAnsi (raw);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_string(iter, Marshal.StringToHGlobalAnsi(val)))
+ IntPtr marshalVal = Marshal.StringToHGlobalAnsi (val);
+
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal))
throw new ApplicationException("Failed to append STRING argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static IntPtr dbus_message_iter_get_string(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_string(IntPtr iter, IntPtr value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr value);
}
}
public UInt32(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_uint32(iter);
+ dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_uint32(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append UINT32 argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.UInt32 dbus_message_iter_get_uint32(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt32 value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_uint32(IntPtr iter, System.UInt32 value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt32 value);
}
}
public UInt64(IntPtr iter, Service service)
{
- this.val = dbus_message_iter_get_uint64(iter);
+ dbus_message_iter_get_basic (iter, out this.val);
}
public void Append(IntPtr iter)
{
- if (!dbus_message_iter_append_uint64(iter, val))
+ if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
throw new ApplicationException("Failed to append UINT64 argument:" + val);
}
}
[DllImport("dbus-1")]
- private extern static System.UInt64 dbus_message_iter_get_uint64(IntPtr iter);
+ private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt64 value);
[DllImport("dbus-1")]
- private extern static bool dbus_message_iter_append_uint64(IntPtr iter, System.UInt64 value);
+ private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt64 value);
}
}
$(srcdir)/Bus.cs \
$(srcdir)/BusDriver.cs \
$(srcdir)/Connection.cs \
- $(srcdir)/Custom.cs \
$(srcdir)/DBusException.cs \
$(srcdir)/Error.cs \
$(srcdir)/ErrorMessage.cs \
$(srcdir)/DBusType/Array.cs \
$(srcdir)/DBusType/Boolean.cs \
$(srcdir)/DBusType/Byte.cs \
- $(srcdir)/DBusType/Custom.cs \
- $(srcdir)/DBusType/Dict.cs \
$(srcdir)/DBusType/Double.cs \
$(srcdir)/DBusType/Int32.cs \
$(srcdir)/DBusType/Int64.cs \
- $(srcdir)/DBusType/Nil.cs \
$(srcdir)/DBusType/ObjectPath.cs \
$(srcdir)/DBusType/String.cs \
$(srcdir)/DBusType/UInt32.cs \
// This isn't used for now
uint flags = 0;
- if (dbus_bus_acquire_service(connection.RawConnection, name, flags, ref error) == -1) {
+ if (dbus_bus_request_name (connection.RawConnection, name, flags, ref error) == -1) {
throw new DBusException(error);
}
this.local = true;
}
- public static bool Exists(Connection connection, string name)
+ public static bool HasOwner(Connection connection, string name)
{
Error error = new Error();
error.Init();
- if (dbus_bus_service_exists(connection.RawConnection,
+ if (dbus_bus_name_has_owner(connection.RawConnection,
name,
ref error)) {
return true;
public static Service Get(Connection connection, string name)
{
- if (Exists(connection, name)) {
+ if (HasOwner(connection, name)) {
return new Service(name, connection);
} else {
- throw new ApplicationException("Service '" + name + "' does not exist.");
+ throw new ApplicationException("Name '" + name + "' does not exist.");
}
}
}
[DllImport("dbus-1")]
- private extern static int dbus_bus_acquire_service(IntPtr rawConnection,
- string serviceName,
- uint flags, ref Error error);
+ private extern static int dbus_bus_request_name(IntPtr rawConnection,
+ string serviceName,
+ uint flags, ref Error error);
[DllImport("dbus-1")]
- private extern static bool dbus_bus_service_exists(IntPtr rawConnection,
+ private extern static bool dbus_bus_name_has_owner(IntPtr rawConnection,
string serviceName,
ref Error error);
public class BusListener
{
- static void OnServiceOwnerChanged (string serviceName,
- string oldOwner,
- string newOwner)
+ static void OnNameOwnerChanged (string name,
+ string oldOwner,
+ string newOwner)
{
if (oldOwner == "")
Console.WriteLine ("{0} created by {1}",
- serviceName, newOwner);
+ name, newOwner);
else if (newOwner == "")
Console.WriteLine ("{0} released by {1}",
- serviceName, oldOwner);
+ name, oldOwner);
else
Console.WriteLine ("{0} transfered from {1} to {2}",
- serviceName, oldOwner, newOwner);
+ name, oldOwner, newOwner);
}
public static int Main (string [] args)
connection = Bus.GetSessionBus ();
BusDriver driver = BusDriver.New (connection);
- driver.ServiceOwnerChanged += new ServiceEventHandler (OnServiceOwnerChanged);
+ driver.NameOwnerChanged += new NameOwnerChangedHandler (OnNameOwnerChanged);
- Console.WriteLine ("Listening for service changes...");
+ Console.WriteLine ("Listening for name owner changes...");
Application.Run ();