[ntcore] Add hidden subscribe option (#6376)

This allows creating subscribers that aren't communicated with the network.
This commit is contained in:
Peter Johnson
2024-02-17 00:40:14 -08:00
committed by GitHub
parent 0cdab55e5b
commit a8a352ed8c
7 changed files with 59 additions and 11 deletions

View File

@@ -611,7 +611,7 @@ LocalStorage::SubscriberData* LocalStorage::Impl::AddLocalSubscriber(
"published as '{}')",
topic->name, config.typeStr, topic->typeStr);
}
if (m_network) {
if (m_network && !subscriber->config.hidden) {
DEBUG4("-> NetworkSubscribe({})", topic->name);
m_network->Subscribe(subscriber->handle, {{topic->name}}, config);
}
@@ -640,7 +640,7 @@ LocalStorage::Impl::RemoveLocalSubscriber(NT_Subscriber subHandle) {
listener.getSecond()->subscriber = nullptr;
}
}
if (m_network) {
if (m_network && !subscriber->config.hidden) {
m_network->Unsubscribe(subscriber->handle);
}
}
@@ -676,7 +676,7 @@ LocalStorage::MultiSubscriberData* LocalStorage::Impl::AddMultiSubscriber(
}
}
}
if (m_network) {
if (m_network && !subscriber->options.hidden) {
DEBUG4("-> NetworkSubscribe");
m_network->Subscribe(subscriber->handle, subscriber->prefixes,
subscriber->options);
@@ -696,7 +696,7 @@ LocalStorage::Impl::RemoveMultiSubscriber(NT_MultiSubscriber subHandle) {
listener.getSecond()->multiSubscriber = nullptr;
}
}
if (m_network) {
if (m_network && !subscriber->options.hidden) {
m_network->Unsubscribe(subscriber->handle);
}
}
@@ -1128,12 +1128,16 @@ void LocalStorage::Impl::StartNetwork(net::NetworkInterface* network) {
}
}
for (auto&& subscriber : m_subscribers) {
network->Subscribe(subscriber->handle, {{subscriber->topic->name}},
subscriber->config);
if (!subscriber->config.hidden) {
network->Subscribe(subscriber->handle, {{subscriber->topic->name}},
subscriber->config);
}
}
for (auto&& subscriber : m_multiSubscribers) {
network->Subscribe(subscriber->handle, subscriber->prefixes,
subscriber->options);
if (!subscriber->options.hidden) {
network->Subscribe(subscriber->handle, subscriber->prefixes,
subscriber->options);
}
}
}

View File

@@ -139,6 +139,7 @@ static nt::PubSubOptions FromJavaPubSubOptions(JNIEnv* env, jobject joptions) {
FIELD(disableRemote, "Z");
FIELD(disableLocal, "Z");
FIELD(excludeSelf, "Z");
FIELD(hidden, "Z");
#undef FIELD
@@ -154,7 +155,8 @@ static nt::PubSubOptions FromJavaPubSubOptions(JNIEnv* env, jobject joptions) {
FIELD(bool, Boolean, prefixMatch),
FIELD(bool, Boolean, disableRemote),
FIELD(bool, Boolean, disableLocal),
FIELD(bool, Boolean, excludeSelf)};
FIELD(bool, Boolean, excludeSelf),
FIELD(bool, Boolean, hidden)};
#undef GET
#undef FIELD

View File

@@ -126,6 +126,7 @@ static PubSubOptions ConvertToCpp(const NT_PubSubOptions* in) {
out.disableRemote = in->disableRemote;
out.disableLocal = in->disableLocal;
out.excludeSelf = in->excludeSelf;
out.hidden = in->hidden;
return out;
}

View File

@@ -367,6 +367,14 @@ struct NT_PubSubOptions {
* internal publisher.
*/
NT_Bool excludeSelf;
/**
* For subscriptions, don't share the existence of the subscription with the
* network. Note this means updates will not be received from the network
* unless another subscription overlaps with this one, and the subscription
* will not appear in metatopics.
*/
NT_Bool hidden;
};
/**

View File

@@ -374,6 +374,14 @@ struct PubSubOptions {
* internal publisher.
*/
bool excludeSelf = false;
/**
* For subscriptions, don't share the existence of the subscription with the
* network. Note this means updates will not be received from the network
* unless another subscription overlaps with this one, and the subscription
* will not appear in metatopics.
*/
bool hidden = false;
};
/**