summaryrefslogtreecommitdiff
path: root/qt
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@trolltech.com>2006-04-23 19:04:53 +0000
committerJohn Palmieri <johnp@remedyz.boston.redhat.com>2006-06-28 08:15:15 -0400
commitda4402ecff0ec03b9344feb44c723cf6f9944c7a (patch)
tree051f341016258d9ea3ab69765672b376eda93164 /qt
parent532621a0f35d9c84d9ca8b7883691180b4285763 (diff)
* 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.
Diffstat (limited to 'qt')
-rw-r--r--qt/qdbusabstractinterface_p.h3
-rw-r--r--qt/qdbusconnection.cpp2
-rw-r--r--qt/qdbusconnection_p.h2
-rw-r--r--qt/qdbusintegrator.cpp45
-rw-r--r--qt/qdbusinterface.cpp15
-rw-r--r--qt/qdbusinterface.h12
-rw-r--r--qt/qdbusmetaobject.cpp30
-rw-r--r--qt/qdbusmetaobject_p.h2
8 files changed, 82 insertions, 29 deletions
diff --git a/qt/qdbusabstractinterface_p.h b/qt/qdbusabstractinterface_p.h
index 38cc422..8f4d8dc 100644
--- a/qt/qdbusabstractinterface_p.h
+++ b/qt/qdbusabstractinterface_p.h
@@ -55,10 +55,11 @@ public:
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() { }
};
diff --git a/qt/qdbusconnection.cpp b/qt/qdbusconnection.cpp
index 668cef5..52875a0 100644
--- a/qt/qdbusconnection.cpp
+++ b/qt/qdbusconnection.cpp
@@ -614,8 +614,6 @@ QDBusInterface *QDBusConnection::findInterface(const QString& service, const QSt
return 0;
QDBusInterfacePrivate *p = d->findInterface(service, path, interface);
- if (!p)
- return 0;
QDBusInterface *retval = new QDBusInterface(p);
retval->setParent(d);
return retval;
diff --git a/qt/qdbusconnection_p.h b/qt/qdbusconnection_p.h
index 53cb436..36f21db 100644
--- a/qt/qdbusconnection_p.h
+++ b/qt/qdbusconnection_p.h
@@ -172,7 +172,7 @@ protected:
private:
QDBusMetaObject *findMetaObject(const QString &service, const QString &path,
- QString &interface);
+ const QString &interface);
public slots:
// public slots
diff --git a/qt/qdbusintegrator.cpp b/qt/qdbusintegrator.cpp
index 4a72d19..4dabd43 100644
--- a/qt/qdbusintegrator.cpp
+++ b/qt/qdbusintegrator.cpp
@@ -1474,27 +1474,44 @@ QDBusConnectionPrivate::findInterface(const QString &service,
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);
+
+ 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"));
+ }
+ }
- 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
+ return p;
}
QDBusMetaObject *
QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &path,
- QString &interface)
+ const QString &interface)
{
if (!interface.isEmpty()) {
QReadLocker locker(&lock);
diff --git a/qt/qdbusinterface.cpp b/qt/qdbusinterface.cpp
index e0d1049..ff8fdc9 100644
--- a/qt/qdbusinterface.cpp
+++ b/qt/qdbusinterface.cpp
@@ -63,7 +63,7 @@ QDBusInterface::~QDBusInterface()
*/
const QMetaObject *QDBusInterface::metaObject() const
{
- return d_func()->metaObject;
+ return d_func()->isValid ? d_func()->metaObject : &QDBusAbstractInterface::staticMetaObject;
}
/*!
@@ -87,7 +87,7 @@ void *QDBusInterface::qt_metacast(const char *_clname)
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 @@ int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv)
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))
+{
+}
+
diff --git a/qt/qdbusinterface.h b/qt/qdbusinterface.h
index 0495ada..f667698 100644
--- a/qt/qdbusinterface.h
+++ b/qt/qdbusinterface.h
@@ -43,4 +43,16 @@ private:
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
diff --git a/qt/qdbusmetaobject.cpp b/qt/qdbusmetaobject.cpp
index ccc3865..2992c70 100644
--- a/qt/qdbusmetaobject.cpp
+++ b/qt/qdbusmetaobject.cpp
@@ -437,7 +437,7 @@ void QDBusMetaObjectGenerator::writeWithoutXml(const QString &interface)
/////////
// 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 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(QString &interface, const QSt
}
- 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 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(QString &interface, const QSt
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
diff --git a/qt/qdbusmetaobject_p.h b/qt/qdbusmetaobject_p.h
index c62c972..7d6c5ca 100644
--- a/qt/qdbusmetaobject_p.h
+++ b/qt/qdbusmetaobject_p.h
@@ -46,7 +46,7 @@ struct QDBUS_EXPORT QDBusMetaObject: public QMetaObject
{
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()