Problem summary: qdbusxml2cpp
generates a QDBusAbstractInterface
sub-class whose methods fetch D-Bus replies asynchronously, but I want it to be synchronous (i.e. it should block until the reply is received).
XML input:
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="some.interface.Foo">
<method name="GetValues">
<arg name="values" type="a(oa{sv})" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QList<SomeStruct>" />
</method>
</interface>
</node>
With this command a header and .cpp file (not shown) is generated:
qdbusxml2cpp-qt5 -c InterfaceFoo -p interface_foo foo.xml
The generated header:
class InterfaceFoo: public QDBusAbstractInterface
{
Q_OBJECT
public:
static inline const char *staticInterfaceName()
{ return "some.interface.Foo"; }
public:
InterfaceFoo(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
~InterfaceFoo();
public Q_SLOTS: // METHODS
inline QDBusPendingReply<QList<SomeStruct> > GetValues()
{
QList<QVariant> argumentList;
// NOTICE THIS LINE.
return asyncCallWithArgumentList(QStringLiteral("GetValues"), argumentList);
}
Q_SIGNALS: // SIGNALS
};
namespace some {
namespace interface {
typedef ::InterfaceFoo Foo;
}
}
#endif
As you can see the method generated asyncCallWithArgumentList()
is asynchronous: it expects to be connect()
ed to a slot that is triggered when the D-Bus reply arrives.
Instead I want to be able to do:
some::interface::Foo *interface = new some::interface::Foo("some::interface", "/Foo", QDBusConnection::systemBus(), this);
// THIS SHOULD block until a reply is received or it times out.
QList<SomeStruct> data = interface->GetValues();