[ntcore] Add sub option for local vs remote changes (#4731)

This is the subscriber readQueue version of the local value listener flag.
This commit is contained in:
Peter Johnson
2022-11-29 21:57:20 -08:00
committed by GitHub
parent 18d28ec5e3
commit 9b319fd56b
7 changed files with 127 additions and 5 deletions

View File

@@ -492,9 +492,12 @@ bool LSImpl::SetValue(TopicData* topic, const Value& value,
void LSImpl::NotifyValue(TopicData* topic, unsigned int eventFlags,
bool isDuplicate) {
bool isNetwork = (eventFlags & NT_EVENT_VALUE_REMOTE) != 0;
for (auto&& subscriber : topic->localSubscribers) {
if (subscriber->active &&
(subscriber->config.keepDuplicates || !isDuplicate)) {
(subscriber->config.keepDuplicates || !isDuplicate) &&
((isNetwork && subscriber->config.fromRemote) ||
(!isNetwork && subscriber->config.fromLocal))) {
subscriber->pollStorage.emplace_back(topic->lastValue);
subscriber->handle.Set();
if (!subscriber->valueListeners.empty()) {

View File

@@ -29,6 +29,25 @@ nt::PubSubOptions::PubSubOptions(std::span<const PubSubOption> options) {
case NT_PUBSUB_POLLSTORAGE:
pollStorageSize = static_cast<size_t>(option.value);
break;
case NT_PUBSUB_LOCALREMOTE:
switch (static_cast<int>(option.value)) {
case 0:
case 3:
fromLocal = true;
fromRemote = true;
break;
case 1:
fromLocal = true;
fromRemote = false;
break;
case 2:
fromLocal = false;
fromRemote = true;
break;
default:
break;
}
break;
default:
break;
}

View File

@@ -22,6 +22,8 @@ class PubSubOptions {
bool topicsOnly = false;
bool prefixMatch = false;
bool keepDuplicates = false;
bool fromRemote = true;
bool fromLocal = true;
};
} // namespace nt