| #pragma once |
| |
| #include <systemd/sd-event.h> |
| |
| namespace sdeventplus |
| { |
| namespace internal |
| { |
| |
| /** @class SdEvent |
| * @brief Overridable direct sd_event interface |
| */ |
| class SdEvent |
| { |
| public: |
| virtual ~SdEvent() = default; |
| |
| virtual int sd_event_default(sd_event** event) const = 0; |
| virtual int sd_event_new(sd_event** event) const = 0; |
| virtual sd_event* sd_event_ref(sd_event* event) const = 0; |
| virtual sd_event* sd_event_unref(sd_event* event) const = 0; |
| |
| virtual int sd_event_add_io(sd_event* event, sd_event_source** source, |
| int fd, uint32_t events, sd_event_io_handler_t, |
| void* userdata) const = 0; |
| virtual int sd_event_add_time(sd_event* event, sd_event_source** source, |
| clockid_t clock, uint64_t usec, |
| uint64_t accuracy, |
| sd_event_time_handler_t callback, |
| void* userdata) const = 0; |
| virtual int sd_event_add_signal(sd_event* event, sd_event_source** source, |
| int sig, sd_event_signal_handler_t callback, |
| void* userdata) const = 0; |
| virtual int sd_event_add_child(sd_event* event, sd_event_source** source, |
| pid_t, int options, |
| sd_event_child_handler_t callback, |
| void* userdata) const = 0; |
| virtual int sd_event_add_defer(sd_event* event, sd_event_source** source, |
| sd_event_handler_t callback, |
| void* userdata) const = 0; |
| virtual int sd_event_add_post(sd_event* event, sd_event_source** source, |
| sd_event_handler_t callback, |
| void* userdata) const = 0; |
| virtual int sd_event_add_exit(sd_event* event, sd_event_source** source, |
| sd_event_handler_t callback, |
| void* userdata) const = 0; |
| |
| virtual int sd_event_prepare(sd_event* event) const = 0; |
| virtual int sd_event_wait(sd_event* event, uint64_t usec) const = 0; |
| virtual int sd_event_dispatch(sd_event* event) const = 0; |
| virtual int sd_event_run(sd_event* event, uint64_t usec) const = 0; |
| virtual int sd_event_loop(sd_event* event) const = 0; |
| virtual int sd_event_exit(sd_event* event, int code) const = 0; |
| |
| virtual int sd_event_now(sd_event* event, clockid_t clock, |
| uint64_t* usec) const = 0; |
| |
| virtual int sd_event_get_exit_code(sd_event* event, int* code) const = 0; |
| virtual int sd_event_get_watchdog(sd_event* event) const = 0; |
| virtual int sd_event_set_watchdog(sd_event* event, int b) const = 0; |
| |
| virtual sd_event_source* |
| sd_event_source_ref(sd_event_source* source) const = 0; |
| virtual sd_event_source* |
| sd_event_source_unref(sd_event_source* source) const = 0; |
| |
| virtual void* |
| sd_event_source_get_userdata(sd_event_source* source) const = 0; |
| virtual void* sd_event_source_set_userdata(sd_event_source* source, |
| void* userdata) const = 0; |
| |
| virtual int |
| sd_event_source_get_description(sd_event_source* source, |
| const char** description) const = 0; |
| virtual int |
| sd_event_source_set_description(sd_event_source* source, |
| const char* description) const = 0; |
| virtual int |
| sd_event_source_set_prepare(sd_event_source* source, |
| sd_event_handler_t callback) const = 0; |
| virtual int sd_event_source_get_pending(sd_event_source* source) const = 0; |
| virtual int sd_event_source_get_priority(sd_event_source* source, |
| int64_t* priority) const = 0; |
| virtual int sd_event_source_set_priority(sd_event_source* source, |
| int64_t priority) const = 0; |
| virtual int sd_event_source_get_enabled(sd_event_source* source, |
| int* enabled) const = 0; |
| virtual int sd_event_source_set_enabled(sd_event_source* source, |
| int enabled) const = 0; |
| virtual int sd_event_source_get_io_fd(sd_event_source* source) const = 0; |
| virtual int sd_event_source_set_io_fd(sd_event_source* source, |
| int fd) const = 0; |
| virtual int sd_event_source_get_io_events(sd_event_source* source, |
| uint32_t* events) const = 0; |
| virtual int sd_event_source_set_io_events(sd_event_source* source, |
| uint32_t events) const = 0; |
| virtual int sd_event_source_get_io_revents(sd_event_source* source, |
| uint32_t* revents) const = 0; |
| virtual int sd_event_source_get_time(sd_event_source* source, |
| uint64_t* usec) const = 0; |
| virtual int sd_event_source_set_time(sd_event_source* source, |
| uint64_t usec) const = 0; |
| virtual int sd_event_source_get_time_accuracy(sd_event_source* source, |
| uint64_t* usec) const = 0; |
| virtual int sd_event_source_set_time_accuracy(sd_event_source* source, |
| uint64_t usec) const = 0; |
| virtual int sd_event_source_get_signal(sd_event_source* source) const = 0; |
| virtual int sd_event_source_get_child_pid(sd_event_source* source, |
| pid_t* pid) const = 0; |
| virtual int sd_event_source_set_destroy_callback( |
| sd_event_source* source, sd_event_destroy_t callback) const = 0; |
| virtual int sd_event_source_get_destroy_callback( |
| sd_event_source* source, sd_event_destroy_t* callback) const = 0; |
| }; |
| |
| /** @class SdEventImpl |
| * @brief sd_event concrete implementation |
| * @details Uses libsystemd to handle all sd_event calls |
| */ |
| class SdEventImpl : public SdEvent |
| { |
| public: |
| int sd_event_default(sd_event** event) const override; |
| int sd_event_new(sd_event** event) const override; |
| sd_event* sd_event_ref(sd_event* event) const override; |
| sd_event* sd_event_unref(sd_event* event) const override; |
| |
| int sd_event_add_io(sd_event* event, sd_event_source** source, int fd, |
| uint32_t events, sd_event_io_handler_t callback, |
| void* userdata) const override; |
| int sd_event_add_time(sd_event* event, sd_event_source** source, |
| clockid_t clock, uint64_t usec, uint64_t accuracy, |
| sd_event_time_handler_t callback, |
| void* userdata) const override; |
| |
| int sd_event_add_signal(sd_event* event, sd_event_source** source, int sig, |
| sd_event_signal_handler_t callback, |
| void* userdata) const override |
| { |
| return ::sd_event_add_signal(event, source, sig, callback, userdata); |
| } |
| |
| int sd_event_add_child(sd_event* event, sd_event_source** source, pid_t pid, |
| int options, sd_event_child_handler_t callback, |
| void* userdata) const override |
| { |
| return ::sd_event_add_child(event, source, pid, options, callback, |
| userdata); |
| } |
| |
| int sd_event_add_defer(sd_event* event, sd_event_source** source, |
| sd_event_handler_t callback, |
| void* userdata) const override; |
| int sd_event_add_post(sd_event* event, sd_event_source** source, |
| sd_event_handler_t callback, |
| void* userdata) const override; |
| int sd_event_add_exit(sd_event* event, sd_event_source** source, |
| sd_event_handler_t callback, |
| void* userdata) const override; |
| |
| int sd_event_prepare(sd_event* event) const override; |
| int sd_event_wait(sd_event* event, uint64_t usec) const override; |
| int sd_event_dispatch(sd_event* event) const override; |
| int sd_event_run(sd_event* event, uint64_t usec) const override; |
| int sd_event_loop(sd_event* event) const override; |
| int sd_event_exit(sd_event* event, int code) const override; |
| |
| int sd_event_now(sd_event* event, clockid_t clock, |
| uint64_t* usec) const override; |
| |
| int sd_event_get_exit_code(sd_event* event, int* code) const override; |
| int sd_event_get_watchdog(sd_event* event) const override; |
| int sd_event_set_watchdog(sd_event* event, int b) const override; |
| |
| sd_event_source* |
| sd_event_source_ref(sd_event_source* source) const override; |
| sd_event_source* |
| sd_event_source_unref(sd_event_source* source) const override; |
| |
| void* sd_event_source_get_userdata(sd_event_source* source) const override; |
| void* sd_event_source_set_userdata(sd_event_source* source, |
| void* userdata) const override; |
| |
| int sd_event_source_get_description( |
| sd_event_source* source, const char** description) const override; |
| int sd_event_source_set_description(sd_event_source* source, |
| const char* description) const override; |
| int sd_event_source_set_prepare(sd_event_source* source, |
| sd_event_handler_t callback) const override; |
| int sd_event_source_get_pending(sd_event_source* source) const override; |
| int sd_event_source_get_priority(sd_event_source* source, |
| int64_t* priority) const override; |
| int sd_event_source_set_priority(sd_event_source* source, |
| int64_t priority) const override; |
| int sd_event_source_get_enabled(sd_event_source* source, |
| int* enabled) const override; |
| int sd_event_source_set_enabled(sd_event_source* source, |
| int enabled) const override; |
| int sd_event_source_get_io_fd(sd_event_source* source) const override; |
| int sd_event_source_set_io_fd(sd_event_source* source, |
| int fd) const override; |
| int sd_event_source_get_io_events(sd_event_source* source, |
| uint32_t* events) const override; |
| int sd_event_source_set_io_events(sd_event_source* source, |
| uint32_t events) const override; |
| int sd_event_source_get_io_revents(sd_event_source* source, |
| uint32_t* revents) const override; |
| int sd_event_source_get_time(sd_event_source* source, |
| uint64_t* usec) const override; |
| int sd_event_source_set_time(sd_event_source* source, |
| uint64_t usec) const override; |
| int sd_event_source_get_time_accuracy(sd_event_source* source, |
| uint64_t* usec) const override; |
| int sd_event_source_set_time_accuracy(sd_event_source* source, |
| uint64_t usec) const override; |
| int sd_event_source_get_signal(sd_event_source* source) const override; |
| int sd_event_source_get_child_pid(sd_event_source* source, |
| pid_t* pid) const override; |
| int sd_event_source_set_destroy_callback( |
| sd_event_source* source, sd_event_destroy_t callback) const override; |
| int sd_event_source_get_destroy_callback( |
| sd_event_source* source, sd_event_destroy_t* callback) const override; |
| }; |
| |
| /** @brief Default instantiation of sd_event |
| */ |
| extern SdEventImpl sdevent_impl; |
| |
| } // namespace internal |
| } // namespace sdeventplus |