chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / login / logind-session.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 typedef struct Session Session;
5 typedef enum KillWho KillWho;
6
7 #include "list.h"
8 #include "login-util.h"
9 #include "logind-user.h"
10
11 typedef enum SessionState {
12         SESSION_OPENING,  /* Session scope is being created */
13         SESSION_ONLINE,   /* Logged in */
14         SESSION_ACTIVE,   /* Logged in and in the fg */
15         SESSION_CLOSING,  /* Logged out, but scope is still there */
16         _SESSION_STATE_MAX,
17         _SESSION_STATE_INVALID = -1
18 } SessionState;
19
20 typedef enum SessionClass {
21         SESSION_USER,
22         SESSION_GREETER,
23         SESSION_LOCK_SCREEN,
24         SESSION_BACKGROUND,
25         _SESSION_CLASS_MAX,
26         _SESSION_CLASS_INVALID = -1
27 } SessionClass;
28
29 typedef enum SessionType {
30         SESSION_UNSPECIFIED,
31         SESSION_TTY,
32         SESSION_X11,
33         SESSION_WAYLAND,
34         SESSION_MIR,
35         SESSION_WEB,
36         _SESSION_TYPE_MAX,
37         _SESSION_TYPE_INVALID = -1
38 } SessionType;
39
40 #define SESSION_TYPE_IS_GRAPHICAL(type) IN_SET(type, SESSION_X11, SESSION_WAYLAND, SESSION_MIR)
41
42 enum KillWho {
43         KILL_LEADER,
44         KILL_ALL,
45         _KILL_WHO_MAX,
46         _KILL_WHO_INVALID = -1
47 };
48
49 struct Session {
50         Manager *manager;
51
52         const char *id;
53         unsigned int position;
54         SessionType type;
55         SessionClass class;
56
57         char *state_file;
58
59         User *user;
60
61         dual_timestamp timestamp;
62
63         char *tty;
64         char *display;
65
66         bool remote;
67         char *remote_user;
68         char *remote_host;
69         char *service;
70         char *desktop;
71
72         char *scope;
73 #if 0 /// UNNEEDED by elogind
74         char *scope_job;
75 #endif // 0
76
77         Seat *seat;
78         unsigned int vtnr;
79         int vtfd;
80
81         pid_t leader;
82         uint32_t audit_id;
83
84         int fifo_fd;
85         char *fifo_path;
86
87         sd_event_source *fifo_event_source;
88
89         bool idle_hint;
90         dual_timestamp idle_hint_timestamp;
91
92         bool locked_hint;
93
94         bool in_gc_queue:1;
95         bool started:1;
96         bool stopping:1;
97
98         bool was_active:1;
99
100         sd_bus_message *create_message;
101
102         sd_event_source *timer_event_source;
103
104         char *controller;
105         Hashmap *devices;
106         sd_bus_track *track;
107
108         LIST_FIELDS(Session, sessions_by_user);
109         LIST_FIELDS(Session, sessions_by_seat);
110
111         LIST_FIELDS(Session, gc_queue);
112 };
113
114 Session *session_new(Manager *m, const char *id);
115 void session_free(Session *s);
116 void session_set_user(Session *s, User *u);
117 bool session_may_gc(Session *s, bool drop_not_started);
118 void session_add_to_gc_queue(Session *s);
119 int session_activate(Session *s);
120 bool session_is_active(Session *s);
121 int session_get_idle_hint(Session *s, dual_timestamp *t);
122 void session_set_idle_hint(Session *s, bool b);
123 int session_get_locked_hint(Session *s);
124 void session_set_locked_hint(Session *s, bool b);
125 int session_create_fifo(Session *s);
126 int session_start(Session *s, sd_bus_message *properties);
127 int session_stop(Session *s, bool force);
128 int session_finalize(Session *s);
129 int session_release(Session *s);
130 int session_save(Session *s);
131 int session_load(Session *s);
132 int session_kill(Session *s, KillWho who, int signo);
133
134 SessionState session_get_state(Session *u);
135
136 extern const sd_bus_vtable session_vtable[];
137 int session_node_enumerator(sd_bus *bus, const char *path,void *userdata, char ***nodes, sd_bus_error *error);
138 int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
139 char *session_bus_path(Session *s);
140
141 int session_send_signal(Session *s, bool new_session);
142 int session_send_changed(Session *s, const char *properties, ...) _sentinel_;
143 int session_send_lock(Session *s, bool lock);
144 int session_send_lock_all(Manager *m, bool lock);
145
146 int session_send_create_reply(Session *s, sd_bus_error *error);
147
148 const char* session_state_to_string(SessionState t) _const_;
149 SessionState session_state_from_string(const char *s) _pure_;
150
151 const char* session_type_to_string(SessionType t) _const_;
152 SessionType session_type_from_string(const char *s) _pure_;
153
154 const char* session_class_to_string(SessionClass t) _const_;
155 SessionClass session_class_from_string(const char *s) _pure_;
156
157 const char *kill_who_to_string(KillWho k) _const_;
158 KillWho kill_who_from_string(const char *s) _pure_;
159
160 int session_prepare_vt(Session *s);
161 void session_restore_vt(Session *s);
162 void session_leave_vt(Session *s);
163
164 bool session_is_controller(Session *s, const char *sender);
165 int session_set_controller(Session *s, const char *sender, bool force, bool prepare);
166 void session_drop_controller(Session *s);
167
168 int bus_session_method_activate(sd_bus_message *message, void *userdata, sd_bus_error *error);
169 int bus_session_method_lock(sd_bus_message *message, void *userdata, sd_bus_error *error);
170 int bus_session_method_terminate(sd_bus_message *message, void *userdata, sd_bus_error *error);
171 int bus_session_method_kill(sd_bus_message *message, void *userdata, sd_bus_error *error);