mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[ntcore] Add typed C GetEntryValue and ReadQueueValue functions (#6256)
This commit is contained in:
@@ -254,13 +254,13 @@ class LocalStorage final : public net::ILocalStorage {
|
||||
wpi::SmallVectorImpl<typename TypeInfo<T>::SmallElem>& buf,
|
||||
typename TypeInfo<T>::View defaultValue);
|
||||
|
||||
std::vector<Value> ReadQueueValue(NT_Handle subentry) {
|
||||
std::vector<Value> ReadQueueValue(NT_Handle subentry, unsigned int types) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto subscriber = m_impl.GetSubEntry(subentry);
|
||||
if (!subscriber) {
|
||||
return {};
|
||||
}
|
||||
return subscriber->pollStorage.ReadValue();
|
||||
return subscriber->pollStorage.ReadValue(types);
|
||||
}
|
||||
|
||||
template <ValidType T>
|
||||
|
||||
@@ -6,10 +6,13 @@
|
||||
|
||||
using namespace nt;
|
||||
|
||||
std::vector<Value> ValueCircularBuffer::ReadValue() {
|
||||
std::vector<Value> ValueCircularBuffer::ReadValue(unsigned int types) {
|
||||
std::vector<Value> rv;
|
||||
rv.reserve(m_storage.size());
|
||||
for (auto&& val : m_storage) {
|
||||
if (types != 0 && (types & val.type()) == 0) {
|
||||
continue;
|
||||
}
|
||||
rv.emplace_back(std::move(val));
|
||||
}
|
||||
m_storage.reset();
|
||||
|
||||
@@ -24,7 +24,7 @@ class ValueCircularBuffer {
|
||||
m_storage.emplace_back(std::forward<Args...>(args...));
|
||||
}
|
||||
|
||||
std::vector<Value> ReadValue();
|
||||
std::vector<Value> ReadValue(unsigned int types);
|
||||
template <ValidType T>
|
||||
std::vector<Timestamped<typename TypeInfo<T>::Value>> Read();
|
||||
|
||||
|
||||
@@ -175,11 +175,19 @@ uint64_t NT_GetEntryLastChange(NT_Entry entry) {
|
||||
}
|
||||
|
||||
void NT_GetEntryValue(NT_Entry entry, struct NT_Value* value) {
|
||||
NT_GetEntryValueType(entry, 0, value);
|
||||
}
|
||||
|
||||
void NT_GetEntryValueType(NT_Entry entry, unsigned int types,
|
||||
struct NT_Value* value) {
|
||||
NT_InitValue(value);
|
||||
auto v = nt::GetEntryValue(entry);
|
||||
if (!v) {
|
||||
return;
|
||||
}
|
||||
if (types != 0 && (types & v.type()) == 0) {
|
||||
return;
|
||||
}
|
||||
ConvertToC(v, value);
|
||||
}
|
||||
|
||||
@@ -204,6 +212,11 @@ struct NT_Value* NT_ReadQueueValue(NT_Handle subentry, size_t* count) {
|
||||
return ConvertToC<NT_Value>(nt::ReadQueueValue(subentry), count);
|
||||
}
|
||||
|
||||
struct NT_Value* NT_ReadQueueValueType(NT_Handle subentry, unsigned int types,
|
||||
size_t* count) {
|
||||
return ConvertToC<NT_Value>(nt::ReadQueueValue(subentry, types), count);
|
||||
}
|
||||
|
||||
NT_Topic* NT_GetTopics(NT_Inst inst, const char* prefix, size_t prefix_len,
|
||||
unsigned int types, size_t* count) {
|
||||
auto info_v = nt::GetTopics(inst, {prefix, prefix_len}, types);
|
||||
|
||||
@@ -144,8 +144,12 @@ unsigned int GetEntryFlags(NT_Entry entry) {
|
||||
}
|
||||
|
||||
std::vector<Value> ReadQueueValue(NT_Handle subentry) {
|
||||
return ReadQueueValue(subentry, 0);
|
||||
}
|
||||
|
||||
std::vector<Value> ReadQueueValue(NT_Handle subentry, unsigned int types) {
|
||||
if (auto ii = InstanceImpl::GetHandle(subentry)) {
|
||||
return ii->localStorage.ReadQueueValue(subentry);
|
||||
return ii->localStorage.ReadQueueValue(subentry, types);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user