]>
Commit | Line | Data |
---|---|---|
7ed3a638 DH |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com> | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | /* | |
23 | * System View | |
24 | * The sysview interface scans and monitors the system for seats, sessions and | |
25 | * devices. It basically mirrors the state of logind on the application side. | |
26 | * It's meant as base for session services that require managed device access. | |
27 | * The logind controller API is employed to allow unprivileged access to all | |
28 | * devices of a user. | |
29 | * Furthermore, the sysview interface can be used for system services that run | |
30 | * in situations where logind is not available, but session-like services are | |
31 | * needed. For instance, the initrd does not run logind but might require | |
32 | * graphics access. It cannot run session services, though. The sysview | |
33 | * interface pretends that a session is available and provides the same | |
34 | * interface as to normal session services. | |
35 | */ | |
36 | ||
37 | #pragma once | |
38 | ||
7ed3a638 | 39 | #include <stdbool.h> |
ce1daea1 TA |
40 | #include "sd-bus.h" |
41 | #include "sd-event.h" | |
7ed3a638 DH |
42 | |
43 | typedef struct sysview_event sysview_event; | |
44 | typedef struct sysview_device sysview_device; | |
45 | typedef struct sysview_session sysview_session; | |
46 | typedef struct sysview_seat sysview_seat; | |
47 | typedef struct sysview_context sysview_context; | |
48 | ||
49 | /* | |
50 | * Events | |
51 | */ | |
52 | ||
53 | enum { | |
b2068772 DH |
54 | SYSVIEW_EVENT_SETTLE, |
55 | ||
7ed3a638 DH |
56 | SYSVIEW_EVENT_SEAT_ADD, |
57 | SYSVIEW_EVENT_SEAT_REMOVE, | |
58 | ||
59 | SYSVIEW_EVENT_SESSION_FILTER, | |
60 | SYSVIEW_EVENT_SESSION_ADD, | |
61 | SYSVIEW_EVENT_SESSION_REMOVE, | |
62 | SYSVIEW_EVENT_SESSION_ATTACH, | |
63 | SYSVIEW_EVENT_SESSION_DETACH, | |
f6e3ee14 | 64 | SYSVIEW_EVENT_SESSION_REFRESH, |
7ed3a638 DH |
65 | SYSVIEW_EVENT_SESSION_CONTROL, |
66 | }; | |
67 | ||
68 | struct sysview_event { | |
69 | unsigned int type; | |
70 | ||
71 | union { | |
72 | struct { | |
73 | sysview_seat *seat; | |
74 | } seat_add, seat_remove; | |
75 | ||
76 | struct { | |
77 | const char *id; | |
78 | const char *seatid; | |
79 | const char *username; | |
80 | unsigned int uid; | |
81 | } session_filter; | |
82 | ||
83 | struct { | |
84 | sysview_session *session; | |
85 | } session_add, session_remove; | |
86 | ||
87 | struct { | |
88 | sysview_session *session; | |
89 | sysview_device *device; | |
90 | } session_attach, session_detach; | |
91 | ||
92 | struct { | |
93 | sysview_session *session; | |
965f7a3f DH |
94 | sysview_device *device; |
95 | struct udev_device *ud; | |
f6e3ee14 DH |
96 | } session_refresh; |
97 | ||
98 | struct { | |
99 | sysview_session *session; | |
100 | int error; | |
101 | } session_control; | |
7ed3a638 DH |
102 | }; |
103 | }; | |
104 | ||
105 | typedef int (*sysview_event_fn) (sysview_context *c, void *userdata, sysview_event *e); | |
106 | ||
107 | /* | |
108 | * Devices | |
109 | */ | |
110 | ||
111 | enum { | |
112 | SYSVIEW_DEVICE_EVDEV, | |
113 | SYSVIEW_DEVICE_DRM, | |
114 | SYSVIEW_DEVICE_CNT | |
115 | }; | |
116 | ||
f2a15d86 | 117 | const char *sysview_device_get_name(sysview_device *device); |
7ed3a638 DH |
118 | unsigned int sysview_device_get_type(sysview_device *device); |
119 | struct udev_device *sysview_device_get_ud(sysview_device *device); | |
120 | ||
121 | /* | |
122 | * Sessions | |
123 | */ | |
124 | ||
f2a15d86 DH |
125 | void sysview_session_set_userdata(sysview_session *session, void *userdata); |
126 | void *sysview_session_get_userdata(sysview_session *session); | |
127 | ||
7ed3a638 | 128 | const char *sysview_session_get_name(sysview_session *session); |
bfd6d8a3 | 129 | sysview_seat *sysview_session_get_seat(sysview_session *session); |
7ed3a638 DH |
130 | |
131 | int sysview_session_take_control(sysview_session *session); | |
132 | void sysview_session_release_control(sysview_session *session); | |
133 | ||
134 | /* | |
135 | * Seats | |
136 | */ | |
137 | ||
138 | const char *sysview_seat_get_name(sysview_seat *seat); | |
1c7830cc | 139 | int sysview_seat_switch_to(sysview_seat *seat, uint32_t nr); |
7ed3a638 DH |
140 | |
141 | /* | |
142 | * Contexts | |
143 | */ | |
144 | ||
145 | enum { | |
146 | SYSVIEW_CONTEXT_SCAN_LOGIND = (1 << 0), | |
147 | SYSVIEW_CONTEXT_SCAN_EVDEV = (1 << 1), | |
148 | SYSVIEW_CONTEXT_SCAN_DRM = (1 << 2), | |
149 | }; | |
150 | ||
151 | int sysview_context_new(sysview_context **out, | |
152 | unsigned int flags, | |
153 | sd_event *event, | |
154 | sd_bus *sysbus, | |
155 | struct udev *ud); | |
156 | sysview_context *sysview_context_free(sysview_context *c); | |
157 | ||
158 | DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_context*, sysview_context_free); | |
159 | ||
160 | bool sysview_context_is_running(sysview_context *c); | |
161 | int sysview_context_start(sysview_context *c, sysview_event_fn event_fn, void *userdata); | |
162 | void sysview_context_stop(sysview_context *c); |