chiark / gitweb /
terminal: add sysview_seat_switch_to()
[elogind.git] / src / libsystemd-terminal / sysview.h
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
39 #include <inttypes.h>
40 #include <libudev.h>
41 #include <stdbool.h>
42 #include <stdlib.h>
43 #include <systemd/sd-bus.h>
44 #include <systemd/sd-event.h>
45 #include "util.h"
46
47 typedef struct sysview_event            sysview_event;
48 typedef struct sysview_device           sysview_device;
49 typedef struct sysview_session          sysview_session;
50 typedef struct sysview_seat             sysview_seat;
51 typedef struct sysview_context          sysview_context;
52
53 /*
54  * Events
55  */
56
57 enum {
58         SYSVIEW_EVENT_SEAT_ADD,
59         SYSVIEW_EVENT_SEAT_REMOVE,
60
61         SYSVIEW_EVENT_SESSION_FILTER,
62         SYSVIEW_EVENT_SESSION_ADD,
63         SYSVIEW_EVENT_SESSION_REMOVE,
64         SYSVIEW_EVENT_SESSION_ATTACH,
65         SYSVIEW_EVENT_SESSION_DETACH,
66         SYSVIEW_EVENT_SESSION_REFRESH,
67         SYSVIEW_EVENT_SESSION_CONTROL,
68 };
69
70 struct sysview_event {
71         unsigned int type;
72
73         union {
74                 struct {
75                         sysview_seat *seat;
76                 } seat_add, seat_remove;
77
78                 struct {
79                         const char *id;
80                         const char *seatid;
81                         const char *username;
82                         unsigned int uid;
83                 } session_filter;
84
85                 struct {
86                         sysview_session *session;
87                 } session_add, session_remove;
88
89                 struct {
90                         sysview_session *session;
91                         sysview_device *device;
92                 } session_attach, session_detach;
93
94                 struct {
95                         sysview_session *session;
96                         sysview_device *device;
97                         struct udev_device *ud;
98                 } session_refresh;
99
100                 struct {
101                         sysview_session *session;
102                         int error;
103                 } session_control;
104         };
105 };
106
107 typedef int (*sysview_event_fn) (sysview_context *c, void *userdata, sysview_event *e);
108
109 /*
110  * Devices
111  */
112
113 enum {
114         SYSVIEW_DEVICE_EVDEV,
115         SYSVIEW_DEVICE_DRM,
116         SYSVIEW_DEVICE_CNT
117 };
118
119 const char *sysview_device_get_name(sysview_device *device);
120 unsigned int sysview_device_get_type(sysview_device *device);
121 struct udev_device *sysview_device_get_ud(sysview_device *device);
122
123 /*
124  * Sessions
125  */
126
127 void sysview_session_set_userdata(sysview_session *session, void *userdata);
128 void *sysview_session_get_userdata(sysview_session *session);
129
130 const char *sysview_session_get_name(sysview_session *session);
131
132 int sysview_session_take_control(sysview_session *session);
133 void sysview_session_release_control(sysview_session *session);
134
135 /*
136  * Seats
137  */
138
139 const char *sysview_seat_get_name(sysview_seat *seat);
140 int sysview_seat_switch_to(sysview_seat *seat, uint32_t nr);
141
142 /*
143  * Contexts
144  */
145
146 enum {
147         SYSVIEW_CONTEXT_SCAN_LOGIND             = (1 << 0),
148         SYSVIEW_CONTEXT_SCAN_EVDEV              = (1 << 1),
149         SYSVIEW_CONTEXT_SCAN_DRM                = (1 << 2),
150 };
151
152 int sysview_context_new(sysview_context **out,
153                         unsigned int flags,
154                         sd_event *event,
155                         sd_bus *sysbus,
156                         struct udev *ud);
157 sysview_context *sysview_context_free(sysview_context *c);
158
159 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_context*, sysview_context_free);
160
161 bool sysview_context_is_running(sysview_context *c);
162 int sysview_context_start(sysview_context *c, sysview_event_fn event_fn, void *userdata);
163 void sysview_context_stop(sysview_context *c);