WPILibC++  2018.4.1-20180810231726-1152-g44099d9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Async.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef WPIUTIL_WPI_UV_ASYNC_H_
9 #define WPIUTIL_WPI_UV_ASYNC_H_
10 
11 #include <uv.h>
12 
13 #include <memory>
14 
15 #include "wpi/Signal.h"
16 #include "wpi/uv/Handle.h"
17 
18 namespace wpi {
19 namespace uv {
20 
21 class Loop;
22 
28 class Async final : public HandleImpl<Async, uv_async_t> {
29  struct private_init {};
30 
31  public:
32  explicit Async(const private_init&) {}
33  ~Async() noexcept override = default;
34 
40  static std::shared_ptr<Async> Create(Loop& loop);
41 
47  static std::shared_ptr<Async> Create(const std::shared_ptr<Loop>& loop) {
48  return Create(*loop);
49  }
50 
57  void Send() { Invoke(&uv_async_send, GetRaw()); }
58 
63 };
64 
65 } // namespace uv
66 } // namespace wpi
67 
68 #endif // WPIUTIL_WPI_UV_ASYNC_H_
uv_async_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:261
Handle.
Definition: Handle.h:246
static std::shared_ptr< Async > Create(Loop &loop)
Create an async handle.
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
void Send()
Wakeup the event loop and emit the event.
Definition: Async.h:57
sig::Signal wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition: Async.h:62
Event loop.
Definition: Loop.h:37
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
Definition: Async.h:47
Async handle.
Definition: Async.h:28
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495