1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
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.
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.
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/>.
26 #include <linux/input.h>
29 #include <systemd/sd-bus.h>
30 #include <systemd/sd-event.h>
31 #include <xkbcommon/xkbcommon.h>
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
;
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
);
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
);
63 /* element-to-device connection */
64 LIST_FIELDS(idev_link
, links_by_element
);
65 idev_element
*element
;
67 /* device-to-element connection */
68 LIST_FIELDS(idev_link
, links_by_device
);
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
);
84 const idev_device_vtable
*vtable
;
85 idev_session
*session
;
88 LIST_HEAD(idev_link
, links
);
94 #define IDEV_DEVICE_INIT(_vtable, _session) ((idev_device){ \
95 .vtable = (_vtable), \
96 .session = (_session), \
99 idev_device
*idev_find_device(idev_session
*s
, const char *name
);
101 int idev_device_add(idev_device
*d
, const char *name
);
102 idev_device
*idev_device_free(idev_device
*d
);
104 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_device
*, idev_device_free
);
106 int idev_device_feed(idev_device
*d
, idev_data
*data
);
107 void idev_device_feedback(idev_device
*d
, idev_data
*data
);
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
);
124 struct idev_element
{
125 const idev_element_vtable
*vtable
;
126 idev_session
*session
;
127 unsigned long n_open
;
130 LIST_HEAD(idev_link
, links
);
137 #define IDEV_ELEMENT_INIT(_vtable, _session) ((idev_element){ \
138 .vtable = (_vtable), \
139 .session = (_session), \
142 idev_element
*idev_find_element(idev_session
*s
, const char *name
);
144 int idev_element_add(idev_element
*e
, const char *name
);
145 idev_element
*idev_element_free(idev_element
*e
);
147 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_element
*, idev_element_free
);
149 int idev_element_feed(idev_element
*e
, idev_data
*data
);
150 void idev_element_feedback(idev_element
*e
, idev_data
*data
);
156 struct idev_session
{
157 idev_context
*context
;
160 sd_bus_slot
*slot_resume_device
;
161 sd_bus_slot
*slot_pause_device
;
163 Hashmap
*element_map
;
166 idev_event_fn event_fn
;
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
);
181 struct idev_context
{
186 Hashmap
*session_map
;