From f33453896716e69cacd0d065b7cc633258678946 Mon Sep 17 00:00:00 2001 From: Owen Fraser-Green Date: Wed, 24 Mar 2004 13:15:20 +0000 Subject: Made all DBusTypes take Service in the constructor because Array also needed it in the case of an array of OBJECT_PATH objects. --- mono/Arguments.cs | 16 +++++----------- mono/DBusType/Array.cs | 14 ++++++++++---- mono/DBusType/Boolean.cs | 4 ++-- mono/DBusType/Byte.cs | 4 ++-- mono/DBusType/Custom.cs | 4 ++-- mono/DBusType/Dict.cs | 4 ++-- mono/DBusType/Double.cs | 4 ++-- mono/DBusType/Int32.cs | 4 ++-- mono/DBusType/Int64.cs | 4 ++-- mono/DBusType/Nil.cs | 4 ++-- mono/DBusType/ObjectPath.cs | 19 ++++--------------- mono/DBusType/String.cs | 4 ++-- mono/DBusType/UInt32.cs | 4 ++-- mono/DBusType/UInt64.cs | 4 ++-- mono/ProxyBuilder.cs | 5 +++-- mono/Service.cs | 4 ++++ 16 files changed, 48 insertions(+), 54 deletions(-) (limited to 'mono') diff --git a/mono/Arguments.cs b/mono/Arguments.cs index 0df205c3..d5407a5d 100644 --- a/mono/Arguments.cs +++ b/mono/Arguments.cs @@ -74,17 +74,15 @@ namespace DBus // 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); } @@ -163,7 +161,7 @@ namespace DBus // 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 + "'"); @@ -254,17 +252,13 @@ namespace DBus { 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; } } diff --git a/mono/DBusType/Array.cs b/mono/DBusType/Array.cs index 3bce3afa..34a842c7 100644 --- a/mono/DBusType/Array.cs +++ b/mono/DBusType/Array.cs @@ -16,19 +16,23 @@ namespace DBus.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; @@ -38,8 +42,9 @@ namespace DBus.DBusType 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)); @@ -58,8 +63,9 @@ namespace DBus.DBusType } 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); } diff --git a/mono/DBusType/Boolean.cs b/mono/DBusType/Boolean.cs index ef8ed498..fa5e1bcf 100644 --- a/mono/DBusType/Boolean.cs +++ b/mono/DBusType/Boolean.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/DBusType/Byte.cs b/mono/DBusType/Byte.cs index eaffd26e..1e083a99 100644 --- a/mono/DBusType/Byte.cs +++ b/mono/DBusType/Byte.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/DBusType/Custom.cs b/mono/DBusType/Custom.cs index d3eb7629..92560649 100644 --- a/mono/DBusType/Custom.cs +++ b/mono/DBusType/Custom.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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; diff --git a/mono/DBusType/Dict.cs b/mono/DBusType/Dict.cs index e6fce159..bd649434 100644 --- a/mono/DBusType/Dict.cs +++ b/mono/DBusType/Dict.cs @@ -19,7 +19,7 @@ namespace DBus.DBusType { } - public Dict(IDictionary val) + public Dict(IDictionary val, Service service) { this.val = new Hashtable(); foreach (DictionaryEntry entry in val) { @@ -27,7 +27,7 @@ namespace DBus.DBusType } } - public Dict(IntPtr iter) + public Dict(IntPtr iter, Service service) { IntPtr dictIter = Marshal.AllocCoTaskMem(Arguments.DBusMessageIterSize); diff --git a/mono/DBusType/Double.cs b/mono/DBusType/Double.cs index d578822f..008f6824 100644 --- a/mono/DBusType/Double.cs +++ b/mono/DBusType/Double.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/DBusType/Int32.cs b/mono/DBusType/Int32.cs index b617a9a0..be78eba8 100644 --- a/mono/DBusType/Int32.cs +++ b/mono/DBusType/Int32.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/DBusType/Int64.cs b/mono/DBusType/Int64.cs index 0905af74..1cc79c7c 100644 --- a/mono/DBusType/Int64.cs +++ b/mono/DBusType/Int64.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/DBusType/Nil.cs b/mono/DBusType/Nil.cs index e39b64a9..a271db3d 100644 --- a/mono/DBusType/Nil.cs +++ b/mono/DBusType/Nil.cs @@ -17,11 +17,11 @@ namespace DBus.DBusType { } - public Nil(object nil) + public Nil(object nil, Service service) { } - public Nil(IntPtr iter) + public Nil(IntPtr iter, Service service) { } diff --git a/mono/DBusType/ObjectPath.cs b/mono/DBusType/ObjectPath.cs index 6e03e2d1..40460bbf 100644 --- a/mono/DBusType/ObjectPath.cs +++ b/mono/DBusType/ObjectPath.cs @@ -20,19 +20,16 @@ namespace DBus.DBusType { } - 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; } @@ -43,17 +40,13 @@ namespace DBus.DBusType 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); } @@ -90,10 +83,6 @@ namespace DBus.DBusType 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) { diff --git a/mono/DBusType/String.cs b/mono/DBusType/String.cs index 1eda1f25..bced310a 100644 --- a/mono/DBusType/String.cs +++ b/mono/DBusType/String.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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)); } diff --git a/mono/DBusType/UInt32.cs b/mono/DBusType/UInt32.cs index 9c0e350a..43753511 100644 --- a/mono/DBusType/UInt32.cs +++ b/mono/DBusType/UInt32.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/DBusType/UInt64.cs b/mono/DBusType/UInt64.cs index 2e474795..7bcccaee 100644 --- a/mono/DBusType/UInt64.cs +++ b/mono/DBusType/UInt64.cs @@ -18,12 +18,12 @@ namespace DBus.DBusType { } - 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); } diff --git a/mono/ProxyBuilder.cs b/mono/ProxyBuilder.cs index 06bdeecb..5bbf3e41 100644 --- a/mono/ProxyBuilder.cs +++ b/mono/ProxyBuilder.cs @@ -108,7 +108,7 @@ namespace DBus 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); } } @@ -145,7 +145,7 @@ namespace DBus 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(...)"); @@ -157,6 +157,7 @@ namespace DBus 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); } diff --git a/mono/Service.cs b/mono/Service.cs index 39dd4f45..16e52d19 100644 --- a/mono/Service.cs +++ b/mono/Service.cs @@ -75,6 +75,10 @@ namespace DBus internal Handler GetHandler(object handledObject) { + if (!registeredHandlers.Contains(handledObject)) { + throw new ArgumentException("No handler registered for object: " + handledObject); + } + return (Handler) registeredHandlers[handledObject]; } -- cgit