WPILibC++  2018.4.1-20180729123227-1139-ga11fcb6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Signal.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_SIGNAL_H_
9 #define WPIUTIL_WPI_UV_SIGNAL_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 
26 class Signal final : public HandleImpl<Signal, uv_signal_t> {
27  struct private_init {};
28 
29  public:
30  explicit Signal(const private_init&) {}
31  ~Signal() noexcept override = default;
32 
38  static std::shared_ptr<Signal> Create(Loop& loop);
39 
45  static std::shared_ptr<Signal> Create(const std::shared_ptr<Loop>& loop) {
46  return Create(*loop);
47  }
48 
54  void Start(int signum);
55 
62  void StartOneshot(int signum);
63 
67  void Stop() { Invoke(&uv_signal_stop, GetRaw()); }
68 
73  int GetSignal() const { return GetRaw()->signum; }
74 
79 };
80 
81 } // namespace uv
82 } // namespace wpi
83 
84 #endif // WPIUTIL_WPI_UV_SIGNAL_H_
uv_signal_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:261
Handle.
Definition: Handle.h:246
static std::shared_ptr< Signal > Create(Loop &loop)
Create a signal handle.
void Start(int signum)
Start watching for the given signal.
namespace to hold default to_json function
Definition: SmallString.h:21
int GetSignal() const
Get the signal being monitored.
Definition: Signal.h:73
static std::shared_ptr< Signal > Create(const std::shared_ptr< Loop > &loop)
Create a signal handle.
Definition: Signal.h:45
void Stop()
Stop watching for the signal.
Definition: Signal.h:67
Event loop.
Definition: Loop.h:37
sig::Signal< int > signal
Signal generated when a signal occurs.
Definition: Signal.h:78
void StartOneshot(int signum)
Start watching for the given signal.
Signal handle.
Definition: Signal.h:26
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495