[ntcore] Revamp listeners (#4511)

- In both C++ and Java, add listener functions to Instance class (same as NT3 provided)
- Add WaitForListenerQueue functions (same as NT3 provided)
- Move Java non-poller implementation to Instance (previously only handled single instance)
- Change C++ listeners to take non-const references for subscribers etc to help avoid footguns from use of temporary objects (also add doc comment)
- Fix Preferences making .type persistent
This commit is contained in:
Peter Johnson
2022-10-24 23:27:24 -07:00
committed by GitHub
parent dcfa85a5d5
commit 794669b346
35 changed files with 1222 additions and 589 deletions

View File

@@ -111,10 +111,10 @@ NetworkTablesModel::NetworkTablesModel()
NetworkTablesModel::NetworkTablesModel(nt::NetworkTableInstance inst)
: m_inst{inst},
m_subscriber{nt::SubscribeMultiple(inst.GetHandle(), {{"", "$"}})},
m_subscriber{inst, {{"", "$"}}},
m_topicPoller{inst},
m_valuePoller{inst} {
m_topicPoller.Add({{""}},
m_topicPoller.Add(m_subscriber,
NT_TOPIC_NOTIFY_IMMEDIATE | NT_TOPIC_NOTIFY_PROPERTIES |
NT_TOPIC_NOTIFY_PUBLISH | NT_TOPIC_NOTIFY_UNPUBLISH);
m_valuePoller.Add(m_subscriber,

View File

@@ -13,6 +13,7 @@
#include <utility>
#include <vector>
#include <networktables/MultiSubscriber.h>
#include <networktables/NetworkTableInstance.h>
#include <networktables/TopicListener.h>
#include <networktables/ValueListener.h>
@@ -179,7 +180,7 @@ class NetworkTablesModel : public Model {
void UpdateClients(std::span<const uint8_t> data);
nt::NetworkTableInstance m_inst;
NT_MultiSubscriber m_subscriber;
nt::MultiSubscriber m_subscriber;
nt::TopicListenerPoller m_topicPoller;
nt::ValueListenerPoller m_valuePoller;
wpi::DenseMap<NT_Topic, std::unique_ptr<Entry>> m_entries;