diff --git a/ntcore/src/main/native/cpp/LocalStorage.h b/ntcore/src/main/native/cpp/LocalStorage.h index 4283274d86..44951137e6 100644 --- a/ntcore/src/main/native/cpp/LocalStorage.h +++ b/ntcore/src/main/native/cpp/LocalStorage.h @@ -254,13 +254,13 @@ class LocalStorage final : public net::ILocalStorage { wpi::SmallVectorImpl::SmallElem>& buf, typename TypeInfo::View defaultValue); - std::vector ReadQueueValue(NT_Handle subentry) { + std::vector 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 diff --git a/ntcore/src/main/native/cpp/ValueCircularBuffer.cpp b/ntcore/src/main/native/cpp/ValueCircularBuffer.cpp index f611a335d9..55c2968616 100644 --- a/ntcore/src/main/native/cpp/ValueCircularBuffer.cpp +++ b/ntcore/src/main/native/cpp/ValueCircularBuffer.cpp @@ -6,10 +6,13 @@ using namespace nt; -std::vector ValueCircularBuffer::ReadValue() { +std::vector ValueCircularBuffer::ReadValue(unsigned int types) { std::vector 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(); diff --git a/ntcore/src/main/native/cpp/ValueCircularBuffer.h b/ntcore/src/main/native/cpp/ValueCircularBuffer.h index b80b5db6bb..9ea01718a7 100644 --- a/ntcore/src/main/native/cpp/ValueCircularBuffer.h +++ b/ntcore/src/main/native/cpp/ValueCircularBuffer.h @@ -24,7 +24,7 @@ class ValueCircularBuffer { m_storage.emplace_back(std::forward(args...)); } - std::vector ReadValue(); + std::vector ReadValue(unsigned int types); template std::vector::Value>> Read(); diff --git a/ntcore/src/main/native/cpp/ntcore_c.cpp b/ntcore/src/main/native/cpp/ntcore_c.cpp index c4322b31a9..c2561c8833 100644 --- a/ntcore/src/main/native/cpp/ntcore_c.cpp +++ b/ntcore/src/main/native/cpp/ntcore_c.cpp @@ -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::ReadQueueValue(subentry), count); } +struct NT_Value* NT_ReadQueueValueType(NT_Handle subentry, unsigned int types, + size_t* count) { + return ConvertToC(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); diff --git a/ntcore/src/main/native/cpp/ntcore_cpp.cpp b/ntcore/src/main/native/cpp/ntcore_cpp.cpp index b27c4f5357..33920ea48f 100644 --- a/ntcore/src/main/native/cpp/ntcore_cpp.cpp +++ b/ntcore/src/main/native/cpp/ntcore_cpp.cpp @@ -144,8 +144,12 @@ unsigned int GetEntryFlags(NT_Entry entry) { } std::vector ReadQueueValue(NT_Handle subentry) { + return ReadQueueValue(subentry, 0); +} + +std::vector 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 {}; } diff --git a/ntcore/src/main/native/include/ntcore_c.h b/ntcore/src/main/native/include/ntcore_c.h index a335f813dd..6259a76e9d 100644 --- a/ntcore/src/main/native/include/ntcore_c.h +++ b/ntcore/src/main/native/include/ntcore_c.h @@ -464,6 +464,24 @@ uint64_t NT_GetEntryLastChange(NT_Entry entry); */ void NT_GetEntryValue(NT_Entry entry, struct NT_Value* value); +/** + * Get Entry Value. + * + * Returns copy of current entry value. + * Note that one of the type options is "unassigned". + * + * @param entry entry handle + * @param types bitmask of NT_Type values; 0 is treated specially + * as a "don't care" + * @param value storage for returned entry value + * + * It is the caller's responsibility to free value once it's no longer + * needed (the utility function NT_DisposeValue() is useful for this + * purpose). + */ +void NT_GetEntryValueType(NT_Entry entry, unsigned int types, + struct NT_Value* value); + /** * Set Default Entry Value. * @@ -518,6 +536,21 @@ unsigned int NT_GetEntryFlags(NT_Entry entry); */ struct NT_Value* NT_ReadQueueValue(NT_Handle subentry, size_t* count); +/** + * Read Entry Queue. + * + * Returns new entry values since last call. The returned array must be freed + * using NT_DisposeValueArray(). + * + * @param subentry subscriber or entry handle + * @param types bitmask of NT_Type values; 0 is treated specially + * as a "don't care" + * @param count count of items in returned array (output) + * @return entry value array; returns NULL and count=0 if no new values + */ +struct NT_Value* NT_ReadQueueValueType(NT_Handle subentry, unsigned int types, + size_t* count); + /** @} */ /** diff --git a/ntcore/src/main/native/include/ntcore_cpp.h b/ntcore/src/main/native/include/ntcore_cpp.h index e2529e1d33..fe50f45437 100644 --- a/ntcore/src/main/native/include/ntcore_cpp.h +++ b/ntcore/src/main/native/include/ntcore_cpp.h @@ -528,6 +528,18 @@ unsigned int GetEntryFlags(NT_Entry entry); */ std::vector ReadQueueValue(NT_Handle subentry); +/** + * Read Entry Queue. + * + * Returns new entry values since last call. + * + * @param subentry subscriber or entry handle + * @param types bitmask of NT_Type values; 0 is treated specially + * as a "don't care" + * @return entry value array + */ +std::vector ReadQueueValue(NT_Handle subentry, unsigned int types); + /** @} */ /**