1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// System.hh
//
// Copyright (C) 2002, 2003, 2004, 2006, 2007, 2011, 2012, 2013 Rob Caelers & Raymond Penners
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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/>.
//
#ifndef SYSTEM_HH
#define SYSTEM_HH
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_GLIB
# include <glib.h>
#endif
#include <vector>
#if defined(HAVE_DBUS)
# include <glib.h>
# include <gio/gio.h>
#endif
#include "IScreenLockMethod.hh"
#include "ISystemStateChangeMethod.hh"
class System
{
public:
class SystemOperation
{
public:
enum SystemOperationType
{
SYSTEM_OPERATION_NONE,
SYSTEM_OPERATION_LOCK_SCREEN,
SYSTEM_OPERATION_SHUTDOWN,
SYSTEM_OPERATION_SUSPEND,
SYSTEM_OPERATION_HIBERNATE,
SYSTEM_OPERATION_SUSPEND_HYBRID,
};
// A simple, English language name of the operation
// Not translated into native language here because
// this class is not concerned with UI
const char *name;
SystemOperationType type;
bool execute() const { return System::execute(type); }
bool operator<(const SystemOperation &other) const { return this->type < other.type; }
private:
SystemOperation(const char *name, const SystemOperationType type)
: name(name)
, type(type){};
friend class System;
};
static bool is_lockable() { return !lock_commands.empty(); }
static bool lock_screen();
static std::vector<SystemOperation> get_supported_system_operations() { return supported_system_operations; }
static bool execute(SystemOperation::SystemOperationType type);
// display will not be owned by System,
// the caller may free it after calling
// this function
static void init(
#if defined(PLATFORM_OS_UNIX)
const char *display
#endif
);
static void clear();
private:
static std::vector<IScreenLockMethod *> lock_commands;
static std::vector<ISystemStateChangeMethod *> system_state_commands;
static std::vector<SystemOperation> supported_system_operations;
#if defined(PLATFORM_OS_UNIX)
# ifdef HAVE_DBUS
static void init_DBus();
static void init_DBus_lock_commands();
static inline bool add_DBus_lock_cmd(const char *dbus_name,
const char *dbus_path,
const char *dbus_interface,
const char *dbus_lock_method,
const char *dbus_method_to_check_existence);
static void add_DBus_system_state_command(ISystemStateChangeMethod *method);
static void init_DBus_system_state_commands();
static GDBusConnection *session_connection;
static GDBusConnection *system_connection;
# endif
static inline void add_cmdline_lock_cmd(const char *command_name, const char *parameters, bool async);
static void init_cmdline_lock_commands(const char *display);
static bool invoke(const gchar *command, bool async = false);
#endif // defined(PLATFORM_OS_UNIX)
};
#endif // SYSTEM_HH
|