2
using System.Runtime.InteropServices;
3
using System.Reflection.Emit;
7
namespace DBus.DBusType
12
public class ObjectPath : IDBusType
14
public const char Code = 'o';
15
private string path = null;
16
private object val = null;
17
private Service service = null;
23
public ObjectPath(object val, Service service)
26
this.service = service;
29
public ObjectPath(IntPtr iter, Service service)
33
dbus_message_iter_get_basic (iter, out raw);
35
this.path = Marshal.PtrToStringAnsi (raw);
36
this.service = service;
42
if (this.path == null && this.val != null) {
43
Handler handler = this.service.GetHandler(this.val);
44
this.path = handler.Path;
51
public void Append(IntPtr iter)
53
IntPtr marshalVal = Marshal.StringToHGlobalAnsi (Path);
55
bool success = dbus_message_iter_append_basic (iter, (int) Code, ref marshalVal);
56
Marshal.FreeHGlobal (marshalVal);
59
throw new ApplicationException("Failed to append OBJECT_PATH argument:" + val);
62
public static bool Suits(System.Type type)
64
object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), false);
65
if (attributes.Length == 1) {
72
public static void EmitMarshalIn(ILGenerator generator, Type type)
75
generator.Emit(OpCodes.Ldind_Ref);
79
public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
81
generator.Emit(OpCodes.Castclass, type);
83
generator.Emit(OpCodes.Stind_Ref);
89
throw new ArgumentException("Cannot call Get on an ObjectPath without specifying type.");
92
public object Get(System.Type type)
95
return this.service.GetObject(type, Path);
96
} catch(Exception ex) {
97
throw new ArgumentException("Cannot cast object pointed to by Object Path to type '" + type.ToString() + "': " + ex);
101
[DllImport("dbus-1")]
102
private extern static void dbus_message_iter_get_basic (IntPtr iter, out IntPtr path);
104
[DllImport("dbus-1")]
105
private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref IntPtr path);