Made all DBusTypes take Service in the constructor because Array also needed it in...
authorOwen Fraser-Green <owen@discobabe.net>
Wed, 24 Mar 2004 13:15:20 +0000 (13:15 +0000)
committerOwen Fraser-Green <owen@discobabe.net>
Wed, 24 Mar 2004 13:15:20 +0000 (13:15 +0000)
16 files changed:
mono/Arguments.cs
mono/DBusType/Array.cs
mono/DBusType/Boolean.cs
mono/DBusType/Byte.cs
mono/DBusType/Custom.cs
mono/DBusType/Dict.cs
mono/DBusType/Double.cs
mono/DBusType/Int32.cs
mono/DBusType/Int64.cs
mono/DBusType/Nil.cs
mono/DBusType/ObjectPath.cs
mono/DBusType/String.cs
mono/DBusType/UInt32.cs
mono/DBusType/UInt64.cs
mono/ProxyBuilder.cs
mono/Service.cs

index 0df205c..d5407a5 100644 (file)
@@ -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;
          }
       }
index 3bce3af..34a842c 100644 (file)
@@ -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);
       }
index ef8ed49..fa5e1bc 100644 (file)
@@ -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);
     }
index eaffd26..1e083a9 100644 (file)
@@ -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);
     }
index d3eb762..9256064 100644 (file)
@@ -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;
index e6fce15..bd64943 100644 (file)
@@ -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);
       
index d578822..008f682 100644 (file)
@@ -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);
     }
index b617a9a..be78eba 100644 (file)
@@ -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);
     }
index 0905af7..1cc79c7 100644 (file)
@@ -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);
     }
index e39b64a..a271db3 100644 (file)
@@ -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)
     {
     }
     
index 6e03e2d..40460bb 100644 (file)
@@ -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) {
index 1eda1f2..bced310 100644 (file)
@@ -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));
     }
index 9c0e350..4375351 100644 (file)
@@ -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);
     }
index 2e47479..7bcccae 100644 (file)
@@ -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);
     }
index 06bdeec..5bbf3e4 100644 (file)
@@ -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);
     }
index 39dd4f4..16e52d1 100644 (file)
@@ -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];
     }