Debian Codegraph @

src/udev/udev-ctrl.h

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #pragma once
3
4 #include "udev-forward.h"
5
6 typedef enum UdevCtrlMessageType {
7 _UDEV_CTRL_END_MESSAGES,
8 UDEV_CTRL_SET_LOG_LEVEL,
9 UDEV_CTRL_STOP_EXEC_QUEUE,
10 UDEV_CTRL_START_EXEC_QUEUE,
11 UDEV_CTRL_RELOAD,
12 UDEV_CTRL_SET_ENV,
13 UDEV_CTRL_SET_CHILDREN_MAX,
14 UDEV_CTRL_PING,
15 UDEV_CTRL_EXIT,
16 } UdevCtrlMessageType;
17
18 typedef union UdevCtrlMessageValue {
19 int intval;
20 char buf[256];
21 } UdevCtrlMessageValue;
22
23 typedef int (*udev_ctrl_handler_t)(UdevCtrl *udev_ctrl, UdevCtrlMessageType type,
24 const UdevCtrlMessageValue *value, void *userdata);
25
26 int udev_ctrl_new_from_fd(UdevCtrl **ret, int fd);
27 static inline int udev_ctrl_new(UdevCtrl **ret) {
28 return udev_ctrl_new_from_fd(ret, -EBADF);
29 }
30
31 int udev_ctrl_enable_receiving(UdevCtrl *uctrl);
32 DECLARE_TRIVIAL_REF_UNREF_FUNC(UdevCtrl, udev_ctrl);
33 int udev_ctrl_attach_event(UdevCtrl *uctrl, sd_event *event);
34 int udev_ctrl_start(UdevCtrl *uctrl, udev_ctrl_handler_t callback, void *userdata);
35 sd_event_source *udev_ctrl_get_event_source(UdevCtrl *uctrl);
36
37 int udev_ctrl_wait(UdevCtrl *uctrl, usec_t timeout);
38
39 int udev_ctrl_send(UdevCtrl *uctrl, UdevCtrlMessageType type, const void *data);
40 static inline int udev_ctrl_send_set_log_level(UdevCtrl *uctrl, int priority) {
41 return udev_ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, INT_TO_PTR(priority));
42 }
43
44 static inline int udev_ctrl_send_stop_exec_queue(UdevCtrl *uctrl) {
45 return udev_ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, NULL);
46 }
47
48 static inline int udev_ctrl_send_start_exec_queue(UdevCtrl *uctrl) {
49 return udev_ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, NULL);
50 }
51
52 static inline int udev_ctrl_send_reload(UdevCtrl *uctrl) {
53 return udev_ctrl_send(uctrl, UDEV_CTRL_RELOAD, NULL);
54 }
55
56 static inline int udev_ctrl_send_set_env(UdevCtrl *uctrl, const char *key) {
57 return udev_ctrl_send(uctrl, UDEV_CTRL_SET_ENV, key);
58 }
59
60 static inline int udev_ctrl_send_set_children_max(UdevCtrl *uctrl, int count) {
61 return udev_ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, INT_TO_PTR(count));
62 }
63
64 static inline int udev_ctrl_send_ping(UdevCtrl *uctrl) {
65 return udev_ctrl_send(uctrl, UDEV_CTRL_PING, NULL);
66 }
67
68 static inline int udev_ctrl_send_exit(UdevCtrl *uctrl) {
69 return udev_ctrl_send(uctrl, UDEV_CTRL_EXIT, NULL);
70 }
71
72 DEFINE_TRIVIAL_CLEANUP_FUNC(UdevCtrl*, udev_ctrl_unref);