dbus/qt qdbusabstractinterface_p.h, 1.1, 1.2 qdbusconnection.cpp, 1.6, 1.7 qdbusconnection_p.h, 1.7, 1.8 qdbusintegrator.cpp, 1.7, 1.8 qdbusinterface.cpp, 1.4, 1.5 qdbusinterface.h, 1.3, 1.4 qdbusmetaobject.cpp, 1.1, 1.2 qdbusmetaobject_p.h, 1.1, 1.2

Thiago J. Macieira thiago at kemper.freedesktop.org
Sun Apr 23 12:04:55 PDT 2006


Update of /cvs/dbus/dbus/qt
In directory kemper:/tmp/cvs-serv31596/qt

Modified Files:
	qdbusabstractinterface_p.h qdbusconnection.cpp 
	qdbusconnection_p.h qdbusintegrator.cpp qdbusinterface.cpp 
	qdbusinterface.h qdbusmetaobject.cpp qdbusmetaobject_p.h 
Log Message:
	* qt/qdbusconnection_p.h:
	* qt/qdbusmetaobject.cpp:
	* qt/qdbusmetaobject_p.h:
	* qt/qdbusintegrator.cpp: Use the new merged-interface mode
	for the dynamic meta object. No need to guess which
	interface to call.
	* qt/qdbusabstractinterface_p.h:
	* qt/qdbusconnection.cpp:
	* qt/qdbusintegrator.cpp:
	* qt/qdbusinterface.cpp:
	* qt/qdbusinterface.h: Make findInterface always return a non-null pointer.
	Add a QDBusRef that looks and behaves like DCOPRef.


Index: qdbusabstractinterface_p.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusabstractinterface_p.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qdbusabstractinterface_p.h	28 Mar 2006 18:56:08 -0000	1.1
+++ qdbusabstractinterface_p.h	23 Apr 2006 19:04:53 -0000	1.2
@@ -55,10 +55,11 @@
     QString path;
     QString interface;
     QDBusError lastError;
+    bool isValid;
 
     inline QDBusAbstractInterfacePrivate(const QDBusConnection& con, QDBusConnectionPrivate *conp,
                                          const QString &serv, const QString &p, const QString &iface)
-        : conn(con), connp(conp), service(serv), path(p), interface(iface)
+        : conn(con), connp(conp), service(serv), path(p), interface(iface), isValid(true)
     { }
     virtual ~QDBusAbstractInterfacePrivate() { }
 };

Index: qdbusconnection.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusconnection.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- qdbusconnection.cpp	28 Mar 2006 18:56:08 -0000	1.6
+++ qdbusconnection.cpp	23 Apr 2006 19:04:53 -0000	1.7
@@ -614,8 +614,6 @@
         return 0;
     
     QDBusInterfacePrivate *p = d->findInterface(service, path, interface);
-    if (!p)
-        return 0;
     QDBusInterface *retval = new QDBusInterface(p);
     retval->setParent(d);
     return retval;

Index: qdbusconnection_p.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusconnection_p.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- qdbusconnection_p.h	28 Mar 2006 18:56:08 -0000	1.7
+++ qdbusconnection_p.h	23 Apr 2006 19:04:53 -0000	1.8
@@ -172,7 +172,7 @@
 
 private:
     QDBusMetaObject *findMetaObject(const QString &service, const QString &path,
-                                    QString &interface);        
+                                    const QString &interface);        
 
 public slots:
     // public slots

Index: qdbusintegrator.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusintegrator.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- qdbusintegrator.cpp	13 Apr 2006 17:36:03 -0000	1.7
+++ qdbusintegrator.cpp	23 Apr 2006 19:04:53 -0000	1.8
@@ -1474,27 +1474,44 @@
                                       const QString &path,
                                       const QString &interface)
 {
-    
-    if (!connection || !QDBusUtil::isValidObjectPath(path))
-        return 0;
-    if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
-        return 0;
-
     // check if it's there first -- FIXME: add binding mode
+    QDBusMetaObject *mo = 0;
     QString owner = getNameOwner(service);
-    if (owner.isEmpty())
-        return 0;
+    if (connection && !owner.isEmpty() && QDBusUtil::isValidObjectPath(path) &&
+        (interface.isEmpty() || QDBusUtil::isValidInterfaceName(interface)))
+        mo = findMetaObject(owner, path, interface);
 
-    QString tmp(interface);
-    QDBusMetaObject *mo = findMetaObject(owner, path, tmp);
-    if (mo)
-        return new QDBusInterfacePrivate(QDBusConnection(name), this, owner, path, tmp, mo);
-    return 0;                   // error has been set
+    QDBusInterfacePrivate *p = new QDBusInterfacePrivate(QDBusConnection(name), this, owner, path, interface, mo);
+
+    if (!mo) {
+        // invalid object
+        p->isValid = false;
+        p->lastError = lastError;
+        if (!lastError.isValid()) {
+            // try to determine why we couldn't get the data
+            if (!connection)
+                p->lastError = QDBusError(QDBusError::Disconnected,
+                                          QLatin1String("Not connected to D-Bus server"));
+            else if (owner.isEmpty())
+                p->lastError = QDBusError(QDBusError::ServiceUnknown,
+                                          QString(QLatin1String("Service %1 is unknown")).arg(service));
+            else if (!QDBusUtil::isValidObjectPath(path))
+                p->lastError = QDBusError(QDBusError::InvalidArgs,
+                                          QString(QLatin1String("Object path %1 is invalid")).arg(path));
+            else if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
+                p->lastError = QDBusError(QDBusError::InvalidArgs,
+                                          QString(QLatin1String("Interface %1 is invalid")).arg(interface));
+            else
+                p->lastError = QDBusError(QDBusError::Other, QLatin1String("Unknown error"));
+        }
+    }
+
+    return p;
 }
 
 QDBusMetaObject *
 QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &path,
