summaryrefslogtreecommitdiffstats
path: root/mono/ProxyBuilder.cs
diff options
context:
space:
mode:
authorOwen Fraser-Green <owen@discobabe.net>2004-03-23 18:07:48 +0000
committerOwen Fraser-Green <owen@discobabe.net>2004-03-23 18:07:48 +0000
commit632d54e0dbf5e405258be7afffbaa48942c06cbc (patch)
tree0b3495f8a0753d427078a90e585dc53a2287200d /mono/ProxyBuilder.cs
parent0a673a8cd751d9eae14f3f5d0eeebf749b07bf09 (diff)
Added InterfaceProxy to Mono bindings to avoid having to generate a proxy for every registered object. Also added object_path functions to dbus-message.
Diffstat (limited to 'mono/ProxyBuilder.cs')
-rw-r--r--mono/ProxyBuilder.cs81
1 files changed, 37 insertions, 44 deletions
diff --git a/mono/ProxyBuilder.cs b/mono/ProxyBuilder.cs
index 8e170c74..06bdeecb 100644
--- a/mono/ProxyBuilder.cs
+++ b/mono/ProxyBuilder.cs
@@ -50,13 +50,13 @@ namespace DBus
this.service = service;
this.pathName = pathName;
this.type = type;
- this.introspector = new Introspector(type);
+ this.introspector = Introspector.GetIntrospector(type);
}
private void BuildMethod(MethodInfo method,
+ InterfaceProxy interfaceProxy,
ref TypeBuilder typeB,
FieldInfo serviceF,
- FieldInfo interfaceF,
FieldInfo pathF)
{
ParameterInfo[] pars = method.GetParameters();
@@ -95,7 +95,7 @@ namespace DBus
generator.Emit(OpCodes.Ldsfld, serviceF);
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Ldfld, pathF);
- generator.Emit(OpCodes.Ldsfld, interfaceF);
+ generator.Emit(OpCodes.Ldstr, interfaceProxy.InterfaceName);
generator.Emit(OpCodes.Ldstr, method.Name);
generator.Emit(OpCodes.Newobj, MethodCall_C);
generator.Emit(OpCodes.Stloc_0);
@@ -190,9 +190,9 @@ namespace DBus
}
}
- public void BuildConstructor(ref TypeBuilder typeB, FieldInfo serviceF, FieldInfo interfaceF, FieldInfo pathF)
+ public void BuildConstructor(ref TypeBuilder typeB, FieldInfo serviceF, FieldInfo pathF)
{
- Type[] pars = {typeof(Service), typeof(string), typeof(string)};
+ Type[] pars = {typeof(Service), typeof(string)};
ConstructorBuilder constructor = typeB.DefineConstructor(MethodAttributes.RTSpecialName |
MethodAttributes.Public,
CallingConventions.Standard, pars);
@@ -202,10 +202,8 @@ namespace DBus
generator.Emit(OpCodes.Call, this.introspector.Constructor);
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Stsfld, serviceF);
- generator.Emit(OpCodes.Ldarg_2);
- generator.Emit(OpCodes.Stsfld, interfaceF);
generator.Emit(OpCodes.Ldarg_0);
- generator.Emit(OpCodes.Ldarg_3);
+ generator.Emit(OpCodes.Ldarg_2);
generator.Emit(OpCodes.Stfld, pathF);
generator.Emit(OpCodes.Ret);
@@ -216,29 +214,28 @@ namespace DBus
// Build the type
TypeBuilder typeB = ServiceModuleBuilder.DefineType(ProxyName, TypeAttributes.Public, this.type);
- //type.AddInterfaceImplementation(typeof(IProxy));
FieldBuilder serviceF = typeB.DefineField("service",
typeof(Service),
FieldAttributes.Private |
FieldAttributes.Static);
- FieldBuilder interfaceF = typeB.DefineField("interfaceName",
- typeof(string),
- FieldAttributes.Private |
- FieldAttributes.Static);
FieldBuilder pathF = typeB.DefineField("pathName",
typeof(string),
FieldAttributes.Private);
- BuildConstructor(ref typeB, serviceF, interfaceF, pathF);
+ BuildConstructor(ref typeB, serviceF, pathF);
// Build the methods
- foreach (MethodInfo method in this.introspector.Methods) {
- BuildMethod(method, ref typeB, serviceF, interfaceF, pathF);
+ foreach (DictionaryEntry interfaceEntry in this.introspector.InterfaceProxies) {
+ InterfaceProxy interfaceProxy = (InterfaceProxy) interfaceEntry.Value;
+ foreach (DictionaryEntry methodEntry in interfaceProxy.Methods) {
+ MethodInfo method = (MethodInfo) methodEntry.Value;
+ BuildMethod(method, interfaceProxy, ref typeB, serviceF, pathF);
+ }
}
- Type [] parTypes = new Type[] {typeof(Service), typeof(string), typeof(string)};
- object [] pars = new object[] {Service, this.introspector.InterfaceName, pathName};
+ Type [] parTypes = new Type[] {typeof(Service), typeof(string)};
+ object [] pars = new object[] {Service, pathName};
Type proxyType = typeB.CreateType();
@@ -247,7 +244,7 @@ namespace DBus
// monodis. Note that in order for this to work you should copy
// the client assembly as a dll file so that monodis can pick it
// up.
- //ProxyAssembly.Save("proxy.dll");
+ ProxyAssembly.Save("proxy.dll");
ConstructorInfo constructor = proxyType.GetConstructor(parTypes);
object instance = constructor.Invoke(pars);
@@ -256,45 +253,41 @@ namespace DBus
private ModuleBuilder ServiceModuleBuilder
{
- get
- {
- if (Service.module == null) {
- Service.module = ProxyAssembly.DefineDynamicModule(Service.Name, "proxy.dll", true);
- }
-
- return Service.module;
+ get {
+ if (Service.module == null) {
+ Service.module = ProxyAssembly.DefineDynamicModule(Service.Name, "proxy.dll", true);
}
+
+ return Service.module;
+ }
}
private Service Service
{
- get
- {
- return this.service;
- }
+ get {
+ return this.service;
+ }
}
private string ProxyName
{
- get
- {
- return this.introspector.InterfaceName + ".Proxy";
- }
+ get {
+ return this.introspector.ToString() + ".Proxy";
+ }
}
private AssemblyBuilder ProxyAssembly
{
- get
- {
- if (this.proxyAssembly == null){
- AssemblyName assemblyName = new AssemblyName();
- assemblyName.Name = "DBusProxy";
- this.proxyAssembly = Thread.GetDomain().DefineDynamicAssembly(assemblyName,
- AssemblyBuilderAccess.RunAndSave);
- }
-
- return this.proxyAssembly;
+ get {
+ if (this.proxyAssembly == null){
+ AssemblyName assemblyName = new AssemblyName();
+ assemblyName.Name = "DBusProxy";
+ this.proxyAssembly = Thread.GetDomain().DefineDynamicAssembly(assemblyName,
+ AssemblyBuilderAccess.RunAndSave);
}
+
+ return this.proxyAssembly;
+ }
}
}
}