1 #pragma once
2 
3 
4 #include <utility>
5 #include <memory>
6 #include <uv.h>
7 #include "handle.hpp"
8 #include "loop.hpp"
9 
10 
11 namespace uvw {
12 
13 
14 /**
15  * @brief CheckEvent event.
16  *
17  * It will be emitted by CheckHandle according with its functionalities.
18  */
19 struct CheckEvent {};
20 
21 
22 /**
23  * @brief The CheckHandle handle.
24  *
25  * Check handles will emit a CheckEvent event once per loop iteration, right
26  * after polling for I/O.
27  *
28  * To create a `CheckHandle` through a `Loop`, no arguments are required.
29  */
30 class CheckHandle final: public Handle<CheckHandle, uv_check_t> {
startCallback(uv_check_t * handle)31     static void startCallback(uv_check_t *handle) {
32         CheckHandle &check = *(static_cast<CheckHandle*>(handle->data));
33         check.publish(CheckEvent{});
34     }
35 
36 public:
37     using Handle::Handle;
38 
39     /**
40      * @brief Initializes the handle.
41      * @return True in case of success, false otherwise.
42      */
init()43     bool init() {
44         return initialize(&uv_check_init);
45     }
46 
47     /**
48      * @brief Starts the handle.
49      *
50      * A CheckEvent event will be emitted once per loop iteration, right after
51      * polling for I/O.
52      */
start()53     void start() {
54         invoke(&uv_check_start, get(), &startCallback);
55     }
56 
57     /**
58      * @brief Stops the handle.
59      */
stop()60     void stop() {
61         invoke(&uv_check_stop, get());
62     }
63 };
64 
65 
66 }
67