QtDBus replying to a DBus signal?
-
Using dbus-monitor, I'm seeing my Qt-based program respond to a DBus signal by sending a DBus method return message. The DBus spec says that signals should not send any kind of reply message. Here's the relevant section of the dbus-monitor output:
=== DataChanged signal sent to Qt program:
signal sender=:1.2 -> dest=(null destination) serial=387 path=/wifi/networks/000e3b449928; interface=dbus.topics.Topic; member=DataChanged
array [
dict entry(
string "SignalLevel"
variant int32 2
)
dict entry(
string "SignalStrength"
variant int32 76
)
]=== Reply from Qt program to sender of signal:
method return sender=:1.3 -> dest=:1.2 reply_serial=387=== Sender of signal sends error message saying a reply was not expected:
error sender=:1.2 -> dest=:1.3 error_name=org.freedesktop.dbus.exceptions.DBusExecutionException reply_serial=205
string "Spurious reply. No message with the given serial id was awaiting a reply."Here's the DBus interface definition I'm using:
@
<node>
<interface name="dbus.topics.Topic">
<method name="GetData">
<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
<arg name="data" direction="out" type="a{sv}"/>
</method>
<signal name="DataChanged">
<annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="QVariantMap"/>
<arg type="a{sv}" name="data"/>
</signal>
</interface>
</node>
@I generated interface files for my Qt program using qdbusxmo2cpp:
@
qdbusxml2cpp -v -c TopicInterface -p TopicInterface.h:TopicInterface.cpp dbus.topics.Topic.xml
@Here's the code that creates and instance of TopicInterface and connects it to the signal handler:
@
m_topicInterface = new TopicInterface(m_service, m_path, QDBusConnection::systemBus());
if (m_topicInterface->isValid()) {
// Connect dbus signals to local signal handlers
QObject::connect(m_topicInterface, SIGNAL(DataChanged(QVariantMap)), this, SLOT(DataChangedHandler(QVariantMap)));
} else {
LOG4CPLUS_ERROR(m_logger, "TopicInterface instance is not valid");
}
@And here's the signal handler which emits a Qt signal for my application to handle, and then returns:
@
void TopicProxy::DataChangedHandler(const QVariantMap &data) {
LOG4CPLUS_TRACE(m_logger, "DataChangedHandler signal handler called");// Emit the dataUpdate signal. The Topic instance will handle this. this->dataUpdate(data);
}
@My application works fine, but I'm puzzled about these errors. Am I doing something wrong that would cause QtDBus to send a reply to an incoming signal?
-
Sorry about the ugly formatting in this post. I didn't realize the posting tool was going to change my whitespace for me. I saw a not about using @ to make source code 'pretty', but didn't understand what that meant. Can someone clue me in about that?
-
Found I could update the post and cleaned up the formatting.