summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build2
-rw-r--r--src/timer_state.cc47
2 files changed, 22 insertions, 27 deletions
diff --git a/meson.build b/meson.build
index d396a42..33ea224 100644
--- a/meson.build
+++ b/meson.build
@@ -33,7 +33,7 @@ xcb_dep = [dependency('xcb', version: '>= 1.14'),
xcb_xrm_dep = dependency('xcb-xrm', version: '>= 1.0', required: false)
-dbus_dep = dependency('sdbus-c++', version: '>= 0.8.3')
+dbus_dep = dependency('sdbus-c++', version: '>= 2.0.0')
timer_sources = [
'src/args.cc',
diff --git a/src/timer_state.cc b/src/timer_state.cc
index ecaed77..8a0844c 100644
--- a/src/timer_state.cc
+++ b/src/timer_state.cc
@@ -18,9 +18,9 @@
namespace {
-constexpr char kServiceName[] = "org.the_jk.timer";
-constexpr char kObjectPath[] = "/org/the_jk/timer/state";
-constexpr char kInterfaceName[] = "org.the_jk.timer.State";
+const sdbus::ServiceName kServiceName{"org.the_jk.timer"};
+const sdbus::ObjectPath kObjectPath{"/org/the_jk/timer/state"};
+const sdbus::InterfaceName kInterfaceName{"org.the_jk.timer.State"};
class TimerStateImpl {
public:
@@ -92,10 +92,9 @@ public:
});
proxy_->uponSignal("reset").onInterface(kInterfaceName)
.call([this](){ signal_reset(); });
- proxy_->finishRegistration();
- dbus_proxy_ = sdbus::createProxy(*conn_.get(), "org.freedesktop.DBus",
- "/org/freedesktop/DBus");
+ dbus_proxy_ = sdbus::createProxy(*conn_.get(), sdbus::ServiceName{"org.freedesktop.DBus"},
+ sdbus::ObjectPath{"/org/freedesktop/DBus"});
dbus_proxy_->uponSignal("NameOwnerChanged")
.onInterface("org.freedesktop.DBus")
.call([this](const std::string& name,
@@ -105,7 +104,6 @@ public:
signal_restart();
}
});
- dbus_proxy_->finishRegistration();
sync_state();
} catch (sdbus::Error const& err) {
@@ -136,7 +134,7 @@ private:
}
void sync_state() {
- auto method = proxy_->createMethodCall(kInterfaceName, "get_state");
+ auto method = proxy_->createMethodCall(kInterfaceName, sdbus::MethodName{"get_state"});
auto reply = proxy_->callMethod(std::move(method));
bool active;
uint32_t total;
@@ -214,24 +212,21 @@ public:
try {
auto object = sdbus::createObject(*conn_.get(), kObjectPath);
- std::function<void()> fun = std::bind(&TimerStateServer::start, this);
- object->registerMethod("start").onInterface(kInterfaceName)
- .implementedAs(fun).withNoReply();
- fun = std::bind(&TimerStateServer::stop, this);
- object->registerMethod("stop").onInterface(kInterfaceName)
- .implementedAs(fun).withNoReply();
- fun = std::bind(&TimerStateServer::reset, this);
- object->registerMethod("reset").onInterface(kInterfaceName)
- .implementedAs(fun).withNoReply();
- std::function<void(sdbus::MethodCall)> call_fun =
- std::bind(&TimerStateServer::get_state, this, std::placeholders::_1);
- object->registerMethod(kInterfaceName, "get_state", "", "bux", call_fun);
- object->registerSignal("started").onInterface(kInterfaceName)
- .withParameters<uint32_t, int64_t>();
- object->registerSignal("stopped").onInterface(kInterfaceName)
- .withParameters<uint32_t>();
- object->registerSignal("reset").onInterface(kInterfaceName);
- object->finishRegistration();
+ auto start = [this]() { this->start(); };
+ auto stop = [this]() { this->stop(); };
+ auto reset = [this]() { this->reset(); };
+ auto get_state = std::bind(&TimerStateServer::get_state, this, std::placeholders::_1);
+ object->addVTable(
+ sdbus::registerMethod("start").implementedAs(std::move(start)).withNoReply(),
+ sdbus::registerMethod("stop").implementedAs(std::move(stop)).withNoReply(),
+ sdbus::registerMethod("reset").implementedAs(std::move(reset)).withNoReply(),
+ sdbus::MethodVTableItem{
+ sdbus::MethodName{"get_state"}, sdbus::Signature{""}, {}, sdbus::Signature{"bux"}, {}, get_state, {}
+ },
+ sdbus::registerSignal("started").withParameters<uint32_t, int64_t>(),
+ sdbus::registerSignal("stopped").withParameters<uint32_t>(),
+ sdbus::registerSignal("reset")
+ ).forInterface(kInterfaceName);
object_ = std::move(object);
} catch (sdbus::Error const& err) {