[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

@@ -89,12 +89,10 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
wpi::mutex m;
std::vector<nt::ConnectionNotification> result;
auto handle = nt::AddConnectionListener(
server_inst,
[&](const nt::ConnectionNotification& event) {
server_inst, false, [&](const nt::ConnectionNotification& event) {
std::scoped_lock lock{m};
result.push_back(event);
},
false);
});
// trigger a connect event
Connect(GetParam().first, 0, 20001 + GetParam().second);
@@ -116,6 +114,9 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
nt::StopClient(client_inst);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// wait for thread
nt::WaitForConnectionListenerQueue(server_inst, 1.0);
// get the event
{
std::scoped_lock lock{m};