summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-06-30 18:50:32 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-07-02 09:43:25 (GMT)
commit11ef1b9bae383c46f7893db0d26c99d354642609 (patch)
treeb86f5fb5a09a21f11149e62c4e8bd04c6705ea0e /src
parent353dacb5e4c45e860ae8be228df9647c5a71093e (diff)
downloadQt-11ef1b9bae383c46f7893db0d26c99d354642609.zip
Qt-11ef1b9bae383c46f7893db0d26c99d354642609.tar.gz
Qt-11ef1b9bae383c46f7893db0d26c99d354642609.tar.bz2
Add a function to check if an interface is implemented by an object.
Also reorganise a bit, moving the function to create the interface name from an object's class name to qdbusmisc.cpp too. Reviewed-By: Trust Me
Diffstat (limited to 'src')
-rw-r--r--src/dbus/qdbusconnection_p.h5
-rw-r--r--src/dbus/qdbusintegrator.cpp8
-rw-r--r--src/dbus/qdbusmisc.cpp47
-rw-r--r--src/dbus/qdbusxmlgenerator.cpp37
4 files changed, 51 insertions, 46 deletions
diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h
index 5c37509..a156a71 100644
--- a/src/dbus/qdbusconnection_p.h
+++ b/src/dbus/qdbusconnection_p.h
@@ -300,6 +300,8 @@ public:
extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes);
extern int qDBusNameToTypeId(const char *name);
extern bool qDBusCheckAsyncTag(const char *tag);
+extern bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name);
+extern QString qDBusInterfaceFromMetaObject(const QMetaObject *mo);
// in qdbusinternalfilters.cpp
extern QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node);
@@ -310,9 +312,6 @@ extern QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNod
extern QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg);
-// in qdbusxmlgenerator.cpp
-extern QString qDBusInterfaceFromMetaObject(const QMetaObject *mo);
-
QT_END_NAMESPACE
#endif
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 0578bf1..76179c9 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -1359,12 +1359,8 @@ void QDBusConnectionPrivate::activateObject(ObjectTreeNode &node, const QDBusMes
// try the object itself:
if (node.flags & (QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportNonScriptableSlots)) {
bool interfaceFound = true;
- if (!msg.interface().isEmpty()) {
- // check if the interface name matches anything in the class hierarchy
- const QMetaObject *mo = node.obj->metaObject();
- for ( ; !interfaceFound && mo != &QObject::staticMetaObject; mo = mo->superClass())
- interfaceFound = msg.interface() == qDBusInterfaceFromMetaObject(mo);
- }
+ if (!msg.interface().isEmpty())
+ interfaceFound = qDBusInterfaceInObject(node.obj, msg.interface());
if (interfaceFound) {
if (!activateCall(node.obj, node.flags, msg))
diff --git a/src/dbus/qdbusmisc.cpp b/src/dbus/qdbusmisc.cpp
index e5c1da6..1b77a9b 100644
--- a/src/dbus/qdbusmisc.cpp
+++ b/src/dbus/qdbusmisc.cpp
@@ -41,12 +41,14 @@
#include <string.h>
+#include <QtCore/qcoreapplication.h>
#include <QtCore/qvariant.h>
#include <QtCore/qmetaobject.h>
#include "qdbusutil_p.h"
#include "qdbusconnection_p.h"
#include "qdbusmetatype_p.h"
+#include "qdbusabstractadaptor_p.h" // for QCLASSINFO_DBUS_*
QT_BEGIN_NAMESPACE
@@ -73,6 +75,51 @@ int qDBusNameToTypeId(const char *name)
return id;
}
+QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
+{
+ QString interface;
+
+ int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
+ if (idx >= mo->classInfoOffset()) {
+ interface = QLatin1String(mo->classInfo(idx).value());
+ } else {
+ interface = QLatin1String(mo->className());
+ interface.replace(QLatin1String("::"), QLatin1String("."));
+
+ if (interface.startsWith(QLatin1String("QDBus"))) {
+ interface.prepend(QLatin1String("com.trolltech.QtDBus."));
+ } else if (interface.startsWith(QLatin1Char('Q')) &&
+ interface.length() >= 2 && interface.at(1).isUpper()) {
+ // assume it's Qt
+ interface.prepend(QLatin1String("com.trolltech.Qt."));
+ } else if (!QCoreApplication::instance()||
+ QCoreApplication::instance()->applicationName().isEmpty()) {
+ interface.prepend(QLatin1String("local."));
+ } else {
+ interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
+ QStringList domainName =
+ QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
+ QString::SkipEmptyParts);
+ if (domainName.isEmpty())
+ interface.prepend(QLatin1String("local."));
+ else
+ for (int i = 0; i < domainName.count(); ++i)
+ interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
+ }
+ }
+
+ return interface;
+}
+
+bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
+{
+ const QMetaObject *mo = obj->metaObject();
+ for ( ; mo != &QObject::staticMetaObject; mo = mo->superClass())
+ if (interface_name == qDBusInterfaceFromMetaObject(mo))
+ return true;
+ return false;
+}
+
// calculates the metatypes for the method
// the slot must have the parameters in the following form:
// - zero or more value or const-ref parameters of any kind
diff --git a/src/dbus/qdbusxmlgenerator.cpp b/src/dbus/qdbusxmlgenerator.cpp
index 82bd762..b426abd 100644
--- a/src/dbus/qdbusxmlgenerator.cpp
+++ b/src/dbus/qdbusxmlgenerator.cpp
@@ -39,7 +39,6 @@
**
****************************************************************************/
-#include <QtCore/qcoreapplication.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qstringlist.h>
@@ -232,42 +231,6 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
return retval;
}
-QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
-{
- QString interface;
-
- int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
- if (idx >= mo->classInfoOffset()) {
- interface = QLatin1String(mo->classInfo(idx).value());
- } else {
- interface = QLatin1String(mo->className());
- interface.replace(QLatin1String("::"), QLatin1String("."));
-
- if (interface.startsWith(QLatin1String("QDBus"))) {
- interface.prepend(QLatin1String("com.trolltech.QtDBus."));
- } else if (interface.startsWith(QLatin1Char('Q')) &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
- // assume it's Qt
- interface.prepend(QLatin1String("com.trolltech.Qt."));
- } else if (!QCoreApplication::instance()||
- QCoreApplication::instance()->applicationName().isEmpty()) {
- interface.prepend(QLatin1String("local."));
- } else {
- interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
- QStringList domainName =
- QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
- QString::SkipEmptyParts);
- if (domainName.isEmpty())
- interface.prepend(QLatin1String("local."));
- else
- for (int i = 0; i < domainName.count(); ++i)
- interface.prepend(QLatin1Char('.')).prepend(domainName.at(i));
- }
- }
-
- return interface;
- }
-
QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
const QMetaObject *base, int flags)
{