[Kde-bindings] playground/bindings/kimono

Richard Dale Richard_Dale at tipitina.demon.co.uk
Fri May 26 11:51:11 UTC 2006


SVN commit 544893 by rdale:

* Added code from Arno Rehn to access obtain the return value of
  a classes Emit() method as an interface and obtain the C++ signal 
  type signatures and set them up in HashTables with a top level
  table with the classes as keys, containing sub tables with the
  C++ signatures as keys which map onto the correponding C# 
  MethodInfo as a value

CCMAIL: kde-bindings at kde.org



 M  +11 -5     ChangeLog  
 M  +61 -1     qyoto/Qyoto.cs  


--- trunk/playground/bindings/kimono/ChangeLog #544892:544893
@@ -1,11 +1,17 @@
 2006-05-26  Richard Dale  <rdale at foton.es>
 
+	* Added code from Arno Rehn to access obtain the return value of
+	  a classes Emit() method as an interface and obtain the C++ signal 
+	  type signatures and set them up in HashTables with a top level
+	  table with the classes as keys, containing sub tables with the
+	  C++ signatures as keys which map onto the correponding C# 
+	  MethodInfo as a value
 	* Some fixes from Paolo Capriotti:
-	* Added fix for a crash in SmokeInvocation.cs when a class with
-	  virtual methods wasn't a subclass of Qt
-	* The code for emitting signals now works with Qt4
-	* The code in QObject.cs to set up the transparent proxy Q_EMIT 
-	  for an instance's signal interfaces now works.
+		* Added fix for a crash in SmokeInvocation.cs when a class with
+		  virtual methods wasn't a subclass of Qt
+		* The code for emitting signals now works with Qt4
+		* The code in QObject.cs to set up the transparent proxy Q_EMIT 
+		  for an instance's signal interfaces now works.
 
 2006-05-26  Richard Dale  <rdale at foton.es>
 
--- trunk/playground/bindings/kimono/qyoto/Qyoto.cs #544892:544893
@@ -1,14 +1,74 @@
 namespace Qt
 {
 	using System;
+	using System.Collections;
+	using System.Reflection;
 	using System.Runtime.InteropServices;
 	
 	public class Qyoto : System.Object
 	{
 		[DllImport("libqyoto", CharSet=CharSet.Ansi)]
 		public static extern void Init_qyoto();
+		
+		/// This Hashtable contains a list of classes with their Hashtables for slots. The class name is the key, the slot-hashtable the value.
+		public static Hashtable classes = new Hashtable();
+		
+		public static void GetSlotSignatures(Type t) {
+			
+			/// Remove the old object if it already exists
+			classes.Remove(t.Name);
+			
+			/// This Hashtable contains the slots of a class. The C++ type signature is the key, the appropriate C# MethodInfo the value.
+			Hashtable slots = new Hashtable();
+			
+			MethodInfo[] mis = t.GetMethods( BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic );
+			
+			foreach (MethodInfo mi in mis) {
+				object[] attributes = mi.GetCustomAttributes(typeof(Q_SLOT), false);
+				foreach (Q_SLOT attr in attributes) {
+					slots.Add(attr.Signature, mi);
+					break;
+				}
+			}
+			
+			classes.Add(t.Name, slots);
+		}
+		
+		public static string[] GetSignalSignatures(QObject o) {
+			Type iface;
+			try {
+				iface = GetSignalsInterface(o);
+			}
+			catch {
+				return null;
+			}
+			MethodInfo[] mis = iface.GetMethods();
+			
+			/// the interface has no signals...
+			if (mis.Length == 0)
+				return null;
+				
+			string[] signatures = new string[mis.Length];
+			int i = 0;
+			
+			foreach (MethodInfo mi in mis) {
+				object[] attributes = mi.GetCustomAttributes(typeof(Q_SIGNAL), false);
+				foreach (Q_SIGNAL attr in attributes) {
+					signatures[i] = attr.Signature;
+				}
+				i++;
+			}
+			
+			return signatures;
+		}
+		
+		public static Type GetSignalsInterface(QObject o) {
+			Type t = o.GetType();
+			MethodInfo mi = t.GetMethod("Emit", BindingFlags.Instance | BindingFlags.NonPublic);
+			return mi.ReturnType;
+		}
 	}
-
+	
 	[AttributeUsage( AttributeTargets.Class )]
 	class SmokeClass : Attribute
 	{



More information about the Kde-bindings mailing list