chiark / gitweb /
Prep v231: Move elogind specific code in login/loginctl.c to login/eloginctl.c
[elogind.git] / src / login / logind-inhibit.h
1 #pragma once
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2012 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 typedef struct Inhibitor Inhibitor;
23
24
25 typedef enum InhibitWhat {
26         INHIBIT_SHUTDOWN = 1,
27         INHIBIT_SLEEP = 2,
28         INHIBIT_IDLE = 4,
29         INHIBIT_HANDLE_POWER_KEY = 8,
30         INHIBIT_HANDLE_SUSPEND_KEY = 16,
31         INHIBIT_HANDLE_HIBERNATE_KEY = 32,
32         INHIBIT_HANDLE_LID_SWITCH = 64,
33         _INHIBIT_WHAT_MAX = 128,
34         _INHIBIT_WHAT_INVALID = -1
35 } InhibitWhat;
36
37 typedef enum InhibitMode {
38         INHIBIT_BLOCK,
39         INHIBIT_DELAY,
40         _INHIBIT_MODE_MAX,
41         _INHIBIT_MODE_INVALID = -1
42 } InhibitMode;
43
44 #include "logind.h"
45
46 struct Inhibitor {
47         Manager *manager;
48
49         sd_event_source *event_source;
50
51         char *id;
52         char *state_file;
53
54         bool started;
55
56         InhibitWhat what;
57         char *who;
58         char *why;
59         InhibitMode mode;
60
61         pid_t pid;
62         uid_t uid;
63
64         dual_timestamp since;
65
66         char *fifo_path;
67         int fifo_fd;
68 };
69
70 Inhibitor* inhibitor_new(Manager *m, const char *id);
71 void inhibitor_free(Inhibitor *i);
72
73 int inhibitor_save(Inhibitor *i);
74 int inhibitor_load(Inhibitor *i);
75
76 int inhibitor_start(Inhibitor *i);
77 int inhibitor_stop(Inhibitor *i);
78
79 int inhibitor_create_fifo(Inhibitor *i);
80 void inhibitor_remove_fifo(Inhibitor *i);
81
82 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
83 bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
84
85 const char *inhibit_what_to_string(InhibitWhat k);
86 InhibitWhat inhibit_what_from_string(const char *s);
87
88 const char *inhibit_mode_to_string(InhibitMode k);
89 InhibitMode inhibit_mode_from_string(const char *s);