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/>.
27 #include <systemd/sd-bus.h>
28 #include <systemd/sd-event.h>
34 typedef struct idev_link idev_link;
35 typedef struct idev_device_vtable idev_device_vtable;
36 typedef struct idev_element idev_element;
37 typedef struct idev_element_vtable idev_element_vtable;
44 /* element-to-device connection */
45 LIST_FIELDS(idev_link, links_by_element);
46 idev_element *element;
48 /* device-to-element connection */
49 LIST_FIELDS(idev_link, links_by_device);
57 struct idev_device_vtable {
58 void (*free) (idev_device *d);
59 void (*attach) (idev_device *d, idev_link *l);
60 void (*detach) (idev_device *d, idev_link *l);
61 int (*feed) (idev_device *d, idev_data *data);
65 const idev_device_vtable *vtable;
66 idev_session *session;
69 LIST_HEAD(idev_link, links);
75 #define IDEV_DEVICE_INIT(_vtable, _session) ((idev_device){ \
76 .vtable = (_vtable), \
77 .session = (_session), \
80 idev_device *idev_find_device(idev_session *s, const char *name);
82 int idev_device_add(idev_device *d, const char *name);
83 idev_device *idev_device_free(idev_device *d);
85 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_device*, idev_device_free);
87 int idev_device_feed(idev_device *d, idev_data *data);
88 void idev_device_feedback(idev_device *d, idev_data *data);
94 struct idev_element_vtable {
95 void (*free) (idev_element *e);
96 void (*enable) (idev_element *e);
97 void (*disable) (idev_element *e);
98 void (*open) (idev_element *e);
99 void (*close) (idev_element *e);
100 void (*feedback) (idev_element *e, idev_data *data);
103 struct idev_element {
104 const idev_element_vtable *vtable;
105 idev_session *session;
106 unsigned long n_open;
109 LIST_HEAD(idev_link, links);
116 #define IDEV_ELEMENT_INIT(_vtable, _session) ((idev_element){ \
117 .vtable = (_vtable), \
118 .session = (_session), \
121 idev_element *idev_find_element(idev_session *s, const char *name);
123 int idev_element_add(idev_element *e, const char *name);
124 idev_element *idev_element_free(idev_element *e);
126 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_element*, idev_element_free);
128 int idev_element_feed(idev_element *e, idev_data *data);
129 void idev_element_feedback(idev_element *e, idev_data *data);
135 struct idev_session {
136 idev_context *context;
140 Hashmap *element_map;
143 idev_event_fn event_fn;
151 idev_session *idev_find_session(idev_context *c, const char *name);
152 int idev_session_raise_device_data(idev_session *s, idev_device *d, idev_data *data);
158 struct idev_context {
163 Hashmap *session_map;