chiark / gitweb /
edaae8d20ac43bbacbaf62aa00eb89ce49f77dd5
[elogind.git] / src / login / logind-session.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 2011 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 Session Session;
25 typedef enum KillWho KillWho;
26
27 #include "list.h"
28 #include "util.h"
29 #include "logind.h"
30 #include "logind-seat.h"
31 #include "logind-user.h"
32
33 typedef enum SessionState {
34         SESSION_OPENING,  /* Session scope is being created */
35         SESSION_ONLINE,   /* Logged in */
36         SESSION_ACTIVE,   /* Logged in and in the fg */
37         SESSION_CLOSING,  /* Logged out, but scope is still there */
38         _SESSION_STATE_MAX,
39         _SESSION_STATE_INVALID = -1
40 } SessionState;
41
42 typedef enum SessionClass {
43         SESSION_USER,
44         SESSION_GREETER,
45         SESSION_LOCK_SCREEN,
46         SESSION_BACKGROUND,
47         _SESSION_CLASS_MAX,
48         _SESSION_CLASS_INVALID = -1
49 } SessionClass;
50
51 typedef enum SessionType {
52         SESSION_UNSPECIFIED,
53         SESSION_TTY,
54         SESSION_X11,
55         _SESSION_TYPE_MAX,
56         _SESSION_TYPE_INVALID = -1
57 } SessionType;
58
59 enum KillWho {
60         KILL_LEADER,
61         KILL_ALL,
62         _KILL_WHO_MAX,
63         _KILL_WHO_INVALID = -1
64 };
65
66 struct Session {
67         Manager *manager;
68
69         char *id;
70         SessionType type;
71         SessionClass class;
72
73         char *state_file;
74
75         User *user;
76
77         dual_timestamp timestamp;
78
79         char *tty;
80         char *display;
81
82         bool remote;
83         char *remote_user;
84         char *remote_host;
85         char *service;
86
87         char *scope;
88         char *scope_job;
89
90         int vtnr;
91         Seat *seat;
92
93         pid_t leader;
94         uint32_t audit_id;
95
96         int fifo_fd;
97         char *fifo_path;
98
99         bool idle_hint;
100         dual_timestamp idle_hint_timestamp;
101
102         bool in_gc_queue:1;
103         bool started:1;
104         bool closing:1;
105
106         DBusMessage *create_message;
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 int session_check_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_create_fifo(Session *s);
124 void session_remove_fifo(Session *s);
125 int session_start(Session *s);
126 int session_stop(Session *s);
127 int session_finalize(Session *s);
128 int session_save(Session *s);
129 int session_load(Session *s);
130 int session_kill(Session *s, KillWho who, int signo);
131
132 char *session_bus_path(Session *s);
133
134 SessionState session_get_state(Session *u);
135
136 extern const DBusObjectPathVTable bus_session_vtable;
137
138 int session_send_signal(Session *s, bool new_session);
139 int session_send_changed(Session *s, const char *properties);
140 int session_send_lock(Session *s, bool lock);
141 int session_send_lock_all(Manager *m, bool lock);
142
143 int session_send_create_reply(Session *s, DBusError *error);
144
145 const char* session_state_to_string(SessionState t) _const_;
146 SessionState session_state_from_string(const char *s) _pure_;
147
148 const char* session_type_to_string(SessionType t) _const_;
149 SessionType session_type_from_string(const char *s) _pure_;
150
151 const char* session_class_to_string(SessionClass t) _const_;
152 SessionClass session_class_from_string(const char *s) _pure_;
153
154 const char *kill_who_to_string(KillWho k) _const_;
155 KillWho kill_who_from_string(const char *s) _pure_;