mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +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 {};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
||||
@@ -528,6 +528,18 @@ unsigned int GetEntryFlags(NT_Entry entry);
|
||||
*/
|
||||
std::vector<Value> 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<Value> ReadQueueValue(NT_Handle subentry, unsigned int types);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user