diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-09-02 01:50:10 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-09-02 01:50:10 +0200 |
| commit | 00d68bd94b4269ddfc55bdc862d41170e688a964 (patch) | |
| tree | 723a926a6b365cf17f95cf143b4a50edfb224d5c | |
| parent | aff8bd54f548ca1dca15b563894db8efb6ed5528 (diff) | |
SystemdWrapper: add CallMethod and use a temporary proxy to call dbus manager
We don't need to keep it around (bzr r4153.9.52)
| -rw-r--r-- | unity-shared/SystemdWrapper.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/unity-shared/SystemdWrapper.cpp b/unity-shared/SystemdWrapper.cpp index 65f33de8f..f3f294f0b 100644 --- a/unity-shared/SystemdWrapper.cpp +++ b/unity-shared/SystemdWrapper.cpp @@ -35,30 +35,37 @@ public: void Start(std::string const& name); void Stop(std::string const& name); - bool IsConnected(); + void CallMethod(std::string const& method, std::string const& unit); private: + bool test_mode_; glib::DBusProxy::Ptr systemd_proxy_; }; SystemdWrapper::Impl::Impl(bool test) + : test_mode_(test) +{} + +void SystemdWrapper::Impl::CallMethod(std::string const& method, std::string const& unit) { - auto const& busname = test ? "com.canonical.Unity.Test.Systemd" : "org.freedesktop.systemd1"; + auto const& busname = test_mode_ ? "com.canonical.Unity.Test.Systemd" : "org.freedesktop.systemd1"; auto flags = static_cast<GDBusProxyFlags>(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS); - systemd_proxy_ = std::make_shared<unity::glib::DBusProxy>(busname, "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - G_BUS_TYPE_SESSION, flags); + auto proxy = std::make_shared<glib::DBusProxy>(busname, "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + G_BUS_TYPE_SESSION, flags); + + proxy->CallBegin(method, g_variant_new("(ss)", unit.c_str(), "replace"), [proxy] (GVariant*, glib::Error const& e) {}); } void SystemdWrapper::Impl::Start(std::string const& name) { - systemd_proxy_->Call("StartUnit", g_variant_new("(ss)", name.c_str(), "replace")); + CallMethod("StartUnit", name); } void SystemdWrapper::Impl::Stop(std::string const& name) { - systemd_proxy_->Call("StopUnit", g_variant_new("(ss)", name.c_str(), "replace")); + CallMethod("StopUnit", name); } // |
