35template <
typename THandle,
typename TStruct,
int16_t size>
54 std::array<std::shared_ptr<TStruct>, size> m_structures;
55 std::array<wpi::util::mutex, size> m_handleMutexes;
58template <
typename THandle,
typename TStruct,
int16_t size>
67 std::scoped_lock lock(m_handleMutexes[
index]);
69 if (m_structures[
index] !=
nullptr) {
73 m_structures[
index]->previousAllocation));
79 m_structures[
index] = std::make_shared<TStruct>();
82 return std::pair{handle, m_structures[
index]};
85template <
typename THandle,
typename TStruct,
int16_t size>
93 std::scoped_lock lock(m_handleMutexes[
index]);
96 return m_structures[
index];
99template <
typename THandle,
typename TStruct,
int16_t size>
108 std::scoped_lock lock(m_handleMutexes[
index]);
109 m_structures[
index].reset();
112template <
typename THandle,
typename TStruct,
int16_t size>
114 for (
int i = 0; i < size; i++) {
115 std::scoped_lock lock(m_handleMutexes[i]);
116 m_structures[i].reset();
@ index
Definition base.h:690
@ name
Definition base.h:690
void Free(THandle handle, HAL_HandleEnum enumValue)
Definition DigitalHandleResource.hpp:100
friend class DigitalHandleResourceTest
Definition DigitalHandleResource.hpp:37
std::shared_ptr< TStruct > Get(THandle handle, HAL_HandleEnum enumValue)
Definition DigitalHandleResource.hpp:86
wpi::util::expected< std::pair< THandle, std::shared_ptr< TStruct > >, HAL_Status > Allocate(int16_t index, HAL_HandleEnum enumValue, std::string_view name)
Definition DigitalHandleResource.hpp:60
int16_t GetIndex(THandle handle, HAL_HandleEnum enumValue)
Definition DigitalHandleResource.hpp:46
DigitalHandleResource & operator=(const DigitalHandleResource &)=delete
DigitalHandleResource(const DigitalHandleResource &)=delete
void ResetHandles() override
Definition DigitalHandleResource.hpp:113
DigitalHandleResource()=default
virtual void ResetHandles()
int16_t m_version
Definition HandlesInternal.hpp:47
An expected<T, E> object is an object that contains the storage for another object and manages the li...
Definition expected:1250
Definition HandlesInternal.hpp:29
#define HAL_RESOURCE_IS_ALLOCATED
Definition Errors.h:39
#define HAL_RESOURCE_OUT_OF_RANGE
Definition Errors.h:41
int32_t HAL_Status
Definition Types.h:67
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition Types.hpp:9
HAL_HandleEnum
Enum of HAL handle types.
Definition HandlesInternal.hpp:55
int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType, int16_t version)
Get if the handle is a correct type and version.
Definition HandlesInternal.hpp:139
HAL_Status MakeErrorIndexOutOfRange(HAL_Status status, std::string_view message, int32_t minimum, int32_t maximum, int32_t channel)
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType, int16_t version)
Create a handle for a specific index, type and version.
HAL_Status MakeErrorPreviouslyAllocated(HAL_Status status, std::string_view message, int32_t channel, std::string_view previousAllocation)