summaryrefslogtreecommitdiffstats
path: root/mono/Introspector.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/Introspector.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/Introspector.cs')
-rw-r--r--mono/Introspector.cs127
1 files changed, 51 insertions, 76 deletions
diff --git a/mono/Introspector.cs b/mono/Introspector.cs
index c7b9d05b..8e97abc6 100644
--- a/mono/Introspector.cs
+++ b/mono/Introspector.cs
@@ -10,97 +10,72 @@ namespace DBus
internal class Introspector
{
private Type type;
- private string interfaceName;
+ private static Hashtable introspectors = new Hashtable();
+ private Hashtable interfaceProxies = null;
- public Introspector(Type type) {
- object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), true);
- if (attributes.Length != 1)
- throw new ApplicationException("Type '" + type + "' is not a D-BUS interface.");
-
- InterfaceAttribute interfaceAttribute = (InterfaceAttribute) attributes[0];
-
- this.interfaceName = interfaceAttribute.InterfaceName;
+ public static Introspector GetIntrospector(Type type)
+ {
+ if (!introspectors.Contains(type)) {
+ introspectors[type] = new Introspector(type);
+ }
+
+ return (Introspector) introspectors[type];
+ }
+
+ private Introspector(Type type)
+ {
+ interfaceProxies = new Hashtable();
+ AddType(type);
this.type = type;
}
- public string InterfaceName
+ private void AddType(Type type)
{
- get
- {
- return this.interfaceName;
- }
+ if (type == typeof(object)) {
+ // Base case
+ return;
+ }
+
+ object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), false);
+ if (attributes.Length >= 1) {
+ // This is a D-BUS interface so add it to the hashtable
+ InterfaceProxy interfaceProxy = InterfaceProxy.GetInterface(type);
+ interfaceProxies.Add(interfaceProxy.InterfaceName, interfaceProxy);
+ }
+
+ AddType(type.BaseType);
+ }
+
+ public InterfaceProxy GetInterface(string interfaceName) {
+ if (interfaceProxies.Contains(interfaceName)) {
+ return (InterfaceProxy) interfaceProxies[interfaceName];
+ } else {
+ return null;
+ }
}
- public ConstructorInfo Constructor
+ public Hashtable InterfaceProxies
{
- get
- {
- ConstructorInfo ret = this.type.GetConstructor(new Type[0]);
- if (ret != null) {
- return ret;
- } else {
- return typeof(object).GetConstructor(new Type[0]);
- }
- }
+ get {
+ return this.interfaceProxies;
+ }
}
- public IntrospectorMethods Methods
+ public ConstructorInfo Constructor
{
- get
- {
- return new IntrospectorMethods(this.type);
+ get {
+ ConstructorInfo ret = this.type.GetConstructor(new Type[0]);
+ if (ret != null) {
+ return ret;
+ } else {
+ return typeof(object).GetConstructor(new Type[0]);
}
+ }
}
- public class IntrospectorMethods : IEnumerable
+ public override string ToString()
{
- private Type type;
-
- public IntrospectorMethods(Type type)
- {
- this.type = type;
- }
-
- public IEnumerator GetEnumerator()
- {
- return new MethodEnumerator(this.type.GetMethods(BindingFlags.Public|BindingFlags.Instance).GetEnumerator());
- }
-
- private class MethodEnumerator : IEnumerator
- {
- private IEnumerator enumerator;
-
- public MethodEnumerator(IEnumerator enumerator)
- {
- this.enumerator = enumerator;
- }
-
- public bool MoveNext()
- {
- while (enumerator.MoveNext()) {
- MethodInfo method = (MethodInfo) enumerator.Current;
- object[] attributes = method.GetCustomAttributes(typeof(MethodAttribute), true);
- if (attributes.GetLength(0) > 0) {
- return true;
- }
- }
-
- return false;
- }
-
- public void Reset()
- {
- enumerator.Reset();
- }
-
- public object Current
- {
- get
- {
- return enumerator.Current;
- }
- }
- }
+ return this.type.ToString();
}
}
}