]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-terminal/idev-internal.h
resloved: transaction - unify IPv4 and IPv6 sockets
[thirdparty/systemd.git] / src / libsystemd-terminal / idev-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 <linux/input.h>
27 #include <stdbool.h>
28 #include <stdlib.h>
29 #include <xkbcommon/xkbcommon.h>
30 #include "sd-bus.h"
31 #include "sd-event.h"
32 #include "hashmap.h"
33 #include "list.h"
34 #include "util.h"
35 #include "idev.h"
36
37 typedef struct idev_link idev_link;
38 typedef struct idev_device_vtable idev_device_vtable;
39 typedef struct idev_element idev_element;
40 typedef struct idev_element_vtable idev_element_vtable;
41
42 /*
43 * Evdev Elements
44 */
45
46 bool idev_is_evdev(idev_element *e);
47 idev_element *idev_find_evdev(idev_session *s, dev_t devnum);
48 int idev_evdev_new(idev_element **out, idev_session *s, struct udev_device *ud);
49
50 /*
51 * Keyboard Devices
52 */
53
54 bool idev_is_keyboard(idev_device *d);
55 idev_device *idev_find_keyboard(idev_session *s, const char *name);
56 int idev_keyboard_new(idev_device **out, idev_session *s, const char *name);
57
58 /*
59 * Element Links
60 */
61
62 struct idev_link {
63 /* element-to-device connection */
64 LIST_FIELDS(idev_link, links_by_element);
65 idev_element *element;
66
67 /* device-to-element connection */
68 LIST_FIELDS(idev_link, links_by_device);
69 idev_device *device;
70 };
71
72 /*
73 * Devices
74 */
75
76 struct idev_device_vtable {
77 void (*free) (idev_device *d);
78 void (*attach) (idev_device *d, idev_link *l);
79 void (*detach) (idev_device *d, idev_link *l);
80 int (*feed) (idev_device *d, idev_data *data);
81 };
82
83 struct idev_device {
84 const idev_device_vtable *vtable;
85 idev_session *session;
86 char *name;
87
88 LIST_HEAD(idev_link, links);
89
90 bool public : 1;
91 bool enabled : 1;
92 };
93
94 #define IDEV_DEVICE_INIT(_vtable, _session) ((idev_device){ \
95 .vtable = (_vtable), \
96 .session = (_session), \
97 })
98
99 idev_device *idev_find_device(idev_session *s, const char *name);
100
101 int idev_device_add(idev_device *d, const char *name);
102 idev_device *idev_device_free(idev_device *d);
103
104 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_device*, idev_device_free);
105
106 int idev_device_feed(idev_device *d, idev_data *data);
107 void idev_device_feedback(idev_device *d, idev_data *data);
108
109 /*
110 * Elements
111 */
112
113 struct idev_element_vtable {
114 void (*free) (idev_element *e);
115 void (*enable) (idev_element *e);
116 void (*disable) (idev_element *e);
117 void (*open) (idev_element *e);
118 void (*close) (idev_element *e);
119 void (*resume) (idev_element *e, int fd);
120 void (*pause) (idev_element *e, const char *mode);
121 void (*feedback) (idev_element *e, idev_data *data);
122 };
123
124 struct idev_element {
125 const idev_element_vtable *vtable;
126 idev_session *session;
127 unsigned long n_open;
128 char *name;
129
130 LIST_HEAD(idev_link, links);
131
132 bool enabled : 1;
133 bool readable : 1;
134 bool writable : 1;
135 };
136
137 #define IDEV_ELEMENT_INIT(_vtable, _session) ((idev_element){ \
138 .vtable = (_vtable), \
139 .session = (_session), \
140 })
141
142 idev_element *idev_find_element(idev_session *s, const char *name);
143
144 int idev_element_add(idev_element *e, const char *name);
145 idev_element *idev_element_free(idev_element *e);
146
147 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_element*, idev_element_free);
148
149 int idev_element_feed(idev_element *e, idev_data *data);
150 void idev_element_feedback(idev_element *e, idev_data *data);
151
152 /*
153 * Sessions
154 */
155
156 struct idev_session {
157 idev_context *context;
158 char *name;
159 char *path;
160 sd_bus_slot *slot_resume_device;
161 sd_bus_slot *slot_pause_device;
162
163 Hashmap *element_map;
164 Hashmap *device_map;
165
166 idev_event_fn event_fn;
167 void *userdata;
168
169 bool custom : 1;
170 bool managed : 1;
171 bool enabled : 1;
172 };
173
174 idev_session *idev_find_session(idev_context *c, const char *name);
175 int idev_session_raise_device_data(idev_session *s, idev_device *d, idev_data *data);
176
177 /*
178 * Contexts
179 */
180
181 struct idev_context {
182 unsigned long ref;
183 sd_event *event;
184 sd_bus *sysbus;
185
186 Hashmap *session_map;
187 Hashmap *data_map;
188 };