This commit is contained in:
Michele Caini 2016-08-01 17:28:46 +02:00
parent 3673362c5c
commit aff7b27f25
3 changed files with 37 additions and 6 deletions

View File

@ -23,8 +23,8 @@ struct AsyncEvent: Event<AsyncEvent> { };
/**
* @brief The AsyncHandle handle.
*
* Async handles allow the user to _wakeup_ the event loop and get a callback
* called from another thread.
* Async handles allow the user to _wakeup_ the event loop and get an event
* emitted from another thread.
*/
class AsyncHandle final: public Handle<AsyncHandle, uv_async_t> {
static void sendCallback(uv_async_t *handle) {
@ -37,9 +37,7 @@ class AsyncHandle final: public Handle<AsyncHandle, uv_async_t> {
public:
/**
* @brief Creates a new async handle.
*
* No arguments required.
*
* @param ref A pointer to the loop from which the handle generated.
* @return A pointer to the newly created handle.
*/
template<typename... Args>
@ -60,7 +58,7 @@ public:
}
/**
* @brief Wakeups the event loop and call the async handles callback.
* @brief Wakeups the event loop and emits the AsyncEvent event.
*
* Its safe to call this function from any thread.<br/>
* An AsyncEvent will be emitted on the loop thread.

View File

@ -12,9 +12,20 @@
namespace uvw {
/**
* @brief Trigger event.
*
* It will be emitted by the CheckHandle according with its functionalities.
*/
struct CheckEvent: Event<CheckEvent> { };
/**
* @brief The CheckHandle handle.
*
* Check handles will emit a CheckEvent once per loop iteration, right after
* polling for I/O.
*/
class CheckHandle final: public Handle<CheckHandle, uv_check_t> {
static void startCallback(uv_check_t *handle) {
CheckHandle &check = *(static_cast<CheckHandle*>(handle->data));
@ -24,19 +35,37 @@ class CheckHandle final: public Handle<CheckHandle, uv_check_t> {
using Handle::Handle;
public:
/**
* @brief Creates a new check handle.
* @param ref A pointer to the loop from which the handle generated.
* @return A pointer to the newly created handle.
*/
template<typename... Args>
static std::shared_ptr<CheckHandle> create(Args&&... args) {
return std::shared_ptr<CheckHandle>{new CheckHandle{std::forward<Args>(args)...}};
}
/**
* @brief Initializes the handle.
* @return True in case of success, false otherwise.
*/
bool init() {
return initialize<uv_check_t>(&uv_check_init);
}
/**
* @brief Starts the handle.
*
* A CheckEvent event will be emitted once per loop iteration, right after
* polling for I/O.
*/
void start() {
invoke(&uv_check_start, get<uv_check_t>(), &startCallback);
}
/**
* @brief Stops the handle.
*/
void stop() {
invoke(&uv_check_stop, get<uv_check_t>());
}

View File

@ -188,6 +188,8 @@ public:
* * Loop::Configure::BLOCK_SIGNAL: Block a signal when polling for new
* events. A second argument is required and it is the signal number.
*
* An ErrorEvent will be emitted in case of errors.
*
* See the official
* [documentation](http://docs.libuv.org/en/v1.x/loop.html#c.uv_loop_configure)
* for further details.
@ -237,6 +239,8 @@ public:
*
* Call this function only when the loop has finished executing and all open
* handles and requests have been closed, or the loop will emit an error.
*
* An ErrorEvent will be emitted in case of errors.
*/
void close() {
auto err = uv_loop_close(loop.get());