1 #pragma once 2 3 #include <systemd/sd-event.h> 4 5 namespace sdeventplus 6 { 7 namespace internal 8 { 9 10 /** @class SdEvent 11 * @brief Overridable direct sd_event interface 12 */ 13 class SdEvent 14 { 15 public: 16 virtual ~SdEvent() = default; 17 18 virtual int sd_event_default(sd_event** event) const = 0; 19 virtual int sd_event_new(sd_event** event) const = 0; 20 virtual sd_event* sd_event_ref(sd_event* event) const = 0; 21 virtual sd_event* sd_event_unref(sd_event* event) const = 0; 22 23 virtual int sd_event_add_io(sd_event* event, sd_event_source** source, 24 int fd, uint32_t events, sd_event_io_handler_t, 25 void* userdata) const = 0; 26 virtual int sd_event_add_time( 27 sd_event* event, sd_event_source** source, clockid_t clock, 28 uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, 29 void* userdata) const = 0; 30 virtual int sd_event_add_signal(sd_event* event, sd_event_source** source, 31 int sig, sd_event_signal_handler_t callback, 32 void* userdata) const = 0; 33 virtual int sd_event_add_child( 34 sd_event* event, sd_event_source** source, pid_t, int options, 35 sd_event_child_handler_t callback, void* userdata) const = 0; 36 virtual int sd_event_add_defer(sd_event* event, sd_event_source** source, 37 sd_event_handler_t callback, 38 void* userdata) const = 0; 39 virtual int sd_event_add_post(sd_event* event, sd_event_source** source, 40 sd_event_handler_t callback, 41 void* userdata) const = 0; 42 virtual int sd_event_add_exit(sd_event* event, sd_event_source** source, 43 sd_event_handler_t callback, 44 void* userdata) const = 0; 45 46 virtual int sd_event_prepare(sd_event* event) const = 0; 47 virtual int sd_event_wait(sd_event* event, uint64_t usec) const = 0; 48 virtual int sd_event_dispatch(sd_event* event) const = 0; 49 virtual int sd_event_run(sd_event* event, uint64_t usec) const = 0; 50 virtual int sd_event_loop(sd_event* event) const = 0; 51 virtual int sd_event_exit(sd_event* event, int code) const = 0; 52 53 virtual int sd_event_now(sd_event* event, clockid_t clock, 54 uint64_t* usec) const = 0; 55 56 virtual int sd_event_get_exit_code(sd_event* event, int* code) const = 0; 57 virtual int sd_event_get_watchdog(sd_event* event) const = 0; 58 virtual int sd_event_set_watchdog(sd_event* event, int b) const = 0; 59 60 virtual sd_event_source* 61 sd_event_source_ref(sd_event_source* source) const = 0; 62 virtual sd_event_source* 63 sd_event_source_unref(sd_event_source* source) const = 0; 64 65 virtual void* 66 sd_event_source_get_userdata(sd_event_source* source) const = 0; 67 virtual void* sd_event_source_set_userdata(sd_event_source* source, 68 void* userdata) const = 0; 69 70 virtual int sd_event_source_get_description( 71 sd_event_source* source, const char** description) const = 0; 72 virtual int sd_event_source_set_description( 73 sd_event_source* source, const char* description) const = 0; 74 virtual int sd_event_source_set_prepare( 75 sd_event_source* source, sd_event_handler_t callback) const = 0; 76 virtual int sd_event_source_get_pending(sd_event_source* source) const = 0; 77 virtual int sd_event_source_get_priority(sd_event_source* source, 78 int64_t* priority) const = 0; 79 virtual int sd_event_source_set_priority(sd_event_source* source, 80 int64_t priority) const = 0; 81 virtual int sd_event_source_get_enabled(sd_event_source* source, 82 int* enabled) const = 0; 83 virtual int sd_event_source_set_enabled(sd_event_source* source, 84 int enabled) const = 0; 85 virtual int sd_event_source_get_io_fd(sd_event_source* source) const = 0; 86 virtual int sd_event_source_set_io_fd(sd_event_source* source, 87 int fd) const = 0; 88 virtual int sd_event_source_get_io_events(sd_event_source* source, 89 uint32_t* events) const = 0; 90 virtual int sd_event_source_set_io_events(sd_event_source* source, 91 uint32_t events) const = 0; 92 virtual int sd_event_source_get_io_revents(sd_event_source* source, 93 uint32_t* revents) const = 0; 94 virtual int sd_event_source_get_time(sd_event_source* source, 95 uint64_t* usec) const = 0; 96 virtual int sd_event_source_set_time(sd_event_source* source, 97 uint64_t usec) const = 0; 98 virtual int sd_event_source_get_time_accuracy(sd_event_source* source, 99 uint64_t* usec) const = 0; 100 virtual int sd_event_source_set_time_accuracy(sd_event_source* source, 101 uint64_t usec) const = 0; 102 virtual int sd_event_source_get_signal(sd_event_source* source) const = 0; 103 virtual int sd_event_source_get_child_pid(sd_event_source* source, 104 pid_t* pid) const = 0; 105 virtual int sd_event_source_set_destroy_callback( 106 sd_event_source* source, sd_event_destroy_t callback) const = 0; 107 virtual int sd_event_source_get_destroy_callback( 108 sd_event_source* source, sd_event_destroy_t* callback) const = 0; 109 virtual int sd_event_source_set_floating(sd_event_source* source, 110 int b) const = 0; 111 virtual int sd_event_source_get_floating(sd_event_source* source) const = 0; 112 }; 113 114 /** @class SdEventImpl 115 * @brief sd_event concrete implementation 116 * @details Uses libsystemd to handle all sd_event calls 117 */ 118 class SdEventImpl : public SdEvent 119 { 120 public: 121 int sd_event_default(sd_event** event) const override; 122 int sd_event_new(sd_event** event) const override; 123 sd_event* sd_event_ref(sd_event* event) const override; 124 sd_event* sd_event_unref(sd_event* event) const override; 125 126 int sd_event_add_io(sd_event* event, sd_event_source** source, int fd, 127 uint32_t events, sd_event_io_handler_t callback, 128 void* userdata) const override; 129 int sd_event_add_time(sd_event* event, sd_event_source** source, 130 clockid_t clock, uint64_t usec, uint64_t accuracy, 131 sd_event_time_handler_t callback, 132 void* userdata) const override; 133 sd_event_add_signal(sd_event * event,sd_event_source ** source,int sig,sd_event_signal_handler_t callback,void * userdata) const134 int sd_event_add_signal(sd_event* event, sd_event_source** source, int sig, 135 sd_event_signal_handler_t callback, 136 void* userdata) const override 137 { 138 return ::sd_event_add_signal(event, source, sig, callback, userdata); 139 } 140 sd_event_add_child(sd_event * event,sd_event_source ** source,pid_t pid,int options,sd_event_child_handler_t callback,void * userdata) const141 int sd_event_add_child(sd_event* event, sd_event_source** source, pid_t pid, 142 int options, sd_event_child_handler_t callback, 143 void* userdata) const override 144 { 145 return ::sd_event_add_child(event, source, pid, options, callback, 146 userdata); 147 } 148 149 int sd_event_add_defer(sd_event* event, sd_event_source** source, 150 sd_event_handler_t callback, 151 void* userdata) const override; 152 int sd_event_add_post(sd_event* event, sd_event_source** source, 153 sd_event_handler_t callback, 154 void* userdata) const override; 155 int sd_event_add_exit(sd_event* event, sd_event_source** source, 156 sd_event_handler_t callback, 157 void* userdata) const override; 158 159 int sd_event_prepare(sd_event* event) const override; 160 int sd_event_wait(sd_event* event, uint64_t usec) const override; 161 int sd_event_dispatch(sd_event* event) const override; 162 int sd_event_run(sd_event* event, uint64_t usec) const override; 163 int sd_event_loop(sd_event* event) const override; 164 int sd_event_exit(sd_event* event, int code) const override; 165 166 int sd_event_now(sd_event* event, clockid_t clock, 167 uint64_t* usec) const override; 168 169 int sd_event_get_exit_code(sd_event* event, int* code) const override; 170 int sd_event_get_watchdog(sd_event* event) const override; 171 int sd_event_set_watchdog(sd_event* event, int b) const override; 172 173 sd_event_source* 174 sd_event_source_ref(sd_event_source* source) const override; 175 sd_event_source* 176 sd_event_source_unref(sd_event_source* source) const override; 177 178 void* sd_event_source_get_userdata(sd_event_source* source) const override; 179 void* sd_event_source_set_userdata(sd_event_source* source, 180 void* userdata) const override; 181 182 int sd_event_source_get_description( 183 sd_event_source* source, const char** description) const override; 184 int sd_event_source_set_description(sd_event_source* source, 185 const char* description) const override; 186 int sd_event_source_set_prepare(sd_event_source* source, 187 sd_event_handler_t callback) const override; 188 int sd_event_source_get_pending(sd_event_source* source) const override; 189 int sd_event_source_get_priority(sd_event_source* source, 190 int64_t* priority) const override; 191 int sd_event_source_set_priority(sd_event_source* source, 192 int64_t priority) const override; 193 int sd_event_source_get_enabled(sd_event_source* source, 194 int* enabled) const override; 195 int sd_event_source_set_enabled(sd_event_source* source, 196 int enabled) const override; 197 int sd_event_source_get_io_fd(sd_event_source* source) const override; 198 int sd_event_source_set_io_fd(sd_event_source* source, 199 int fd) const override; 200 int sd_event_source_get_io_events(sd_event_source* source, 201 uint32_t* events) const override; 202 int sd_event_source_set_io_events(sd_event_source* source, 203 uint32_t events) const override; 204 int sd_event_source_get_io_revents(sd_event_source* source, 205 uint32_t* revents) const override; 206 int sd_event_source_get_time(sd_event_source* source, 207 uint64_t* usec) const override; 208 int sd_event_source_set_time(sd_event_source* source, 209 uint64_t usec) const override; 210 int sd_event_source_get_time_accuracy(sd_event_source* source, 211 uint64_t* usec) const override; 212 int sd_event_source_set_time_accuracy(sd_event_source* source, 213 uint64_t usec) const override; 214 int sd_event_source_get_signal(sd_event_source* source) const override; 215 int sd_event_source_get_child_pid(sd_event_source* source, 216 pid_t* pid) const override; 217 int sd_event_source_set_destroy_callback( 218 sd_event_source* source, sd_event_destroy_t callback) const override; 219 int sd_event_source_get_destroy_callback( 220 sd_event_source* source, sd_event_destroy_t* callback) const override; 221 int sd_event_source_set_floating(sd_event_source* source, 222 int b) const override; 223 int sd_event_source_get_floating(sd_event_source* source) const override; 224 }; 225 226 /** @brief Default instantiation of sd_event 227 */ 228 extern SdEventImpl sdevent_impl; 229 230 } // namespace internal 231 } // namespace sdeventplus 232