-                                       QString &interface)
+                                       const QString &interface)
 {
     if (!interface.isEmpty()) {
         QReadLocker locker(&lock);

Index: qdbusinterface.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusinterface.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- qdbusinterface.cpp	28 Mar 2006 18:56:08 -0000	1.4
+++ qdbusinterface.cpp	23 Apr 2006 19:04:53 -0000	1.5
@@ -63,7 +63,7 @@
 */
 const QMetaObject *QDBusInterface::metaObject() const
 {
-    return d_func()->metaObject;
+    return d_func()->isValid ? d_func()->metaObject : &QDBusAbstractInterface::staticMetaObject;
 }
 
 /*!
@@ -87,7 +87,7 @@
 int QDBusInterface::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
 {
     _id = QDBusAbstractInterface::qt_metacall(_c, _id, _a);
-    if (_id < 0)
+    if (_id < 0 || !d_func()->isValid)
         return _id;
     return d_func()->metacall(_c, _id, _a);
 }
@@ -238,3 +238,14 @@
     return id;
 }
 
+QDBusRef::QDBusRef(QDBusConnection &conn, const QString &service, const QString &path,
+                   const QString &interface)
+    : d(conn.findInterface(service, path, interface))
+{
+}
+
+QDBusRef::QDBusRef(const QString &service, const QString &path, const QString &interface)
+    : d(QDBus::sessionBus().findInterface(service, path, interface))
+{
+}
+

Index: qdbusinterface.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusinterface.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- qdbusinterface.h	28 Mar 2006 18:56:08 -0000	1.3
+++ qdbusinterface.h	23 Apr 2006 19:04:53 -0000	1.4
@@ -43,4 +43,16 @@
     Q_DECLARE_PRIVATE(QDBusInterface);
 };
 
+struct QDBUS_EXPORT QDBusRef
+{
+    QDBusRef(QDBusConnection &conn, const QString &service, const QString &path,
+             const QString &interface = QString());
+    QDBusRef(const QString &service, const QString &path, const QString &interface = QString());
+    ~QDBusRef() { delete d; }
+
+    QDBusInterface* operator->() const { return d; }
+private:
+    QDBusInterface *const d;
+};
+
 #endif

Index: qdbusmetaobject.cpp
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusmetaobject.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qdbusmetaobject.cpp	28 Mar 2006 18:56:08 -0000	1.1
+++ qdbusmetaobject.cpp	23 Apr 2006 19:04:53 -0000	1.2
@@ -437,7 +437,7 @@
 /////////
 // class QDBusMetaObject
 
-QDBusMetaObject *QDBusMetaObject::createMetaObject(QString &interface, const QString &xml,
+QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, const QString &xml,
                                                    QHash<QString, QDBusMetaObject *> &cache,
                                                    QDBusError &error)
 {
@@ -462,15 +462,9 @@
 
         }
 
-        if (it.key() == interface) {
+        if (it.key() == interface)
             // it's us
             we = obj;
-        } else if (interface.isEmpty() &&
-                 !it.key().startsWith(QLatin1String("org.freedesktop.DBus."))) {
-            // also us
-            we = obj;
-            interface = it.key();
-        }
     }
 
     if (we)
@@ -484,6 +478,26 @@
         generator.write(we);
         we->cached = false;
         return we;
+    } else if (interface.isEmpty()) {
+        // merge all interfaces
+        it = parsed.constBegin();
+        QDBusIntrospection::Interface merged = *it.value().constData();
+ 
+        for (++it; it != end; ++it) {
+            merged.annotations.unite(it.value()->annotations);
+            merged.methods.unite(it.value()->methods);
+            merged.signals_.unite(it.value()->signals_);
+            merged.properties.unite(it.value()->properties);
+        }
+
+        merged.name = QLatin1String("local.Merged");
+        merged.introspection.clear();
+
+        we = new QDBusMetaObject;
+        QDBusMetaObjectGenerator generator(merged.name, &merged);
+        generator.write(we);
+        we->cached = false;
+        return we;
     }
 
     // mark as an error

Index: qdbusmetaobject_p.h
===================================================================
RCS file: /cvs/dbus/dbus/qt/qdbusmetaobject_p.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- qdbusmetaobject_p.h	28 Mar 2006 18:56:08 -0000	1.1
+++ qdbusmetaobject_p.h	23 Apr 2006 19:04:53 -0000	1.2
@@ -46,7 +46,7 @@
 {
     bool cached;
 
-    static QDBusMetaObject *createMetaObject(QString &interface, const QString &xml,
+    static QDBusMetaObject *createMetaObject(const QString &interface, const QString &xml,
                                              QHash<QString, QDBusMetaObject *> &map,
                                              QDBusError &error);
     ~QDBusMetaObject()



More information about the dbus-commit mailing list