[Kde-bindings] playground/bindings/kimono

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue Jan 30 15:36:19 UTC 2007


SVN commit 628595 by rdale:

* Fixed regressions caused by adding signal return values
* Added a QDBusVariant class and marshalling for it
* The complexpong example still doesn't return a QDBusVariant value

CCMAIL: kde-bindings at kde.org



 M  +7 -1      ChangeLog  
 M  +1 -2      examples/qdbus/complexpingpong/complexping.cs  
 M  +9 -11     examples/qdbus/complexpingpong/complexpong.cs  
 M  +59 -33    handlers.cpp  
 A             qdbus/QDBusVariant.cs  
 M  +20 -27    qyoto.cpp  


--- trunk/playground/bindings/kimono/ChangeLog #628594:628595
@@ -1,5 +1,11 @@
-2007-28-01  Richard Dale  <rdale at foton.es>
+2007-30-01  Richard Dale  <rdale at foton.es>
 
+	* Fixed regressions caused by adding signal return values
+	* Added a QDBusVariant class and marshalling for it
+	* The complexpong example still doesn't return a QDBusVariant value
+
+2007-29-01  Richard Dale  <rdale at foton.es>
+
 	* Added reply values when emitting signals
 	* Some static methods were being dropped because they had the same
 	  name as property names. So make the static methods start with a
--- trunk/playground/bindings/kimono/examples/qdbus/complexpingpong/complexping.cs #628594:628595
@@ -22,7 +22,6 @@
 
 using Qyoto;
 using System;
-using System.Collections.Generic;
 
 class Ping : QObject
 {
@@ -47,7 +46,7 @@
         Connect(iface, SIGNAL("aboutToQuit()"), QCoreApplication.Instance(), SLOT("quit()"));
 
         while (true) {
-            Console.WriteLine("Ask your question: ");
+            Console.Write("Ask your question: ");
 
             string line = Console.ReadLine().Trim();
 
--- trunk/playground/bindings/kimono/examples/qdbus/complexpingpong/complexpong.cs #628594:628595
@@ -52,25 +52,24 @@
         QTimer.singleShot(0, QCoreApplication.Instance(), SLOT("quit()"));
     }
 
-    [Q_SLOT("QDBusVariant query(QString)")]
-    public QVariant query(string query)
+    [Q_SLOT]
+    public QDBusVariant query(string query)
     {
-        Console.WriteLine("Pong Received a query: {}", query);
-
         string q = query.ToLower();
+
         if (q == "hello")
-            return new QVariant("World");
+            return new QDBusVariant(new QVariant("World"));
         if (q == "ping")
-            return new QVariant("Pong");
+            return new QDBusVariant(new QVariant("Pong"));
         if (q == "the answer to life, the universe and everything")
-            return new QVariant(42);
+            return new QDBusVariant(new QVariant(42));
         if (q.IndexOf("unladen swallow") != -1) {
             if (q.IndexOf("european") != -1)
-                return new QVariant(11.0);
-            return new QVariant(new QByteArray("african or european?"));
+                return new QDBusVariant(new QVariant(11.0));
+            return new QDBusVariant(new QVariant(new QByteArray("african or european?")));
         }
 
-        return new QVariant("Sorry, I don't know the answer");
+        return new QDBusVariant(new QVariant("Sorry, I don't know the answer"));
     }
 
     public static int Main(string[] args) {
@@ -79,7 +78,6 @@
         QObject obj = new QObject();
         Pong pong = new Pong(obj);
         pong.Connect(app, SIGNAL("aboutToQuit()"), SIGNAL("aboutToQuit()"));
-//        pong.SetProperty("value", "initial value");
         pong.value = "initial value";
         QDBusConnection.SessionBus().RegisterObject("/", obj);
 
--- trunk/playground/bindings/kimono/handlers.cpp #628594:628595
@@ -418,39 +418,6 @@
 	return smoke->binding->className(classId);
 }
 
-/*static bool
-isPrimitive(const char* type) {
-	if (type == "void") {
-		return true;
-	} else if (type == "bool") {
-		return true;
-	} else if (type == "int") {
-		return true;
-	} else if (type == "long") {
-		return true;
-	} else if (type == "uint") {
-		return true;
-	} else if (type == "ulong") {
-		return true;
-	} else if (type == "short") {
-		return true;
-	} else if (type == "ushort") {
-		return true;
-	} else if (type == "byte") {
-		return true;
-	} else if (type == "sbyte") {
-		return true;
-	} else if (type == "double") {
-		return true;
-	} else if (type == "float") {
-		return true;
-	} else if (type == "char") {
-		return true;
-	}
-	
-	return false;
-}*/
-
 bool
 matches_arg(Smoke *smoke, Smoke::Index meth, Smoke::Index argidx, const char *argtype)
 {
@@ -959,7 +926,64 @@
 		break;
 	}
 }
+#include <QtDBus/qdbusextratypes.h>
 
