chiark / gitweb /
6f618f37af5e2355161096f9cabab424b3fb459e
[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 <stdbool.h>
30 #include <stdlib.h>
31 #include <systemd/sd-bus.h>
32 #include <systemd/sd-event.h>
33 #include "util.h"
34
35 typedef struct idev_data                idev_data;
36
37 typedef struct idev_event               idev_event;
38 typedef struct idev_device              idev_device;
39 typedef struct idev_session             idev_session;
40 typedef struct idev_context             idev_context;
41
42 /*
43  * Types
44  */
45
46 enum {
47         IDEV_ELEMENT_CNT
48 };
49
50 enum {
51         IDEV_DEVICE_CNT
52 };
53
54 /*
55  * Data Packets
56  */
57
58 enum {
59         IDEV_DATA_RESYNC,
60         IDEV_DATA_CNT
61 };
62
63 struct idev_data {
64         unsigned int type;
65         bool resync : 1;
66 };
67
68 /*
69  * Events
70  */
71
72 enum {
73         IDEV_EVENT_DEVICE_ADD,
74         IDEV_EVENT_DEVICE_REMOVE,
75         IDEV_EVENT_DEVICE_DATA,
76         IDEV_EVENT_CNT
77 };
78
79 struct idev_event {
80         unsigned int type;
81         union {
82                 struct {
83                         idev_device *device;
84                 } device_add, device_remove;
85
86                 struct {
87                         idev_device *device;
88                         idev_data data;
89                 } device_data;
90         };
91 };
92
93 typedef int (*idev_event_fn) (idev_session *s, void *userdata, idev_event *ev);
94
95 /*
96  * Devices
97  */
98
99 void idev_device_enable(idev_device *d);
100 void idev_device_disable(idev_device *d);
101
102 /*
103  * Sessions
104  */
105
106 enum {
107         IDEV_SESSION_CUSTOM                     = (1 << 0),
108         IDEV_SESSION_MANAGED                    = (1 << 1),
109 };
110
111 int idev_session_new(idev_session **out,
112                      idev_context *c,
113                      unsigned int flags,
114                      const char *name,
115                      idev_event_fn event_fn,
116                      void *userdata);
117 idev_session *idev_session_free(idev_session *s);
118
119 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_session*, idev_session_free);
120
121 bool idev_session_is_enabled(idev_session *s);
122 void idev_session_enable(idev_session *s);
123 void idev_session_disable(idev_session *s);
124
125 /*
126  * Contexts
127  */
128
129 int idev_context_new(idev_context **out, sd_event *event, sd_bus *sysbus);
130 idev_context *idev_context_ref(idev_context *c);
131 idev_context *idev_context_unref(idev_context *c);
132
133 DEFINE_TRIVIAL_CLEANUP_FUNC(idev_context*, idev_context_unref);