Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : #pragma once 3 : 4 : typedef struct Inhibitor Inhibitor; 5 : 6 : typedef enum InhibitWhat { 7 : INHIBIT_SHUTDOWN = 1 << 0, 8 : INHIBIT_SLEEP = 1 << 1, 9 : INHIBIT_IDLE = 1 << 2, 10 : INHIBIT_HANDLE_POWER_KEY = 1 << 3, 11 : INHIBIT_HANDLE_SUSPEND_KEY = 1 << 4, 12 : INHIBIT_HANDLE_HIBERNATE_KEY = 1 << 5, 13 : INHIBIT_HANDLE_LID_SWITCH = 1 << 6, 14 : _INHIBIT_WHAT_MAX = 1 << 7, 15 : _INHIBIT_WHAT_INVALID = -1 16 : } InhibitWhat; 17 : 18 : typedef enum InhibitMode { 19 : INHIBIT_BLOCK, 20 : INHIBIT_DELAY, 21 : _INHIBIT_MODE_MAX, 22 : _INHIBIT_MODE_INVALID = -1 23 : } InhibitMode; 24 : 25 : #include "logind.h" 26 : 27 : struct Inhibitor { 28 : Manager *manager; 29 : 30 : sd_event_source *event_source; 31 : 32 : const char *id; 33 : char *state_file; 34 : 35 : bool started; 36 : 37 : InhibitWhat what; 38 : char *who; 39 : char *why; 40 : InhibitMode mode; 41 : 42 : pid_t pid; 43 : uid_t uid; 44 : 45 : dual_timestamp since; 46 : 47 : char *fifo_path; 48 : int fifo_fd; 49 : }; 50 : 51 : int inhibitor_new(Inhibitor **ret, Manager *m, const char* id); 52 : Inhibitor* inhibitor_free(Inhibitor *i); 53 : 54 0 : DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free); 55 : 56 : int inhibitor_load(Inhibitor *i); 57 : 58 : int inhibitor_start(Inhibitor *i); 59 : void inhibitor_stop(Inhibitor *i); 60 : 61 : int inhibitor_create_fifo(Inhibitor *i); 62 : 63 : bool inhibitor_is_orphan(Inhibitor *i); 64 : 65 : InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm); 66 : bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending); 67 : 68 : const char *inhibit_what_to_string(InhibitWhat k); 69 : InhibitWhat inhibit_what_from_string(const char *s); 70 : 71 : const char *inhibit_mode_to_string(InhibitMode k); 72 : InhibitMode inhibit_mode_from_string(const char *s);