3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2014 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
|
|
18 |
*/
|
|
19 |
||
20 |
#include "SessionDBusManager.h" |
|
21 |
||
22 |
namespace unity |
|
23 |
{
|
|
24 |
namespace session |
|
25 |
{
|
|
26 |
namespace dbus |
|
27 |
{
|
|
28 |
const std::string NAME = "com.canonical.Unity"; |
|
29 |
const std::string INTERFACE = "com.canonical.Unity.Session"; |
|
30 |
const std::string OBJECT_PATH = "/com/canonical/Unity/Session"; |
|
31 |
const std::string INTROSPECTION_XML = |
|
32 |
R"(<node> |
|
33 |
<interface name="com.canonical.Unity.Session">
|
|
34 |
<method name="RealName">
|
|
35 |
<arg type="s" direction="out" name="realname" />
|
|
36 |
</method>
|
|
37 |
<method name="UserName">
|
|
38 |
<arg type="s" direction="out" name="username" />
|
|
39 |
</method>
|
|
40 |
<method name="HostName">
|
|
41 |
<arg type="s" direction="out" name="hostname" />
|
|
42 |
</method>
|
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
43 |
<method name="Lock" />
|
3736.1.38
by Marco Trevisan (Treviño)
SessionDBusManager: export PromptLock method on the dbus |
44 |
<method name="PromptLock" />
|
3736.1.41
by Marco Trevisan (Treviño)
SessionManager: add ScreenSaver{Activate,Deactivate} and relevant signals and export them |
45 |
<method name="ActivateScreenSaver" />
|
46 |
<method name="DeactivateScreenSaver" />
|
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
47 |
<method name="Logout" />
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
48 |
<method name="RequestLogout" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
49 |
<method name="Reboot" />
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
50 |
<method name="RequestReboot" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
51 |
<method name="Shutdown" />
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
52 |
<method name="RequestShutdown" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
53 |
<method name="Suspend" />
|
54 |
<method name="Hibernate" />
|
|
55 |
<method name="CancelAction" />
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
56 |
<method name="IsLocked">
|
57 |
<arg type="b" direction="out" name="is_locked" />
|
|
58 |
</method>
|
|
59 |
<method name="CanLock">
|
|
60 |
<arg type="b" direction="out" name="can_lock" />
|
|
61 |
</method>
|
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
62 |
<method name="CanShutdown">
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
63 |
<arg type="b" direction="out" name="can_shutdown" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
64 |
</method>
|
65 |
<method name="CanSuspend">
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
66 |
<arg type="b" direction="out" name="can_suspend" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
67 |
</method>
|
68 |
<method name="CanHibernate">
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
69 |
<arg type="b" direction="out" name="can_hibernate" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
70 |
</method>
|
71 |
||
72 |
<signal name="LockRequested" />
|
|
3695.4.55
by Marco Trevisan (Treviño)
SessionManager: add locked/unlocked signals |
73 |
<signal name="Locked" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
74 |
<signal name="UnlockRequested" />
|
3695.4.55
by Marco Trevisan (Treviño)
SessionManager: add locked/unlocked signals |
75 |
<signal name="Unlocked" />
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
76 |
<signal name="LogoutRequested">
|
77 |
<arg type="b" name="have_inhibitors" />
|
|
78 |
</signal>
|
|
79 |
<signal name="RebootRequested">
|
|
80 |
<arg type="b" name="have_inhibitors" />
|
|
81 |
</signal>
|
|
82 |
<signal name="ShutdownRequested">
|
|
83 |
<arg type="b" name="have_inhibitors" />
|
|
84 |
</signal>
|
|
85 |
</interface>
|
|
86 |
</node>)"; |
|
87 |
}
|
|
88 |
||
89 |
DBusManager::DBusManager(session::Manager::Ptr const& session) |
|
90 |
: session_(session) |
|
91 |
, server_(dbus::NAME) |
|
92 |
{
|
|
93 |
server_.AddObjects(dbus::INTROSPECTION_XML, dbus::OBJECT_PATH); |
|
94 |
object_ = server_.GetObject(dbus::INTERFACE); |
|
95 |
object_->SetMethodsCallsHandler([this] (std::string const& method, GVariant*) -> GVariant* { |
|
96 |
if (method == "RealName") |
|
97 |
{
|
|
98 |
return g_variant_new("(s)", session_->RealName().c_str()); |
|
99 |
}
|
|
100 |
else if (method == "UserName") |
|
101 |
{
|
|
102 |
return g_variant_new("(s)", session_->UserName().c_str()); |
|
103 |
}
|
|
104 |
else if (method == "HostName") |
|
105 |
{
|
|
106 |
return g_variant_new("(s)", session_->HostName().c_str()); |
|
107 |
}
|
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
108 |
else if (method == "Lock") |
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
109 |
{
|
110 |
session_->LockScreen(); |
|
111 |
}
|
|
3736.1.31
by Marco Trevisan (Treviño)
SessionDBusManager: add support for "PromptLock" |
112 |
else if (method == "PromptLock") |
113 |
{
|
|
114 |
session_->PromptLockScreen(); |
|
115 |
}
|
|
3736.1.41
by Marco Trevisan (Treviño)
SessionManager: add ScreenSaver{Activate,Deactivate} and relevant signals and export them |
116 |
else if (method == "ActivateScreenSaver") |
117 |
{
|
|
118 |
session_->ScreenSaverActivate(); |
|
119 |
}
|
|
120 |
else if (method == "DeactivateScreenSaver") |
|
121 |
{
|
|
122 |
session_->ScreenSaverDeactivate(); |
|
123 |
}
|
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
124 |
else if (method == "Logout") |
125 |
{
|
|
126 |
session_->Logout(); |
|
127 |
}
|
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
128 |
else if (method == "RequestLogout") |
129 |
{
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
130 |
session_->logout_requested.emit(session_->HasInhibitors()); |
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
131 |
}
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
132 |
else if (method == "Reboot") |
133 |
{
|
|
134 |
session_->Reboot(); |
|
135 |
}
|
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
136 |
else if (method == "RequestReboot") |
137 |
{
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
138 |
session_->reboot_requested.emit(session_->HasInhibitors()); |
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
139 |
}
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
140 |
else if (method == "Shutdown") |
141 |
{
|
|
142 |
session_->Shutdown(); |
|
143 |
}
|
|
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
144 |
else if (method == "RequestShutdown") |
145 |
{
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
146 |
session_->shutdown_requested.emit(session_->HasInhibitors()); |
3695.4.52
by Marco Trevisan (Treviño)
SessionDBusManager: add Request actions (to prompt dialogs) |
147 |
}
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
148 |
else if (method == "Suspend") |
149 |
{
|
|
150 |
session_->Suspend(); |
|
151 |
}
|
|
152 |
else if (method == "Hibernate") |
|
153 |
{
|
|
154 |
session_->Hibernate(); |
|
155 |
}
|
|
156 |
else if (method == "CancelAction") |
|
157 |
{
|
|
158 |
session_->CancelAction(); |
|
3695.4.54
by Marco Trevisan (Treviño)
SessionDBusManager: make sure we cancel an action also UI side |
159 |
session_->cancel_requested.emit(); |
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
160 |
}
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
161 |
else if (method == "IsLocked") |
162 |
{
|
|
163 |
return g_variant_new("(b)", session_->is_locked() != false); |
|
164 |
}
|
|
165 |
else if (method == "CanLock") |
|
166 |
{
|
|
167 |
return g_variant_new("(b)", session_->CanLock() != false); |
|
168 |
}
|
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
169 |
else if (method == "CanShutdown") |
170 |
{
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
171 |
return g_variant_new("(b)", session_->CanShutdown() != false); |
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
172 |
}
|
173 |
else if (method == "CanSuspend") |
|
174 |
{
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
175 |
return g_variant_new("(b)", session_->CanSuspend() != false); |
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
176 |
}
|
177 |
else if (method == "CanHibernate") |
|
178 |
{
|
|
3800.1.5
by Marco Trevisan (Treviño)
LockScreenAcceleratorController: do ther configured action on power special keys press |
179 |
return g_variant_new("(b)", session_->CanHibernate() != false); |
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
180 |
}
|
181 |
||
182 |
return nullptr; |
|
183 |
});
|
|
184 |
||
185 |
connections_.Add(session_->lock_requested.connect([this] { |
|
186 |
object_->EmitSignal("LockRequested"); |
|
187 |
}));
|
|
3736.1.31
by Marco Trevisan (Treviño)
SessionDBusManager: add support for "PromptLock" |
188 |
connections_.Add(session_->prompt_lock_requested.connect([this] { |
189 |
object_->EmitSignal("LockRequested"); |
|
190 |
}));
|
|
3695.4.55
by Marco Trevisan (Treviño)
SessionManager: add locked/unlocked signals |
191 |
connections_.Add(session_->locked.connect([this] { |
192 |
object_->EmitSignal("Locked"); |
|
193 |
}));
|
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
194 |
connections_.Add(session_->unlock_requested.connect([this] { |
195 |
object_->EmitSignal("UnlockRequested"); |
|
196 |
}));
|
|
3695.4.55
by Marco Trevisan (Treviño)
SessionManager: add locked/unlocked signals |
197 |
connections_.Add(session_->unlocked.connect([this] { |
198 |
object_->EmitSignal("Unlocked"); |
|
199 |
}));
|
|
3695.4.51
by Marco Trevisan (Treviño)
SessionDBusManager: add new dbus server to reply to session controlling requests |
200 |
connections_.Add(session_->logout_requested.connect([this] (bool inhibitors) { |
201 |
object_->EmitSignal("LogoutRequested", g_variant_new("(b)", inhibitors)); |
|
202 |
}));
|
|
203 |
connections_.Add(session_->reboot_requested.connect([this] (bool inhibitors) { |
|
204 |
object_->EmitSignal("RebootRequested", g_variant_new("(b)", inhibitors)); |
|
205 |
}));
|
|
206 |
connections_.Add(session_->shutdown_requested.connect([this] (bool inhibitors) { |
|
207 |
object_->EmitSignal("ShutdownRequested", g_variant_new("(b)", inhibitors)); |
|
208 |
}));
|
|
209 |
}
|
|
210 |
||
211 |
} // session |
|
212 |
} // unity |