dbus: Add method serial() and replySerial() to class DBusMessage.

This patch includes setup of class member 'msg' in
QDBusMessagePrivate::toDBusMessage() to be able to get the
serial after message sending.

Testcases for comparing the 'reply serial to' with the 'serial'
are included.

Task-number: QTBUG-44490
Change-Id: Iae7c48f5b0c70a6c5ae500904072b38b46dfd876
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ralf Habacker 2015-02-18 02:13:49 +01:00
parent c09412fcea
commit 618e2cc081
5 changed files with 54 additions and 0 deletions

View File

@ -286,6 +286,8 @@ DEFINEFUNC(const char* , dbus_message_get_sender, (DBusMessage *message),
(message), return) (message), return)
DEFINEFUNC(dbus_uint32_t , dbus_message_get_serial, (DBusMessage *message), DEFINEFUNC(dbus_uint32_t , dbus_message_get_serial, (DBusMessage *message),
(message), return) (message), return)
DEFINEFUNC(dbus_uint32_t , dbus_message_get_reply_serial, (DBusMessage *message),
(message), return)
DEFINEFUNC(const char* , dbus_message_get_signature, (DBusMessage *message), DEFINEFUNC(const char* , dbus_message_get_signature, (DBusMessage *message),
(message), return) (message), return)
DEFINEFUNC(int , dbus_message_get_type, (DBusMessage *message), DEFINEFUNC(int , dbus_message_get_type, (DBusMessage *message),

View File

@ -188,7 +188,12 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
// check if everything is ok // check if everything is ok
if (marshaller.ok) if (marshaller.ok)
{
QDBusMessage *m = (QDBusMessage*)&message;
q_dbus_message_ref(msg);
m->d_ptr->msg = msg;
return msg; return msg;
}
// not ok; // not ok;
q_dbus_message_unref(msg); q_dbus_message_unref(msg);
@ -317,6 +322,16 @@ QDBusMessage QDBusMessagePrivate::makeLocalReply(const QDBusConnectionPrivate &c
return QDBusMessage(); // failed return QDBusMessage(); // failed
} }
uint QDBusMessagePrivate::serial()
{
return msg ? q_dbus_message_get_serial(msg) : reply ? q_dbus_message_get_serial(reply) : 0;
}
uint QDBusMessagePrivate::replySerial()
{
return msg ? q_dbus_message_get_reply_serial(msg) : reply ? q_dbus_message_get_reply_serial(reply) : 0;
}
/*! /*!
\class QDBusMessage \class QDBusMessage
\inmodule QtDBus \inmodule QtDBus
@ -632,6 +647,32 @@ QString QDBusMessage::signature() const
return d_ptr->signature; return d_ptr->signature;
} }
/*!
Returns the serial of the message or 0 if undefined.
The serial number is a unique identifier of a message coming from a
given connection.
The serial is set to a non zero value after the message has been sent
over a D-Bus connection.
*/
uint QDBusMessage::serial() const
{
return d_ptr->serial();
}
/*!
Returns the serial of the message this is a reply to or 0 if undefined.
The serial number is a unique identifier of a message coming from a
given connection and D-Bus messages of 'method return' or 'error' type
use them to match the reply to the method call message.
*/
uint QDBusMessage::replySerial() const
{
return d_ptr->replySerial();
}
/*! /*!
Returns the flag that indicates if this message should see a reply Returns the flag that indicates if this message should see a reply
or not. This is only meaningful for \l {MethodCallMessage}{method or not. This is only meaningful for \l {MethodCallMessage}{method

View File

@ -104,6 +104,8 @@ public:
QString errorMessage() const; QString errorMessage() const;
MessageType type() const; MessageType type() const;
QString signature() const; QString signature() const;
uint serial() const;
uint replySerial() const;
bool isReplyRequired() const; bool isReplyRequired() const;

View File

@ -93,6 +93,8 @@ public:
const QDBusMessage &asSent); const QDBusMessage &asSent);
static QDBusMessage makeLocalReply(const QDBusConnectionPrivate &conn, static QDBusMessage makeLocalReply(const QDBusConnectionPrivate &conn,
const QDBusMessage &asSent); const QDBusMessage &asSent);
uint serial();
uint replySerial();
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -71,6 +71,7 @@ void tst_QDBusConnection::noConnection()
QVERIFY(con.callWithCallback(msg, &spy, SLOT(asyncReply)) == 0); QVERIFY(con.callWithCallback(msg, &spy, SLOT(asyncReply)) == 0);
QDBusMessage reply = con.call(msg); QDBusMessage reply = con.call(msg);
QCOMPARE(msg.serial(), reply.replySerial());
QVERIFY(reply.type() == QDBusMessage::ErrorMessage); QVERIFY(reply.type() == QDBusMessage::ErrorMessage);
QDBusReply<void> voidreply(reply); QDBusReply<void> voidreply(reply);
@ -152,6 +153,7 @@ void tst_QDBusConnection::send()
QDBusMessage reply = con.call(msg); QDBusMessage reply = con.call(msg);
QCOMPARE(msg.serial(), reply.replySerial());
QCOMPARE(reply.arguments().count(), 1); QCOMPARE(reply.arguments().count(), 1);
QCOMPARE(reply.arguments().at(0).typeName(), "QStringList"); QCOMPARE(reply.arguments().at(0).typeName(), "QStringList");
QVERIFY(reply.arguments().at(0).toStringList().contains(con.baseService())); QVERIFY(reply.arguments().at(0).toStringList().contains(con.baseService()));
@ -171,6 +173,7 @@ void tst_QDBusConnection::sendWithGui()
QDBusMessage reply = con.call(msg, QDBus::BlockWithGui); QDBusMessage reply = con.call(msg, QDBus::BlockWithGui);
QCOMPARE(msg.serial(), reply.replySerial());
QCOMPARE(reply.arguments().count(), 1); QCOMPARE(reply.arguments().count(), 1);
QCOMPARE(reply.arguments().at(0).typeName(), "QStringList"); QCOMPARE(reply.arguments().at(0).typeName(), "QStringList");
QVERIFY(reply.arguments().at(0).toStringList().contains(con.baseService())); QVERIFY(reply.arguments().at(0).toStringList().contains(con.baseService()));
@ -840,6 +843,7 @@ void tst_QDBusConnection::callSelf()
QString(), "test3"); QString(), "test3");
msg << 44; msg << 44;
reply = connection.call(msg); reply = connection.call(msg);
QCOMPARE(msg.serial(), reply.replySerial());
QCOMPARE(reply.arguments().value(0).toInt(), 45); QCOMPARE(reply.arguments().value(0).toInt(), 45);
} }
@ -907,6 +911,7 @@ void tst_QDBusConnection::callSelfByAnotherName()
QString(), "test0"); QString(), "test0");
QDBusMessage reply = con.call(msg, QDBus::Block, 1000); QDBusMessage reply = con.call(msg, QDBus::Block, 1000);
QCOMPARE(msg.serial(), reply.replySerial());
QVERIFY(reply.type() == QDBusMessage::ReplyMessage); QVERIFY(reply.type() == QDBusMessage::ReplyMessage);
} }
@ -922,6 +927,7 @@ void tst_QDBusConnection::multipleInterfacesInQObject()
QDBusMessage msg = QDBusMessage::createMethodCall(con.baseService(), "/p1", QDBusMessage msg = QDBusMessage::createMethodCall(con.baseService(), "/p1",
"local.BaseObject", "anotherMethod"); "local.BaseObject", "anotherMethod");
QDBusMessage reply = con.call(msg, QDBus::Block); QDBusMessage reply = con.call(msg, QDBus::Block);
QCOMPARE(msg.serial(), reply.replySerial());
QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); QCOMPARE(reply.type(), QDBusMessage::ReplyMessage);
QVERIFY(reply.arguments().count() == 0); QVERIFY(reply.arguments().count() == 0);
} }
@ -1202,6 +1208,7 @@ void tst_QDBusConnection::callVirtualObjectLocal()
QDBusMessage message = QDBusMessage::createMethodCall(con.baseService(), path, QString(), "hello"); QDBusMessage message = QDBusMessage::createMethodCall(con.baseService(), path, QString(), "hello");
QDBusMessage reply = con.call(message, QDBus::Block, 5000); QDBusMessage reply = con.call(message, QDBus::Block, 5000);
QCOMPARE(message.serial(), reply.replySerial());
QCOMPARE(obj.callCount, 1); QCOMPARE(obj.callCount, 1);
QCOMPARE(obj.lastMessage.service(), con.baseService()); QCOMPARE(obj.lastMessage.service(), con.baseService());
QCOMPARE(obj.lastMessage.interface(), QString()); QCOMPARE(obj.lastMessage.interface(), QString());