87
87
shell_object_ = shell_server_.GetObject(shell::DBUS_INTERFACE);
88
88
shell_object_->SetMethodsCallsHandler(sigc::mem_fun(this, &Impl::OnShellMethodCall));
90
CallUPowerMethod("HibernateAllowed", [this] (GVariant* variant) {
91
can_hibernate_ = glib::Variant(variant).GetBool();
92
LOG_INFO(logger) << "Can hibernate: " << can_hibernate_;
90
CallLogindMethod("CanHibernate", nullptr, [this] (GVariant* variant, glib::Error const& err) {
93
// fall back to upower
94
CallUPowerMethod("HibernateAllowed", [this] (GVariant* variant) {
95
can_hibernate_ = glib::Variant(variant).GetBool();
96
LOG_INFO(logger) << "Can hibernate (upower): " << can_hibernate_;
101
can_hibernate_ = glib::Variant(variant).GetString() == "yes";
102
LOG_INFO(logger) << "Can hibernate (logind): " << can_hibernate_;
95
CallUPowerMethod("SuspendAllowed", [this] (GVariant* variant) {
96
can_suspend_ = glib::Variant(variant).GetBool();
97
LOG_INFO(logger) << "Can suspend: " << can_suspend_;
106
CallLogindMethod("CanSuspend", nullptr, [this] (GVariant* variant, glib::Error const& err) {
109
// fall back to upower
110
CallUPowerMethod("SuspendAllowed", [this] (GVariant* variant) {
111
can_suspend_ = glib::Variant(variant).GetBool();
112
LOG_INFO(logger) << "Can suspend (upower): " << can_suspend_;
117
can_suspend_ = glib::Variant(variant).GetString() == "yes";
118
LOG_INFO(logger) << "Can suspend (logind): " << can_suspend_;
100
122
CallGnomeSessionMethod("CanShutdown", nullptr, [this] (GVariant* variant, glib::Error const& e) {
323
void GnomeManager::Impl::CallLogindMethod(std::string const& method, GVariant* parameters, glib::DBusProxy::CallFinishedCallback const& cb)
325
auto proxy = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.login1",
326
"/org/freedesktop/login1",
327
"org.freedesktop.login1.Manager",
328
test_mode_ ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM);
330
// By passing the proxy to the lambda we ensure that it will be smartly handled
331
proxy->CallBegin(method, parameters, [proxy, cb, method] (GVariant* ret, glib::Error const& e) {
334
LOG_ERROR(logger) << "logind " << method << " call failed: " << e.Message();
301
344
void GnomeManager::Impl::CallConsoleKitMethod(std::string const& method, GVariant* parameters)
303
346
auto proxy = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.ConsoleKit",
379
422
LOG_WARNING(logger) << "Got error during call: " << err.Message();
381
424
impl_->pending_action_ = shell::Action::NONE;
382
const char* cookie = g_getenv("XDG_SESSION_COOKIE");
384
if (cookie && cookie[0] != '\0')
385
impl_->CallConsoleKitMethod("CloseSession", g_variant_new("(s)", cookie));
425
// fallback to logind
426
const char* session_id = g_getenv("XDG_SESSION_ID");
428
auto call_consolekit_lambda = [this] {
429
// fallback to ConsoleKit
430
const char* cookie = g_getenv("XDG_SESSION_COOKIE");
432
if (cookie && cookie[0] != '\0')
433
impl_->CallConsoleKitMethod("CloseSession", g_variant_new("(s)", cookie));
436
if (session_id && session_id[0] != '\0')
438
impl_->CallLogindMethod("TerminateSession", g_variant_new("(s)", session_id), [call_consolekit_lambda] (GVariant*, glib::Error const& err) {
440
call_consolekit_lambda();
445
call_consolekit_lambda();
399
460
<< ". Using fallback method";
401
462
impl_->pending_action_ = shell::Action::NONE;
402
impl_->CallConsoleKitMethod("Restart");
464
impl_->CallLogindMethod("Reboot", g_variant_new("(b)", FALSE), [this] (GVariant* variant, glib::Error const& err) {
465
// ConsoleKit fallback
467
impl_->CallConsoleKitMethod("Restart");
416
482
<< ". Using fallback method";
418
484
impl_->pending_action_ = shell::Action::NONE;
419
impl_->CallConsoleKitMethod("Stop");
486
impl_->CallLogindMethod("PowerOff", g_variant_new("(b)", FALSE), [this] (GVariant* variant, glib::Error const& err) {
487
// ConsoleKit fallback
489
impl_->CallConsoleKitMethod("Stop");
424
495
void GnomeManager::Suspend()
426
497
impl_->EnsureCancelPendingAction();
427
impl_->CallUPowerMethod("Suspend");
498
impl_->CallLogindMethod("Suspend", g_variant_new("(b)", FALSE), [this] (GVariant* variant, glib::Error const& err) {
499
// fallback to UPower
501
impl_->CallUPowerMethod("Suspend");
430
505
void GnomeManager::Hibernate()
432
507
impl_->EnsureCancelPendingAction();
433
impl_->CallUPowerMethod("Hibernate");
508
impl_->CallLogindMethod("Hibernate", g_variant_new("(b)", FALSE), [this] (GVariant* variant, glib::Error const& err) {
509
// fallback to UPower
511
impl_->CallUPowerMethod("Hibernate");
436
515
bool GnomeManager::CanShutdown() const