WPILibC++ 2024.3.2
CallbackStore.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#pragma once
6
7#include <functional>
8#include <string_view>
9
10#include <hal/Value.h>
11
12namespace frc::sim {
13
14using NotifyCallback = std::function<void(std::string_view, const HAL_Value*)>;
15using ConstBufferCallback = std::function<void(
16 std::string_view, const unsigned char* buffer, unsigned int count)>;
17using CancelCallbackFunc = void (*)(int32_t index, int32_t uid);
18using CancelCallbackNoIndexFunc = void (*)(int32_t uid);
19using CancelCallbackChannelFunc = void (*)(int32_t index, int32_t channel,
20 int32_t uid);
21
22void CallbackStoreThunk(const char* name, void* param, const HAL_Value* value);
23void ConstBufferCallbackStoreThunk(const char* name, void* param,
24 const unsigned char* buffer,
25 unsigned int count);
26
27/**
28 * Manages simulation callbacks; each object is associated with a callback.
29 */
31 public:
33
34 CallbackStore(int32_t i, int32_t u, NotifyCallback cb,
36
37 CallbackStore(int32_t i, int32_t c, int32_t u, NotifyCallback cb,
39
42
43 CallbackStore(int32_t i, int32_t u, ConstBufferCallback cb,
45
46 CallbackStore(int32_t i, int32_t c, int32_t u, ConstBufferCallback cb,
48
49 CallbackStore(const CallbackStore&) = delete;
51
53
54 void SetUid(int32_t uid);
55
56 friend void CallbackStoreThunk(const char* name, void* param,
57 const HAL_Value* value);
58
59 friend void ConstBufferCallbackStoreThunk(const char* name, void* param,
60 const unsigned char* buffer,
61 unsigned int count);
62
63 private:
64 int32_t index;
65 int32_t channel;
66 int32_t uid;
67
68 NotifyCallback callback;
69 ConstBufferCallback constBufferCallback;
70 union {
74 };
75 enum CancelType { Normal, Channel, NoIndex };
76 CancelType cancelType;
77};
78} // namespace frc::sim
Manages simulation callbacks; each object is associated with a callback.
Definition: CallbackStore.h:30
CallbackStore(int32_t i, int32_t c, int32_t u, ConstBufferCallback cb, CancelCallbackChannelFunc ccf)
CallbackStore & operator=(const CallbackStore &)=delete
void SetUid(int32_t uid)
CallbackStore(int32_t i, int32_t u, ConstBufferCallback cb, CancelCallbackFunc ccf)
CallbackStore(int32_t i, int32_t c, int32_t u, NotifyCallback cb, CancelCallbackChannelFunc ccf)
CancelCallbackFunc ccf
Definition: CallbackStore.h:71
CallbackStore(int32_t i, int32_t u, NotifyCallback cb, CancelCallbackFunc ccf)
CancelCallbackNoIndexFunc ccnif
Definition: CallbackStore.h:73
CallbackStore(int32_t i, ConstBufferCallback cb, CancelCallbackNoIndexFunc ccf)
friend void CallbackStoreThunk(const char *name, void *param, const HAL_Value *value)
CallbackStore(const CallbackStore &)=delete
CancelCallbackChannelFunc cccf
Definition: CallbackStore.h:72
CallbackStore(int32_t i, NotifyCallback cb, CancelCallbackNoIndexFunc ccf)
friend void ConstBufferCallbackStoreThunk(const char *name, void *param, const unsigned char *buffer, unsigned int count)
basic_string_view< char > string_view
Definition: core.h:501
constexpr auto count() -> size_t
Definition: core.h:1203
Definition: XboxControllerSim.h:13
void(*)(int32_t index, int32_t channel, int32_t uid) CancelCallbackChannelFunc
Definition: CallbackStore.h:20
void(*)(int32_t uid) CancelCallbackNoIndexFunc
Definition: CallbackStore.h:18
void(*)(int32_t index, int32_t uid) CancelCallbackFunc
Definition: CallbackStore.h:17
std::function< void(std::string_view, const unsigned char *buffer, unsigned int count)> ConstBufferCallback
Definition: CallbackStore.h:16
void CallbackStoreThunk(const char *name, void *param, const HAL_Value *value)
void ConstBufferCallbackStoreThunk(const char *name, void *param, const unsigned char *buffer, unsigned int count)
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
HAL Entry Value.
Definition: Value.h:20