uvtd: seat: implement session IDs
[platform/upstream/kmscon.git] / src / uvtd_seat.h
1 /*
2  * uvtd - User-space VT daemon
3  *
4  * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 /*
27  * Seats
28  * Each set of input+output devices form a single seat. Each seat is independent
29  * of each other and there can be exactly one user per seat interacting with the
30  * system.
31  * Per seat, we have multiple sessions. But only one session can be active at a
32  * time per seat. We allow external sessions, so session activation/deactivation
33  * may be asynchronous.
34  */
35
36 #ifndef UVTD_SEAT_H
37 #define UVTD_SEAT_H
38
39 #include <stdlib.h>
40 #include "eloop.h"
41
42 /* sessions */
43
44 struct uvtd_session;
45
46 enum uvtd_session_event_type {
47         UVTD_SESSION_ACTIVATE,
48         UVTD_SESSION_DEACTIVATE,
49         UVTD_SESSION_UNREGISTER,
50 };
51
52 typedef int (*uvtd_session_cb_t) (struct uvtd_session *session,
53                                   unsigned int event,
54                                   void *data);
55
56 void uvtd_session_ref(struct uvtd_session *sess);
57 void uvtd_session_unref(struct uvtd_session *sess);
58 void uvtd_session_unregister(struct uvtd_session *sess);
59 bool uvtd_session_is_registered(struct uvtd_session *sess);
60
61 bool uvtd_session_is_active(struct uvtd_session *sess);
62 void uvtd_session_schedule(struct uvtd_session *sess);
63
64 void uvtd_session_enable(struct uvtd_session *sess);
65 void uvtd_session_disable(struct uvtd_session *sess);
66 bool uvtd_session_is_enabled(struct uvtd_session *sess);
67
68 void uvtd_session_notify_deactivated(struct uvtd_session *sess);
69
70 /* seats */
71
72 struct uvtd_seat;
73
74 enum uvtd_seat_event {
75         UVTD_SEAT_SLEEP,
76 };
77
78 typedef void (*uvtd_seat_cb_t) (struct uvtd_seat *seat, unsigned int event,
79                                 void *data);
80
81 int uvtd_seat_new(struct uvtd_seat **out, const char *seatname,
82                   struct ev_eloop *eloop, uvtd_seat_cb_t cb, void *data);
83 void uvtd_seat_free(struct uvtd_seat *seat);
84
85 const char *uvtd_seat_get_name(struct uvtd_seat *seat);
86 struct ev_eloop *uvtd_seat_get_eloop(struct uvtd_seat *seat);
87 int uvtd_seat_sleep(struct uvtd_seat *seat, bool force);
88 void uvtd_seat_wake_up(struct uvtd_seat *seat);
89 void uvtd_seat_schedule(struct uvtd_seat *seat, unsigned int id);
90
91 int uvtd_seat_register_session(struct uvtd_seat *seat,
92                                struct uvtd_session **out,
93                                unsigned int id, uvtd_session_cb_t cb,
94                                void *data);
95
96 #endif /* UVTD_SEAT_H */