19template <
typename T, HAL_Value (*MakeValue)(T)>
43 HAL_Bool initialNotify,
const char* name) {
53 callback(name, param, &
value);
59 std::scoped_lock lock(this->
m_mutex);
86template <
typename T,
HAL_Value (*MakeValue)(T),
const char* (*GetName)(),
87 T (*GetDefault)() =
nullptr>
96#pragma GCC diagnostic push
97#pragma GCC diagnostic ignored "-Waddress"
100 : impl::SimDataValueBase<T, MakeValue>(
101 GetDefault != nullptr ? GetDefault() : T()) {}
103#pragma GCC diagnostic pop
106 : impl::SimDataValueBase<T, MakeValue>(
value) {}
110 return this->DoRegisterCallback(callback, param, initialNotify, GetName());
114 this->DoSet(
value, GetName());
128#define HAL_SIMDATAVALUE_DEFINE_NAME(NAME) \
129 static LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr const char* \
130 Get##NAME##Name() { \
151#define HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, NS, CAPINAME, DATA, LOWERNAME) \
152 int32_t NS##_Register##CAPINAME##Callback( \
153 int32_t index, HAL_NotifyCallback callback, void* param, \
154 HAL_Bool initialNotify) { \
155 return DATA[index].LOWERNAME.RegisterCallback(callback, param, \
159 void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) { \
160 DATA[index].LOWERNAME.CancelCallback(uid); \
163 TYPE NS##_Get##CAPINAME(int32_t index) { \
164 return DATA[index].LOWERNAME; \
167 void NS##_Set##CAPINAME(int32_t index, TYPE LOWERNAME) { \
168 DATA[index].LOWERNAME = LOWERNAME; \
188#define HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(TYPE, NS, CAPINAME, DATA, \
190 int32_t NS##_Register##CAPINAME##Callback( \
191 int32_t index, int32_t channel, HAL_NotifyCallback callback, \
192 void* param, HAL_Bool initialNotify) { \
193 return DATA[index].LOWERNAME[channel].RegisterCallback(callback, param, \
197 void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t channel, \
199 DATA[index].LOWERNAME[channel].CancelCallback(uid); \
202 TYPE NS##_Get##CAPINAME(int32_t index, int32_t channel) { \
203 return DATA[index].LOWERNAME[channel]; \
206 void NS##_Set##CAPINAME(int32_t index, int32_t channel, TYPE LOWERNAME) { \
207 DATA[index].LOWERNAME[channel] = LOWERNAME; \
226#define HAL_SIMDATAVALUE_DEFINE_CAPI_NOINDEX(TYPE, NS, CAPINAME, DATA, \
228 int32_t NS##_Register##CAPINAME##Callback( \
229 HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) { \
230 return DATA->LOWERNAME.RegisterCallback(callback, param, initialNotify); \
233 void NS##_Cancel##CAPINAME##Callback(int32_t uid) { \
234 DATA->LOWERNAME.CancelCallback(uid); \
237 TYPE NS##_Get##CAPINAME(void) { \
238 return DATA->LOWERNAME; \
241 void NS##_Set##CAPINAME(TYPE LOWERNAME) { \
242 DATA->LOWERNAME = LOWERNAME; \
261#define HAL_SIMDATAVALUE_STUB_CAPI(TYPE, NS, CAPINAME, RETURN) \
262 int32_t NS##_Register##CAPINAME##Callback( \
263 int32_t index, HAL_NotifyCallback callback, void* param, \
264 HAL_Bool initialNotify) { \
268 void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t uid) {} \
270 TYPE NS##_Get##CAPINAME(int32_t index) { \
274 void NS##_Set##CAPINAME(int32_t index, TYPE) {}
292#define HAL_SIMDATAVALUE_STUB_CAPI_CHANNEL(TYPE, NS, CAPINAME, RETURN) \
293 int32_t NS##_Register##CAPINAME##Callback( \
294 int32_t index, int32_t channel, HAL_NotifyCallback callback, \
295 void* param, HAL_Bool initialNotify) { \
299 void NS##_Cancel##CAPINAME##Callback(int32_t index, int32_t channel, \
302 TYPE NS##_Get##CAPINAME(int32_t index, int32_t channel) { \
306 void NS##_Set##CAPINAME(int32_t index, int32_t channel, TYPE) {}
323#define HAL_SIMDATAVALUE_STUB_CAPI_NOINDEX(TYPE, NS, CAPINAME, RETURN) \
324 int32_t NS##_Register##CAPINAME##Callback( \
325 HAL_NotifyCallback callback, void* param, HAL_Bool initialNotify) { \
329 void NS##_Cancel##CAPINAME##Callback(int32_t uid) {} \
331 TYPE NS##_Get##CAPINAME(void) { \
335 void NS##_Set##CAPINAME(TYPE) {}
#define LLVM_ATTRIBUTE_ALWAYS_INLINE
LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do so, mark a method "always...
Definition: Compiler.h:274
void(* HAL_NotifyCallback)(const char *name, void *param, const struct HAL_Value *value)
Definition: NotifyListener.h:9
Simulation data value wrapper.
Definition: SimDataValue.h:88
SimDataValue()
Definition: SimDataValue.h:99
LLVM_ATTRIBUTE_ALWAYS_INLINE SimDataValue & operator=(T value)
Definition: SimDataValue.h:117
LLVM_ATTRIBUTE_ALWAYS_INLINE int32_t RegisterCallback(HAL_NotifyCallback callback, void *param, HAL_Bool initialNotify)
Definition: SimDataValue.h:108
SimDataValue(T value)
Definition: SimDataValue.h:105
LLVM_ATTRIBUTE_ALWAYS_INLINE void Set(T value)
Definition: SimDataValue.h:113
Definition: SimCallbackRegistry.h:20
void Cancel(int32_t uid)
Definition: SimCallbackRegistry.h:28
LLVM_ATTRIBUTE_ALWAYS_INLINE void DoReset()
Definition: SimCallbackRegistry.h:54
wpi::recursive_spinlock m_mutex
Definition: SimCallbackRegistry.h:60
void(*)() RawFunctor
Definition: SimCallbackRegistry.h:22
int32_t DoRegister(RawFunctor callback, void *param)
Definition: SimCallbackRegistry.h:43
std::unique_ptr< CallbackVector > m_callbacks
Definition: SimCallbackRegistry.h:61
Definition: SimDataValue.h:20
void DoSet(T value, const char *name)
Definition: SimDataValue.h:58
LLVM_ATTRIBUTE_ALWAYS_INLINE void CancelCallback(int32_t uid)
Definition: SimDataValue.h:24
wpi::recursive_spinlock & GetMutex()
Definition: SimDataValue.h:39
int32_t DoRegisterCallback(HAL_NotifyCallback callback, void *param, HAL_Bool initialNotify, const char *name)
Definition: SimDataValue.h:42
SimDataValueBase(T value)
Definition: SimDataValue.h:22
T Get() const
Definition: SimDataValue.h:26
void Reset(T value)
Definition: SimDataValue.h:33
T m_value
Definition: SimDataValue.h:72
A recursive spinlock mutex.
Definition: spinlock.h:46
int32_t HAL_Bool
Definition: Types.h:73
::int32_t int32_t
Definition: Meta.h:57
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: ChipObject.h:40
HAL Entry Value.
Definition: Value.h:20