WPILibC++  2020.3.2
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_
wpi::uv::HandleImpl< Signal, uv_signal_t >::GetRaw
uv_signal_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:288
wpi::uv::Signal::Create
static std::shared_ptr< Signal > Create(const std::shared_ptr< Loop > &loop)
Create a signal handle.
Definition: Signal.h:45
wpi::uv::Signal::StartOneshot
void StartOneshot(int signum)
Start watching for the given signal.
wpi::uv::Signal::signal
sig::Signal< int > signal
Signal generated when a signal occurs.
Definition: Signal.h:78
wpi::uv::Signal::Stop
void Stop()
Stop watching for the signal.
Definition: Signal.h:67
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
wpi::uv::Signal::Start
void Start(int signum)
Start watching for the given signal.
wpi::uv::Signal::GetSignal
int GetSignal() const
Get the signal being monitored.
Definition: Signal.h:73
wpi::uv::HandleImpl
Handle.
Definition: Handle.h:273
wpi::uv::Signal::Create
static std::shared_ptr< Signal > Create(Loop &loop)
Create a signal handle.
wpi::uv::Loop
Event loop.
Definition: Loop.h:39
wpi::uv::Signal
Signal handle.
Definition: Signal.h:26
wpi::sig::SignalBase
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495