EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
signal.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************
16  * This file is a part of EtcPal. For more information, go to:
17  * https://github.com/ETCLabs/EtcPal
18  ******************************************************************************/
19 
22 
23 #ifndef ETCPAL_CPP_SIGNAL_H_
24 #define ETCPAL_CPP_SIGNAL_H_
25 
26 #include "etcpal/cpp/common.h"
27 #include "etcpal/signal.h"
28 
29 namespace etcpal
30 {
39 
88 class Signal
89 {
90 public:
91  Signal();
92  ~Signal();
93 
94  Signal(const Signal& other) = delete;
95  Signal& operator=(const Signal& other) = delete;
96  Signal(Signal&& other) = delete;
97  Signal& operator=(Signal&& other) = delete;
98 
99  bool Wait();
100  bool TryWait(int timeout_ms = 0);
101  void Notify();
102  void NotifyFromIsr();
103 
104  etcpal_signal_t& get();
105 
106 private:
107  etcpal_signal_t signal_{};
108 };
109 
112 {
113  (void)etcpal_signal_create(&signal_);
114 }
115 
118 {
119  etcpal_signal_destroy(&signal_);
120 }
121 
124 inline bool Signal::Wait()
125 {
126  return etcpal_signal_wait(&signal_);
127 }
128 
138 inline bool Signal::TryWait(int timeout_ms)
139 {
140  return etcpal_signal_timed_wait(&signal_, timeout_ms);
141 }
142 
146 inline void Signal::Notify()
147 {
148  etcpal_signal_post(&signal_);
149 }
150 
157 {
158  etcpal_signal_post_from_isr(&signal_);
159 }
160 
163 {
164  return signal_;
165 }
166 
167 }; // namespace etcpal
168 
169 #endif // ETCPAL_CPP_SIGNAL_H_
A wrapper class for the EtcPal signal type.
Definition: signal.h:89
~Signal()
Destroy the signal.
Definition: signal.h:117
Signal()
Create a new signal.
Definition: signal.h:111
etcpal_signal_t & get()
Get a reference to the underlying etcpal_signal_t type.
Definition: signal.h:162
void Notify()
Notify those waiting on the signal.
Definition: signal.h:146
bool TryWait(int timeout_ms=0)
Wait for the signal until either it is received or a timeout expires.
Definition: signal.h:138
void NotifyFromIsr()
Notify those waiting on the signal from an interrupt context.
Definition: signal.h:156
bool Wait()
Wait for the signal.
Definition: signal.h:124
Common definitions used by EtcPal C++ wrappers.
bool etcpal_signal_wait(etcpal_signal_t *id)
Wait for a signal.
bool etcpal_signal_create(etcpal_signal_t *id)
Create a new signal.
void etcpal_signal_destroy(etcpal_signal_t *id)
Destroy a signal object.
bool etcpal_signal_timed_wait(etcpal_signal_t *id, int timeout_ms)
Wait for a signal, giving up after a timeout.
PLATFORM_DEFINED etcpal_signal_t
The signal identifier.
Definition: signal.dox:86
void etcpal_signal_post_from_isr(etcpal_signal_t *id)
Post a signal from an interrupt context.
void etcpal_signal_post(etcpal_signal_t *id)
Post a signal.