diff options
Diffstat (limited to 'qt')
-rw-r--r-- | qt/qdbusabstractinterface.cpp | 22 | ||||
-rw-r--r-- | qt/qdbusabstractinterface.h | 5 | ||||
-rw-r--r-- | qt/qdbusreply.h | 28 | ||||
-rw-r--r-- | qt/qdbustypehelper_p.h | 4 |
4 files changed, 52 insertions, 7 deletions
diff --git a/qt/qdbusabstractinterface.cpp b/qt/qdbusabstractinterface.cpp index 127b161..291888f 100644 --- a/qt/qdbusabstractinterface.cpp +++ b/qt/qdbusabstractinterface.cpp @@ -146,6 +146,28 @@ QDBusMessage QDBusAbstractInterface::callWithArgs(const QString& method, const Q sig = method.mid(pos + 1); } + if (mode == AutoDetect) { + // determine if this a sync or async call + mode = UseEventLoop; + const QMetaObject *mo = metaObject(); + QByteArray match = method.toLatin1() + '('; + + for (int i = staticMetaObject.methodCount(); i < mo->methodCount(); ++i) { + QMetaMethod mm = mo->method(i); + if (QByteArray(mm.signature()).startsWith(match)) { + // found a method with the same name as what we're looking for + // hopefully, nobody is overloading asynchronous and synchronous methods with + // the same name + + QList<QByteArray> tags = QByteArray(mm.tag()).split(' '); + if (tags.contains("async") || tags.contains("Q_ASYNC")) + mode = NoWaitForReply; + + break; + } + } + } + QDBusMessage msg = QDBusMessage::methodCall(service(), path(), interface(), m); msg.setSignature(sig); msg.QList<QVariant>::operator=(args); diff --git a/qt/qdbusabstractinterface.h b/qt/qdbusabstractinterface.h index 5c34677..ae80b0a 100644 --- a/qt/qdbusabstractinterface.h +++ b/qt/qdbusabstractinterface.h @@ -45,7 +45,8 @@ public: enum CallMode { NoWaitForReply, UseEventLoop, - NoUseEventLoop + NoUseEventLoop, + AutoDetect }; public: @@ -60,7 +61,7 @@ public: QDBusError lastError() const; QDBusMessage callWithArgs(const QString &method, const QList<QVariant> &args = QList<QVariant>(), - CallMode mode = UseEventLoop); + CallMode mode = AutoDetect); bool callWithArgs(const QString &method, QObject *receiver, const char *slot, const QList<QVariant> &args = QList<QVariant>()); diff --git a/qt/qdbusreply.h b/qt/qdbusreply.h index f22082c..ff0d5d5 100644 --- a/qt/qdbusreply.h +++ b/qt/qdbusreply.h @@ -39,15 +39,37 @@ class QDBUS_EXPORT QDBusReply typedef T Type; public: inline QDBusReply(const QDBusMessage &reply) - : m_error(reply), m_data(Type()) + : m_data(Type()) { + *this = reply; + } + inline QDBusReply& operator=(const QDBusMessage& reply) + { + m_error = reply; if (isSuccess()) m_data = QDBusTypeHelper<Type>::fromVariant(reply.at(0)); + else + m_data = Type(); + return *this; } - inline QDBusReply(const QDBusError &error) + + inline QDBusReply(const QDBusError &error = QDBusError()) : m_error(error), m_data(Type()) { - } + } + inline QDBusReply& operator=(const QDBusError& error) + { + m_error = error; + m_data = Type(); + return *this; + } + + inline QDBusReply& operator=(const QDBusReply& other) + { + m_error = other.m_error; + m_data = other.m_data; + return *this; + } inline bool isError() const { return m_error.isValid(); } inline bool isSuccess() const { return !m_error.isValid(); } diff --git a/qt/qdbustypehelper_p.h b/qt/qdbustypehelper_p.h index bcb0896..72d5bbe 100644 --- a/qt/qdbustypehelper_p.h +++ b/qt/qdbustypehelper_p.h @@ -122,7 +122,7 @@ struct QDBusTypeHelper static inline QVariantList toVariantList(const List &list) { QVariantList tmp; - foreach (const Type &t, list) + Q_FOREACH (const Type &t, list) tmp.append(toVariant(t)); return tmp; } @@ -135,7 +135,7 @@ struct QDBusTypeHelper static inline List fromVariantList(const QVariantList &list) { List tmp; - foreach (const QVariant &v, list) + Q_FOREACH (const QVariant &v, list) tmp.append(fromVariant(v)); return tmp; } |