summaryrefslogtreecommitdiffstats
path: root/mono/InterfaceProxy.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/InterfaceProxy.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/InterfaceProxy.cs')
-rw-r--r--mono/InterfaceProxy.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/mono/InterfaceProxy.cs b/mono/InterfaceProxy.cs
new file mode 100644
index 00000000..6ccc9636
--- /dev/null
+++ b/mono/InterfaceProxy.cs
@@ -0,0 +1,86 @@
+namespace DBus
+{
+ using System;
+ using System.Collections;
+ using System.Reflection;
+
+ internal class InterfaceProxy
+ {
+ private static Hashtable interfaceProxies = new Hashtable();
+ private Hashtable methods = null;
+
+ private string interfaceName;
+
+ private InterfaceProxy(Type type)
+ {
+ object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), true);
+ InterfaceAttribute interfaceAttribute = (InterfaceAttribute) attributes[0];
+ this.interfaceName = interfaceAttribute.InterfaceName;
+ AddMethods(type);
+ }
+
+ private void AddMethods(Type type)
+ {
+ this.methods = new Hashtable();
+ foreach (MethodInfo method in type.GetMethods(BindingFlags.Public |
+ BindingFlags.Instance |
+ BindingFlags.DeclaredOnly)) {
+ object[] attributes = method.GetCustomAttributes(typeof(MethodAttribute), true);
+ if (attributes.GetLength(0) > 0) {
+ methods.Add(GetKey(method), method);
+ }
+ }
+ }
+
+
+ public static InterfaceProxy GetInterface(Type type)
+ {
+ if (!interfaceProxies.Contains(type)) {
+ interfaceProxies[type] = new InterfaceProxy(type);
+ }
+
+ return (InterfaceProxy) interfaceProxies[type];
+ }
+
+ public bool HasMethod(string key)
+ {
+ return this.Methods.Contains(key);
+ }
+
+ public MethodInfo GetMethod(string key)
+ {
+ return (MethodInfo) this.Methods[key];
+ }
+
+ private string GetKey(MethodInfo method)
+ {
+ ParameterInfo[] pars = method.GetParameters();
+ string key = method.Name + " ";
+
+ foreach (ParameterInfo par in pars) {
+ if (!par.IsOut) {
+ Type dbusType = Arguments.MatchType(par.ParameterType);
+ key += Arguments.GetCode(dbusType);
+ }
+ }
+
+ return key;
+ }
+
+ public Hashtable Methods
+ {
+ get {
+ return this.methods;
+ }
+ }
+
+ public string InterfaceName
+ {
+ get {
+ return this.interfaceName;
+ }
+ }
+ }
+}
+
+