Add wrapper for uv_timer_t
This commit is contained in:
parent
309fd8221a
commit
7b5285b51e
2 changed files with 14 additions and 10 deletions
|
@ -128,6 +128,16 @@ struct PipeHandle : public UVHandleGeneric<uv_pipe_t, uv_stream_t, ssize_t, cons
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TimerHandle : public UVHandle<uv_timer_t> {
|
||||||
|
TimerHandle(uv_loop_t* loop, std::function<void(void)> fun) : UVHandle(fun) {
|
||||||
|
UV(uv_timer_init, loop, handle.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
void start(uint64_t timeout, uint64_t repeat) {
|
||||||
|
UV(uv_timer_start, handle.get(), &cb.callback, timeout, repeat);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class eventloop {
|
class eventloop {
|
||||||
public:
|
public:
|
||||||
eventloop();
|
eventloop();
|
||||||
|
|
|
@ -246,10 +246,6 @@ void controller::screenshot_handler() {
|
||||||
trigger_update(true);
|
trigger_update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void screenshot_cb_wrapper(uv_timer_t* handle) {
|
|
||||||
static_cast<controller*>(handle->data)->screenshot_handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read events from configured file descriptors
|
* Read events from configured file descriptors
|
||||||
*/
|
*/
|
||||||
|
@ -261,7 +257,7 @@ void controller::read_events(bool confwatch) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ipc_handle = std::unique_ptr<PipeHandle>(nullptr);
|
auto ipc_handle = std::unique_ptr<PipeHandle>(nullptr);
|
||||||
auto screenshot_timer_handle = std::unique_ptr<uv_timer_t>(nullptr);
|
auto screenshot_timer_handle = std::unique_ptr<TimerHandle>(nullptr);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eloop = std::make_unique<eventloop>();
|
eloop = std::make_unique<eventloop>();
|
||||||
|
@ -289,11 +285,9 @@ void controller::read_events(bool confwatch) {
|
||||||
m_notifier->data = this;
|
m_notifier->data = this;
|
||||||
|
|
||||||
if (!m_snapshot_dst.empty()) {
|
if (!m_snapshot_dst.empty()) {
|
||||||
screenshot_timer_handle = std::make_unique<uv_timer_t>();
|
screenshot_timer_handle = std::make_unique<TimerHandle>(loop, [this]() { screenshot_handler(); });
|
||||||
UV(uv_timer_init, loop, screenshot_timer_handle.get());
|
// Trigger a single screenshot after 3 seconds
|
||||||
screenshot_timer_handle->data = this;
|
screenshot_timer_handle->start(3000, 0);
|
||||||
// Trigger a screenshot after 3 seconds
|
|
||||||
UV(uv_timer_start, screenshot_timer_handle.get(), screenshot_cb_wrapper, 3000, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_eloop_ready.store(true);
|
m_eloop_ready.store(true);
|
||||||
|
|
Loading…
Reference in a new issue