WPILibC++ 2025.3.2
Loading...
Searching...
No Matches
Signal.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#ifndef WPINET_UV_SIGNAL_H_
6#define WPINET_UV_SIGNAL_H_
7
8#include <uv.h>
9
10#include <memory>
11
12#include <wpi/Signal.h>
13
14#include "wpinet/uv/Handle.h"
15
16namespace wpi::uv {
17
18class Loop;
19
20/**
21 * Signal handle.
22 */
23class Signal final : public HandleImpl<Signal, uv_signal_t> {
24 struct private_init {};
25
26 public:
27 explicit Signal(const private_init&) {}
28 ~Signal() noexcept override = default;
29
30 /**
31 * Create a signal handle.
32 *
33 * @param loop Loop object where this handle runs.
34 */
35 static std::shared_ptr<Signal> Create(Loop& loop);
36
37 /**
38 * Create a signal handle.
39 *
40 * @param loop Loop object where this handle runs.
41 */
42 static std::shared_ptr<Signal> Create(const std::shared_ptr<Loop>& loop) {
43 return Create(*loop);
44 }
45
46 /**
47 * Start watching for the given signal.
48 *
49 * @param signum Signal to watch for.
50 */
51 void Start(int signum);
52
53 /**
54 * Start watching for the given signal. Same as Start() but the signal
55 * handler is reset the moment the signal is received.
56 *
57 * @param signum Signal to watch for.
58 */
59 void StartOneshot(int signum);
60
61 /**
62 * Stop watching for the signal.
63 */
65
66 /**
67 * Get the signal being monitored.
68 * @return Signal number.
69 */
70 int GetSignal() const { return GetRaw()->signum; }
71
72 /**
73 * Signal generated when a signal occurs.
74 */
76};
77
78} // namespace wpi::uv
79
80#endif // WPINET_UV_SIGNAL_H_
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition Signal.h:495
bool Invoke(F &&f, Args &&... args) const
Definition Handle.h:267
Handle.
Definition Handle.h:290
uv_signal_t * GetRaw() const noexcept
Definition Handle.h:305
Event loop.
Definition Loop.h:37
Signal handle.
Definition Signal.h:23
int GetSignal() const
Get the signal being monitored.
Definition Signal.h:70
sig::Signal< int > signal
Signal generated when a signal occurs.
Definition Signal.h:75
~Signal() noexcept override=default
static std::shared_ptr< Signal > Create(Loop &loop)
Create a signal handle.
void Start(int signum)
Start watching for the given signal.
Signal(const private_init &)
Definition Signal.h:27
void StartOneshot(int signum)
Start watching for the given signal.
void Stop()
Stop watching for the signal.
Definition Signal.h:64
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
Definition Loop.h:22
int signum
Definition uv.h:1691
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)