diff --git a/include/components/eventloop.hpp b/include/components/eventloop.hpp index c74bd445..441cf951 100644 --- a/include/components/eventloop.hpp +++ b/include/components/eventloop.hpp @@ -30,7 +30,7 @@ void close_callback(uv_handle_t*); */ template struct UVHandleGeneric { - UVHandleGeneric(std::function fun) { + UVHandleGeneric(function fun) { handle = new H; handle->data = this; this->func = fun; @@ -59,56 +59,56 @@ struct UVHandleGeneric { } H* handle; - std::function func; + function func; }; template struct UVHandle : public UVHandleGeneric { - UVHandle(std::function fun) : UVHandleGeneric(fun) {} + UVHandle(function fun) : UVHandleGeneric(fun) {} }; struct SignalHandle : public UVHandle { - SignalHandle(uv_loop_t* loop, std::function fun); + SignalHandle(uv_loop_t* loop, function fun); void start(int signum); }; struct PollHandle : public UVHandle { - PollHandle(uv_loop_t* loop, int fd, std::function fun, std::function err_cb); + PollHandle(uv_loop_t* loop, int fd, function fun, function err_cb); void start(int events); void poll_cb(int status, int events); - std::function func; - std::function err_cb; + function func; + function err_cb; }; struct FSEventHandle : public UVHandle { - FSEventHandle(uv_loop_t* loop, std::function fun, std::function err_cb); + FSEventHandle(uv_loop_t* loop, function fun, function err_cb); void start(const string& path); void fs_event_cb(const char* path, int events, int status); - std::function func; - std::function err_cb; + function func; + function err_cb; }; struct PipeHandle : public UVHandleGeneric { - PipeHandle(uv_loop_t* loop, std::function fun, std::function eof_cb, - std::function err_cb); + PipeHandle( + uv_loop_t* loop, function fun, function eof_cb, function err_cb); void start(int fd); void read_cb(ssize_t nread, const uv_buf_t* buf); - std::function func; - std::function eof_cb; - std::function err_cb; + function func; + function eof_cb; + function err_cb; int fd; }; struct TimerHandle : public UVHandle { - TimerHandle(uv_loop_t* loop, std::function fun); + TimerHandle(uv_loop_t* loop, function fun); void start(uint64_t timeout, uint64_t repeat); }; struct AsyncHandle : public UVHandle { - AsyncHandle(uv_loop_t* loop, std::function fun); + AsyncHandle(uv_loop_t* loop, function fun); void send(); }; @@ -126,14 +126,12 @@ class eventloop { ~eventloop(); void run(); void stop(); - void signal_handler(int signum, std::function fun); - void poll_handler(int events, int fd, std::function fun, std::function err_cb); - void fs_event_handler( - const string& path, std::function fun, std::function err_cb); - void pipe_handle( - int fd, std::function fun, std::function eof_cb, std::function err_cb); - void timer_handle(uint64_t timeout, uint64_t repeat, std::function fun); - AsyncHandle_t async_handle(std::function fun); + void signal_handle(int signum, function fun); + void poll_handle(int events, int fd, function fun, function err_cb); + void fs_event_handle(const string& path, function fun, function err_cb); + void pipe_handle(int fd, function fun, function eof_cb, function err_cb); + void timer_handle(uint64_t timeout, uint64_t repeat, function fun); + AsyncHandle_t async_handle(function fun); protected: uv_loop_t* get() const; diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 73ade056..f9ccc646 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -242,16 +242,16 @@ void controller::read_events(bool confwatch) { try { eloop = std::make_unique(); - eloop->poll_handler( + eloop->poll_handle( UV_READABLE, m_connection.get_file_descriptor(), [this](uv_poll_event events) { conn_cb(events); }, [](int status) { throw runtime_error("libuv error while polling X connection: "s + uv_strerror(status)); }); for (auto s : {SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGALRM}) { - eloop->signal_handler(s, [this](int signum) { signal_handler(signum); }); + eloop->signal_handle(s, [this](int signum) { signal_handler(signum); }); } if (confwatch) { - eloop->fs_event_handler( + eloop->fs_event_handle( m_conf.filepath(), [this](const char* path, uv_fs_event events) { confwatch_handler(path, events); }, [this](int status) { m_log.err("libuv error while watching config file for changes: %s", uv_strerror(status)); diff --git a/src/components/eventloop.cpp b/src/components/eventloop.cpp index e5738f7e..811939e2 100644 --- a/src/components/eventloop.cpp +++ b/src/components/eventloop.cpp @@ -41,7 +41,7 @@ static void alloc_cb(uv_handle_t*, size_t, uv_buf_t* buf) { } // SignalHandle {{{ -SignalHandle::SignalHandle(uv_loop_t* loop, std::function fun) : UVHandle(fun) { +SignalHandle::SignalHandle(uv_loop_t* loop, function fun) : UVHandle(fun) { UV(uv_signal_init, loop, handle); } @@ -51,7 +51,7 @@ void SignalHandle::start(int signum) { // }}} // PollHandle {{{ -PollHandle::PollHandle(uv_loop_t* loop, int fd, std::function fun, std::function err_cb) +PollHandle::PollHandle(uv_loop_t* loop, int fd, function fun, function err_cb) : UVHandle([this](int status, int events) { poll_cb(status, events); }), func(fun), err_cb(err_cb) { UV(uv_poll_init, loop, handle, fd); } @@ -72,8 +72,7 @@ void PollHandle::poll_cb(int status, int events) { // }}} // FSEventHandle {{{ -FSEventHandle::FSEventHandle( - uv_loop_t* loop, std::function fun, std::function err_cb) +FSEventHandle::FSEventHandle(uv_loop_t* loop, function fun, function err_cb) : UVHandle([this](const char* path, int events, int status) { fs_event_cb(path, events, status); }) , func(fun) , err_cb(err_cb) { @@ -96,8 +95,8 @@ void FSEventHandle::fs_event_cb(const char* path, int events, int status) { // }}} // PipeHandle {{{ -PipeHandle::PipeHandle(uv_loop_t* loop, std::function fun, std::function eof_cb, - std::function err_cb) +PipeHandle::PipeHandle( + uv_loop_t* loop, function fun, function eof_cb, function err_cb) : UVHandleGeneric([&](ssize_t nread, const uv_buf_t* buf) { read_cb(nread, buf); }) , func(fun) , eof_cb(eof_cb) @@ -132,7 +131,7 @@ void PipeHandle::read_cb(ssize_t nread, const uv_buf_t* buf) { // }}} // TimerHandle {{{ -TimerHandle::TimerHandle(uv_loop_t* loop, std::function fun) : UVHandle(fun) { +TimerHandle::TimerHandle(uv_loop_t* loop, function fun) : UVHandle(fun) { UV(uv_timer_init, loop, handle); } @@ -142,7 +141,7 @@ void TimerHandle::start(uint64_t timeout, uint64_t repeat) { // }}} // AsyncHandle {{{ -AsyncHandle::AsyncHandle(uv_loop_t* loop, std::function fun) : UVHandle(fun) { +AsyncHandle::AsyncHandle(uv_loop_t* loop, function fun) : UVHandle(fun) { UV(uv_async_init, loop, handle, callback); } @@ -199,35 +198,34 @@ uv_loop_t* eventloop::get() const { return m_loop.get(); } -void eventloop::signal_handler(int signum, std::function fun) { +void eventloop::signal_handle(int signum, function fun) { m_sig_handles.emplace_back(std::make_unique(get(), fun)); m_sig_handles.back()->start(signum); } -void eventloop::poll_handler( - int events, int fd, std::function fun, std::function err_cb) { +void eventloop::poll_handle(int events, int fd, function fun, function err_cb) { m_poll_handles.emplace_back(std::make_unique(get(), fd, fun, err_cb)); m_poll_handles.back()->start(events); } -void eventloop::fs_event_handler( - const string& path, std::function fun, std::function err_cb) { +void eventloop::fs_event_handle( + const string& path, function fun, function err_cb) { m_fs_event_handles.emplace_back(std::make_unique(get(), fun, err_cb)); m_fs_event_handles.back()->start(path); } void eventloop::pipe_handle( - int fd, std::function fun, std::function eof_cb, std::function err_cb) { + int fd, function fun, function eof_cb, function err_cb) { m_pipe_handles.emplace_back(std::make_unique(get(), fun, eof_cb, err_cb)); m_pipe_handles.back()->start(fd); } -void eventloop::timer_handle(uint64_t timeout, uint64_t repeat, std::function fun) { +void eventloop::timer_handle(uint64_t timeout, uint64_t repeat, function fun) { m_timer_handles.emplace_back(std::make_unique(get(), fun)); m_timer_handles.back()->start(timeout, repeat); } -AsyncHandle_t eventloop::async_handle(std::function fun) { +AsyncHandle_t eventloop::async_handle(function fun) { m_async_handles.emplace_back(std::make_shared(get(), fun)); return m_async_handles.back(); }