[Kde-bindings] KDE/kdebindings/php/phpqt

Richard Dale Richard_Dale at tipitina.demon.co.uk
Wed Feb 3 03:54:04 UTC 2010


SVN commit 1084419 by rdale:

* Make a first pass at getting the PHPQt bindings working with the more module
Smoke libraries. Needs more work as a single PHPQt::smoke() is a bit hard
wired all over the place.

CCMAIL: kde-bindings at kde.org


 M  +3 -3      CMakeLists.txt  
 M  +10 -3     src/CMakeLists.txt  
 M  +14 -20    src/phpqt_internals.cpp  
 M  +3 -2      src/phpqt_internals.h  
 M  +39 -31    src/smokephp.cpp  
 M  +40 -0     src/smokephp.h  
 M  +2 -2      src/unittests.cpp  
 M  +1 -1      src/zphp/z_extension.cpp  
 M  +2 -2      src/zphp/z_handler.cpp  
 M  +2 -2      tests/config.php.conf  


--- trunk/KDE/kdebindings/php/phpqt/CMakeLists.txt #1084418:1084419
@@ -53,11 +53,11 @@
   MESSAGE(STATUS "phpunit found: configuring for tests")
   ENABLE_TESTING()
   SET(RUNTIME_OUTPUT_DIRECTORY_ORIG)
-  SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}"/tests/")
+  SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BUILD_DIR}php/phpqt"/tests/")
 
-  CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/tests/config.php.conf ${CMAKE_BUILD_DIR}config.php @ONLY )
+  CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/tests/config.php.conf ${CMAKE_BUILD_DIR}php/phpqt/tests/config.php @ONLY )
   FOREACH(TEST_CASE ${PHPQT_TEST_FILES} )
-    CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/tests/${TEST_CASE} ${CMAKE_BUILD_DIR}${TEST_CASE} COPYONLY )
+    CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/tests/${TEST_CASE} ${CMAKE_BUILD_DIR}php/phpqt/tests/${TEST_CASE} COPYONLY )
     ADD_TEST( ${TEST_CASE} ${PHPUNIT_EXECUTABLE} --log-tap ${TEST_CASE}.log ${TEST_CASE} )
     MESSAGE(STATUS "added "${TEST_CASE} )
   ENDFOREACH(TEST_CASE)
--- trunk/KDE/kdebindings/php/phpqt/src/CMakeLists.txt #1084418:1084419
@@ -65,9 +65,16 @@
 add_library(php_qt MODULE ${phpqt_LIB_SRCS})
 
 target_link_libraries(php_qt 
-			     ${QT_QTCORE_LIBRARY} 
-			     ${QT_QTTEST_LIBRARY}
-			     smokeqt
+                        ${QT_QTCORE_LIBRARY} 
+                        ${QT_QTTEST_LIBRARY}
+                        smokeqtcore 
+                        smokeqtgui 
+                        smokeqtxml 
+                        smokeqtopengl 
+                        smokeqtsql 
+                        smokeqtnetwork 
+                        smokeqtdbus 
+                        smokeqtsvg
 )
 
 if(${CMAKE_MODULE_LINKER_FLAGS} MATCHES "no-undefined")
--- trunk/KDE/kdebindings/php/phpqt/src/phpqt_internals.cpp #1084418:1084419
@@ -37,7 +37,7 @@
 
 extern zend_object_handlers php_qt_handler;
 extern zend_class_entry* qstring_ce;
-extern Smoke::Index cachedQObjectSmokeId;
+extern Smoke::ModuleIndex cachedQObjectSmokeId;
 
 zend_class_entry* qobject_ce;
 QHash<const void*, smokephp_object*> SmokeQtObjects;
@@ -318,7 +318,7 @@
             * We go through QMetaObject::activate, because it can either be connected to a C++ Slot or a user space Slot
             * cast to a QObject using smoke cast
             * */
-            QObject* ptr = (QObject*) o->smoke()->cast( const_cast<void*>( o->ptr() ), o->classId(), cachedQObjectSmokeId );
+            QObject* ptr = (QObject*) o->smoke()->cast( const_cast<void*>( o->ptr() ), Smoke::ModuleIndex(o->smoke(), o->classId()), cachedQObjectSmokeId );
             void *_b[] = { 0, ((void**) args[3].s_voidp)[1] };
             QMetaObject::activate( ptr, staticMetaObject, 0, _b );
             return true; // success
