WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Signal.hpp
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#pragma once
6
7#include <memory>
8
9#include <uv.h>
10
11#include "wpi/net/uv/Handle.hpp"
12#include "wpi/util/Signal.h"
13
14namespace wpi::net::uv {
15
16class Loop;
17
18/**
19 * Signal handle.
20 */
21class Signal final : public HandleImpl<Signal, uv_signal_t> {
22 struct private_init {};
23
24 public:
25 explicit Signal(const private_init&) {}
26 ~Signal() noexcept override = default;
27
28 /**
29 * Create a signal handle.
30 *
31 * @param loop Loop object where this handle runs.
32 */
33 static std::shared_ptr<Signal> Create(Loop& loop);
34
35 /**
36 * Create a signal handle.
37 *
38 * @param loop Loop object where this handle runs.
39 */
40 static std::shared_ptr<Signal> Create(const std::shared_ptr<Loop>& loop) {
41 return Create(*loop);
42 }
43
44 /**
45 * Start watching for the given signal.
46 *
47 * @param signum Signal to watch for.
48 */
49 void Start(int signum);
50
51 /**
52 * Start watching for the given signal. Same as Start() but the signal
53 * handler is reset the moment the signal is received.
54 *
55 * @param signum Signal to watch for.
56 */
57 void StartOneshot(int signum);
58
59 /**
60 * Stop watching for the signal.
61 */
63
64 /**
65 * Get the signal being monitored.
66 * @return Signal number.
67 */
68 int GetSignal() const { return GetRaw()->signum; }
69
70 /**
71 * Signal generated when a signal occurs.
72 */
74};
75
76} // namespace wpi::net::uv
bool Invoke(F &&f, Args &&... args) const
Definition Handle.hpp:265
uv_signal_t * GetRaw() const noexcept
Definition Handle.hpp:303
Event loop.
Definition Loop.hpp:35
static std::shared_ptr< Signal > Create(Loop &loop)
Create a signal handle.
void Stop()
Stop watching for the signal.
Definition Signal.hpp:62
~Signal() noexcept override=default
wpi::util::sig::Signal< int > signal
Signal generated when a signal occurs.
Definition Signal.hpp:73
void Start(int signum)
Start watching for the given signal.
Signal(const private_init &)
Definition Signal.hpp:25
int GetSignal() const
Get the signal being monitored.
Definition Signal.hpp:68
void StartOneshot(int signum)
Start watching for the given signal.
Definition StringMap.hpp:773
Definition Prepare.hpp:14
SignalBase< detail::NullMutex, T... > Signal
Specialization of SignalBase to be used in single threaded contexts.
Definition Signal.h:809
int signum
Definition uv.h:1691
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)