Introduce support for some common D-Bus annotations (#30)

* Add ability to declare property behavior on PropertyChanged signal

* Add support for Method.NoReply annotation (WIP)

* Add support for common annotations/flags
This commit is contained in:
Stanislav Angelovič
2019-01-10 08:47:59 +01:00
committed by Lukáš Ďurfina
parent 2c78e08d19
commit 9c0e98c580
24 changed files with 1036 additions and 93 deletions

View File

@@ -571,7 +571,28 @@ void* Message::getMsg() const
return msg_;
}
void MethodCall::dontExpectReply()
{
auto r = sd_bus_message_set_expect_reply((sd_bus_message*)getMsg(), 0);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to set the dont-expect-reply flag", -r);
}
bool MethodCall::doesntExpectReply() const
{
auto r = sd_bus_message_get_expect_reply((sd_bus_message*)getMsg());
SDBUS_THROW_ERROR_IF(r < 0, "Failed to get the dont-expect-reply flag", -r);
return r > 0 ? false : true;
}
MethodReply MethodCall::send() const
{
if (!doesntExpectReply())
return sendWithReply();
else
return sendWithNoReply();
}
MethodReply MethodCall::sendWithReply() const
{
sd_bus_message* sdbusReply{};
SCOPE_EXIT{ sd_bus_message_unref(sdbusReply); }; // Returned message will become an owner of sdbusReply
@@ -590,6 +611,13 @@ MethodReply MethodCall::send() const
return MethodReply(sdbusReply);
}
MethodReply MethodCall::sendWithNoReply() const
{
auto r = sd_bus_send(nullptr, (sd_bus_message*)getMsg(), nullptr);
SDBUS_THROW_ERROR_IF(r < 0, "Failed to call method with no reply", -r);
return MethodReply{}; // No reply
}
MethodReply MethodCall::createReply() const
{
sd_bus_message *sdbusReply{};