@@ -328,19 +328,13 @@
 }
 
 // time critical
-extern Smoke::Index cachedQObjectSmokeId;
-bool PHPQt::isQObject(const Smoke::Index classId)
+extern Smoke::ModuleIndex cachedQObjectSmokeId;
+bool PHPQt::isQObject(const Smoke::ModuleIndex classId)
 {
     if( classId == cachedQObjectSmokeId )
         return true;
 
-    const Smoke* smoke = PHPQt::smoke();
-    for(Smoke::Index *p = smoke->inheritanceList + smoke->classes[classId].parents; *p; p++)
-    {
-        if( PHPQt::isQObject(*p) )
-            return true;
-    }
-    return false;
+    return Smoke::isDerivedFrom(classId, cachedQObjectSmokeId);
 }
 
 // time critical
@@ -454,7 +448,7 @@
 SmokeBinding *qt_binding;
 Smoke::Index PHPQt::findMethod( const char* className, const char* methodName, const int argc, zval** args )
 {
-    Smoke::ModuleIndex method = PHPQt::smoke()->findMethod(className, methodName); // qt_Smoke->methods
+    Smoke::ModuleIndex method = PHPQt::smoke()->findMethod(className, methodName); // qtcore_Smoke->methods
     Smoke::Index i = PHPQt::smoke()->methodMaps[ method.index ].method;
 
     if(i <= 0)
@@ -536,14 +530,14 @@
     return i;
 }
 
-void PHPQt::callCppMethod(void *obj, const Smoke::Index method, Smoke::Stack qargs)
+void PHPQt::callCppMethod(void *obj, const Smoke::ModuleIndex& method, Smoke::Stack qargs)
 {
-    const Smoke::Method *m = PHPQt::smoke()->methods + method;
-    const Smoke::ClassFn fn = PHPQt::smoke()->classes[m->classId].classFn;
+    const Smoke::Method *m = method.smoke->methods + method.index;
+    const Smoke::ClassFn fn = method.smoke->classes[m->classId].classFn;
     fn(m->method, obj, qargs);
 }
 
-extern Smoke* qt_Smoke;
+extern Smoke* qtcore_Smoke;
 QList<MocArgument*> PHPQt::QtToMoc( Smoke* smoke, void** a, const QList<QByteArray> methodTypes )
 {
     static QRegExp * rx = 0;
@@ -592,7 +586,7 @@
                 typeName += "*";
             }
             typeId = smoke->idType( typeName.constData() );
-            smoke = qt_Smoke;
+            smoke = qtcore_Smoke;
             if( typeId == 0 ) {
                 pNotice() << "Cannot handle " << typeName << " as slot argument";
                 return result;
@@ -613,10 +607,10 @@
     return result;
 }
 
-inline Smoke* PHPQt::smoke(){ return qt_Smoke; }
+Smoke* PHPQt::smoke(){ return qtcore_Smoke; }
 
-extern SmokeBinding* qt_binding;
-SmokeBinding* PHPQt::binding(){ return qt_binding; }
+extern SmokeBinding* qtcore_binding;
+SmokeBinding* PHPQt::binding(){ return qtcore_binding; }
 
 const char* PHPQt::findRealMethodName(const char* methodName)
 {
--- trunk/KDE/kdebindings/php/phpqt/src/phpqt_internals.h #1084418:1084419
@@ -88,7 +88,7 @@
      * @param classId
      * @return
      */
-    bool isQObject( const Smoke::Index classId );
+    bool isQObject( const Smoke::ModuleIndex classId );
 
     /**
      * Prepares the name of the method: it appends certain characters that indicate the argument types.
@@ -127,7 +127,7 @@
      * @param method
      * @param qargs
      */
-    void callCppMethod(void *obj, Smoke::Index method, Smoke::Stack qargs);
+    void callCppMethod(void *obj, const Smoke::ModuleIndex& method, Smoke::Stack qargs);
 
     /**
      * initializes Smoke and creates an instance of the binding
@@ -295,6 +295,7 @@
      */
     const QString printType(int type);
 
+    Smoke* smoke();
 }; // namespace PHPQt
 
 #endif
--- trunk/KDE/kdebindings/php/phpqt/src/smokephp.cpp #1084418:1084419
@@ -27,6 +27,15 @@
 #include <QDebug>
 #include <QByteArray>
 
