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