chiark / gitweb /
terminal: add evdev elements to idev
[elogind.git] / src / libsystemd-terminal / idev.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  * IDev
24  */
25
26 #pragma once
27
28 #include <inttypes.h>
29 #include <libudev.h>
30 #include <linux/input.h>
31 #include <stdbool.h>
32 #include <stdlib.h>
33 #include <systemd/sd-bus.h>
34 #include <systemd/sd-event.h>
35 #include "util.h"
36
37 typedef struct idev_data                idev_data;
38 typedef struct idev_data_evdev          idev_data_evdev;
39
40 typedef struct idev_event               idev_event;
41 typedef struct idev_device              idev_device;
42 typedef struct idev_session             idev_session;
43 typedef struct idev_context             idev_context;
44
45 /*
46  * Types
47  */
48
49 enum {
50         IDEV_ELEMENT_EVDEV,
51         IDEV_ELEMENT_CNT
52 };
53
54 enum {
55         IDEV_DEVICE_CNT
56 };
57
58 /*
59  * Evdev Elements
60  */
61
62 struct idev_data_evdev {
63         struct input_event event;
64 };
65
66 /*
67  * Data Packets
68  */
69
70 enum {
71         IDEV_DATA_RESYNC,
72         IDEV_DATA_EVDEV,
73         IDEV_DATA_CNT
74 };
75
76 struct idev_data {
77         unsigned int type;
78         bool resync : 1;
79
80         union {
81                 idev_data_evdev evdev;
82         };
83 };
84
85 /*
86  * Events
87  */
88
89 enum {
90         IDEV_EVENT_DEVICE_ADD,
91         IDEV_EVENT_DEVICE_REMOVE,
92         IDEV_EVENT_DEVICE_DATA,
93         IDEV_EVENT_CNT
94 };
95
96 struct idev_event {
97         unsigned int type;
98         union {
99                 struct {
100                         idev_device *device;
101                 } device_add, device_remove;
102
103                 struct {
104                         idev_device *device;
105                         idev_data data;
106                 } device_data;
107         };
108 };
109
110 typedef int (*idev_event_fn) (idev_session *s, void *userdata, idev_event *ev);
111
112 /*
113  * Devices
114  */
115
116 void idev_device_enable(idev_device *d);
117 void idev_device_disable(idev_device *d);
118
119 /*
120  * Sessions
121  */
122
123 enum {
124         IDEV_SESSION_CUSTOM                     = (1 << 0),
125         IDEV_SESSION_MANAGED                    = (1 << 1),
126 };
127
128 int idev_session_new(idev_session **out,
129                      idev_context *c,
130                      unsigned int flags,
131                      const char *name,
132                      idev_event_fn event_fn,
133                      void *userdata);
134 idev_session *idev_session_free(idev_session *s);
135
136 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_session*, idev_session_free);
137
138 bool idev_session_is_enabled(idev_session *s);
139 void idev_session_enable(idev_session *s);
140 void idev_session_disable(idev_session *s);
141
142 int idev_session_add_evdev(idev_session *s, struct udev_device *ud);
143 int idev_session_remove_evdev(idev_session *s, struct udev_device *ud);
144
145 /*
146  * Contexts
147  */
148
149 int idev_context_new(idev_context **out, sd_event *event, sd_bus *sysbus);
150 idev_context *idev_context_ref(idev_context *c);
151 idev_context *idev_context_unref(idev_context *c);
152
153 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_context*, idev_context_unref);