[gst-cvs] qt-gstreamer: Handle interfaces properly in Value.

George Kiagiadakis gkiagia at kemper.freedesktop.org
Sat Dec 18 02:52:23 PST 2010


Module: qt-gstreamer
Branch: master
Commit: b68c2396d8bc009cace13a07bd4d7e024af2df35
URL:    http://cgit.freedesktop.org/gstreamer/qt-gstreamer/commit/?id=b68c2396d8bc009cace13a07bd4d7e024af2df35

Author: George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
Date:   Thu Dec 16 12:53:36 2010 +0200

Handle interfaces properly in Value.

All interfaces that can be assigned to a GValue have an instantiatable
prerequisite which is the actual type stored inside the GValue.
Here, we make use of this invariant to find the proper vtable
that can be used to set/get the interface pointer to/from the GValue.

---

 src/QGlib/value.cpp      |   19 +++++++++++++++++++
 tests/auto/valuetest.cpp |   15 +++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/QGlib/value.cpp b/src/QGlib/value.cpp
index e4145c3..0ee7dd7 100644
--- a/src/QGlib/value.cpp
+++ b/src/QGlib/value.cpp
@@ -82,6 +82,25 @@ Dispatcher::Dispatcher()
 
 ValueVTable Dispatcher::getVTable(Type t) const
 {
+    //if the type is an interface, try to find its
+    //instantiatable prerequisite and get the vtable
+    //of this instantiatable type instead.
+    if (t.isInterface()) {
+        QList<Type> prerequisites = t.interfacePrerequisites();
+        Q_FOREACH(Type prereq, prerequisites) {
+            if (prereq.isInstantiatable()) {
+                t = prereq;
+            }
+        }
+
+        //Check if the prerequisite was found and
+        //bail out if not, since such interfaces
+        //are not compatible with GValue.
+        if (!t.isInstantiatable()) {
+            return ValueVTable();
+        }
+    }
+
     QReadLocker l(&lock);
 
     if (dispatchTable.contains(t)) {
diff --git a/tests/auto/valuetest.cpp b/tests/auto/valuetest.cpp
index 4161d3e..47ff9a4 100644
--- a/tests/auto/valuetest.cpp
+++ b/tests/auto/valuetest.cpp
@@ -36,6 +36,7 @@ private Q_SLOTS:
     void miniObjectTest();
     void capsTest();
     void valueTest();
+    void interfaceTest();
     void conversionsTest();
     void copyTest();
     void castTest();
@@ -144,6 +145,20 @@ void ValueTest::valueTest()
     QCOMPARE(v2.toByteArray(), QByteArray("foobar"));
 }
 
+void ValueTest::interfaceTest()
+{
+    QGlib::Value v;
+    v.init<QGst::ChildProxy>();
+    QCOMPARE(v.type(), QGlib::GetType<QGst::ChildProxy>());
+
+    QGst::ChildProxyPtr childProxy = QGst::Bin::create();
+    v.set(childProxy);
+
+    QGst::ChildProxyPtr cp2 = v.get<QGst::ChildProxyPtr>();
+    QVERIFY(!cp2.isNull());
+    QCOMPARE(static_cast<GstChildProxy*>(childProxy), static_cast<GstChildProxy*>(cp2));
+}
+
 void ValueTest::conversionsTest()
 {
     QGlib::Value v;





More information about the Gstreamer-commits mailing list