diff --git a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp index 49c8abba6c..cbc426b3af 100644 --- a/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp +++ b/cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp @@ -152,7 +152,7 @@ CS_Property CreateSourceProperty(CS_Source source, std::string_view name, int property = static_cast(*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(*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; diff --git a/cscore/src/main/native/cpp/Handle.hpp b/cscore/src/main/native/cpp/Handle.hpp index 1711b02390..01ab89017c 100644 --- a/cscore/src/main/native/cpp/Handle.hpp +++ b/cscore/src/main/native/cpp/Handle.hpp @@ -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(m_handle) >> 16) & 0xff : -1; } diff --git a/cscore/src/main/native/cpp/Instance.hpp b/cscore/src/main/native/cpp/Instance.hpp index e07a7d3ac1..0bcd00164a 100644 --- a/cscore/src/main/native/cpp/Instance.hpp +++ b/cscore/src/main/native/cpp/Instance.hpp @@ -56,8 +56,8 @@ class Instance { UsbCameraListener usbCameraListener; private: - UnlimitedHandleResource m_sources; - UnlimitedHandleResource m_sinks; + UnlimitedHandleResource m_sources; + UnlimitedHandleResource m_sinks; public: wpi::net::EventLoopRunner eventLoop; diff --git a/cscore/src/main/native/cpp/Notifier.cpp b/cscore/src/main/native/cpp/Notifier.cpp index 851d5fc657..0f27b146ba 100644 --- a/cscore/src/main/native/cpp/Notifier.cpp +++ b/cscore/src/main/native/cpp/Notifier.cpp @@ -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(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(kind), - Handle{handleData.first, property, Handle::kSinkProperty}, propertyKind, + Handle{handleData.first, property, Handle::SINK_PROPERTY}, propertyKind, value, valueStr); } diff --git a/cscore/src/main/native/cpp/Notifier.hpp b/cscore/src/main/native/cpp/Notifier.hpp index 20565025ca..7803e7feee 100644 --- a/cscore/src/main/native/cpp/Notifier.hpp +++ b/cscore/src/main/native/cpp/Notifier.hpp @@ -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 callback, diff --git a/cscore/src/main/native/cpp/Telemetry.cpp b/cscore/src/main/native/cpp/Telemetry.cpp index cf02d46c22..5f09ca4ef9 100644 --- a/cscore/src/main/native/cpp/Telemetry.cpp +++ b/cscore/src/main/native/cpp/Telemetry.cpp @@ -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(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(CS_SOURCE_FRAMES_RECEIVED)}] += quantity; } diff --git a/cscore/src/main/native/cpp/cscore_cpp.cpp b/cscore/src/main/native/cpp/cscore_cpp.cpp index 23ae7cc8cc..8dd12e6cb5 100644 --- a/cscore/src/main/native/cpp/cscore_cpp.cpp +++ b/cscore/src/main/native/cpp/cscore_cpp.cpp @@ -27,17 +27,17 @@ static std::shared_ptr GetPropertyContainer( CS_Property propertyHandle, int* propertyIndex, CS_Status* status) { std::shared_ptr 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 EnumerateSourceProperties( @@ -300,7 +300,7 @@ std::span EnumerateSourceProperties( wpi::util::SmallVector 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 EnumerateSinkProperties( @@ -598,7 +598,7 @@ std::span EnumerateSinkProperties( wpi::util::SmallVector 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 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 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 PollListener(CS_ListenerPoller poller) { std::vector 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 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; } diff --git a/cscore/src/main/native/include/wpi/cs/RawEvent.hpp b/cscore/src/main/native/include/wpi/cs/RawEvent.hpp index b8e31b901b..ce740d051c 100644 --- a/cscore/src/main/native/include/wpi/cs/RawEvent.hpp +++ b/cscore/src/main/native/include/wpi/cs/RawEvent.hpp @@ -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; diff --git a/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp index 2342b81249..5ff43305f2 100644 --- a/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp +++ b/hal/src/main/native/cpp/jni/simulation/BufferCallbackStore.cpp @@ -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; } diff --git a/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp index eaae197610..c7e5f3b281 100644 --- a/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp +++ b/hal/src/main/native/cpp/jni/simulation/CallbackStore.cpp @@ -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; } diff --git a/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp index b1ea7fc917..b8f5d9758b 100644 --- a/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp +++ b/hal/src/main/native/cpp/jni/simulation/ConstBufferCallbackStore.cpp @@ -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; } diff --git a/hal/src/main/native/cpp/jni/simulation/OpModeOptionsCallbackStore.cpp b/hal/src/main/native/cpp/jni/simulation/OpModeOptionsCallbackStore.cpp index 14f4f5775b..e0e1ca091d 100644 --- a/hal/src/main/native/cpp/jni/simulation/OpModeOptionsCallbackStore.cpp +++ b/hal/src/main/native/cpp/jni/simulation/OpModeOptionsCallbackStore.cpp @@ -20,12 +20,12 @@ using namespace wpi::hal::sim; using namespace wpi::util::java; static UnlimitedHandleResource* callbackHandles; + HAL_HandleEnum::SIMULATION_JNI>* callbackHandles; namespace wpi::hal::sim { void InitializeOpModeOptionsStore() { static UnlimitedHandleResource + HAL_HandleEnum::SIMULATION_JNI> cb; callbackHandles = &cb; } diff --git a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp index f237c2b232..0f77a3bb89 100644 --- a/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp +++ b/hal/src/main/native/cpp/jni/simulation/SimDeviceDataJNI.cpp @@ -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; diff --git a/hal/src/main/native/include/wpi/hal/handles/HandlesInternal.hpp b/hal/src/main/native/include/wpi/hal/handles/HandlesInternal.hpp index 1ba0564ba5..45a9709156 100644 --- a/hal/src/main/native/include/wpi/hal/handles/HandlesInternal.hpp +++ b/hal/src/main/native/include/wpi/hal/handles/HandlesInternal.hpp @@ -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); diff --git a/hal/src/main/native/sim/AddressableLED.cpp b/hal/src/main/native/sim/AddressableLED.cpp index ad95f0a076..1fb0fc086a 100644 --- a/hal/src/main/native/sim/AddressableLED.cpp +++ b/hal/src/main/native/sim/AddressableLED.cpp @@ -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; diff --git a/hal/src/main/native/sim/Alert.cpp b/hal/src/main/native/sim/Alert.cpp index 8b96d03e21..9cf5538a55 100644 --- a/hal/src/main/native/sim/Alert.cpp +++ b/hal/src/main/native/sim/Alert.cpp @@ -33,12 +33,12 @@ struct Alert { using namespace wpi::hal; -static UnlimitedHandleResource* +static UnlimitedHandleResource* alertHandles; namespace wpi::hal::init { void InitializeAlert() { - static UnlimitedHandleResource + static UnlimitedHandleResource aH; alertHandles = &aH; } diff --git a/hal/src/main/native/sim/AnalogInternal.cpp b/hal/src/main/native/sim/AnalogInternal.cpp index 0919280f2b..4978725129 100644 --- a/hal/src/main/native/sim/AnalogInternal.cpp +++ b/hal/src/main/native/sim/AnalogInternal.cpp @@ -9,14 +9,14 @@ namespace wpi::hal { IndexedHandleResource* + kNumAnalogInputs, HAL_HandleEnum::ANALOG_INPUT>* analogInputHandles; } // namespace wpi::hal namespace wpi::hal::init { void InitializeAnalogInternal() { static IndexedHandleResource + kNumAnalogInputs, HAL_HandleEnum::ANALOG_INPUT> aiH; analogInputHandles = &aiH; } diff --git a/hal/src/main/native/sim/AnalogInternal.hpp b/hal/src/main/native/sim/AnalogInternal.hpp index c34d3d20a2..1a98dcbb1c 100644 --- a/hal/src/main/native/sim/AnalogInternal.hpp +++ b/hal/src/main/native/sim/AnalogInternal.hpp @@ -26,6 +26,6 @@ struct AnalogPort { }; extern IndexedHandleResource* + kNumAnalogInputs, HAL_HandleEnum::ANALOG_INPUT>* analogInputHandles; } // namespace wpi::hal diff --git a/hal/src/main/native/sim/CTREPCM.cpp b/hal/src/main/native/sim/CTREPCM.cpp index 2e9a543da7..df59cf64bc 100644 --- a/hal/src/main/native/sim/CTREPCM.cpp +++ b/hal/src/main/native/sim/CTREPCM.cpp @@ -24,12 +24,12 @@ struct PCM { } // namespace static IndexedHandleResource* pcmHandles; + HAL_HandleEnum::CTRE_PCM>* pcmHandles; namespace wpi::hal::init { void InitializeCTREPCM() { static IndexedHandleResource + HAL_HandleEnum::CTRE_PCM> pH; pcmHandles = &pH; } diff --git a/hal/src/main/native/sim/Counter.cpp b/hal/src/main/native/sim/Counter.cpp index 9e71af126c..08c3fbad9d 100644 --- a/hal/src/main/native/sim/Counter.cpp +++ b/hal/src/main/native/sim/Counter.cpp @@ -13,13 +13,13 @@ namespace wpi::hal { LimitedHandleResource* counterHandles; + HAL_HandleEnum::COUNTER>* counterHandles; } // namespace wpi::hal namespace wpi::hal::init { void InitializeCounter() { static LimitedHandleResource + HAL_HandleEnum::COUNTER> cH; counterHandles = &cH; } diff --git a/hal/src/main/native/sim/CounterInternal.hpp b/hal/src/main/native/sim/CounterInternal.hpp index 8e2054d423..e8eaea549e 100644 --- a/hal/src/main/native/sim/CounterInternal.hpp +++ b/hal/src/main/native/sim/CounterInternal.hpp @@ -15,6 +15,6 @@ struct Counter { }; extern LimitedHandleResource* counterHandles; + HAL_HandleEnum::COUNTER>* counterHandles; } // namespace wpi::hal diff --git a/hal/src/main/native/sim/DIO.cpp b/hal/src/main/native/sim/DIO.cpp index 2632f82c73..38934257b7 100644 --- a/hal/src/main/native/sim/DIO.cpp +++ b/hal/src/main/native/sim/DIO.cpp @@ -16,14 +16,14 @@ using namespace wpi::hal; static LimitedHandleResource* - digitalPWMHandles; + kNumDigitalPWMOutputs, + HAL_HandleEnum::DIGITAL_PWM>* digitalPWMHandles; namespace wpi::hal::init { void InitializeDIO() { static LimitedHandleResource + HAL_HandleEnum::DIGITAL_PWM> dpH; digitalPWMHandles = &dpH; } diff --git a/hal/src/main/native/sim/DutyCycle.cpp b/hal/src/main/native/sim/DutyCycle.cpp index 86277e226f..5c1b95af11 100644 --- a/hal/src/main/native/sim/DutyCycle.cpp +++ b/hal/src/main/native/sim/DutyCycle.cpp @@ -25,12 +25,12 @@ struct Empty {}; } // namespace static IndexedHandleResource* dutyCycleHandles; + HAL_HandleEnum::DUTY_CYCLE>* dutyCycleHandles; namespace wpi::hal::init { void InitializeDutyCycle() { static IndexedHandleResource + HAL_HandleEnum::DUTY_CYCLE> dcH; dutyCycleHandles = &dcH; } diff --git a/hal/src/main/native/sim/Encoder.cpp b/hal/src/main/native/sim/Encoder.cpp index 3d786ef097..e13015ab95 100644 --- a/hal/src/main/native/sim/Encoder.cpp +++ b/hal/src/main/native/sim/Encoder.cpp @@ -31,20 +31,20 @@ struct Empty {}; static LimitedHandleResource* encoderHandles; + HAL_HandleEnum::ENCODER>* encoderHandles; static LimitedHandleResource* fpgaEncoderHandles; + HAL_HandleEnum::FPGA_ENCODER>* fpgaEncoderHandles; namespace wpi::hal::init { void InitializeEncoder() { static LimitedHandleResource + HAL_HandleEnum::FPGA_ENCODER> feH; fpgaEncoderHandles = &feH; static LimitedHandleResource + 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; diff --git a/hal/src/main/native/sim/Notifier.cpp b/hal/src/main/native/sim/Notifier.cpp index 39ca6a1e88..2c6cd1ea8d 100644 --- a/hal/src/main/native/sim/Notifier.cpp +++ b/hal/src/main/native/sim/Notifier.cpp @@ -52,7 +52,7 @@ class NotifierThread : public wpi::util::SafeThread { bool m_paused = false; UnlimitedHandleResource + HAL_HandleEnum::NOTIFIER> m_handles; struct Alarm { diff --git a/hal/src/main/native/sim/REVPH.cpp b/hal/src/main/native/sim/REVPH.cpp index c42551cb04..14fc6c8f02 100644 --- a/hal/src/main/native/sim/REVPH.cpp +++ b/hal/src/main/native/sim/REVPH.cpp @@ -24,12 +24,12 @@ struct PCM { } // namespace static IndexedHandleResource* pcmHandles; + HAL_HandleEnum::REV_PH>* pcmHandles; namespace wpi::hal::init { void InitializeREVPH() { static IndexedHandleResource + HAL_HandleEnum::REV_PH> pH; pcmHandles = &pH; } diff --git a/hal/src/main/native/systemcore/AddressableLED.cpp b/hal/src/main/native/systemcore/AddressableLED.cpp index 37bbe73eb2..d0a022bfe4 100644 --- a/hal/src/main/native/systemcore/AddressableLED.cpp +++ b/hal/src/main/native/systemcore/AddressableLED.cpp @@ -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; diff --git a/hal/src/main/native/systemcore/Alert.cpp b/hal/src/main/native/systemcore/Alert.cpp index c6fa25c411..deb1d9d1b9 100644 --- a/hal/src/main/native/systemcore/Alert.cpp +++ b/hal/src/main/native/systemcore/Alert.cpp @@ -33,12 +33,12 @@ struct Alert { using namespace wpi::hal; -static UnlimitedHandleResource* +static UnlimitedHandleResource* alertHandles; namespace wpi::hal::init { void InitializeAlert() { - static UnlimitedHandleResource + static UnlimitedHandleResource aH; alertHandles = &aH; } diff --git a/hal/src/main/native/systemcore/AnalogInput.cpp b/hal/src/main/native/systemcore/AnalogInput.cpp index a571f1b3c6..1ee4ca25cb 100644 --- a/hal/src/main/native/systemcore/AnalogInput.cpp +++ b/hal/src/main/native/systemcore/AnalogInput.cpp @@ -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; diff --git a/hal/src/main/native/systemcore/CAN.cpp b/hal/src/main/native/systemcore/CAN.cpp index e2cdd86d9d..44090e8fb2 100644 --- a/hal/src/main/native/systemcore/CAN.cpp +++ b/hal/src/main/native/systemcore/CAN.cpp @@ -117,7 +117,7 @@ struct SocketCanState { } // namespace static UnlimitedHandleResource* 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_HandleEnum::CAN_STREAM> cSH; canStreamHandles = &cSH; } diff --git a/hal/src/main/native/systemcore/CTREPCM.cpp b/hal/src/main/native/systemcore/CTREPCM.cpp index c184a78802..b227d0b835 100644 --- a/hal/src/main/native/systemcore/CTREPCM.cpp +++ b/hal/src/main/native/systemcore/CTREPCM.cpp @@ -134,12 +134,12 @@ struct PCM { } // namespace static IndexedHandleResource* pcmHandles; + HAL_HandleEnum::CTRE_PCM>* pcmHandles; namespace wpi::hal::init { void InitializeCTREPCM() { static IndexedHandleResource + HAL_HandleEnum::CTRE_PCM> pH; pcmHandles = &pH; } diff --git a/hal/src/main/native/systemcore/CTREPDP.cpp b/hal/src/main/native/systemcore/CTREPDP.cpp index 32adb3c6c9..1f1b077066 100644 --- a/hal/src/main/native/systemcore/CTREPDP.cpp +++ b/hal/src/main/native/systemcore/CTREPDP.cpp @@ -115,12 +115,12 @@ struct PDP { } // namespace static IndexedHandleResource* pdpHandles; + HAL_HandleEnum::CTRE_PDP>* pdpHandles; namespace wpi::hal::init { void InitializeCTREPDP() { static IndexedHandleResource + HAL_HandleEnum::CTRE_PDP> pH; pdpHandles = &pH; } diff --git a/hal/src/main/native/systemcore/Counter.cpp b/hal/src/main/native/systemcore/Counter.cpp index e5efb73b0a..49b59dc113 100644 --- a/hal/src/main/native/systemcore/Counter.cpp +++ b/hal/src/main/native/systemcore/Counter.cpp @@ -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; diff --git a/hal/src/main/native/systemcore/DutyCycle.cpp b/hal/src/main/native/systemcore/DutyCycle.cpp index d9bf3f31c4..e2c6424e81 100644 --- a/hal/src/main/native/systemcore/DutyCycle.cpp +++ b/hal/src/main/native/systemcore/DutyCycle.cpp @@ -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; diff --git a/hal/src/main/native/systemcore/Notifier.cpp b/hal/src/main/native/systemcore/Notifier.cpp index 6e64e4ada2..66fe172a47 100644 --- a/hal/src/main/native/systemcore/Notifier.cpp +++ b/hal/src/main/native/systemcore/Notifier.cpp @@ -43,7 +43,7 @@ class NotifierThread : public wpi::util::SafeThread { void ProcessAlarms(); UnlimitedHandleResource + HAL_HandleEnum::NOTIFIER> m_handles; struct Alarm { diff --git a/hal/src/main/native/systemcore/PowerDistribution.cpp b/hal/src/main/native/systemcore/PowerDistribution.cpp index b3c0680432..818fb09d6a 100644 --- a/hal/src/main/native/systemcore/PowerDistribution.cpp +++ b/hal/src/main/native/systemcore/PowerDistribution.cpp @@ -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)) { diff --git a/hal/src/main/native/systemcore/REVPDH.cpp b/hal/src/main/native/systemcore/REVPDH.cpp index e3f6b8f162..d5fe5c6f08 100644 --- a/hal/src/main/native/systemcore/REVPDH.cpp +++ b/hal/src/main/native/systemcore/REVPDH.cpp @@ -75,12 +75,12 @@ static constexpr int32_t kPDHFrameStatus3Timeout = 20; static constexpr int32_t kPDHFrameStatus4Timeout = 20; static IndexedHandleResource* REVPDHHandles; + HAL_HandleEnum::REV_PDH>* REVPDHHandles; namespace wpi::hal::init { void InitializeREVPDH() { static IndexedHandleResource + HAL_HandleEnum::REV_PDH> rH; REVPDHHandles = &rH; } diff --git a/hal/src/main/native/systemcore/REVPH.cpp b/hal/src/main/native/systemcore/REVPH.cpp index 6efc028dd1..9552896340 100644 --- a/hal/src/main/native/systemcore/REVPH.cpp +++ b/hal/src/main/native/systemcore/REVPH.cpp @@ -72,12 +72,12 @@ struct REV_PHObj { } // namespace static IndexedHandleResource* REVPHHandles; + HAL_HandleEnum::REV_PH>* REVPHHandles; namespace wpi::hal::init { void InitializeREVPH() { static IndexedHandleResource + HAL_HandleEnum::REV_PH> rH; REVPHHandles = &rH; } diff --git a/hal/src/test/native/cpp/handles/HandleTest.cpp b/hal/src/test/native/cpp/handles/HandleTest.cpp index 9f75059a3d..32684cc0e1 100644 --- a/hal/src/test/native/cpp/handles/HandleTest.cpp +++ b/hal/src/test/native/cpp/handles/HandleTest.cpp @@ -17,7 +17,7 @@ class MyTestClass {}; namespace wpi::hal { TEST(HandleTest, ClassedHandle) { wpi::hal::IndexedClassedHandleResource + HAL_HandleEnum::VENDOR> testClass; int32_t status = 0; testClass.Allocate(0, std::make_unique(), &status); diff --git a/ntcore/src/main/native/cpp/ConnectionList.hpp b/ntcore/src/main/native/cpp/ConnectionList.hpp index 916619c8db..2831b45722 100644 --- a/ntcore/src/main/native/cpp/ConnectionList.hpp +++ b/ntcore/src/main/native/cpp/ConnectionList.hpp @@ -55,7 +55,7 @@ class ConnectionList final : public IConnectionList { wpi::util::UidVector, 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) diff --git a/ntcore/src/main/native/cpp/Handle.hpp b/ntcore/src/main/native/cpp/Handle.hpp index 452403029c..15663b67aa 100644 --- a/ntcore/src/main/native/cpp/Handle.hpp +++ b/ntcore/src/main/native/cpp/Handle.hpp @@ -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 diff --git a/ntcore/src/main/native/cpp/ListenerStorage.hpp b/ntcore/src/main/native/cpp/ListenerStorage.hpp index d62aa3f59e..b4cd9dfdbb 100644 --- a/ntcore/src/main/native/cpp/ListenerStorage.hpp +++ b/ntcore/src/main/native/cpp/ListenerStorage.hpp @@ -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 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} {} diff --git a/ntcore/src/main/native/cpp/LocalStorage.cpp b/ntcore/src/main/native/cpp/LocalStorage.cpp index f958294e0a..7555631e3f 100644 --- a/ntcore/src/main/native/cpp/LocalStorage.cpp +++ b/ntcore/src/main/native/cpp/LocalStorage.cpp @@ -48,16 +48,16 @@ std::vector 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: diff --git a/ntcore/src/main/native/cpp/local/LocalDataLogger.hpp b/ntcore/src/main/native/cpp/local/LocalDataLogger.hpp index 2b73ba9a09..6ae0a9e55a 100644 --- a/ntcore/src/main/native/cpp/local/LocalDataLogger.hpp +++ b/ntcore/src/main/native/cpp/local/LocalDataLogger.hpp @@ -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) diff --git a/ntcore/src/main/native/cpp/local/LocalEntry.hpp b/ntcore/src/main/native/cpp/local/LocalEntry.hpp index 0ef9d45bb6..977dd7c13c 100644 --- a/ntcore/src/main/native/cpp/local/LocalEntry.hpp +++ b/ntcore/src/main/native/cpp/local/LocalEntry.hpp @@ -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} {} diff --git a/ntcore/src/main/native/cpp/local/LocalMultiSubscriber.hpp b/ntcore/src/main/native/cpp/local/LocalMultiSubscriber.hpp index ed75ecb2a2..eb6f61988c 100644 --- a/ntcore/src/main/native/cpp/local/LocalMultiSubscriber.hpp +++ b/ntcore/src/main/native/cpp/local/LocalMultiSubscriber.hpp @@ -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 prefixes, diff --git a/ntcore/src/main/native/cpp/local/LocalPublisher.hpp b/ntcore/src/main/native/cpp/local/LocalPublisher.hpp index bc763f0cab..5626ca8f0e 100644 --- a/ntcore/src/main/native/cpp/local/LocalPublisher.hpp +++ b/ntcore/src/main/native/cpp/local/LocalPublisher.hpp @@ -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)} {} diff --git a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp index 188e1a4715..5296710f3c 100644 --- a/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp +++ b/ntcore/src/main/native/cpp/local/LocalStorageImpl.cpp @@ -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 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 { diff --git a/ntcore/src/main/native/cpp/local/LocalStorageImpl.hpp b/ntcore/src/main/native/cpp/local/LocalStorageImpl.hpp index 50182d4620..5179a93424 100644 --- a/ntcore/src/main/native/cpp/local/LocalStorageImpl.hpp +++ b/ntcore/src/main/native/cpp/local/LocalStorageImpl.hpp @@ -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); diff --git a/ntcore/src/main/native/cpp/local/LocalSubscriber.hpp b/ntcore/src/main/native/cpp/local/LocalSubscriber.hpp index 6744987afd..e9faede2ca 100644 --- a/ntcore/src/main/native/cpp/local/LocalSubscriber.hpp +++ b/ntcore/src/main/native/cpp/local/LocalSubscriber.hpp @@ -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}, diff --git a/ntcore/src/main/native/cpp/local/LocalTopic.hpp b/ntcore/src/main/native/cpp/local/LocalTopic.hpp index dfe19acb07..2bb67e6a5a 100644 --- a/ntcore/src/main/native/cpp/local/LocalTopic.hpp +++ b/ntcore/src/main/native/cpp/local/LocalTopic.hpp @@ -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)} {} diff --git a/ntcore/src/main/native/cpp/ntcore_cpp.cpp b/ntcore/src/main/native/cpp/ntcore_cpp.cpp index 0e7e88f4a9..fa5be9558a 100644 --- a/ntcore/src/main/native/cpp/ntcore_cpp.cpp +++ b/ntcore/src/main/native/cpp/ntcore_cpp.cpp @@ -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 ReadQueueValue(NT_Handle subentry, unsigned int types) { std::vector 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 GetTopics(NT_Inst inst, std::string_view prefix, std::vector GetTopics(NT_Inst inst, std::string_view prefix, std::span 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 GetTopics(NT_Inst inst, std::string_view prefix, std::vector 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 GetTopicInfo(NT_Inst inst, std::string_view prefix, std::vector GetTopicInfo(NT_Inst inst, std::string_view prefix, std::span 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 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 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 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 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 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 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> servers) { - if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) { + if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) { std::vector> 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> 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 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 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 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 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 schema) { - if (auto ii = InstanceImpl::GetTyped(inst, Handle::kInstance)) { + if (auto ii = InstanceImpl::GetTyped(inst, Handle::INSTANCE)) { ii->localStorage.AddSchema(name, type, schema); } } diff --git a/ntcore/src/test/native/cpp/LoggerTest.cpp b/ntcore/src/test/native/cpp/LoggerTest.cpp index 0e438f80af..8b915c2e7a 100644 --- a/ntcore/src/test/native/cpp/LoggerTest.cpp +++ b/ntcore/src/test/native/cpp/LoggerTest.cpp @@ -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, ""); } diff --git a/ntcore/src/test/native/cpp/TestPrinters.cpp b/ntcore/src/test/native/cpp/TestPrinters.cpp index 4ee35168eb..2284e29c57 100644 --- a/ntcore/src/test/native/cpp/TestPrinters.cpp +++ b/ntcore/src/test/native/cpp/TestPrinters.cpp @@ -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"; diff --git a/ntcore/src/test/native/cpp/server/ServerImplTest.cpp b/ntcore/src/test/native/cpp/server/ServerImplTest.cpp index 4778425e5d..196e968b09 100644 --- a/ntcore/src/test/native/cpp/server/ServerImplTest.cpp +++ b/ntcore/src/test/native/cpp/server/ServerImplTest.cpp @@ -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); diff --git a/wpiutil/src/main/native/cpp/Synchronization.cpp b/wpiutil/src/main/native/cpp/Synchronization.cpp index 44b1a0afb4..884c8b0824 100644 --- a/wpiutil/src/main/native/cpp/Synchronization.cpp +++ b/wpiutil/src/main/native/cpp/Synchronization.cpp @@ -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) { diff --git a/wpiutil/src/main/native/include/wpi/util/Synchronization.hpp b/wpiutil/src/main/native/include/wpi/util/Synchronization.hpp index eb6607176a..0349f1d196 100644 --- a/wpiutil/src/main/native/include/wpi/util/Synchronization.hpp +++ b/wpiutil/src/main/native/include/wpi/util/Synchronization.hpp @@ -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; /** @} */ /**