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.
This commit is contained in:
Joe Shaw 2005-01-25 19:47:13 +00:00
parent f4d4d5ace5
commit b0002eb697
20 changed files with 173 additions and 295 deletions

View file

@ -1,3 +1,49 @@
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

View file

@ -183,6 +183,12 @@ namespace DBus
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()
{
@ -217,7 +223,7 @@ namespace DBus
// Begin appending
public void InitAppending()
{
dbus_message_append_iter_init(message.RawMessage, appenderIter);
dbus_message_iter_init_append(message.RawMessage, appenderIter);
}
// Get the enumerator
@ -277,7 +283,7 @@ namespace DBus
}
[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);

View file

@ -3,7 +3,7 @@ namespace DBus
using System;
public delegate void ServiceEventHandler (string serviceName,
public delegate void NameOwnerChangedHandler (string name,
string oldOwner,
string newOwner);
@ -14,14 +14,14 @@ namespace DBus
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)
{

View file

@ -76,11 +76,11 @@ namespace DBus
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));
}
}
@ -192,6 +192,6 @@ namespace DBus
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);
}
}

View file

@ -1,18 +0,0 @@
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;
}
}
}

View file

@ -25,7 +25,7 @@ namespace DBus.DBusType
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;
}
@ -35,13 +35,13 @@ namespace DBus.DBusType
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];
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();
elements = new ArrayList ();
if (notEmpty) {
if (dbus_message_iter_get_arg_type (arrayIter) != 0) {
do {
object [] pars = new Object[2];
pars[0] = arrayIter;
@ -56,12 +56,13 @@ namespace DBus.DBusType
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) {
@ -72,7 +73,11 @@ namespace DBus.DBusType
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)
@ -123,19 +128,28 @@ namespace DBus.DBusType
}
[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_append_array(IntPtr iter,
IntPtr arrayIter,
int elementType);
private extern static bool dbus_message_iter_close_container (IntPtr iter,
IntPtr subIter);
[DllImport("dbus-1")]
private extern static bool dbus_message_iter_has_next(IntPtr iter);
private extern static int dbus_message_iter_get_element_type(IntPtr iter);
[DllImport("dbus-1")]
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);
}
}

View file

@ -25,12 +25,12 @@ namespace DBus.DBusType
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);
}
@ -78,9 +78,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -30,12 +30,12 @@ namespace DBus.DBusType
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);
}
@ -97,9 +97,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -1,109 +0,0 @@
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);
}
}

View file

@ -25,12 +25,12 @@ namespace DBus.DBusType
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);
}
@ -78,9 +78,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -25,12 +25,12 @@ namespace DBus.DBusType
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);
}
@ -85,9 +85,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -25,12 +25,12 @@ namespace DBus.DBusType
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);
}
@ -86,9 +86,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -1,68 +0,0 @@
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);
}
}

View file

@ -28,8 +28,11 @@ namespace DBus.DBusType
public ObjectPath(IntPtr iter, Service service)
{
IntPtr raw;
this.path = Marshal.PtrToStringAnsi(dbus_message_iter_get_object_path(iter));
dbus_message_iter_get_basic (iter, out raw);
this.path = Marshal.PtrToStringAnsi (raw);
this.service = service;
}
@ -47,7 +50,9 @@ namespace DBus.DBusType
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);
}
@ -91,9 +96,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -25,12 +25,18 @@ namespace DBus.DBusType
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);
}
@ -78,9 +84,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -25,12 +25,12 @@ namespace DBus.DBusType
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);
}
@ -87,9 +87,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -25,12 +25,12 @@ namespace DBus.DBusType
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);
}
@ -87,9 +87,9 @@ namespace DBus.DBusType
}
[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);
}
}

View file

@ -10,7 +10,6 @@ DBUS_SHARP_FILES= \
$(srcdir)/Bus.cs \
$(srcdir)/BusDriver.cs \
$(srcdir)/Connection.cs \
$(srcdir)/Custom.cs \
$(srcdir)/DBusException.cs \
$(srcdir)/Error.cs \
$(srcdir)/ErrorMessage.cs \
@ -31,12 +30,9 @@ DBUS_SHARP_FILES= \
$(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 \

View file

@ -38,7 +38,7 @@ namespace DBus
// 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);
}
@ -47,12 +47,12 @@ namespace DBus
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;
@ -66,10 +66,10 @@ namespace DBus
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.");
}
}
@ -184,12 +184,12 @@ namespace DBus
}
[DllImport("dbus-1")]
private extern static int dbus_bus_acquire_service(IntPtr rawConnection,
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);

View file

@ -7,19 +7,19 @@ namespace Foo
public class BusListener
{
static void OnServiceOwnerChanged (string serviceName,
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)
@ -30,9 +30,9 @@ namespace Foo
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 ();