Question

I would like to generate C++ headers using dbusxx-xml2cpp where some methods are non-blocking, e.g. using invoke_method_noreply instead of invoke_method. Is this possible?

For example the following XML:

<?xml version="1.0" encoding="UTF-8" ?>
<node name="/me/MyService">
    <interface name="me.MyService">
            <method name="MyMethod">
                    <arg direction="in" type="s" name="argument"/>
            </method>
    </interface>
</node>

Would generate (partly):

void MyMethod(const std::string& argument)
{
    ::DBus::CallMessage call;
    ::DBus::MessageIter wi = call.writer();

    wi << argument;
    call.member("MyMethod");
    ::DBus::Message ret = invoke_method (call);
}

But I would like to have something like:

void MyMethod(const std::string& argument)
{
    ::DBus::CallMessage call;
    ::DBus::MessageIter wi = call.writer();

    wi << argument;
    call.member("MyMethod");
    bool ret = invoke_method_noreply (call);
}
Was it helpful?

Solution

Use the annotation org.freedesktop.DBus.Method.NoReply"

Example XML:

<node>
  <interface name="org.test.example">
    <method name="NoReplyMethod">
      <arg name="data" direction="in" type="i"/>
      <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
    </method>
  </interface>
</node>

Generated Code:

void NoReplyMethod(const int32_t& data)
{
    ::DBus::CallMessage call;
    ::DBus::MessageIter wi = call.writer();

    wi << data;
    call.member("NoReplyMethod");
    assert (invoke_method_noreply (call));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top