mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal,ntcore,cscore] Update Handle constants to all caps
This commit is contained in:
@@ -152,7 +152,7 @@ CS_Property CreateSourceProperty(CS_Source source, std::string_view name,
|
||||
int property = static_cast<ConfigurableSourceImpl&>(*data->source)
|
||||
.CreateProperty(name, kind, minimum, maximum, step,
|
||||
defaultValue, value);
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
return Handle{source, property, Handle::PROPERTY};
|
||||
}
|
||||
|
||||
CS_Property CreateSourcePropertyCallback(
|
||||
@@ -167,7 +167,7 @@ CS_Property CreateSourcePropertyCallback(
|
||||
int property = static_cast<ConfigurableSourceImpl&>(*data->source)
|
||||
.CreateProperty(name, kind, minimum, maximum, step,
|
||||
defaultValue, value, onChange);
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
return Handle{source, property, Handle::PROPERTY};
|
||||
}
|
||||
|
||||
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
@@ -186,7 +186,7 @@ void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::kSource});
|
||||
auto data2 = Instance::GetInstance().GetSource(Handle{i, Handle::SOURCE});
|
||||
if (!data2 || data->source.get() != data2->source.get()) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace wpi::cs {
|
||||
class Handle {
|
||||
public:
|
||||
enum Type {
|
||||
kUndefined = 0,
|
||||
kProperty = wpi::util::kHandleTypeCSBase,
|
||||
kSource,
|
||||
kSink,
|
||||
kListener,
|
||||
kSinkProperty,
|
||||
kListenerPoller
|
||||
UNDEFINED = 0,
|
||||
PROPERTY = wpi::util::HANDLE_TYPE_CS_BASE,
|
||||
SOURCE,
|
||||
SINK,
|
||||
LISTENER,
|
||||
SINK_PROPERTY,
|
||||
LISTENER_POLLER
|
||||
};
|
||||
enum { kIndexMax = 0xffff };
|
||||
|
||||
@@ -53,7 +53,7 @@ class Handle {
|
||||
bool IsType(Type type) const { return type == GetType(); }
|
||||
int GetTypedIndex(Type type) const { return IsType(type) ? GetIndex() : -1; }
|
||||
int GetParentIndex() const {
|
||||
return (IsType(Handle::kProperty) || IsType(Handle::kSinkProperty))
|
||||
return (IsType(Handle::PROPERTY) || IsType(Handle::SINK_PROPERTY))
|
||||
? (static_cast<int>(m_handle) >> 16) & 0xff
|
||||
: -1;
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ class Instance {
|
||||
UsbCameraListener usbCameraListener;
|
||||
|
||||
private:
|
||||
UnlimitedHandleResource<Handle, SourceData, Handle::kSource> m_sources;
|
||||
UnlimitedHandleResource<Handle, SinkData, Handle::kSink> m_sinks;
|
||||
UnlimitedHandleResource<Handle, SourceData, Handle::SOURCE> m_sources;
|
||||
UnlimitedHandleResource<Handle, SinkData, Handle::SINK> m_sinks;
|
||||
|
||||
public:
|
||||
wpi::net::EventLoopRunner eventLoop;
|
||||
|
||||
@@ -53,7 +53,7 @@ void Notifier::NotifySourceProperty(const SourceImpl& source, CS_EventKind kind,
|
||||
auto handleData = Instance::GetInstance().FindSource(source);
|
||||
Send(UINT_MAX, propertyName, handleData.first,
|
||||
static_cast<RawEvent::Kind>(kind),
|
||||
Handle{handleData.first, property, Handle::kProperty}, propertyKind,
|
||||
Handle{handleData.first, property, Handle::PROPERTY}, propertyKind,
|
||||
value, valueStr);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ void Notifier::NotifySinkProperty(const SinkImpl& sink, CS_EventKind kind,
|
||||
auto handleData = Instance::GetInstance().FindSink(sink);
|
||||
Send(UINT_MAX, propertyName, handleData.first,
|
||||
static_cast<RawEvent::Kind>(kind),
|
||||
Handle{handleData.first, property, Handle::kSinkProperty}, propertyKind,
|
||||
Handle{handleData.first, property, Handle::SINK_PROPERTY}, propertyKind,
|
||||
value, valueStr);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class NotifierThread
|
||||
}
|
||||
|
||||
void SetListener(RawEvent* data, unsigned int listener_uid) {
|
||||
data->listener = Handle(listener_uid, Handle::kListener);
|
||||
data->listener = Handle(listener_uid, Handle::LISTENER);
|
||||
}
|
||||
|
||||
void DoCallback(std::function<void(const RawEvent& event)> callback,
|
||||
|
||||
@@ -134,7 +134,7 @@ void Telemetry::RecordSourceBytes(const SourceImpl& source, int quantity) {
|
||||
return;
|
||||
}
|
||||
auto handleData = Instance::GetInstance().FindSource(source);
|
||||
thr->m_current[std::pair{Handle{handleData.first, Handle::kSource},
|
||||
thr->m_current[std::pair{Handle{handleData.first, Handle::SOURCE},
|
||||
static_cast<int>(CS_SOURCE_BYTES_RECEIVED)}] +=
|
||||
quantity;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ void Telemetry::RecordSourceFrames(const SourceImpl& source, int quantity) {
|
||||
return;
|
||||
}
|
||||
auto handleData = Instance::GetInstance().FindSource(source);
|
||||
thr->m_current[std::pair{Handle{handleData.first, Handle::kSource},
|
||||
thr->m_current[std::pair{Handle{handleData.first, Handle::SOURCE},
|
||||
static_cast<int>(CS_SOURCE_FRAMES_RECEIVED)}] +=
|
||||
quantity;
|
||||
}
|
||||
|
||||
@@ -27,17 +27,17 @@ static std::shared_ptr<PropertyContainer> GetPropertyContainer(
|
||||
CS_Property propertyHandle, int* propertyIndex, CS_Status* status) {
|
||||
std::shared_ptr<PropertyContainer> container;
|
||||
Handle handle{propertyHandle};
|
||||
if (handle.IsType(Handle::kProperty)) {
|
||||
if (handle.IsType(Handle::PROPERTY)) {
|
||||
int i = handle.GetParentIndex();
|
||||
auto data = Instance::GetInstance().GetSource(Handle{i, Handle::kSource});
|
||||
auto data = Instance::GetInstance().GetSource(Handle{i, Handle::SOURCE});
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return nullptr;
|
||||
}
|
||||
container = data->source;
|
||||
} else if (handle.IsType(Handle::kSinkProperty)) {
|
||||
} else if (handle.IsType(Handle::SINK_PROPERTY)) {
|
||||
int i = handle.GetParentIndex();
|
||||
auto data = Instance::GetInstance().GetSink(Handle{i, Handle::kSink});
|
||||
auto data = Instance::GetInstance().GetSink(Handle{i, Handle::SINK});
|
||||
if (!data) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return nullptr;
|
||||
@@ -286,7 +286,7 @@ CS_Property GetSourceProperty(CS_Source source, std::string_view name,
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return Handle{source, property, Handle::kProperty};
|
||||
return Handle{source, property, Handle::PROPERTY};
|
||||
}
|
||||
|
||||
std::span<CS_Property> EnumerateSourceProperties(
|
||||
@@ -300,7 +300,7 @@ std::span<CS_Property> EnumerateSourceProperties(
|
||||
wpi::util::SmallVector<int, 32> properties_buf;
|
||||
for (auto property :
|
||||
data->source->EnumerateProperties(properties_buf, status)) {
|
||||
vec.push_back(Handle{source, property, Handle::kProperty});
|
||||
vec.push_back(Handle{source, property, Handle::PROPERTY});
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
@@ -584,7 +584,7 @@ CS_Property GetSinkProperty(CS_Sink sink, std::string_view name,
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
}
|
||||
return Handle{sink, property, Handle::kSinkProperty};
|
||||
return Handle{sink, property, Handle::SINK_PROPERTY};
|
||||
}
|
||||
|
||||
std::span<CS_Property> EnumerateSinkProperties(
|
||||
@@ -598,7 +598,7 @@ std::span<CS_Property> EnumerateSinkProperties(
|
||||
wpi::util::SmallVector<int, 32> properties_buf;
|
||||
for (auto property :
|
||||
data->sink->EnumerateProperties(properties_buf, status)) {
|
||||
vec.push_back(Handle{sink, property, Handle::kSinkProperty});
|
||||
vec.push_back(Handle{sink, property, Handle::SINK_PROPERTY});
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
@@ -748,11 +748,11 @@ CS_Listener AddListener(std::function<void(const RawEvent& event)> callback,
|
||||
if (immediateNotify) {
|
||||
// TODO
|
||||
}
|
||||
return Handle{uid, Handle::kListener};
|
||||
return Handle{uid, Handle::LISTENER};
|
||||
}
|
||||
|
||||
void RemoveListener(CS_Listener handle, CS_Status* status) {
|
||||
int uid = Handle{handle}.GetTypedIndex(Handle::kListener);
|
||||
int uid = Handle{handle}.GetTypedIndex(Handle::LISTENER);
|
||||
if (uid < 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
@@ -762,11 +762,11 @@ void RemoveListener(CS_Listener handle, CS_Status* status) {
|
||||
|
||||
CS_ListenerPoller CreateListenerPoller() {
|
||||
auto& inst = Instance::GetInstance();
|
||||
return Handle(inst.notifier.CreatePoller(), Handle::kListenerPoller);
|
||||
return Handle(inst.notifier.CreatePoller(), Handle::LISTENER_POLLER);
|
||||
}
|
||||
|
||||
void DestroyListenerPoller(CS_ListenerPoller poller) {
|
||||
int uid = Handle{poller}.GetTypedIndex(Handle::kListenerPoller);
|
||||
int uid = Handle{poller}.GetTypedIndex(Handle::LISTENER_POLLER);
|
||||
if (uid < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -776,7 +776,7 @@ void DestroyListenerPoller(CS_ListenerPoller poller) {
|
||||
CS_Listener AddPolledListener(CS_ListenerPoller poller, int eventMask,
|
||||
bool immediateNotify, CS_Status* status) {
|
||||
Handle handle{poller};
|
||||
int id = handle.GetTypedIndex(Handle::kListenerPoller);
|
||||
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
|
||||
if (id < 0) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return 0;
|
||||
@@ -785,12 +785,12 @@ CS_Listener AddPolledListener(CS_ListenerPoller poller, int eventMask,
|
||||
auto& inst = Instance::GetInstance();
|
||||
int uid = inst.notifier.AddPolled(id, eventMask);
|
||||
StartBackground(eventMask, immediateNotify);
|
||||
return Handle{uid, Handle::kListener};
|
||||
return Handle{uid, Handle::LISTENER};
|
||||
}
|
||||
|
||||
std::vector<RawEvent> PollListener(CS_ListenerPoller poller) {
|
||||
Handle handle{poller};
|
||||
int id = handle.GetTypedIndex(Handle::kListenerPoller);
|
||||
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
|
||||
if (id < 0) {
|
||||
return {};
|
||||
}
|
||||
@@ -800,7 +800,7 @@ std::vector<RawEvent> PollListener(CS_ListenerPoller poller) {
|
||||
std::vector<RawEvent> PollListener(CS_ListenerPoller poller, double timeout,
|
||||
bool* timedOut) {
|
||||
Handle handle{poller};
|
||||
int id = handle.GetTypedIndex(Handle::kListenerPoller);
|
||||
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
|
||||
if (id < 0) {
|
||||
return {};
|
||||
}
|
||||
@@ -809,7 +809,7 @@ std::vector<RawEvent> PollListener(CS_ListenerPoller poller, double timeout,
|
||||
|
||||
void CancelPollListener(CS_ListenerPoller poller) {
|
||||
Handle handle{poller};
|
||||
int id = handle.GetTypedIndex(Handle::kListenerPoller);
|
||||
int id = handle.GetTypedIndex(Handle::LISTENER_POLLER);
|
||||
if (id < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user