]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #ifndef foosddevicehfoo | |
3 | #define foosddevicehfoo | |
4 | ||
5 | /*** | |
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <https://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include <sys/stat.h> | |
21 | #include <sys/sysmacros.h> | |
22 | ||
23 | #include "_sd-common.h" | |
24 | #include "sd-event.h" | |
25 | #include "sd-id128.h" | |
26 | ||
27 | _SD_BEGIN_DECLARATIONS; | |
28 | ||
29 | typedef struct sd_device sd_device; | |
30 | typedef struct sd_device_enumerator sd_device_enumerator; | |
31 | typedef struct sd_device_monitor sd_device_monitor; | |
32 | ||
33 | __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_device_action_t) { | |
34 | SD_DEVICE_ADD, | |
35 | SD_DEVICE_REMOVE, | |
36 | SD_DEVICE_CHANGE, | |
37 | SD_DEVICE_MOVE, | |
38 | SD_DEVICE_ONLINE, | |
39 | SD_DEVICE_OFFLINE, | |
40 | SD_DEVICE_BIND, | |
41 | SD_DEVICE_UNBIND, | |
42 | _SD_DEVICE_ACTION_MAX, | |
43 | _SD_DEVICE_ACTION_INVALID = -EINVAL, | |
44 | _SD_ENUM_FORCE_S64(DEVICE_ACTION) | |
45 | } sd_device_action_t; | |
46 | ||
47 | /* callback */ | |
48 | ||
49 | typedef int (*sd_device_monitor_handler_t)(sd_device_monitor *m, sd_device *device, void *userdata); | |
50 | ||
51 | /* device */ | |
52 | ||
53 | sd_device *sd_device_ref(sd_device *device); | |
54 | sd_device *sd_device_unref(sd_device *device); | |
55 | ||
56 | int sd_device_new_from_syspath(sd_device **ret, const char *syspath); | |
57 | int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum); | |
58 | int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname); | |
59 | int sd_device_new_from_device_id(sd_device **ret, const char *id); | |
60 | int sd_device_new_from_stat_rdev(sd_device **ret, const struct stat *st); | |
61 | int sd_device_new_from_devname(sd_device **ret, const char *devname); | |
62 | int sd_device_new_from_path(sd_device **ret, const char *path); | |
63 | int sd_device_new_from_ifname(sd_device **ret, const char *ifname); | |
64 | int sd_device_new_from_ifindex(sd_device **ret, int ifindex); | |
65 | ||
66 | int sd_device_new_child(sd_device **ret, sd_device *device, const char *suffix); | |
67 | ||
68 | int sd_device_get_parent(sd_device *child, sd_device **ret); | |
69 | int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret); | |
70 | ||
71 | int sd_device_get_syspath(sd_device *device, const char **ret); | |
72 | int sd_device_get_subsystem(sd_device *device, const char **ret); | |
73 | int sd_device_get_driver_subsystem(sd_device *device, const char **ret); | |
74 | int sd_device_get_devtype(sd_device *device, const char **ret); | |
75 | int sd_device_get_devnum(sd_device *device, dev_t *devnum); | |
76 | int sd_device_get_ifindex(sd_device *device, int *ifindex); | |
77 | int sd_device_get_driver(sd_device *device, const char **ret); | |
78 | int sd_device_get_devpath(sd_device *device, const char **ret); | |
79 | int sd_device_get_devname(sd_device *device, const char **ret); | |
80 | int sd_device_get_sysname(sd_device *device, const char **ret); | |
81 | int sd_device_get_sysnum(sd_device *device, const char **ret); | |
82 | int sd_device_get_action(sd_device *device, sd_device_action_t *ret); | |
83 | int sd_device_get_seqnum(sd_device *device, uint64_t *ret); | |
84 | int sd_device_get_diskseq(sd_device *device, uint64_t *ret); | |
85 | int sd_device_get_device_id(sd_device *device, const char **ret); | |
86 | ||
87 | int sd_device_get_is_initialized(sd_device *device); | |
88 | int sd_device_get_usec_initialized(sd_device *device, uint64_t *ret); | |
89 | int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *ret); | |
90 | ||
91 | const char* sd_device_get_tag_first(sd_device *device); | |
92 | const char* sd_device_get_tag_next(sd_device *device); | |
93 | const char* sd_device_get_current_tag_first(sd_device *device); | |
94 | const char* sd_device_get_current_tag_next(sd_device *device); | |
95 | const char* sd_device_get_devlink_first(sd_device *device); | |
96 | const char* sd_device_get_devlink_next(sd_device *device); | |
97 | const char* sd_device_get_property_first(sd_device *device, const char **value); | |
98 | const char* sd_device_get_property_next(sd_device *device, const char **value); | |
99 | const char* sd_device_get_sysattr_first(sd_device *device); | |
100 | const char* sd_device_get_sysattr_next(sd_device *device); | |
101 | sd_device *sd_device_get_child_first(sd_device *device, const char **ret_suffix); | |
102 | sd_device *sd_device_get_child_next(sd_device *device, const char **ret_suffix); | |
103 | ||
104 | int sd_device_has_tag(sd_device *device, const char *tag); | |
105 | int sd_device_has_current_tag(sd_device *device, const char *tag); | |
106 | int sd_device_get_property_value(sd_device *device, const char *key, const char **value); | |
107 | int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret); | |
108 | int sd_device_get_sysattr_value_with_size(sd_device *device, const char *sysattr, const char **ret_value, size_t *ret_size); | |
109 | int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, const char **ret_value); | |
110 | ||
111 | int sd_device_set_sysattr_value(sd_device *device, const char *sysattr, const char *value); | |
112 | int sd_device_set_sysattr_valuef(sd_device *device, const char *sysattr, const char *format, ...) _sd_printf_(3, 4); | |
113 | int sd_device_trigger(sd_device *device, sd_device_action_t action); | |
114 | int sd_device_trigger_with_uuid(sd_device *device, sd_device_action_t action, sd_id128_t *ret_uuid); | |
115 | int sd_device_open(sd_device *device, int flags); | |
116 | ||
117 | /* device enumerator */ | |
118 | ||
119 | int sd_device_enumerator_new(sd_device_enumerator **ret); | |
120 | sd_device_enumerator *sd_device_enumerator_ref(sd_device_enumerator *enumerator); | |
121 | sd_device_enumerator *sd_device_enumerator_unref(sd_device_enumerator *enumerator); | |
122 | ||
123 | sd_device *sd_device_enumerator_get_device_first(sd_device_enumerator *enumerator); | |
124 | sd_device *sd_device_enumerator_get_device_next(sd_device_enumerator *enumerator); | |
125 | sd_device *sd_device_enumerator_get_subsystem_first(sd_device_enumerator *enumerator); | |
126 | sd_device *sd_device_enumerator_get_subsystem_next(sd_device_enumerator *enumerator); | |
127 | ||
128 | int sd_device_enumerator_add_match_subsystem(sd_device_enumerator *enumerator, const char *subsystem, int match); | |
129 | int sd_device_enumerator_add_match_sysattr(sd_device_enumerator *enumerator, const char *sysattr, const char *value, int match); | |
130 | int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, const char *property, const char *value); | |
131 | int sd_device_enumerator_add_match_property_required(sd_device_enumerator *enumerator, const char *property, const char *value); | |
132 | int sd_device_enumerator_add_match_sysname(sd_device_enumerator *enumerator, const char *sysname); | |
133 | int sd_device_enumerator_add_nomatch_sysname(sd_device_enumerator *enumerator, const char *sysname); | |
134 | int sd_device_enumerator_add_match_tag(sd_device_enumerator *enumerator, const char *tag); | |
135 | int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumerator, sd_device *parent); | |
136 | int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator); | |
137 | int sd_device_enumerator_add_all_parents(sd_device_enumerator *enumerator); | |
138 | ||
139 | /* device monitor */ | |
140 | ||
141 | int sd_device_monitor_new(sd_device_monitor **ret); | |
142 | sd_device_monitor *sd_device_monitor_ref(sd_device_monitor *m); | |
143 | sd_device_monitor *sd_device_monitor_unref(sd_device_monitor *m); | |
144 | ||
145 | int sd_device_monitor_get_fd(sd_device_monitor *m); | |
146 | int sd_device_monitor_get_events(sd_device_monitor *m); | |
147 | int sd_device_monitor_get_timeout(sd_device_monitor *m, uint64_t *ret); | |
148 | int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size); | |
149 | int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event); | |
150 | int sd_device_monitor_detach_event(sd_device_monitor *m); | |
151 | sd_event *sd_device_monitor_get_event(sd_device_monitor *m); | |
152 | sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m); | |
153 | int sd_device_monitor_set_description(sd_device_monitor *m, const char *description); | |
154 | int sd_device_monitor_get_description(sd_device_monitor *m, const char **ret); | |
155 | int sd_device_monitor_is_running(sd_device_monitor *m); | |
156 | int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata); | |
157 | int sd_device_monitor_stop(sd_device_monitor *m); | |
158 | int sd_device_monitor_receive(sd_device_monitor *m, sd_device **ret); | |
159 | ||
160 | int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor *m, const char *subsystem, const char *devtype); | |
161 | int sd_device_monitor_filter_add_match_tag(sd_device_monitor *m, const char *tag); | |
162 | int sd_device_monitor_filter_add_match_sysattr(sd_device_monitor *m, const char *sysattr, const char *value, int match); | |
163 | int sd_device_monitor_filter_add_match_parent(sd_device_monitor *m, sd_device *device, int match); | |
164 | int sd_device_monitor_filter_update(sd_device_monitor *m); | |
165 | int sd_device_monitor_filter_remove(sd_device_monitor *m); | |
166 | ||
167 | _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device, sd_device_unref); | |
168 | _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device_enumerator, sd_device_enumerator_unref); | |
169 | _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_device_monitor, sd_device_monitor_unref); | |
170 | ||
171 | _SD_END_DECLARATIONS; | |
172 | ||
173 | #endif |