+#include <smoke/qtcore_smoke.h>
+#include <smoke/qtgui_smoke.h>
+#include <smoke/qtxml_smoke.h>
+#include <smoke/qtsql_smoke.h>
+#include <smoke/qtopengl_smoke.h>
+#include <smoke/qtnetwork_smoke.h>
+#include <smoke/qtsvg_smoke.h>
+#include <smoke/qtdbus_smoke.h>
+
 #include "phpqt_internals.h"
 #include "php_qt.h"
 #include "context.h"
@@ -43,22 +52,9 @@
 extern QHash<const void*, smokephp_object*> SmokeQtObjects;
 extern "C" void init_qt_Smoke();
 
-/**
- * Binding class that handles virtual calls and deletion of objects
- */
-class PHPQtSmokeBinding : public SmokeBinding
-{
-public:
-    PHPQtSmokeBinding(Smoke *s) : SmokeBinding(s) {}
-
-    /**
-     * called by destructors in shell classes of smoke, e.g. from within
-     * ~x_QByteArray(), ~QMetaObject(), ~QObject(), ~x_QModelIndex(), ~x_QTextStream(),~x_QVariant(),
-     * ~x_QDomDocument(), ~x_QDomElement(), ~x_QIODevice()
-     * @param classId
-     * @param ptr
-     */
-    void deleted( Smoke::Index classId, void* ptr ) {
+namespace PHPQt {
+    
+    void Binding::deleted( Smoke::Index classId, void* ptr ) {
         pDebug( PHPQt::Destruct ) << "deleting p" << ptr;
         if( PHPQt::SmokePHPObjectExists(ptr) ) {
             smokephp_object *o = (smokephp_object*) PHPQt::getSmokePHPObjectFromQt(ptr);
@@ -84,7 +80,7 @@
      * @param pureVirtual
      * @return  true if succeeded
      */
-    bool callMethod(Smoke::Index method, void* QtPtr, Smoke::Stack args, bool pureVirtual) {
+    bool Binding::callMethod(Smoke::Index method, void* QtPtr, Smoke::Stack args, bool pureVirtual) {
 
         //! - get a corresponding smokephp_object
         smokephp_object *o = (smokephp_object*) PHPQt::getSmokePHPObjectFromQt(QtPtr);
@@ -136,7 +132,7 @@
         return false;
     }
 
-    virtual char *className(Smoke::Index classId) {
+    char *Binding::className(Smoke::Index classId) {
         // return a new[] copy of the language-specific name of this Smoke class
         // poorly designed function, but oh well. Sorry.
 
@@ -145,8 +141,8 @@
         strcpy(buf, className);
         return buf;
     }
-
-    virtual ~PHPQtSmokeBinding() {}
+    
+    QHash<Smoke*, Module> modules;
 };
 
 
@@ -168,18 +164,30 @@
     return false;
 }
 
-extern Smoke* qt_Smoke;
-extern SmokeBinding* qt_binding;
+extern SmokeBinding* qtcore_binding;
 
+#define INIT_BINDING(module) \
+    static PHPQt::Binding module##_binding = PHPQt::Binding(module##_Smoke); \
+    PHPQt::Module module = { "PHPQt_" #module, &module##_binding }; \
+    PHPQt::modules[module##_Smoke] = module;
+
 void PHPQt::init()
 {
-    if (qt_Smoke != 0L)
-        php_error(E_ERROR,"could not initialize smoke");
-
-    init_qt_Smoke();
-
-    if(PHPQt::smoke()->numClasses <= 0)
-        php_error(E_ERROR,"could not initialize smoke (no class definitions)");
-
-    qt_binding = new PHPQtSmokeBinding( PHPQt::smoke() );
+    init_qtcore_Smoke();
+    init_qtgui_Smoke();
+    init_qtxml_Smoke();
+    init_qtsql_Smoke();
+    init_qtopengl_Smoke();
+    init_qtnetwork_Smoke();
+    init_qtsvg_Smoke();
+    init_qtdbus_Smoke();
+    
+    INIT_BINDING(qtcore)
+    INIT_BINDING(qtgui)
+    INIT_BINDING(qtxml)
+    INIT_BINDING(qtsql)
+    INIT_BINDING(qtopengl)
+    INIT_BINDING(qtnetwork)
+    INIT_BINDING(qtsvg)
+    INIT_BINDING(qtdbus)
 }
--- trunk/KDE/kdebindings/php/phpqt/src/smokephp.h #1084418:1084419
@@ -34,6 +34,7 @@
 #endif
 
 #include "marshall.h"
+#include <QtCore/QHash>
 
 #define Qnil (zval *) NULL
 
@@ -278,7 +279,46 @@
 
 namespace PHPQt
 {
+    
+    /**
+    * Binding class that handles virtual calls and deletion of objects
+    */
+    class Binding : public SmokeBinding
+    {
+    public:
+        Binding(Smoke *s) : SmokeBinding(s) {}
 
+        /**
+        * called by destructors in shell classes of smoke, e.g. from within
+        * ~x_QByteArray(), ~QMetaObject(), ~QObject(), ~x_QModelIndex(), ~x_QTextStream(),~x_QVariant(),
+        * ~x_QDomDocument(), ~x_QDomElement(), ~x_QIODevice()
+        * @param classId
+        * @param ptr
+        */
+        void deleted( Smoke::Index classId, void* ptr );
+
+        /**
+        * every virtual C++ method call causes a callMethod() to call the PHP method if there is one
+        * @param method
+        * @param QtPtr
+        * @param args
+        * @param pureVirtual
+        * @return  true if succeeded
+        */
+        bool callMethod(Smoke::Index method, void* QtPtr, Smoke::Stack args, bool pureVirtual);
+
+        virtual char *className(Smoke::Index classId);
+
+        virtual ~Binding() {}
+    };
+
+    struct Module {
+        const char* name;
+        Binding* binding;
+    };
+
+    extern QHash<Smoke*, Module> modules;
+
 };
 
 #ifdef THOMAS_TEMP_DISABLED
--- trunk/KDE/kdebindings/php/phpqt/src/unittests.cpp #1084418:1084419
@@ -31,10 +31,10 @@
 #include "smokephp.h"
 
 
-extern Smoke* qt_Smoke;
+extern Smoke* qtcore_Smoke;
 
 TestPHPQt::TestPHPQt( SmokeBinding* binding, zval* z )
-  : _binding(binding), _z(z), _smoke( qt_Smoke )
+  : _binding(binding), _z(z), _smoke( qtcore_Smoke )
 {
   std::cout << "setting up unittests" << std::endl;
 }
--- trunk/KDE/kdebindings/php/phpqt/src/zphp/z_extension.cpp #1084418:1084419
@@ -245,7 +245,7 @@
 
     // Metaobject
     // TODO only if derived
-    if( PHPQt::isQObject( PHPQt::smoke()->idClass(ce->name).index ) )
+    if( PHPQt::isQObject( Smoke::findClass(ce->name) ) )
         PHPQt::createMetaObject(o, getThis());
 
     // cleanup
--- trunk/KDE/kdebindings/php/phpqt/src/zphp/z_handler.cpp #1084418:1084419
@@ -106,7 +106,7 @@
             //! - get the Qt value
             Smoke::Stack args = new Smoke::StackItem;
             void* dummy; // dummy here
-            PHPQt::callCppMethod(dummy, method, args);
+            PHPQt::callCppMethod(dummy, Smoke::ModuleIndex(PHPQt::smoke(), method), args);
 
             //! - write the zend return value
             zval* return_value;
@@ -179,7 +179,7 @@
             php_error(E_ERROR, "%s can not be cloned", o->ce_ptr()->name);
 
         smokephp_object* so = PHPQt::cloneObject( EX_T(opline->result.u.var).var.ptr, o, copyPtr );
-        if( PHPQt::isQObject( so->classId() ) )
+        if( PHPQt::isQObject( Smoke::ModuleIndex(so->smoke(), so->classId()) ) )
             PHPQt::createMetaObject( so, EX_T(opline->result.u.var).var.ptr );
 
         return _ret;
--- trunk/KDE/kdebindings/php/phpqt/tests/config.php.conf #1084418:1084419
@@ -2,5 +2,5 @@
 /*
  * helper file, don't touch
  */
-$tests_path = "@CMAKE_SOURCE_DIR@/tests/unittesthelper/"
-?>
\ No newline at end of file
+$tests_path = "@CMAKE_CURRENT_SOURCE_DIR@/tests/unittesthelper/"
+?>



More information about the Kde-bindings mailing list