+void marshall_QDBusVariant(Marshall *m) {
+	switch(m->action()) {
+	case Marshall::FromObject: 
+	{
+		if (m->var().s_class == 0) {
+			m->item().s_class = 0;
+			return;
+		}
+
+		smokeqyoto_object *o = value_obj_info(m->var().s_class);
+		if (!o || !o->ptr) {
+			if (m->type().isRef()) {
+				m->unsupported();
+			}
+		    m->item().s_class = 0;
+		    break;
+		}
+		m->item().s_class = o->ptr;
+		break;
+	}
+
+	case Marshall::ToObject: 
+	{
+		if (m->item().s_voidp == 0) {
+			m->var().s_voidp = 0;
+		    break;
+		}
+
+		void *p = m->item().s_voidp;
+		void * obj = getPointerObject(p);
+		if(obj != 0) {
+			m->var().s_voidp = obj;
+		    break;
+		}
+		smokeqyoto_object  * o = alloc_smokeqyoto_object(false, m->smoke(), m->smoke()->idClass("QVariant"), p);
+		
+		obj = set_obj_info("Qyoto.QDBusVariant", o);
+		if (do_debug & qtdb_calls) {
+			printf("allocating %s %p -> %p\n", "QDBusVariant", o->ptr, (void*)obj);
+		}
+
+		if (m->type().isStack()) {
+		    o->allocated = true;
+			// Keep a mapping of the pointer so that it is only wrapped once
+		    mapPointer(obj, o, o->classId, 0);
+		}
+		
+		m->var().s_class = obj;
+	}
+	
+	default:
+		m->unsupported();
+		break;
+    }
+}
+
 void marshall_QMapintQVariant(Marshall *m) {
 	switch(m->action()) {
 		case Marshall::FromObject: 
@@ -1393,6 +1417,8 @@
     { "int*", marshall_intR },
     { "char*", marshall_charP },
     { "char**", marshall_charP_array },
+    { "QDBusVariant", marshall_QDBusVariant },
+    { "QDBusVariant&", marshall_QDBusVariant },
     { "QStringList", marshall_QStringList },
     { "QStringList&", marshall_QStringList },
     { "QStringList*", marshall_QStringList },
--- trunk/playground/bindings/kimono/qyoto.cpp #628594:628595
@@ -732,6 +732,8 @@
 		// qt_metacall()
 		void * ptr = o[0];
 		smokeStackToQtStack(_stack, o, 1, _replyType);
+			printf("SlotReturnValue o[0]: %p\n", o[0]);
+
 		// Only if the zeroth element of the arrary of 'void*'s passed to qt_metacall()
 		// contains an address, is the return value of the slot needed.
 		if (ptr != 0) {
@@ -775,7 +777,7 @@
     Smoke::StackItem *_sp;
     Smoke::Stack _stack;
 public:
-    const MocArgument &arg() { return _args[_cur]; }
+    const MocArgument &arg() { return _args[_cur + 1]; }
     SmokeType type() { return arg().st; }
     Marshall::Action action() { return Marshall::ToObject; }
     Smoke::StackItem &item() { return _stack[_cur]; }
@@ -786,7 +788,7 @@
 		qFatal("Cannot handle '%s' as slot argument\n", type().name());
 	}
 	void copyArguments() {
-		smokeStackFromQtStack(_stack, _o + 1, _items, _args);
+		smokeStackFromQtStack(_stack, _o + 1, _items, _args + 1);
 	}
 	void invokeSlot() {
 		if (_called) return;
@@ -795,9 +797,9 @@
 		(*InvokeCustomSlot)(_obj, _slotname, _sp, ret);
 		
 		if (_mocret[0].argType != xmoc_void) {
-#ifdef DEBUG
+// #ifdef DEBUG
 			printf("CREATE SlotReturnValue()\n");
-#endif
+// #endif
 			SlotReturnValue r(_o, ret, _mocret);
 		}
 	}
@@ -817,7 +819,7 @@
 	}
 
     InvokeSlot(void * obj, const char * slotname, int items, MocArgument * args, void** o) :
-    _obj(obj), _slotname(slotname), _items(items), _args(args + 1), _o(o), _cur(-1), _called(false)
+    _obj(obj), _slotname(slotname), _items(items), _args(args), _o(o), _cur(-1), _called(false)
     {
 		_sp = new Smoke::StackItem[_items];
 		_stack = new Smoke::StackItem[_items];
@@ -1136,43 +1138,34 @@
 	if (replyType.isEmpty()) {
 		replyType = "void";
 	}
+	QStringList args(replyType);
 
 	QString argStr = rx1.cap(1);
 
-	QStringList args;
-	args << argStr.split(",");
-	if (args[0] == "") {
-       args[0] = replyType;
-	} else {
-		args.prepend(replyType);
+    if (!argStr.isEmpty()) {
+		args << argStr.split(",");
 	}
 
 	number = args.size() - 1;
 
 	MocArgument * mocargs = new MocArgument[args.size()];
 	int i = 0;
-	for (QStringList::Iterator it = args.begin(); it != args.end(); ++it) {
+	for (	QStringList::Iterator it = args.begin(); 
+			it != args.end(); 
+			++it, i++ ) 
+	{
 		QString a = (*it);
 
-		if (a == "QDBusVariant") {
-			a = "QVariant";
-		}
-
 		if (a == "void" || a == "" || a == " ") {
 			mocargs[i].argType = xmoc_void;
-			continue;
-		}
+		} else {
+			a.replace(QRegExp("^const\\s+"), "");
+			a = (rx2.indexIn(a) == -1) ? "ptr" : rx2.cap(1);
 
-		a.replace(QRegExp("^const\\s+"), "");
-		a = (rx2.indexIn(a) == -1) ? "ptr" : rx2.cap(1);
-
-		QByteArray name = (*it).toLatin1();
-		if (name == "QDBusVariant") {
-			name = "QVariant";
+			QByteArray name = (*it).toLatin1();
+			QByteArray static_type = a.toLatin1();
+			bool valid = setMocType(mocargs, i, name.constData(), static_type.constData());
 		}
-		QByteArray static_type = a.toLatin1();
-		bool valid = setMocType(mocargs, i, name.constData(), static_type.constData());
-		i++;
     }
 
 	return mocargs;



More information about the Kde-bindings mailing list