mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
[ntcore] Remove table multi-subscriber (#4789)
This wasn't well thought out, and leaks horribly in Java. Reverts part of #4640.
This commit is contained in:
@@ -22,7 +22,6 @@ public final class NetworkTable {
|
|||||||
private final String m_path;
|
private final String m_path;
|
||||||
private final String m_pathWithSep;
|
private final String m_pathWithSep;
|
||||||
private final NetworkTableInstance m_inst;
|
private final NetworkTableInstance m_inst;
|
||||||
private final MultiSubscriber m_topicSub;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the "base name" of a key. For example, "/foo/bar" becomes "bar". If the key has a trailing
|
* Gets the "base name" of a key. For example, "/foo/bar" becomes "bar". If the key has a trailing
|
||||||
@@ -115,8 +114,6 @@ public final class NetworkTable {
|
|||||||
m_path = path;
|
m_path = path;
|
||||||
m_pathWithSep = path + PATH_SEPARATOR;
|
m_pathWithSep = path + PATH_SEPARATOR;
|
||||||
m_inst = inst;
|
m_inst = inst;
|
||||||
m_topicSub =
|
|
||||||
new MultiSubscriber(inst, new String[] {m_pathWithSep}, PubSubOption.topicsOnly(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -533,7 +530,7 @@ public final class NetworkTable {
|
|||||||
final NetworkTable parent = this;
|
final NetworkTable parent = this;
|
||||||
|
|
||||||
return m_inst.addListener(
|
return m_inst.addListener(
|
||||||
m_topicSub,
|
new String[] {m_pathWithSep},
|
||||||
EnumSet.of(NetworkTableEvent.Kind.kPublish, NetworkTableEvent.Kind.kImmediate),
|
EnumSet.of(NetworkTableEvent.Kind.kPublish, NetworkTableEvent.Kind.kImmediate),
|
||||||
new Consumer<NetworkTableEvent>() {
|
new Consumer<NetworkTableEvent>() {
|
||||||
final Set<String> m_notifiedTables = new HashSet<>();
|
final Set<String> m_notifiedTables = new HashSet<>();
|
||||||
@@ -583,8 +580,4 @@ public final class NetworkTable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(m_inst, m_path);
|
return Objects.hash(m_inst, m_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close() {
|
|
||||||
m_topicSub.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,14 +88,9 @@ std::vector<std::string> NetworkTable::GetHierarchy(std::string_view key) {
|
|||||||
|
|
||||||
NetworkTable::NetworkTable(NT_Inst inst, std::string_view path,
|
NetworkTable::NetworkTable(NT_Inst inst, std::string_view path,
|
||||||
const private_init&)
|
const private_init&)
|
||||||
: m_inst(inst),
|
: m_inst(inst), m_path(path) {}
|
||||||
m_path(path),
|
|
||||||
m_topicSub{::nt::SubscribeMultiple(inst, {{fmt::format("{}/", path)}},
|
|
||||||
{{PubSubOption::TopicsOnly(true)}})} {}
|
|
||||||
|
|
||||||
NetworkTable::~NetworkTable() {
|
NetworkTable::~NetworkTable() = default;
|
||||||
::nt::UnsubscribeMultiple(m_topicSub);
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkTableInstance NetworkTable::GetInstance() const {
|
NetworkTableInstance NetworkTable::GetInstance() const {
|
||||||
return NetworkTableInstance{m_inst};
|
return NetworkTableInstance{m_inst};
|
||||||
@@ -405,8 +400,8 @@ NT_Listener NetworkTable::AddSubTableListener(SubTableListener listener) {
|
|||||||
// a shared_ptr to it.
|
// a shared_ptr to it.
|
||||||
auto notified_tables = std::make_shared<wpi::StringMap<char>>();
|
auto notified_tables = std::make_shared<wpi::StringMap<char>>();
|
||||||
|
|
||||||
return ::nt::AddListener(
|
return NetworkTableInstance{m_inst}.AddListener(
|
||||||
m_topicSub, NT_EVENT_PUBLISH | NT_EVENT_IMMEDIATE,
|
{{fmt::format("{}/", m_path)}}, NT_EVENT_PUBLISH | NT_EVENT_IMMEDIATE,
|
||||||
[this, cb = std::move(listener), notified_tables](const Event& event) {
|
[this, cb = std::move(listener), notified_tables](const Event& event) {
|
||||||
auto topicInfo = event.GetTopicInfo();
|
auto topicInfo = event.GetTopicInfo();
|
||||||
if (!topicInfo) {
|
if (!topicInfo) {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ class NetworkTable final {
|
|||||||
private:
|
private:
|
||||||
NT_Inst m_inst;
|
NT_Inst m_inst;
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
NT_MultiSubscriber m_topicSub;
|
|
||||||
mutable wpi::mutex m_mutex;
|
mutable wpi::mutex m_mutex;
|
||||||
mutable wpi::StringMap<NT_Entry> m_entries;
|
mutable wpi::StringMap<NT_Entry> m_entries;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user