diff options
| author | Ted Gould <ted@gould.cx> | 2016-07-20 16:44:32 +0200 |
|---|---|---|
| committer | Ted Gould <ted@gould.cx> | 2016-07-20 16:44:32 +0200 |
| commit | 01b30314870ddb70733e20e57f84ddabee4d1545 (patch) | |
| tree | 4aca625cb52a3178d5e9021f97f73c857fb6c4b3 /unity-shared | |
| parent | 15d1574e529aaefcc2566b1fa1b5e529eaa1214c (diff) | |
Add systemd events to the lock screen
(bzr r4153.9.5)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/SystemdWrapper.cpp | 88 | ||||
| -rw-r--r-- | unity-shared/SystemdWrapper.h | 54 |
3 files changed, 143 insertions, 0 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 7ad243f57..c7a406d46 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -59,6 +59,7 @@ set (UNITY_SHARED_SOURCES SearchBarSpinner.cpp SpreadFilter.cpp StaticCairoText.cpp + SystemdWrapper.cpp TextureCache.cpp TextInput.cpp TextureThumbnailProvider.cpp diff --git a/unity-shared/SystemdWrapper.cpp b/unity-shared/SystemdWrapper.cpp new file mode 100644 index 000000000..2daaf4881 --- /dev/null +++ b/unity-shared/SystemdWrapper.cpp @@ -0,0 +1,88 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 3 -*- +/* +* Copyright © 2016 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Authored by: Ted Gould <ted@canonical.com> +*/ + +#include "SystemdWrapper.h" + +#include <UnityCore/GLibDBusProxy.h> + +namespace unity +{ + +// +// Start private implementation +// + +class SystemdWrapper::Impl +{ +public: + Impl(); + + void Start(std::string const& name); + void Stop(std::string const& name); + +private: + glib::DBusProxy::Ptr systemd_proxy_; +}; + +SystemdWrapper::Impl::Impl() +{ + std::string busname = "org.freedesktop.systemd1"; + if (g_getenv("UNITY_TEST_SYSTEMD)")) { + busname = "com.canonical.Unity.Test.Systemd"; + } + + systemd_proxy_ = std::make_shared<unity::glib::DBusProxy>(busname, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager"); +} + +void SystemdWrapper::Impl::Start(std::string const& name) +{ + systemd_proxy_->Call("StartUnit", g_variant_new("(ss)", name.c_str(), "replace")); +} + +void SystemdWrapper::Impl::Stop(std::string const& name) +{ + systemd_proxy_->Call("StopUnit", g_variant_new("(ss)", name.c_str(), "replace")); +} + +// +// End private implementation +// + +SystemdWrapper::SystemdWrapper() + : pimpl_(new Impl) +{} + +SystemdWrapper::SystemdWrapper(SystemdWrapper::TestMode const& tm) + : pimpl_(new Impl) +{} + +SystemdWrapper::~SystemdWrapper() +{} + +void SystemdWrapper::Start(std::string const& name) +{ + pimpl_->Start(name); +} + +void SystemdWrapper::Stop(std::string const& name) +{ + pimpl_->Stop(name); +} + +} diff --git a/unity-shared/SystemdWrapper.h b/unity-shared/SystemdWrapper.h new file mode 100644 index 000000000..0bd4ba0e7 --- /dev/null +++ b/unity-shared/SystemdWrapper.h @@ -0,0 +1,54 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright © 2016 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Authored by: Ted Gould <ted@canonical.com> +*/ + +#ifndef UNITY_SYSTEMD_WRAPPER +#define UNITY_SYSTEMD_WRAPPER + +#include <memory> + +namespace unity +{ + +class SystemdWrapper +{ +public: + typedef std::shared_ptr<SystemdWrapper> Ptr; + + SystemdWrapper(); + ~SystemdWrapper(); + + void Start(std::string const& name); + void Stop(std::string const& name); + +protected: + struct TestMode {}; + SystemdWrapper(TestMode const&); + +private: + // Noncopyable + SystemdWrapper(SystemdWrapper const&) = delete; + SystemdWrapper& operator=(SystemdWrapper const&) = delete; + + class Impl; + std::unique_ptr<Impl> pimpl_; +}; + +} + +#endif |
