chiark / gitweb /
terminal: allow user-context to be retrieved/stored
[elogind.git] / src / libsystemd-terminal / sysview-internal.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 #pragma once
23
24 #include <inttypes.h>
25 #include <libudev.h>
26 #include <stdbool.h>
27 #include <stdlib.h>
28 #include <systemd/sd-bus.h>
29 #include <systemd/sd-event.h>
30 #include "hashmap.h"
31 #include "list.h"
32 #include "macro.h"
33 #include "sysview.h"
34 #include "util.h"
35
36 /*
37  * Devices
38  */
39
40 struct sysview_device {
41         sysview_seat *seat;
42         char *name;
43         unsigned int type;
44
45         union {
46                 struct {
47                         struct udev_device *ud;
48                 } evdev, drm;
49         };
50 };
51
52 sysview_device *sysview_find_device(sysview_context *c, const char *name);
53
54 int sysview_device_new(sysview_device **out, sysview_seat *seat, const char *name);
55 sysview_device *sysview_device_free(sysview_device *device);
56
57 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_device*, sysview_device_free);
58
59 /*
60  * Sessions
61  */
62
63 struct sysview_session {
64         sysview_seat *seat;
65         char *name;
66         char *path;
67         void *userdata;
68
69         sd_bus_slot *slot_take_control;
70
71         bool custom : 1;
72         bool public : 1;
73         bool wants_control : 1;
74         bool has_control : 1;
75 };
76
77 sysview_session *sysview_find_session(sysview_context *c, const char *name);
78
79 int sysview_session_new(sysview_session **out, sysview_seat *seat, const char *name);
80 sysview_session *sysview_session_free(sysview_session *session);
81
82 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_session*, sysview_session_free);
83
84 /*
85  * Seats
86  */
87
88 struct sysview_seat {
89         sysview_context *context;
90         char *name;
91
92         Hashmap *session_map;
93         Hashmap *device_map;
94
95         bool scanned : 1;
96         bool public : 1;
97 };
98
99 sysview_seat *sysview_find_seat(sysview_context *c, const char *name);
100
101 int sysview_seat_new(sysview_seat **out, sysview_context *c, const char *name);
102 sysview_seat *sysview_seat_free(sysview_seat *seat);
103
104 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_seat*, sysview_seat_free);
105
106 /*
107  * Contexts
108  */
109
110 struct sysview_context {
111         sd_event *event;
112         sd_bus *sysbus;
113         struct udev *ud;
114         uint64_t custom_sid;
115
116         Hashmap *seat_map;
117         Hashmap *session_map;
118         Hashmap *device_map;
119
120         sd_event_source *scan_src;
121         sysview_event_fn event_fn;
122         void *userdata;
123
124         /* udev scanner */
125         struct udev_monitor *ud_monitor;
126         sd_event_source *ud_monitor_src;
127
128         /* logind scanner */
129         sd_bus_slot *ld_slot_manager_signal;
130         sd_bus_slot *ld_slot_list_seats;
131         sd_bus_slot *ld_slot_list_sessions;
132
133         bool scan_logind : 1;
134         bool scan_evdev : 1;
135         bool scan_drm : 1;
136         bool running : 1;
137         bool scanned : 1;
138         bool rescan : 1;
139 };
140
141 int sysview_context_rescan(sysview_context *c);