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>
36 typedef struct idev_link idev_link;
37 typedef struct idev_device_vtable idev_device_vtable;
38 typedef struct idev_element idev_element;
39 typedef struct idev_element_vtable idev_element_vtable;
45 bool idev_is_evdev(idev_element *e);
46 idev_element *idev_find_evdev(idev_session *s, dev_t devnum);
47 int idev_evdev_new(idev_element **out, idev_session *s, struct udev_device *ud);
54 /* element-to-device connection */
55 LIST_FIELDS(idev_link, links_by_element);
56 idev_element *element;
58 /* device-to-element connection */
59 LIST_FIELDS(idev_link, links_by_device);
67 struct idev_device_vtable {
68 void (*free) (idev_device *d);
69 void (*attach) (idev_device *d, idev_link *l);
70 void (*detach) (idev_device *d, idev_link *l);
71 int (*feed) (idev_device *d, idev_data *data);
75 const idev_device_vtable *vtable;
76 idev_session *session;
79 LIST_HEAD(idev_link, links);
85 #define IDEV_DEVICE_INIT(_vtable, _session) ((idev_device){ \
86 .vtable = (_vtable), \
87 .session = (_session), \
90 idev_device *idev_find_device(idev_session *s, const char *name);
92 int idev_device_add(idev_device *d, const char *name);
93 idev_device *idev_device_free(idev_device *d);
95 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_device*, idev_device_free);
97 int idev_device_feed(idev_device *d, idev_data *data);
98 void idev_device_feedback(idev_device *d, idev_data *data);
104 struct idev_element_vtable {
105 void (*free) (idev_element *e);
106 void (*enable) (idev_element *e);
107 void (*disable) (idev_element *e);
108 void (*open) (idev_element *e);
109 void (*close) (idev_element *e);
110 void (*feedback) (idev_element *e, idev_data *data);
113 struct idev_element {
114 const idev_element_vtable *vtable;
115 idev_session *session;
116 unsigned long n_open;
119 LIST_HEAD(idev_link, links);
126 #define IDEV_ELEMENT_INIT(_vtable, _session) ((idev_element){ \
127 .vtable = (_vtable), \
128 .session = (_session), \
131 idev_element *idev_find_element(idev_session *s, const char *name);
133 int idev_element_add(idev_element *e, const char *name);
134 idev_element *idev_element_free(idev_element *e);
136 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_element*, idev_element_free);
138 int idev_element_feed(idev_element *e, idev_data *data);
139 void idev_element_feedback(idev_element *e, idev_data *data);
145 struct idev_session {
146 idev_context *context;
150 Hashmap *element_map;
153 idev_event_fn event_fn;
161 idev_session *idev_find_session(idev_context *c, const char *name);
162 int idev_session_raise_device_data(idev_session *s, idev_device *d, idev_data *data);
168 struct idev_context {
173 Hashmap *session_map;