[hal,ntcore,cscore] Update Handle constants to all caps

This commit is contained in:
Peter Johnson
2026-03-16 21:49:21 -07:00
parent aa88fa0fcf
commit 4059797635
57 changed files with 283 additions and 281 deletions

View File

@@ -152,7 +152,7 @@ CS_Property CreateSourceProperty(CS_Source source, std::string_view name,
int property = static_cast<ConfigurableSourceImpl&>(*data->source)
.CreateProperty(name, kind, minimum, maximum, step,
defaultValue, value);
return Handle{source, property, Handle::kProperty};
return Handle{source, property, Handle::PROPERTY};
}
CS_Property CreateSourcePropertyCallback(
@@ -167,7 +167,7 @@ CS_Property CreateSourcePropertyCallback(
int property = static_cast<ConfigurableSourceImpl&>(*data->source)
.CreateProperty(name, kind, minimum, maximum, step,
defaultValue, value, onChange);
return Handle{source, property, Handle::kProperty};
return Handle{source, property, Handle::PROPERTY};
}
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
@@ -186,7 +186,7 @@ void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
*status = CS_INVALID_HANDLE;
return;
}
auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::kSource});
auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::SOURCE});
if (!data2 || data->source.get() != data2->source.get()) {
*status = CS_INVALID_HANDLE;
return;

View File

@@ -17,13 +17,13 @@ namespace wpi::cs {
class Handle {
public:
enum Type {
kUndefined = 0,
kProperty = wpi::util::kHandleTypeCSBase,
kSource,
kSink,
kListener,
kSinkProperty,
kListenerPoller
UNDEFINED = 0,
PROPERTY = wpi::util::HANDLE_TYPE_CS_BASE,
SOURCE,
SINK,
LISTENER,
SINK_PROPERTY,
LISTENER_POLLER
};
enum { kIndexMax = 0xffff };
@@ -53,7 +53,7 @@ class Handle {
bool IsType(Type type) const { return type == GetType(); }
int GetTypedIndex(Type type) const { return IsType(type) ? GetIndex() : -1; }
int GetParentIndex() const {
return (IsType(Handle::kProperty) || IsType(Handle::kSinkProperty))
return (IsType(Handle::PROPERTY) || IsType(Handle::SINK_PROPERTY))
? (static_cast<int>(m_handle) >> 16) & 0xff
: -1;
}

View File

@@ -56,8 +56,8 @@ class Instance {
UsbCameraListener usbCameraListener;
private:
UnlimitedHandleResource<Handle, SourceData, Handle::kSource> m_sources;
UnlimitedHandleResource<Handle, SinkData, Handle::kSink> m_sinks;
UnlimitedHandleResource<Handle, SourceData, Handle::SOURCE> m_sources;
UnlimitedHandleResource<Handle, SinkData, Handle::SINK> m_sinks;
public:
wpi::net::EventLoopRunner eventLoop;

View File

@@ -53,7 +53,7 @@ void Notifier::NotifySourceProperty(const SourceImpl& source, CS_EventKind kind,
auto handleData = Instance::GetInstance().FindSource(source);
Send(UINT_MAX, propertyName, handleData.first,
static_cast<RawEvent::Kind>(kind),
Handle{handleData.first, property, Handle::kProperty}, propertyKind,
Handle{handleData.first, property, Handle::PROPERTY}, propertyKind,
value, valueStr);
}
@@ -81,7 +81,7 @@ void Notifier::NotifySinkProperty(const SinkImpl& sink, CS_EventKind kind,
auto handleData = Instance::GetInstance().FindSink(sink);
Send(UINT_MAX, propertyName, handleData.first,
static_cast<RawEvent::Kind>(kind),
Handle{handleData.first, property, Handle::kSinkProperty}, propertyKind,
Handle{handleData.first, property, Handle::SINK_PROPERTY}, propertyKind,
value, valueStr);
}

View File

@@ -42,7 +42,7 @@ class NotifierThread
}
void SetListener(RawEvent* data, unsigned int listener_uid) {
data->listener = Handle(listener_uid, Handle::kListener);
data->listener = Handle(listener_uid, Handle::LISTENER);
}
void DoCallback(std::function<void(const RawEvent& event)> callback,

View File

@@ -134,7 +134,7 @@ void Telemetry::RecordSourceBytes(const SourceImpl& source, int quantity) {
return;
}
auto handleData = Instance::GetInstance().FindSource(source);
thr->m_current[std::pair{Handle{handleData.first, Handle::kSource},
thr->m_current[std::pair{Handle{handleData.first, Handle::SOURCE},
static_cast<int>(CS_SOURCE_BYTES_RECEIVED)}] +=
quantity;
}
@@ -145,7 +145,7 @@ void Telemetry::RecordSourceFrames(const SourceImpl& source, int quantity) {
return;
}
auto handleData = Instance::GetInstance().FindSource(source);
thr->m_current[std::pair{Handle{handleData.first, Handle::kSource},
thr->m_current[std::pair{Handle{handleData.first, Handle::SOURCE},
static_cast<int>(CS_SOURCE_FRAMES_RECEIVED)}] +=
quantity;
}

View File

@@ -27,17 +27,17 @@ static std::shared_ptr<PropertyContainer> GetPropertyContainer(
CS_Property propertyHandle, int* propertyIndex, CS_Status* status) {
std::shared_ptr<PropertyContainer> container;
Handle handle{propertyHandle};
if (handle.IsType(Handle::kProperty)) {
if (handle.IsType(Handle::PROPERTY)) {
int i = handle.GetParentIndex();
auto data = Instance::GetInstance().GetSource(Handle{i, Handle::kSource});
auto data = Instance::GetInstance().GetSource(Handle{i, Handle::SOURCE});
if (!data) {
*status = CS_INVALID_HANDLE;
return nullptr;
}
container = data->source;
} else if (handle.IsType(Handle::kSinkProperty)) {
} else if (handle.IsType(Handle::SINK_PROPERTY)) {
int i = handle.GetParentIndex();
auto data = Instance::GetInstance().GetSink(Handle{i, Handle::kSink});
auto data = Instance::GetInstance().GetSink(Handle{i, Handle::SINK});
if (!data) {
*status = CS_INVALID_HANDLE;
return nullptr;
@@ -286,7 +286,7 @@ CS_Property GetSourceProperty(CS_Source source, std::string_view name,
*status = CS_INVALID_HANDLE;
return 0;
}
return Handle{source, property, Handle::kProperty};
return Handle{source, property, Handle::PROPERTY};
}
std::span<CS_Property> EnumerateSourceProperties(
@@ -300,7 +300,7 @@ std::span<CS_Property> EnumerateSourceProperties(
wpi::util::SmallVector<int, 32> properties_buf;
for (auto property :
data->source->EnumerateProperties(properties_buf, status)) {
vec.push_back(Handle{source, property, Handle::kProperty});
vec.push_back(Handle{source, property, Handle::PROPERTY});
}
return vec;
}
@@ -584,7 +584,7 @@ CS_Property GetSinkProperty(CS_Sink sink, std::string_view name,
*status = CS_INVALID_HANDLE;
return 0;
}
return Handle{sink, property, Handle::kSinkProperty};
return Handle{sink, property, Handle::SINK_PROPERTY};
}
std::span<CS_Property> EnumerateSinkProperties(
@@ -598,7 +598,7 @@ std::span<CS_Property> EnumerateSinkProperties(
wpi::util::SmallVector<int, 32> properties_buf;
for (auto property :
data->sink->EnumerateProperties(properties_buf, status)) {
vec.push_back(Handle{sink, property, Handle::kSinkProperty});
vec.push_back(Handle{sink, property, Handle::SINK_PROPERTY});
}
return vec;
}
@@ -748,11 +748,11 @@ CS_Listener AddListener(std::function<void(const RawEvent& event)> callback,
if (immediateNotify) {
// TODO
}
return Handle{uid, Handle::kListener};
return Handle{uid, Handle::LISTENER};
}
void RemoveListener(CS_Listener handle, CS_Status* status) {
int uid = Handle{handle}.GetTypedIndex(Handle::kListener);
int uid = Handle{handle}.GetTypedIndex(Handle::LISTENER);
if (uid < 0) {
*status = CS_INVALID_HANDLE;
return;
@@ -762,11 +762,11 @@ void RemoveListener(CS_Listener handle, CS_Status* status) {
CS_ListenerPoller CreateListenerPoller() {
auto& inst = Instance::GetInstance();
return Handle(inst.notifier.CreatePoller(), Handle::kListenerPoller);
return Handle(inst.notifier.CreatePoller(), Handle::LISTENER_POLLER);
}
void DestroyListenerPoller(CS_ListenerPoller poller) {
int uid = Handle{poller}.GetTypedIndex(Handle::kListenerPoller);
int uid = Handle{poller}.GetTypedIndex(Handle::LISTENER_POLLER);
if (uid < 0) {
return;
}
@@ -776,7 +776,7 @@ void DestroyListenerPoller(CS_ListenerPoller poller) {
CS_Listener AddPolledListener(CS_ListenerPoller poller, int eventMask,
bool immediateNotify, CS_Status* status) {
Handle handle{poller};
int id = handle.GetTypedIndex(Handle::kListenerPoller);
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
if (id < 0) {
*status = CS_INVALID_HANDLE;
return 0;
@@ -785,12 +785,12 @@ CS_Listener AddPolledListener(CS_ListenerPoller poller, int eventMask,
auto& inst = Instance::GetInstance();
int uid = inst.notifier.AddPolled(id, eventMask);
StartBackground(eventMask, immediateNotify);
return Handle{uid, Handle::kListener};
return Handle{uid, Handle::LISTENER};
}
std::vector<RawEvent> PollListener(CS_ListenerPoller poller) {
Handle handle{poller};
int id = handle.GetTypedIndex(Handle::kListenerPoller);
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
if (id < 0) {
return {};
}
@@ -800,7 +800,7 @@ std::vector<RawEvent> PollListener(CS_ListenerPoller poller) {
std::vector<RawEvent> PollListener(CS_ListenerPoller poller, double timeout,
bool* timedOut) {
Handle handle{poller};
int id = handle.GetTypedIndex(Handle::kListenerPoller);
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
if (id < 0) {
return {};
}
@@ -809,7 +809,7 @@ std::vector<RawEvent> PollListener(CS_ListenerPoller poller, double timeout,
void CancelPollListener(CS_ListenerPoller poller) {
Handle handle{poller};
int id = handle.GetTypedIndex(Handle::kListenerPoller);
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
if (id < 0) {
return;
}

View File

@@ -68,7 +68,7 @@ struct RawEvent {
Kind kind;
// Valid for kSource* and kSink* respectively
// Valid for SOURCE* and SINK* respectively
CS_Source sourceHandle = CS_INVALID_HANDLE;
CS_Sink sinkHandle = CS_INVALID_HANDLE;

View File

@@ -20,13 +20,13 @@ using namespace wpi::util::java;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, BufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>* callbackHandles;
namespace wpi::hal::sim {
void InitializeBufferStore() {
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, BufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>
cb;
callbackHandles = &cb;
}

View File

@@ -20,13 +20,13 @@ using namespace wpi::hal::sim;
using namespace wpi::util::java;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, CallbackStore, wpi::hal::HAL_HandleEnum::SimulationJni>*
SIM_JniHandle, CallbackStore, wpi::hal::HAL_HandleEnum::SIMULATION_JNI>*
callbackHandles;
namespace wpi::hal::sim {
void InitializeStore() {
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, CallbackStore, wpi::hal::HAL_HandleEnum::SimulationJni>
SIM_JniHandle, CallbackStore, wpi::hal::HAL_HandleEnum::SIMULATION_JNI>
cb;
callbackHandles = &cb;
}

View File

@@ -20,13 +20,13 @@ using namespace wpi::util::java;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ConstBufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>* callbackHandles;
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>* callbackHandles;
namespace wpi::hal::sim {
void InitializeConstBufferStore() {
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ConstBufferCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>
cb;
callbackHandles = &cb;
}

View File

@@ -20,12 +20,12 @@ using namespace wpi::hal::sim;
using namespace wpi::util::java;
static UnlimitedHandleResource<SIM_JniHandle, OpModeOptionsCallbackStore,
HAL_HandleEnum::SimulationJni>* callbackHandles;
HAL_HandleEnum::SIMULATION_JNI>* callbackHandles;
namespace wpi::hal::sim {
void InitializeOpModeOptionsStore() {
static UnlimitedHandleResource<SIM_JniHandle, OpModeOptionsCallbackStore,
HAL_HandleEnum::SimulationJni>
HAL_HandleEnum::SIMULATION_JNI>
cb;
callbackHandles = &cb;
}

View File

@@ -195,7 +195,7 @@ void ValueCallbackStore::performCallback(const char* name,
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, DeviceCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>* deviceCallbackHandles;
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>* deviceCallbackHandles;
namespace {
using RegisterDeviceCallbackFunc =
@@ -251,8 +251,8 @@ static void FreeDeviceCallback(JNIEnv* env, SIM_JniHandle handle,
}
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ValueCallbackStore, wpi::hal::HAL_HandleEnum::SimulationJni>*
valueCallbackHandles;
SIM_JniHandle, ValueCallbackStore,
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>* valueCallbackHandles;
namespace {
using FreeValueCallbackFunc = void (*)(int32_t uid);
@@ -348,13 +348,13 @@ bool InitializeSimDeviceDataJNI(JNIEnv* env) {
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, DeviceCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>
cbDevice;
deviceCallbackHandles = &cbDevice;
static wpi::hal::UnlimitedHandleResource<
SIM_JniHandle, ValueCallbackStore,
wpi::hal::HAL_HandleEnum::SimulationJni>
wpi::hal::HAL_HandleEnum::SIMULATION_JNI>
cbValue;
valueCallbackHandles = &cbValue;

View File

@@ -37,42 +37,42 @@ class HandleBase {
int16_t m_version;
};
constexpr int16_t InvalidHandleIndex = -1;
constexpr int16_t INVALID_HANDLE_INDEX = -1;
/**
* Enum of HAL handle types. Vendors/Teams should use Vendor (17).
*/
enum class HAL_HandleEnum {
Undefined = 0,
DIO = wpi::util::kHandleTypeHALBase,
Port = 2,
Notifier = 3,
Interrupt = 4,
AnalogOutput = 5,
AnalogInput = 6,
AnalogTrigger = 7,
Relay = 8,
UNDEFINED = 0,
DIO = wpi::util::HANDLE_TYPE_HAL_BASE,
PORT = 2,
NOTIFIER = 3,
INTERRUPT = 4,
ANALOG_OUTPUT = 5,
ANALOG_INPUT = 6,
ANALOG_TRIGGER = 7,
RELAY = 8,
PWM = 9,
DigitalPWM = 10,
Counter = 11,
FPGAEncoder = 12,
Encoder = 13,
Compressor = 14,
Solenoid = 15,
AnalogGyro = 16,
Vendor = 17,
SimulationJni = 18,
DIGITAL_PWM = 10,
COUNTER = 11,
FPGA_ENCODER = 12,
ENCODER = 13,
COMPRESSOR = 14,
SOLENOID = 15,
ANALOG_GYRO = 16,
VENDOR = 17,
SIMULATION_JNI = 18,
CAN = 19,
SerialPort = 20,
DutyCycle = 21,
SERIAL_PORT = 20,
DUTY_CYCLE = 21,
DMA = 22,
AddressableLED = 23,
CTREPCM = 24,
CTREPDP = 25,
REVPDH = 26,
REVPH = 27,
CANStream = 28,
Alert = 29,
ADDRESSABLE_LED = 23,
CTRE_PCM = 24,
CTRE_PDP = 25,
REV_PDH = 26,
REV_PH = 27,
CAN_STREAM = 28,
ALERT = 29,
};
/**
@@ -135,11 +135,11 @@ static inline bool isHandleCorrectVersion(HAL_Handle handle, int16_t version) {
inline int16_t getHandleTypedIndex(HAL_Handle handle, HAL_HandleEnum enumType,
int16_t version) {
if (!isHandleType(handle, enumType)) {
return InvalidHandleIndex;
return INVALID_HANDLE_INDEX;
}
#if !defined(__FIRST_SYSTEMCORE__)
if (!isHandleCorrectVersion(handle, version)) {
return InvalidHandleIndex;
return INVALID_HANDLE_INDEX;
}
#endif
return getHandleIndex(handle);

View File

@@ -36,7 +36,7 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
HAL_DigitalHandle handle;
auto port = digitalChannelHandles->Allocate(
channel, HAL_HandleEnum::AddressableLED, &handle, status);
channel, HAL_HandleEnum::ADDRESSABLE_LED, &handle, status);
if (*status != 0) {
if (port) {
@@ -62,9 +62,9 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
auto port =
digitalChannelHandles->Get(handle, HAL_HandleEnum::AddressableLED);
digitalChannelHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED);
// no status, so no need to check for a proper free.
digitalChannelHandles->Free(handle, HAL_HandleEnum::AddressableLED);
digitalChannelHandles->Free(handle, HAL_HandleEnum::ADDRESSABLE_LED);
if (port == nullptr) {
return;
}
@@ -74,7 +74,7 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start,
int32_t* status) {
auto port =
digitalChannelHandles->Get(handle, HAL_HandleEnum::AddressableLED);
digitalChannelHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED);
if (!port) {
*status = HAL_HANDLE_ERROR;
return;
@@ -94,7 +94,7 @@ void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start,
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle,
int32_t length, int32_t* status) {
auto port =
digitalChannelHandles->Get(handle, HAL_HandleEnum::AddressableLED);
digitalChannelHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED);
if (!port) {
*status = HAL_HANDLE_ERROR;
return;

View File

@@ -33,12 +33,12 @@ struct Alert {
using namespace wpi::hal;
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::Alert>*
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::ALERT>*
alertHandles;
namespace wpi::hal::init {
void InitializeAlert() {
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::Alert>
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::ALERT>
aH;
alertHandles = &aH;
}

View File

@@ -9,14 +9,14 @@
namespace wpi::hal {
IndexedHandleResource<HAL_AnalogInputHandle, wpi::hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>*
kNumAnalogInputs, HAL_HandleEnum::ANALOG_INPUT>*
analogInputHandles;
} // namespace wpi::hal
namespace wpi::hal::init {
void InitializeAnalogInternal() {
static IndexedHandleResource<HAL_AnalogInputHandle, wpi::hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>
kNumAnalogInputs, HAL_HandleEnum::ANALOG_INPUT>
aiH;
analogInputHandles = &aiH;
}

View File

@@ -26,6 +26,6 @@ struct AnalogPort {
};
extern IndexedHandleResource<HAL_AnalogInputHandle, wpi::hal::AnalogPort,
kNumAnalogInputs, HAL_HandleEnum::AnalogInput>*
kNumAnalogInputs, HAL_HandleEnum::ANALOG_INPUT>*
analogInputHandles;
} // namespace wpi::hal

View File

@@ -24,12 +24,12 @@ struct PCM {
} // namespace
static IndexedHandleResource<HAL_CTREPCMHandle, PCM, kNumCTREPCMModules,
HAL_HandleEnum::CTREPCM>* pcmHandles;
HAL_HandleEnum::CTRE_PCM>* pcmHandles;
namespace wpi::hal::init {
void InitializeCTREPCM() {
static IndexedHandleResource<HAL_CTREPCMHandle, PCM, kNumCTREPCMModules,
HAL_HandleEnum::CTREPCM>
HAL_HandleEnum::CTRE_PCM>
pH;
pcmHandles = &pH;
}

View File

@@ -13,13 +13,13 @@
namespace wpi::hal {
LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
HAL_HandleEnum::Counter>* counterHandles;
HAL_HandleEnum::COUNTER>* counterHandles;
} // namespace wpi::hal
namespace wpi::hal::init {
void InitializeCounter() {
static LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
HAL_HandleEnum::Counter>
HAL_HandleEnum::COUNTER>
cH;
counterHandles = &cH;
}

View File

@@ -15,6 +15,6 @@ struct Counter {
};
extern LimitedHandleResource<HAL_CounterHandle, Counter, kNumCounters,
HAL_HandleEnum::Counter>* counterHandles;
HAL_HandleEnum::COUNTER>* counterHandles;
} // namespace wpi::hal

View File

@@ -16,14 +16,14 @@
using namespace wpi::hal;
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
kNumDigitalPWMOutputs, HAL_HandleEnum::DigitalPWM>*
digitalPWMHandles;
kNumDigitalPWMOutputs,
HAL_HandleEnum::DIGITAL_PWM>* digitalPWMHandles;
namespace wpi::hal::init {
void InitializeDIO() {
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
kNumDigitalPWMOutputs,
HAL_HandleEnum::DigitalPWM>
HAL_HandleEnum::DIGITAL_PWM>
dpH;
digitalPWMHandles = &dpH;
}

View File

@@ -25,12 +25,12 @@ struct Empty {};
} // namespace
static IndexedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
HAL_HandleEnum::DutyCycle>* dutyCycleHandles;
HAL_HandleEnum::DUTY_CYCLE>* dutyCycleHandles;
namespace wpi::hal::init {
void InitializeDutyCycle() {
static IndexedHandleResource<HAL_DutyCycleHandle, DutyCycle, kNumDutyCycles,
HAL_HandleEnum::DutyCycle>
HAL_HandleEnum::DUTY_CYCLE>
dcH;
dutyCycleHandles = &dcH;
}

View File

@@ -31,20 +31,20 @@ struct Empty {};
static LimitedHandleResource<HAL_EncoderHandle, Encoder,
kNumEncoders + kNumCounters,
HAL_HandleEnum::Encoder>* encoderHandles;
HAL_HandleEnum::ENCODER>* encoderHandles;
static LimitedHandleResource<HAL_FPGAEncoderHandle, Empty, kNumEncoders,
HAL_HandleEnum::FPGAEncoder>* fpgaEncoderHandles;
HAL_HandleEnum::FPGA_ENCODER>* fpgaEncoderHandles;
namespace wpi::hal::init {
void InitializeEncoder() {
static LimitedHandleResource<HAL_FPGAEncoderHandle, Empty, kNumEncoders,
HAL_HandleEnum::FPGAEncoder>
HAL_HandleEnum::FPGA_ENCODER>
feH;
fpgaEncoderHandles = &feH;
static LimitedHandleResource<HAL_EncoderHandle, Encoder,
kNumEncoders + kNumCounters,
HAL_HandleEnum::Encoder>
HAL_HandleEnum::ENCODER>
eH;
encoderHandles = &eH;
}
@@ -120,9 +120,9 @@ void HAL_FreeEncoder(HAL_EncoderHandle encoderHandle) {
if (encoder == nullptr) {
return;
}
if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::FPGAEncoder)) {
if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::FPGA_ENCODER)) {
fpgaEncoderHandles->Free(encoder->nativeHandle);
} else if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::Counter)) {
} else if (isHandleType(encoder->nativeHandle, HAL_HandleEnum::COUNTER)) {
counterHandles->Free(encoder->nativeHandle);
}
SimEncoderData[encoder->index].initialized = false;

View File

@@ -52,7 +52,7 @@ class NotifierThread : public wpi::util::SafeThread {
bool m_paused = false;
UnlimitedHandleResource<HAL_NotifierHandle, Notifier,
HAL_HandleEnum::Notifier>
HAL_HandleEnum::NOTIFIER>
m_handles;
struct Alarm {

View File

@@ -24,12 +24,12 @@ struct PCM {
} // namespace
static IndexedHandleResource<HAL_REVPHHandle, PCM, kNumREVPHModules,
HAL_HandleEnum::REVPH>* pcmHandles;
HAL_HandleEnum::REV_PH>* pcmHandles;
namespace wpi::hal::init {
void InitializeREVPH() {
static IndexedHandleResource<HAL_REVPHHandle, PCM, kNumREVPHModules,
HAL_HandleEnum::REVPH>
HAL_HandleEnum::REV_PH>
pH;
pcmHandles = &pH;
}

View File

@@ -97,7 +97,7 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
HAL_DigitalHandle handle;
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::AddressableLED,
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::ADDRESSABLE_LED,
&handle, status);
if (*status != 0) {
@@ -115,7 +115,7 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
*status = port->InitializeMode(SmartIoMode::AddressableLED);
if (*status != 0) {
smartIoHandles->Free(handle, HAL_HandleEnum::AddressableLED);
smartIoHandles->Free(handle, HAL_HandleEnum::ADDRESSABLE_LED);
return HAL_kInvalidHandle;
}
@@ -125,12 +125,12 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED(
}
void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
auto port = smartIoHandles->Get(handle, HAL_HandleEnum::AddressableLED);
auto port = smartIoHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED);
if (port == nullptr) {
return;
}
smartIoHandles->Free(handle, HAL_HandleEnum::AddressableLED);
smartIoHandles->Free(handle, HAL_HandleEnum::ADDRESSABLE_LED);
// Wait for no other object to hold this handle.
auto start = wpi::hal::monotonic_clock::now();
@@ -147,7 +147,7 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) {
void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start,
int32_t* status) {
auto port = smartIoHandles->Get(handle, HAL_HandleEnum::AddressableLED);
auto port = smartIoHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
@@ -158,7 +158,7 @@ void HAL_SetAddressableLEDStart(HAL_AddressableLEDHandle handle, int32_t start,
void HAL_SetAddressableLEDLength(HAL_AddressableLEDHandle handle,
int32_t length, int32_t* status) {
auto port = smartIoHandles->Get(handle, HAL_HandleEnum::AddressableLED);
auto port = smartIoHandles->Get(handle, HAL_HandleEnum::ADDRESSABLE_LED);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return;

View File

@@ -33,12 +33,12 @@ struct Alert {
using namespace wpi::hal;
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::Alert>*
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::ALERT>*
alertHandles;
namespace wpi::hal::init {
void InitializeAlert() {
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::Alert>
static UnlimitedHandleResource<HAL_AlertHandle, Alert, HAL_HandleEnum::ALERT>
aH;
alertHandles = &aH;
}

View File

@@ -36,7 +36,7 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
HAL_DigitalHandle handle;
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::AnalogInput,
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::ANALOG_INPUT,
&handle, status);
if (*status != 0) {
@@ -54,7 +54,7 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
*status = port->InitializeMode(SmartIoMode::AnalogInput);
if (*status != 0) {
smartIoHandles->Free(handle, HAL_HandleEnum::AnalogInput);
smartIoHandles->Free(handle, HAL_HandleEnum::ANALOG_INPUT);
return HAL_kInvalidHandle;
}
@@ -65,12 +65,12 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analogPortHandle) {
auto port =
smartIoHandles->Get(analogPortHandle, HAL_HandleEnum::AnalogInput);
smartIoHandles->Get(analogPortHandle, HAL_HandleEnum::ANALOG_INPUT);
if (port == nullptr) {
return;
}
smartIoHandles->Free(analogPortHandle, HAL_HandleEnum::AnalogInput);
smartIoHandles->Free(analogPortHandle, HAL_HandleEnum::ANALOG_INPUT);
// Wait for no other object to hold this handle.
auto start = wpi::hal::monotonic_clock::now();
@@ -133,7 +133,7 @@ int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analogPortHandle,
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port =
smartIoHandles->Get(analogPortHandle, HAL_HandleEnum::AnalogInput);
smartIoHandles->Get(analogPortHandle, HAL_HandleEnum::ANALOG_INPUT);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -159,7 +159,7 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analogPortHandle,
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analogPortHandle,
int32_t* status) {
auto port =
smartIoHandles->Get(analogPortHandle, HAL_HandleEnum::AnalogInput);
smartIoHandles->Get(analogPortHandle, HAL_HandleEnum::ANALOG_INPUT);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;

View File

@@ -117,7 +117,7 @@ struct SocketCanState {
} // namespace
static UnlimitedHandleResource<HAL_CANStreamHandle, CANStreamStorage,
HAL_HandleEnum::CANStream>* canStreamHandles;
HAL_HandleEnum::CAN_STREAM>* canStreamHandles;
static SocketCanState* canState;
@@ -125,7 +125,7 @@ namespace wpi::hal::init {
void InitializeCAN() {
canState = new SocketCanState{};
static UnlimitedHandleResource<HAL_CANStreamHandle, CANStreamStorage,
HAL_HandleEnum::CANStream>
HAL_HandleEnum::CAN_STREAM>
cSH;
canStreamHandles = &cSH;
}

View File

@@ -134,12 +134,12 @@ struct PCM {
} // namespace
static IndexedHandleResource<HAL_CTREPCMHandle, PCM, kNumCTREPCMModules,
HAL_HandleEnum::CTREPCM>* pcmHandles;
HAL_HandleEnum::CTRE_PCM>* pcmHandles;
namespace wpi::hal::init {
void InitializeCTREPCM() {
static IndexedHandleResource<HAL_CTREPCMHandle, PCM, kNumCTREPCMModules,
HAL_HandleEnum::CTREPCM>
HAL_HandleEnum::CTRE_PCM>
pH;
pcmHandles = &pH;
}

View File

@@ -115,12 +115,12 @@ struct PDP {
} // namespace
static IndexedHandleResource<HAL_PDPHandle, PDP, kNumCTREPDPModules,
HAL_HandleEnum::CTREPDP>* pdpHandles;
HAL_HandleEnum::CTRE_PDP>* pdpHandles;
namespace wpi::hal::init {
void InitializeCTREPDP() {
static IndexedHandleResource<HAL_PDPHandle, PDP, kNumCTREPDPModules,
HAL_HandleEnum::CTREPDP>
HAL_HandleEnum::CTRE_PDP>
pH;
pdpHandles = &pH;
}

View File

@@ -27,7 +27,7 @@ HAL_CounterHandle HAL_InitializeCounter(int channel, HAL_Bool risingEdge,
const char* allocationLocation,
int32_t* status) {
wpi::hal::init::CheckInit();
if (channel == InvalidHandleIndex || channel >= kNumSmartIo) {
if (channel == INVALID_HANDLE_INDEX || channel >= kNumSmartIo) {
*status = RESOURCE_OUT_OF_RANGE;
wpi::hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for Counter",
0, kNumSmartIo, channel);
@@ -36,7 +36,7 @@ HAL_CounterHandle HAL_InitializeCounter(int channel, HAL_Bool risingEdge,
HAL_CounterHandle handle;
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::Counter,
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::COUNTER,
&handle, status);
if (*status != 0) {
@@ -56,7 +56,7 @@ HAL_CounterHandle HAL_InitializeCounter(int channel, HAL_Bool risingEdge,
port->InitializeMode(risingEdge ? SmartIoMode::SingleCounterRising
: SmartIoMode::SingleCounterFalling);
if (*status != 0) {
smartIoHandles->Free(handle, HAL_HandleEnum::Counter);
smartIoHandles->Free(handle, HAL_HandleEnum::COUNTER);
return HAL_kInvalidHandle;
}
@@ -66,12 +66,12 @@ HAL_CounterHandle HAL_InitializeCounter(int channel, HAL_Bool risingEdge,
}
void HAL_FreeCounter(HAL_CounterHandle counterHandle) {
auto port = smartIoHandles->Get(counterHandle, HAL_HandleEnum::Counter);
auto port = smartIoHandles->Get(counterHandle, HAL_HandleEnum::COUNTER);
if (port == nullptr) {
return;
}
smartIoHandles->Free(counterHandle, HAL_HandleEnum::Counter);
smartIoHandles->Free(counterHandle, HAL_HandleEnum::COUNTER);
// Wait for no other object to hold this handle.
auto start = wpi::hal::monotonic_clock::now();
@@ -98,7 +98,7 @@ void HAL_ResetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
}
int32_t HAL_GetCounter(HAL_CounterHandle counterHandle, int32_t* status) {
auto port = smartIoHandles->Get(counterHandle, HAL_HandleEnum::Counter);
auto port = smartIoHandles->Get(counterHandle, HAL_HandleEnum::COUNTER);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;

View File

@@ -36,7 +36,7 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
HAL_DigitalHandle handle;
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::DutyCycle,
auto port = smartIoHandles->Allocate(channel, HAL_HandleEnum::DUTY_CYCLE,
&handle, status);
if (*status != 0) {
@@ -54,7 +54,7 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
*status = port->InitializeMode(SmartIoMode::PwmInput);
if (*status != 0) {
smartIoHandles->Free(handle, HAL_HandleEnum::DutyCycle);
smartIoHandles->Free(handle, HAL_HandleEnum::DUTY_CYCLE);
return HAL_kInvalidHandle;
}
@@ -63,12 +63,12 @@ HAL_DutyCycleHandle HAL_InitializeDutyCycle(int32_t channel,
return handle;
}
void HAL_FreeDutyCycle(HAL_DutyCycleHandle dutyCycleHandle) {
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle);
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DUTY_CYCLE);
if (port == nullptr) {
return;
}
smartIoHandles->Free(dutyCycleHandle, HAL_HandleEnum::DutyCycle);
smartIoHandles->Free(dutyCycleHandle, HAL_HandleEnum::DUTY_CYCLE);
// Wait for no other object to hold this handle.
auto start = wpi::hal::monotonic_clock::now();
@@ -88,7 +88,7 @@ void HAL_SetDutyCycleSimDevice(HAL_EncoderHandle handle,
double HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
int32_t* status) {
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle);
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DUTY_CYCLE);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
@@ -106,7 +106,7 @@ double HAL_GetDutyCycleFrequency(HAL_DutyCycleHandle dutyCycleHandle,
double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
int32_t* status) {
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle);
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DUTY_CYCLE);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0.0;
@@ -131,7 +131,7 @@ double HAL_GetDutyCycleOutput(HAL_DutyCycleHandle dutyCycleHandle,
int32_t HAL_GetDutyCycleHighTime(HAL_DutyCycleHandle dutyCycleHandle,
int32_t* status) {
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DutyCycle);
auto port = smartIoHandles->Get(dutyCycleHandle, HAL_HandleEnum::DUTY_CYCLE);
if (port == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;

View File

@@ -43,7 +43,7 @@ class NotifierThread : public wpi::util::SafeThread {
void ProcessAlarms();
UnlimitedHandleResource<HAL_NotifierHandle, Notifier,
HAL_HandleEnum::Notifier>
HAL_HandleEnum::NOTIFIER>
m_handles;
struct Alarm {

View File

@@ -72,7 +72,8 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
}
}
#define IsCtre(handle) ::wpi::hal::isHandleType(handle, HAL_HandleEnum::CTREPDP)
#define IsCtre(handle) \
::wpi::hal::isHandleType(handle, HAL_HandleEnum::CTRE_PDP)
void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle) {
if (IsCtre(handle)) {

View File

@@ -75,12 +75,12 @@ static constexpr int32_t kPDHFrameStatus3Timeout = 20;
static constexpr int32_t kPDHFrameStatus4Timeout = 20;
static IndexedHandleResource<HAL_REVPDHHandle, REV_PDHObj, kNumREVPDHModules,
HAL_HandleEnum::REVPDH>* REVPDHHandles;
HAL_HandleEnum::REV_PDH>* REVPDHHandles;
namespace wpi::hal::init {
void InitializeREVPDH() {
static IndexedHandleResource<HAL_REVPDHHandle, REV_PDHObj, kNumREVPDHModules,
HAL_HandleEnum::REVPDH>
HAL_HandleEnum::REV_PDH>
rH;
REVPDHHandles = &rH;
}

View File

@@ -72,12 +72,12 @@ struct REV_PHObj {
} // namespace
static IndexedHandleResource<HAL_REVPHHandle, REV_PHObj, 63,
HAL_HandleEnum::REVPH>* REVPHHandles;
HAL_HandleEnum::REV_PH>* REVPHHandles;
namespace wpi::hal::init {
void InitializeREVPH() {
static IndexedHandleResource<HAL_REVPHHandle, REV_PHObj, kNumREVPHModules,
HAL_HandleEnum::REVPH>
HAL_HandleEnum::REV_PH>
rH;
REVPHHandles = &rH;
}

View File

@@ -17,7 +17,7 @@ class MyTestClass {};
namespace wpi::hal {
TEST(HandleTest, ClassedHandle) {
wpi::hal::IndexedClassedHandleResource<HAL_TestHandle, MyTestClass, 8,
HAL_HandleEnum::Vendor>
HAL_HandleEnum::VENDOR>
testClass;
int32_t status = 0;
testClass.Allocate(0, std::make_unique<MyTestClass>(), &status);

View File

@@ -55,7 +55,7 @@ class ConnectionList final : public IConnectionList {
wpi::util::UidVector<std::optional<ConnectionInfo>, 8> m_connections;
struct DataLoggerData {
static constexpr auto kType = Handle::kConnectionDataLogger;
static constexpr auto kType = Handle::CONNECTION_DATA_LOGGER;
DataLoggerData(NT_ConnectionDataLogger handle, wpi::log::DataLog& log,
std::string_view name, int64_t time)

View File

@@ -17,20 +17,20 @@ namespace wpi::nt {
class Handle {
public:
enum Type {
kListener = wpi::util::kHandleTypeNTBase,
kListenerPoller,
kEntry,
kInstance,
kDataLogger,
kConnectionDataLogger,
kMultiSubscriber,
kTopic,
kSubscriber,
kPublisher,
kTypeMax
LISTENER = wpi::util::HANDLE_TYPE_NT_BASE,
LISTENER_POLLER,
ENTRY,
INSTANCE,
DATA_LOGGER,
CONNECTION_DATA_LOGGER,
MULTI_SUBSCRIBER,
TOPIC,
SUBSCRIBER,
PUBLISHER,
MAX_TYPE
};
static_assert(kTypeMax <= wpi::util::kHandleTypeHALBase);
enum { kIndexMax = 0xfffff };
static_assert(MAX_TYPE <= wpi::util::HANDLE_TYPE_HAL_BASE);
enum { MAX_INDEX = 0xfffff };
constexpr explicit Handle(NT_Handle handle) : m_handle(handle) {}
constexpr operator NT_Handle() const { return m_handle; } // NOLINT

View File

@@ -75,7 +75,7 @@ class ListenerStorage final : public IListenerStorage {
mutable wpi::util::mutex m_mutex;
struct PollerData {
static constexpr auto kType = Handle::kListenerPoller;
static constexpr auto kType = Handle::LISTENER_POLLER;
explicit PollerData(NT_ListenerPoller handle) : handle{handle} {}
@@ -85,7 +85,7 @@ class ListenerStorage final : public IListenerStorage {
HandleMap<PollerData, 8> m_pollers;
struct ListenerData {
static constexpr auto kType = Handle::kListener;
static constexpr auto kType = Handle::LISTENER;
ListenerData(NT_Listener handle, PollerData* poller)
: handle{handle}, poller{poller} {}

View File

@@ -48,16 +48,16 @@ std::vector<TopicInfo> LocalStorage::GetTopicInfo(
void LocalStorage::Release(NT_Handle pubsubentryHandle) {
switch (Handle{pubsubentryHandle}.GetType()) {
case Handle::kEntry:
case Handle::ENTRY:
ReleaseEntry(pubsubentryHandle);
break;
case Handle::kPublisher:
case Handle::PUBLISHER:
Unpublish(pubsubentryHandle);
break;
case Handle::kSubscriber:
case Handle::SUBSCRIBER:
Unsubscribe(pubsubentryHandle);
break;
case Handle::kMultiSubscriber:
case Handle::MULTI_SUBSCRIBER:
UnsubscribeMultiple(pubsubentryHandle);
break;
default:

View File

@@ -21,7 +21,7 @@ namespace wpi::nt::local {
struct LocalTopic;
struct LocalDataLogger {
static constexpr auto kType = Handle::kDataLogger;
static constexpr auto kType = Handle::DATA_LOGGER;
LocalDataLogger(NT_DataLogger handle, wpi::log::DataLog& log,
std::string_view prefix, std::string_view logPrefix)

View File

@@ -13,7 +13,7 @@ namespace wpi::nt::local {
struct LocalPublisher;
struct LocalEntry {
static constexpr auto kType = Handle::kEntry;
static constexpr auto kType = Handle::ENTRY;
LocalEntry(NT_Entry handle, LocalSubscriber* subscriber)
: handle{handle}, topic{subscriber->topic}, subscriber{subscriber} {}

View File

@@ -24,7 +24,7 @@ constexpr bool PrefixMatch(std::string_view name, std::string_view prefix,
}
struct LocalMultiSubscriber {
static constexpr auto kType = Handle::kMultiSubscriber;
static constexpr auto kType = Handle::MULTI_SUBSCRIBER;
LocalMultiSubscriber(NT_MultiSubscriber handle,
std::span<const std::string_view> prefixes,

View File

@@ -14,7 +14,7 @@
namespace wpi::nt::local {
struct LocalPublisher {
static constexpr auto kType = Handle::kPublisher;
static constexpr auto kType = Handle::PUBLISHER;
LocalPublisher(NT_Publisher handle, LocalTopic* topic, PubSubConfig config)
: handle{handle}, topic{topic}, config{std::move(config)} {}

View File

@@ -380,11 +380,11 @@ LocalEntry* StorageImpl::GetEntry(std::string_view name) {
void StorageImpl::RemoveSubEntry(NT_Handle subentryHandle) {
Handle h{subentryHandle};
if (h.IsType(Handle::kSubscriber)) {
if (h.IsType(Handle::SUBSCRIBER)) {
RemoveLocalSubscriber(subentryHandle);
} else if (h.IsType(Handle::kMultiSubscriber)) {
} else if (h.IsType(Handle::MULTI_SUBSCRIBER)) {
RemoveMultiSubscriber(subentryHandle);
} else if (h.IsType(Handle::kEntry)) {
} else if (h.IsType(Handle::ENTRY)) {
if (auto entry = RemoveEntry(subentryHandle)) {
RemoveLocalSubscriber(entry->subscriber->handle);
if (entry->publisher) {
@@ -395,7 +395,7 @@ void StorageImpl::RemoveSubEntry(NT_Handle subentryHandle) {
}
void StorageImpl::Unpublish(NT_Handle pubentryHandle) {
if (Handle{pubentryHandle}.IsType(Handle::kPublisher)) {
if (Handle{pubentryHandle}.IsType(Handle::PUBLISHER)) {
RemoveLocalPublisher(pubentryHandle);
} else if (auto entry = GetEntryByHandle(pubentryHandle)) {
if (entry->publisher) {
@@ -462,25 +462,25 @@ std::unique_ptr<LocalMultiSubscriber> StorageImpl::RemoveMultiSubscriber(
LocalTopic* StorageImpl::GetTopic(NT_Handle handle) {
switch (Handle{handle}.GetType()) {
case Handle::kEntry: {
case Handle::ENTRY: {
if (auto entry = m_entries.Get(handle)) {
return entry->topic;
}
break;
}
case Handle::kSubscriber: {
case Handle::SUBSCRIBER: {
if (auto subscriber = m_subscribers.Get(handle)) {
return subscriber->topic;
}
break;
}
case Handle::kPublisher: {
case Handle::PUBLISHER: {
if (auto publisher = m_publishers.Get(handle)) {
return publisher->topic;
}
break;
}
case Handle::kTopic:
case Handle::TOPIC:
return m_topics.Get(handle);
default:
break;
@@ -490,9 +490,9 @@ LocalTopic* StorageImpl::GetTopic(NT_Handle handle) {
LocalSubscriber* StorageImpl::GetSubEntry(NT_Handle subentryHandle) {
Handle h{subentryHandle};
if (h.IsType(Handle::kSubscriber)) {
if (h.IsType(Handle::SUBSCRIBER)) {
return m_subscribers.Get(subentryHandle);
} else if (h.IsType(Handle::kEntry)) {
} else if (h.IsType(Handle::ENTRY)) {
auto entry = m_entries.Get(subentryHandle);
return entry ? entry->subscriber : nullptr;
} else {

View File

@@ -196,7 +196,7 @@ class StorageImpl {
return it->second;
}
LocalTopic* GetTopicById(int topicId) {
return m_topics.Get(Handle{m_inst, topicId, Handle::kTopic});
return m_topics.Get(Handle{m_inst, topicId, Handle::TOPIC});
}
LocalSubscriber* GetSubEntry(NT_Handle subentryHandle);

View File

@@ -18,7 +18,7 @@
namespace wpi::nt::local {
struct LocalSubscriber {
static constexpr auto kType = Handle::kSubscriber;
static constexpr auto kType = Handle::SUBSCRIBER;
LocalSubscriber(NT_Subscriber handle, LocalTopic* topic, PubSubConfig config)
: handle{handle},

View File

@@ -31,7 +31,7 @@ constexpr bool IsSpecial(std::string_view name) {
}
struct LocalTopic {
static constexpr auto kType = Handle::kTopic;
static constexpr auto kType = Handle::TOPIC;
LocalTopic(NT_Topic handle, std::string_view name)
: handle{handle}, name{name}, special{IsSpecial(name)} {}

View File

@@ -41,21 +41,21 @@ wpi::util::json TopicInfo::GetProperties() const {
*/
NT_Inst GetDefaultInstance() {
return Handle{InstanceImpl::GetDefaultIndex(), 0, Handle::kInstance};
return Handle{InstanceImpl::GetDefaultIndex(), 0, Handle::INSTANCE};
}
NT_Inst CreateInstance() {
return Handle{InstanceImpl::Alloc(), 0, Handle::kInstance};
return Handle{InstanceImpl::Alloc(), 0, Handle::INSTANCE};
}
void ResetInstance(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->Reset();
}
}
void DestroyInstance(NT_Inst inst) {
int i = Handle{inst}.GetTypedInst(Handle::kInstance);
int i = Handle{inst}.GetTypedInst(Handle::INSTANCE);
if (i < 0) {
return;
}
@@ -65,8 +65,8 @@ void DestroyInstance(NT_Inst inst) {
NT_Inst GetInstanceFromHandle(NT_Handle handle) {
Handle h{handle};
auto type = h.GetType();
if (type >= Handle::kListener && type < Handle::kTypeMax) {
return Handle(h.GetInst(), 0, Handle::kInstance);
if (type >= Handle::LISTENER && type < Handle::MAX_TYPE) {
return Handle(h.GetInst(), 0, Handle::INSTANCE);
}
return 0;
@@ -77,7 +77,7 @@ NT_Inst GetInstanceFromHandle(NT_Handle handle) {
*/
NT_Entry GetEntry(NT_Inst inst, std::string_view name) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.GetEntry(name);
} else {
return {};
@@ -164,7 +164,7 @@ std::vector<Value> ReadQueueValue(NT_Handle subentry, unsigned int types) {
std::vector<NT_Topic> GetTopics(NT_Inst inst, std::string_view prefix,
unsigned int types) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.GetTopics(prefix, types);
} else {
return {};
@@ -173,7 +173,7 @@ std::vector<NT_Topic> GetTopics(NT_Inst inst, std::string_view prefix,
std::vector<NT_Topic> GetTopics(NT_Inst inst, std::string_view prefix,
std::span<const std::string_view> types) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.GetTopics(prefix, types);
} else {
return {};
@@ -182,7 +182,7 @@ std::vector<NT_Topic> GetTopics(NT_Inst inst, std::string_view prefix,
std::vector<TopicInfo> GetTopicInfo(NT_Inst inst, std::string_view prefix,
unsigned int types) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.GetTopicInfo(prefix, types);
} else {
return {};
@@ -191,7 +191,7 @@ std::vector<TopicInfo> GetTopicInfo(NT_Inst inst, std::string_view prefix,
std::vector<TopicInfo> GetTopicInfo(NT_Inst inst, std::string_view prefix,
std::span<const std::string_view> types) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.GetTopicInfo(prefix, types);
} else {
return {};
@@ -199,7 +199,7 @@ std::vector<TopicInfo> GetTopicInfo(NT_Inst inst, std::string_view prefix,
}
TopicInfo GetTopicInfo(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicInfo(topic);
} else {
return {};
@@ -207,7 +207,7 @@ TopicInfo GetTopicInfo(NT_Topic topic) {
}
NT_Topic GetTopic(NT_Inst inst, std::string_view name) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.GetTopic(name);
} else {
return {};
@@ -215,7 +215,7 @@ NT_Topic GetTopic(NT_Inst inst, std::string_view name) {
}
std::string GetTopicName(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicName(topic);
} else {
return {};
@@ -223,7 +223,7 @@ std::string GetTopicName(NT_Topic topic) {
}
NT_Type GetTopicType(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicType(topic);
} else {
return {};
@@ -231,7 +231,7 @@ NT_Type GetTopicType(NT_Topic topic) {
}
std::string GetTopicTypeString(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicTypeString(topic);
} else {
return {};
@@ -239,7 +239,7 @@ std::string GetTopicTypeString(NT_Topic topic) {
}
void SetTopicPersistent(NT_Topic topic, bool value) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
ii->localStorage.SetTopicPersistent(topic, value);
} else {
return;
@@ -247,7 +247,7 @@ void SetTopicPersistent(NT_Topic topic, bool value) {
}
bool GetTopicPersistent(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicPersistent(topic);
} else {
return {};
@@ -255,7 +255,7 @@ bool GetTopicPersistent(NT_Topic topic) {
}
void SetTopicRetained(NT_Topic topic, bool value) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
ii->localStorage.SetTopicRetained(topic, value);
} else {
return;
@@ -263,7 +263,7 @@ void SetTopicRetained(NT_Topic topic, bool value) {
}
bool GetTopicRetained(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicRetained(topic);
} else {
return {};
@@ -271,7 +271,7 @@ bool GetTopicRetained(NT_Topic topic) {
}
void SetTopicCached(NT_Topic topic, bool value) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
ii->localStorage.SetTopicCached(topic, value);
} else {
return;
@@ -279,7 +279,7 @@ void SetTopicCached(NT_Topic topic, bool value) {
}
bool GetTopicCached(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicCached(topic);
} else {
return {};
@@ -294,7 +294,7 @@ bool GetTopicExists(NT_Handle handle) {
}
wpi::util::json GetTopicProperty(NT_Topic topic, std::string_view name) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicProperty(topic, name);
} else {
return {};
@@ -303,7 +303,7 @@ wpi::util::json GetTopicProperty(NT_Topic topic, std::string_view name) {
void SetTopicProperty(NT_Topic topic, std::string_view name,
const wpi::util::json& value) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
ii->localStorage.SetTopicProperty(topic, name, value);
} else {
return;
@@ -311,13 +311,13 @@ void SetTopicProperty(NT_Topic topic, std::string_view name,
}
void DeleteTopicProperty(NT_Topic topic, std::string_view name) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
ii->localStorage.DeleteTopicProperty(topic, name);
}
}
wpi::util::json GetTopicProperties(NT_Topic topic) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetTopicProperties(topic);
} else {
return {};
@@ -325,7 +325,7 @@ wpi::util::json GetTopicProperties(NT_Topic topic) {
}
bool SetTopicProperties(NT_Topic topic, const wpi::util::json& properties) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.SetTopicProperties(topic, properties);
} else {
return {};
@@ -334,7 +334,7 @@ bool SetTopicProperties(NT_Topic topic, const wpi::util::json& properties) {
NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr,
const PubSubOptions& options) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.Subscribe(topic, type, typeStr, options);
} else {
return {};
@@ -342,7 +342,7 @@ NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr,
}
void Unsubscribe(NT_Subscriber sub) {
if (auto ii = InstanceImpl::GetTyped(sub, Handle::kSubscriber)) {
if (auto ii = InstanceImpl::GetTyped(sub, Handle::SUBSCRIBER)) {
ii->localStorage.Unsubscribe(sub);
}
}
@@ -355,7 +355,7 @@ NT_Publisher Publish(NT_Topic topic, NT_Type type, std::string_view typeStr,
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr,
const wpi::util::json& properties,
const PubSubOptions& options) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.Publish(topic, type, typeStr, properties, options);
} else {
return {};
@@ -370,7 +370,7 @@ void Unpublish(NT_Handle pubentry) {
NT_Entry GetEntry(NT_Topic topic, NT_Type type, std::string_view typeStr,
const PubSubOptions& options) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::kTopic)) {
if (auto ii = InstanceImpl::GetTyped(topic, Handle::TOPIC)) {
return ii->localStorage.GetEntry(topic, type, typeStr, options);
} else {
return {};
@@ -378,7 +378,7 @@ NT_Entry GetEntry(NT_Topic topic, NT_Type type, std::string_view typeStr,
}
void ReleaseEntry(NT_Entry entry) {
if (auto ii = InstanceImpl::GetTyped(entry, Handle::kEntry)) {
if (auto ii = InstanceImpl::GetTyped(entry, Handle::ENTRY)) {
ii->localStorage.ReleaseEntry(entry);
}
}
@@ -400,7 +400,7 @@ NT_Topic GetTopicFromHandle(NT_Handle pubsubentry) {
NT_MultiSubscriber SubscribeMultiple(NT_Inst inst,
std::span<const std::string_view> prefixes,
const PubSubOptions& options) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.SubscribeMultiple(prefixes, options);
} else {
return {};
@@ -408,7 +408,7 @@ NT_MultiSubscriber SubscribeMultiple(NT_Inst inst,
}
void UnsubscribeMultiple(NT_MultiSubscriber sub) {
if (auto ii = InstanceImpl::GetTyped(sub, Handle::kMultiSubscriber)) {
if (auto ii = InstanceImpl::GetTyped(sub, Handle::MULTI_SUBSCRIBER)) {
ii->localStorage.UnsubscribeMultiple(sub);
}
}
@@ -438,7 +438,7 @@ static void CleanupListeners(
static void DoAddListener(InstanceImpl& ii, NT_Listener listener,
NT_Handle handle, unsigned int mask) {
if (Handle{handle}.IsType(Handle::kInstance)) {
if (Handle{handle}.IsType(Handle::INSTANCE)) {
if ((mask & NT_EVENT_CONNECTION) != 0) {
ii.connectionList.AddListener(listener, mask);
}
@@ -454,7 +454,7 @@ static void DoAddListener(InstanceImpl& ii, NT_Listener listener,
}
NT_ListenerPoller CreateListenerPoller(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->listenerStorage.CreateListenerPoller();
} else {
return {};
@@ -462,13 +462,13 @@ NT_ListenerPoller CreateListenerPoller(NT_Inst inst) {
}
void DestroyListenerPoller(NT_ListenerPoller poller) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::kListenerPoller)) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::LISTENER_POLLER)) {
CleanupListeners(*ii, ii->listenerStorage.DestroyListenerPoller(poller));
}
}
std::vector<Event> ReadListenerQueue(NT_ListenerPoller poller) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::kListenerPoller)) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::LISTENER_POLLER)) {
return ii->listenerStorage.ReadListenerQueue(poller);
} else {
return {};
@@ -476,7 +476,7 @@ std::vector<Event> ReadListenerQueue(NT_ListenerPoller poller) {
}
void RemoveListener(NT_Listener listener) {
if (auto ii = InstanceImpl::GetTyped(listener, Handle::kListener)) {
if (auto ii = InstanceImpl::GetTyped(listener, Handle::LISTENER)) {
CleanupListeners(*ii, ii->listenerStorage.RemoveListener(listener));
}
}
@@ -492,7 +492,7 @@ bool WaitForListenerQueue(NT_Handle handle, double timeout) {
NT_Listener AddListener(NT_Inst inst,
std::span<const std::string_view> prefixes,
unsigned int mask, ListenerCallback callback) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if ((mask & (NT_EVENT_TOPIC | NT_EVENT_VALUE_ALL)) != 0) {
auto listener = ii->listenerStorage.AddListener(std::move(callback));
ii->localStorage.AddListener(listener, prefixes, mask);
@@ -516,7 +516,7 @@ NT_Listener AddListener(NT_Handle handle, unsigned int mask,
NT_Listener AddPolledListener(NT_ListenerPoller poller,
std::span<const std::string_view> prefixes,
unsigned int mask) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::kListenerPoller)) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::LISTENER_POLLER)) {
if ((mask & (NT_EVENT_TOPIC | NT_EVENT_VALUE_ALL)) != 0) {
auto listener = ii->listenerStorage.AddListener(poller);
ii->localStorage.AddListener(listener, prefixes, mask);
@@ -528,7 +528,7 @@ NT_Listener AddPolledListener(NT_ListenerPoller poller,
NT_Listener AddPolledListener(NT_ListenerPoller poller, NT_Handle handle,
unsigned int mask) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::kListenerPoller)) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::LISTENER_POLLER)) {
if (Handle{handle}.GetInst() != Handle{poller}.GetInst()) {
WPI_ERROR(
ii->logger,
@@ -579,7 +579,7 @@ std::string_view GetStringFromType(NT_Type type) {
NT_DataLogger StartEntryDataLog(NT_Inst inst, wpi::log::DataLog& log,
std::string_view prefix,
std::string_view logPrefix) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.StartDataLog(log, prefix, logPrefix);
} else {
return 0;
@@ -587,7 +587,7 @@ NT_DataLogger StartEntryDataLog(NT_Inst inst, wpi::log::DataLog& log,
}
void StopEntryDataLog(NT_DataLogger logger) {
if (auto ii = InstanceImpl::GetTyped(logger, Handle::kDataLogger)) {
if (auto ii = InstanceImpl::GetTyped(logger, Handle::DATA_LOGGER)) {
ii->localStorage.StopDataLog(logger);
}
}
@@ -595,7 +595,7 @@ void StopEntryDataLog(NT_DataLogger logger) {
NT_ConnectionDataLogger StartConnectionDataLog(NT_Inst inst,
wpi::log::DataLog& log,
std::string_view name) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->connectionList.StartDataLog(log, name);
} else {
return 0;
@@ -603,7 +603,8 @@ NT_ConnectionDataLogger StartConnectionDataLog(NT_Inst inst,
}
void StopConnectionDataLog(NT_ConnectionDataLogger logger) {
if (auto ii = InstanceImpl::GetTyped(logger, Handle::kConnectionDataLogger)) {
if (auto ii =
InstanceImpl::GetTyped(logger, Handle::CONNECTION_DATA_LOGGER)) {
ii->connectionList.StopDataLog(logger);
}
}
@@ -613,7 +614,7 @@ void StopConnectionDataLog(NT_ConnectionDataLogger logger) {
*/
unsigned int GetNetworkMode(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->networkMode;
} else {
return {};
@@ -621,13 +622,13 @@ unsigned int GetNetworkMode(NT_Inst inst) {
}
void StartLocal(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->StartLocal();
}
}
void StopLocal(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->StopLocal();
}
}
@@ -635,25 +636,25 @@ void StopLocal(NT_Inst inst) {
void StartServer(NT_Inst inst, std::string_view persist_filename,
std::string_view listen_address, std::string_view mdns_service,
unsigned int port) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->StartServer(persist_filename, listen_address, mdns_service, port);
}
}
void StopServer(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->StopServer();
}
}
void StartClient(NT_Inst inst, std::string_view identity) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->StartClient(identity);
}
}
void StopClient(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->StopClient();
}
}
@@ -665,7 +666,7 @@ void SetServer(NT_Inst inst, std::string_view server_name, unsigned int port) {
void SetServer(
NT_Inst inst,
std::span<const std::pair<std::string_view, unsigned int>> servers) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
std::vector<std::pair<std::string, unsigned int>> serversCopy;
serversCopy.reserve(servers.size());
for (auto&& server : servers) {
@@ -676,7 +677,7 @@ void SetServer(
}
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
std::vector<std::pair<std::string, unsigned int>> servers;
servers.reserve(5);
@@ -702,7 +703,7 @@ void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port) {
}
void Disconnect(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if (auto client = ii->GetClient()) {
client->Disconnect();
}
@@ -710,7 +711,7 @@ void Disconnect(NT_Inst inst) {
}
void StartDSClient(NT_Inst inst, unsigned int port) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if (auto client = ii->GetClient()) {
client->StartDSClient(port);
}
@@ -718,7 +719,7 @@ void StartDSClient(NT_Inst inst, unsigned int port) {
}
void StopDSClient(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if (auto client = ii->GetClient()) {
client->StopDSClient();
}
@@ -726,7 +727,7 @@ void StopDSClient(NT_Inst inst) {
}
void FlushLocal(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if (auto client = ii->GetClient()) {
client->FlushLocal();
} else if (auto server = ii->GetServer()) {
@@ -736,7 +737,7 @@ void FlushLocal(NT_Inst inst) {
}
void Flush(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if (auto client = ii->GetClient()) {
client->Flush();
} else if (auto server = ii->GetServer()) {
@@ -746,7 +747,7 @@ void Flush(NT_Inst inst) {
}
std::vector<ConnectionInfo> GetConnections(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->connectionList.GetConnections();
} else {
return {};
@@ -754,7 +755,7 @@ std::vector<ConnectionInfo> GetConnections(NT_Inst inst) {
}
bool IsConnected(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->networkMode == NT_NET_MODE_LOCAL ||
ii->connectionList.IsConnected();
} else {
@@ -763,7 +764,7 @@ bool IsConnected(NT_Inst inst) {
}
std::optional<int64_t> GetServerTimeOffset(NT_Inst inst) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->GetServerTimeOffset();
} else {
return {};
@@ -772,7 +773,7 @@ std::optional<int64_t> GetServerTimeOffset(NT_Inst inst) {
NT_Listener AddLogger(NT_Inst inst, unsigned int minLevel,
unsigned int maxLevel, ListenerCallback func) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
if (minLevel < ii->logger.min_level()) {
ii->logger.set_min_level(minLevel);
}
@@ -786,7 +787,7 @@ NT_Listener AddLogger(NT_Inst inst, unsigned int minLevel,
NT_Listener AddPolledLogger(NT_ListenerPoller poller, unsigned int minLevel,
unsigned int maxLevel) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::kListenerPoller)) {
if (auto ii = InstanceImpl::GetTyped(poller, Handle::LISTENER_POLLER)) {
if (minLevel < ii->logger.min_level()) {
ii->logger.set_min_level(minLevel);
}
@@ -799,7 +800,7 @@ NT_Listener AddPolledLogger(NT_ListenerPoller poller, unsigned int minLevel,
}
bool HasSchema(NT_Inst inst, std::string_view name) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
return ii->localStorage.HasSchema(name);
} else {
return false;
@@ -808,7 +809,7 @@ bool HasSchema(NT_Inst inst, std::string_view name) {
void AddSchema(NT_Inst inst, std::string_view name, std::string_view type,
std::span<const uint8_t> schema) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) {
if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) {
ii->localStorage.AddSchema(name, type, schema);
}
}

View File

@@ -31,7 +31,7 @@ void LoggerTest::Generate() {
// generate error message
wpi::nt::Publish(wpi::nt::Handle(wpi::nt::Handle{m_inst}.GetInst(), 5,
wpi::nt::Handle::kTopic),
wpi::nt::Handle::TOPIC),
NT_DOUBLE, "");
}

View File

@@ -25,26 +25,26 @@ void PrintTo(const Event& event, std::ostream* os) {
void PrintTo(const Handle& handle, std::ostream* os) {
*os << "Handle{";
switch (handle.GetType()) {
case Handle::kListener:
*os << "kListener";
case Handle::LISTENER:
*os << "LISTENER";
break;
case Handle::kListenerPoller:
*os << "kListenerPoller";
case Handle::LISTENER_POLLER:
*os << "LISTENER_POLLER";
break;
case Handle::kEntry:
*os << "kEntry";
case Handle::ENTRY:
*os << "ENTRY";
break;
case Handle::kInstance:
*os << "kInstance";
case Handle::INSTANCE:
*os << "INSTANCE";
break;
case Handle::kTopic:
case Handle::TOPIC:
*os << "kTopic";
break;
case Handle::kSubscriber:
*os << "kSubscriber";
case Handle::SUBSCRIBER:
*os << "SUBSCRIBER";
break;
case Handle::kPublisher:
*os << "kPublisher";
case Handle::PUBLISHER:
*os << "PUBLISHER";
break;
default:
*os << "UNKNOWN";

View File

@@ -378,7 +378,7 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
// publish before client connect
server.SetLocal(&local, &queue);
constexpr int pubuid = 1;
NT_Topic topicHandle = wpi::nt::Handle{0, 1, wpi::nt::Handle::kTopic};
NT_Topic topicHandle = wpi::nt::Handle{0, 1, wpi::nt::Handle::TOPIC};
constexpr int subuid = 1;
Value defaultValue = Value::MakeDouble(1.0, 10);
defaultValue.SetTime(0);

View File

@@ -106,7 +106,7 @@ WPI_EventHandle wpi::util::CreateEvent(bool manualReset, bool initialState) {
std::scoped_lock lock{manager.mutex};
auto index = manager.eventIds.emplace_back(0);
WPI_EventHandle handle = (kHandleTypeEvent << 24) | (index & 0xffffff);
WPI_EventHandle handle = (HANDLE_TYPE_EVENT << 24) | (index & 0xffffff);
// configure state data
auto& state = manager.states[handle];
@@ -116,7 +116,7 @@ WPI_EventHandle wpi::util::CreateEvent(bool manualReset, bool initialState) {
}
void wpi::util::DestroyEvent(WPI_EventHandle handle) {
if ((handle >> 24) != kHandleTypeEvent) {
if ((handle >> 24) != HANDLE_TYPE_EVENT) {
return;
}
@@ -132,7 +132,7 @@ void wpi::util::DestroyEvent(WPI_EventHandle handle) {
}
void wpi::util::SetEvent(WPI_EventHandle handle) {
if ((handle >> 24) != kHandleTypeEvent) {
if ((handle >> 24) != HANDLE_TYPE_EVENT) {
return;
}
@@ -140,7 +140,7 @@ void wpi::util::SetEvent(WPI_EventHandle handle) {
}
void wpi::util::ResetEvent(WPI_EventHandle handle) {
if ((handle >> 24) != kHandleTypeEvent) {
if ((handle >> 24) != HANDLE_TYPE_EVENT) {
return;
}
@@ -157,7 +157,7 @@ WPI_SemaphoreHandle wpi::util::CreateSemaphore(int initialCount,
std::scoped_lock lock{manager.mutex};
auto index = manager.semaphoreIds.emplace_back(maximumCount);
WPI_EventHandle handle = (kHandleTypeSemaphore << 24) | (index & 0xffffff);
WPI_EventHandle handle = (HANDLE_TYPE_SEMAPHORE << 24) | (index & 0xffffff);
// configure state data
auto& state = manager.states[handle];
@@ -168,7 +168,7 @@ WPI_SemaphoreHandle wpi::util::CreateSemaphore(int initialCount,
}
void wpi::util::DestroySemaphore(WPI_SemaphoreHandle handle) {
if ((handle >> 24) != kHandleTypeSemaphore) {
if ((handle >> 24) != HANDLE_TYPE_SEMAPHORE) {
return;
}
@@ -185,7 +185,7 @@ void wpi::util::DestroySemaphore(WPI_SemaphoreHandle handle) {
bool wpi::util::ReleaseSemaphore(WPI_SemaphoreHandle handle, int releaseCount,
int* prevCount) {
if ((handle >> 24) != kHandleTypeSemaphore) {
if ((handle >> 24) != HANDLE_TYPE_SEMAPHORE) {
return false;
}
if (releaseCount <= 0) {

View File

@@ -13,18 +13,18 @@
namespace wpi::util {
/** Constant representing an invalid handle. */
constexpr unsigned int kInvalidHandle = 0;
constexpr unsigned int INVALID_HANDLE = 0;
/**
* Standard types for handles.
* @{
*/
constexpr int kHandleTypeEvent = 1;
constexpr int kHandleTypeSemaphore = 2;
constexpr int kHandleTypeCSBase = 3;
constexpr int kHandleTypeNTBase = 16;
constexpr int kHandleTypeHALBase = 48;
constexpr int kHandleTypeUserBase = 80;
constexpr int HANDLE_TYPE_EVENT = 1;
constexpr int HANDLE_TYPE_SEMAPHORE = 2;
constexpr int HANDLE_TYPE_CS_BASE = 3;
constexpr int HANDLE_TYPE_NT_BASE = 16;
constexpr int HANDLE_TYPE_HAL_BASE = 48;
constexpr int HANDLE_TYPE_USER_BASE = 80;
/** @} */
/**