[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

@@ -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);