// Append an argument
public void Append(DBusType.IDBusType dbusType)
{
- if (dbusType.GetType() == typeof(DBusType.ObjectPath)) {
- ((DBusType.ObjectPath) dbusType).SetService(message.Service);
- }
dbusType.Append(appenderIter);
}
// Append an argument of the specified type
private void AppendType(Type type, object val)
{
- object [] pars = new Object[1];
+ object [] pars = new Object[2];
pars[0] = val;
+ pars[1] = message.Service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(MatchType(type), pars);
Append(dbusType);
}
// Get the appropriate constructor for a D-BUS type
public static ConstructorInfo GetDBusTypeConstructor(Type dbusType, Type type)
{
- ConstructorInfo constructor = dbusType.GetConstructor(new Type[] {type.UnderlyingSystemType});
+ ConstructorInfo constructor = dbusType.GetConstructor(new Type[] {type.UnderlyingSystemType, typeof(Service)});
if (constructor == null)
throw new ArgumentException("There is no valid constructor for '" + dbusType + "' from type '" + type + "'");
{
get
{
- object [] pars = new Object[1];
+ object [] pars = new Object[2];
pars[0] = iter;
+ pars[1] = arguments.message.Service;
Type type = (Type) DBusTypes[(char) dbus_message_iter_get_arg_type(iter)];
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(type, pars);
- // Special case for ObjectPath
- if (type == typeof(DBusType.ObjectPath)) {
- ((DBusType.ObjectPath) dbusType).SetService(arguments.message.Service);
- }
-
return dbusType;
}
}
private System.Array val;
private ArrayList elements;
private Type elementType;
+ private Service service = null;
private Array()
{
}
- public Array(System.Array val)
+ public Array(System.Array val, Service service)
{
this.val = val;
this.elementType = Arguments.MatchType(val.GetType().UnderlyingSystemType);
+ this.service = service;
}
- public Array(IntPtr iter)
+ public Array(IntPtr iter, Service service)
{
+ this.service = service;
+
IntPtr arrayIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
int elementTypeCode;
elements = new ArrayList();
do {
- object [] pars = new Object[1];
+ object [] pars = new Object[2];
pars[0] = arrayIter;
+ pars[1] = service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
elements.Add(dbusType);
} while (dbus_message_iter_next(arrayIter));
}
foreach (object element in this.val) {
- object [] pars = new Object[1];
+ object [] pars = new Object[2];
pars[0] = element;
+ pars[1] = this.service;
DBusType.IDBusType dbusType = (DBusType.IDBusType) Activator.CreateInstance(elementType, pars);
dbusType.Append(arrayIter);
}
{
}
- public Boolean(System.Boolean val)
+ public Boolean(System.Boolean val, Service service)
{
this.val = val;
}
- public Boolean(IntPtr iter)
+ public Boolean(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_boolean(iter);
}
{
}
- public Byte(System.Byte val)
+ public Byte(System.Byte val, Service service)
{
this.val = val;
}
- public Byte(IntPtr iter)
+ public Byte(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_byte(iter);
}
{
}
- public Custom(DBus.Custom val)
+ public Custom(DBus.Custom val, Service service)
{
this.val = val;
}
- public Custom(IntPtr iter)
+ public Custom(IntPtr iter, Service service)
{
string name;
IntPtr value;
{
}
- public Dict(IDictionary val)
+ public Dict(IDictionary val, Service service)
{
this.val = new Hashtable();
foreach (DictionaryEntry entry in val) {
}
}
- public Dict(IntPtr iter)
+ public Dict(IntPtr iter, Service service)
{
IntPtr dictIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize);
{
}
- public Double(System.Double val)
+ public Double(System.Double val, Service service)
{
this.val = val;
}
- public Double(IntPtr iter)
+ public Double(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_double(iter);
}
{
}
- public Int32(System.Int32 val)
+ public Int32(System.Int32 val, Service service)
{
this.val = val;
}
- public Int32(IntPtr iter)
+ public Int32(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_int32(iter);
}
{
}
- public Int64(System.Int64 val)
+ public Int64(System.Int64 val, Service service)
{
this.val = val;
}
- public Int64(IntPtr iter)
+ public Int64(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_int64(iter);
}
{
}
- public Nil(object nil)
+ public Nil(object nil, Service service)
{
}
- public Nil(IntPtr iter)
+ public Nil(IntPtr iter, Service service)
{
}
{
}
- public ObjectPath(object val)
+ public ObjectPath(object val, Service service)
{
this.val = val;
+ this.service = service;
}
- public ObjectPath(IntPtr iter)
+ public ObjectPath(IntPtr iter, Service service)
{
this.pathName = Marshal.PtrToStringAnsi(dbus_message_iter_get_object_path(iter));
- }
-
- public void SetService(Service service)
- {
this.service = service;
}
Handler handler = this.service.GetHandler(this.val);
this.pathName = handler.PathName;
}
-
+
return this.pathName;
}
}
public void Append(IntPtr iter)
{
- if (PathName == null) {
- throw new ApplicationException("Unable to append ObjectPath before calling SetService()");
- }
-
if (!dbus_message_iter_append_object_path(iter, Marshal.StringToHGlobalAnsi(PathName)))
throw new ApplicationException("Failed to append OBJECT_PATH argument:" + val);
}
public object Get(System.Type type)
{
- if (this.service == null) {
- throw new ApplicationException("Unable to get ObjectPath before calling SetService()");
- }
-
try {
return this.service.GetObject(type, PathName);
} catch(Exception ex) {
{
}
- public String(string val)
+ public String(string val, Service service)
{
this.val = val;
}
- public String(IntPtr iter)
+ public String(IntPtr iter, Service service)
{
this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter));
}
{
}
- public UInt32(System.UInt32 val)
+ public UInt32(System.UInt32 val, Service service)
{
this.val = val;
}
- public UInt32(IntPtr iter)
+ public UInt32(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_uint32(iter);
}
{
}
- public UInt64(System.UInt64 val)
+ public UInt64(System.UInt64 val, Service service)
{
this.val = val;
}
- public UInt64(IntPtr iter)
+ public UInt64(IntPtr iter, Service service)
{
this.val = dbus_message_iter_get_uint64(iter);
}
for (int parN = 0; parN < pars.Length; parN++) {
ParameterInfo par = pars[parN];
if (!par.IsOut) {
- EmitIn(generator, par.ParameterType, parN);
+ EmitIn(generator, par.ParameterType, parN, serviceF);
}
}
typeB.DefineMethodOverride(methodBuilder, method);
}
- private void EmitIn(ILGenerator generator, Type parType, int parN)
+ private void EmitIn(ILGenerator generator, Type parType, int parN, FieldInfo serviceF)
{
Type inParType = Arguments.MatchType(parType);
//generator.EmitWriteLine("methodCall.Arguments.Append(...)");
object[] pars = new object[] {generator, parType};
inParType.InvokeMember("EmitMarshalIn", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, pars, null);
+ generator.Emit(OpCodes.Ldsfld, serviceF);
generator.Emit(OpCodes.Newobj, Arguments.GetDBusTypeConstructor(inParType, parType));
generator.EmitCall(OpCodes.Callvirt, Arguments_AppendMI, null);
}
internal Handler GetHandler(object handledObject)
{
+ if (!registeredHandlers.Contains(handledObject)) {
+ throw new ArgumentException("No handler registered for object: " + handledObject);
+ }
+
return (Handler) registeredHandlers[handledObject];
}