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