summaryrefslogtreecommitdiff
path: root/shutdown
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2014-03-07 04:26:23 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2014-03-07 04:26:23 +0100
commit652097020da3fc9cab99a241fe7fa88333d1b913 (patch)
tree6546dd220dc9af6263cf0bc1de35065ed7799aed /shutdown
parentf4abfbcceb2b7e99d500da40e0c8bfabfec3e0f2 (diff)
SessionDBusManager: add new dbus server to reply to session controlling requests
(bzr r3695.4.51)
Diffstat (limited to 'shutdown')
-rw-r--r--shutdown/CMakeLists.txt1
-rw-r--r--shutdown/SessionDBusManager.cpp156
-rw-r--r--shutdown/SessionDBusManager.h50
3 files changed, 207 insertions, 0 deletions
diff --git a/shutdown/CMakeLists.txt b/shutdown/CMakeLists.txt
index df1de7d4e..29e332788 100644
--- a/shutdown/CMakeLists.txt
+++ b/shutdown/CMakeLists.txt
@@ -19,6 +19,7 @@ include_directories (.. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR
set (SHUTDOWN_SOURCES
SessionButton.cpp
SessionController.cpp
+ SessionDBusManager.cpp
SessionView.cpp
)
diff --git a/shutdown/SessionDBusManager.cpp b/shutdown/SessionDBusManager.cpp
new file mode 100644
index 000000000..8be836319
--- /dev/null
+++ b/shutdown/SessionDBusManager.cpp
@@ -0,0 +1,156 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2014 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: Marco Trevisan <marco.trevisan@canonical.com>
+ */
+
+#include "SessionDBusManager.h"
+
+namespace unity
+{
+namespace session
+{
+namespace dbus
+{
+const std::string NAME = "com.canonical.Unity";
+const std::string INTERFACE = "com.canonical.Unity.Session";
+const std::string OBJECT_PATH = "/com/canonical/Unity/Session";
+const std::string INTROSPECTION_XML =
+R"(<node>
+ <interface name="com.canonical.Unity.Session">
+ <method name="RealName">
+ <arg type="s" direction="out" name="realname" />
+ </method>
+ <method name="UserName">
+ <arg type="s" direction="out" name="username" />
+ </method>
+ <method name="HostName">
+ <arg type="s" direction="out" name="hostname" />
+ </method>
+ <method name="LockScreen" />
+ <method name="Logout" />
+ <method name="Reboot" />
+ <method name="Shutdown" />
+ <method name="Suspend" />
+ <method name="Hibernate" />
+ <method name="CancelAction" />
+ <method name="CanShutdown">
+ <arg type="b" direction="out" name="canshutdown" />
+ </method>
+ <method name="CanSuspend">
+ <arg type="b" direction="out" name="cansuspend" />
+ </method>
+ <method name="CanHibernate">
+ <arg type="b" direction="out" name="canhibernate" />
+ </method>
+
+ <signal name="LockRequested" />
+ <signal name="UnlockRequested" />
+ <signal name="LogoutRequested">
+ <arg type="b" name="have_inhibitors" />
+ </signal>
+ <signal name="RebootRequested">
+ <arg type="b" name="have_inhibitors" />
+ </signal>
+ <signal name="ShutdownRequested">
+ <arg type="b" name="have_inhibitors" />
+ </signal>
+ </interface>
+</node>)";
+}
+
+DBusManager::DBusManager(session::Manager::Ptr const& session)
+ : session_(session)
+ , server_(dbus::NAME)
+{
+ server_.AddObjects(dbus::INTROSPECTION_XML, dbus::OBJECT_PATH);
+ object_ = server_.GetObject(dbus::INTERFACE);
+ object_->SetMethodsCallsHandler([this] (std::string const& method, GVariant*) -> GVariant* {
+ if (method == "RealName")
+ {
+ return g_variant_new("(s)", session_->RealName().c_str());
+ }
+ else if (method == "UserName")
+ {
+ return g_variant_new("(s)", session_->UserName().c_str());
+ }
+ else if (method == "HostName")
+ {
+ return g_variant_new("(s)", session_->HostName().c_str());
+ }
+ else if (method == "LockScreen")
+ {
+ session_->LockScreen();
+ }
+ else if (method == "Logout")
+ {
+ session_->Logout();
+ }
+ else if (method == "Reboot")
+ {
+ session_->Reboot();
+ }
+ else if (method == "Shutdown")
+ {
+ session_->Shutdown();
+ }
+ else if (method == "Suspend")
+ {
+ session_->Suspend();
+ }
+ else if (method == "Hibernate")
+ {
+ session_->Hibernate();
+ }
+ else if (method == "CancelAction")
+ {
+ session_->CancelAction();
+ }
+ else if (method == "CanShutdown")
+ {
+ return g_variant_new("(b)", session_->CanShutdown() != FALSE);
+ }
+ else if (method == "CanSuspend")
+ {
+ return g_variant_new("(b)", session_->CanSuspend() != FALSE);
+ }
+ else if (method == "CanHibernate")
+ {
+ return g_variant_new("(b)", session_->CanHibernate() != FALSE);
+ }
+
+ return nullptr;
+ });
+
+ connections_.Add(session_->lock_requested.connect([this] {
+ object_->EmitSignal("LockRequested");
+ }));
+ connections_.Add(session_->unlock_requested.connect([this] {
+ object_->EmitSignal("UnlockRequested");
+ }));
+ connections_.Add(session_->logout_requested.connect([this] (bool inhibitors) {
+ object_->EmitSignal("LogoutRequested", g_variant_new("(b)", inhibitors));
+ }));
+ connections_.Add(session_->reboot_requested.connect([this] (bool inhibitors) {
+ object_->EmitSignal("RebootRequested", g_variant_new("(b)", inhibitors));
+ }));
+ connections_.Add(session_->shutdown_requested.connect([this] (bool inhibitors) {
+ object_->EmitSignal("ShutdownRequested", g_variant_new("(b)", inhibitors));
+ }));
+}
+
+} // session
+} // unity
diff --git a/shutdown/SessionDBusManager.h b/shutdown/SessionDBusManager.h
new file mode 100644
index 000000000..dbbb2bda9
--- /dev/null
+++ b/shutdown/SessionDBusManager.h
@@ -0,0 +1,50 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2014 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: Marco Trevisan <marco.trevisan@canonical.com>
+ */
+
+#ifndef UNITYSHELL_SESSION_DBUS_MANAGER_H
+#define UNITYSHELL_SESSION_DBUS_MANAGER_H
+
+#include <UnityCore/ConnectionManager.h>
+#include <UnityCore/GLibDBusServer.h>
+#include <UnityCore/SessionManager.h>
+
+namespace unity
+{
+namespace session
+{
+
+class DBusManager
+{
+public:
+ typedef std::shared_ptr<DBusManager> Ptr;
+
+ DBusManager(session::Manager::Ptr const& manager);
+ virtual ~DBusManager() = default;
+
+private:
+ session::Manager::Ptr session_;
+ glib::DBusServer server_;
+ glib::DBusObject::Ptr object_;
+ connection::Manager connections_;
+};
+
+} // session
+} // unity
+
+#endif