2015-06-21 23:42:29 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2015-06-25 23:12:49 -07:00
|
|
|
#include "Storage.h"
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2016-10-03 10:04:30 -07:00
|
|
|
#include "support/timestamp.h"
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
|
|
|
|
|
#include "Handle.h"
|
|
|
|
|
#include "IDispatcher.h"
|
|
|
|
|
#include "IEntryNotifier.h"
|
2017-09-04 22:01:59 -07:00
|
|
|
#include "INetworkConnection.h"
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
#include "IRpcServer.h"
|
2015-07-31 22:41:26 -07:00
|
|
|
#include "Log.h"
|
2015-06-27 10:22:59 -07:00
|
|
|
|
2015-07-17 07:21:07 -07:00
|
|
|
using namespace nt;
|
2015-06-21 23:42:29 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Storage::Storage(IEntryNotifier& notifier, IRpcServer& rpc_server,
|
|
|
|
|
wpi::Logger& logger)
|
|
|
|
|
: m_notifier(notifier), m_rpc_server(rpc_server), m_logger(logger) {
|
2015-08-13 13:12:15 -07:00
|
|
|
m_terminating = false;
|
|
|
|
|
}
|
2015-06-21 23:42:29 -07:00
|
|
|
|
2015-08-13 13:12:15 -07:00
|
|
|
Storage::~Storage() {
|
|
|
|
|
m_terminating = true;
|
|
|
|
|
m_rpc_results_cond.notify_all();
|
|
|
|
|
}
|
2015-06-27 10:22:59 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
void Storage::SetDispatcher(IDispatcher* dispatcher, bool server) {
|
2015-07-28 22:06:42 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_dispatcher = dispatcher;
|
2015-07-29 23:45:04 -07:00
|
|
|
m_server = server;
|
2015-07-28 22:06:42 -07:00
|
|
|
}
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
void Storage::ClearDispatcher() { m_dispatcher = nullptr; }
|
2015-07-29 20:33:13 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
NT_Type Storage::GetMessageEntryType(unsigned int id) const {
|
2015-07-29 20:33:13 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2015-07-29 23:45:04 -07:00
|
|
|
if (id >= m_idmap.size()) return NT_UNASSIGNED;
|
2015-08-01 11:47:35 -07:00
|
|
|
Entry* entry = m_idmap[id];
|
2015-07-31 14:16:13 -07:00
|
|
|
if (!entry || !entry->value) return NT_UNASSIGNED;
|
|
|
|
|
return entry->value->type();
|
2015-07-29 23:45:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::ProcessIncoming(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn,
|
|
|
|
|
std::weak_ptr<INetworkConnection> conn_weak) {
|
2015-07-29 23:45:04 -07:00
|
|
|
switch (msg->type()) {
|
|
|
|
|
case Message::kKeepAlive:
|
|
|
|
|
break; // ignore
|
|
|
|
|
case Message::kClientHello:
|
|
|
|
|
case Message::kProtoUnsup:
|
|
|
|
|
case Message::kServerHelloDone:
|
|
|
|
|
case Message::kServerHello:
|
|
|
|
|
case Message::kClientHelloDone:
|
|
|
|
|
// shouldn't get these, but ignore if we do
|
|
|
|
|
break;
|
2017-08-13 08:20:28 -07:00
|
|
|
case Message::kEntryAssign:
|
|
|
|
|
ProcessIncomingEntryAssign(std::move(msg), conn);
|
|
|
|
|
break;
|
|
|
|
|
case Message::kEntryUpdate:
|
|
|
|
|
ProcessIncomingEntryUpdate(std::move(msg), conn);
|
|
|
|
|
break;
|
|
|
|
|
case Message::kFlagsUpdate:
|
|
|
|
|
ProcessIncomingFlagsUpdate(std::move(msg), conn);
|
|
|
|
|
break;
|
|
|
|
|
case Message::kEntryDelete:
|
|
|
|
|
ProcessIncomingEntryDelete(std::move(msg), conn);
|
|
|
|
|
break;
|
|
|
|
|
case Message::kClearEntries:
|
|
|
|
|
ProcessIncomingClearEntries(std::move(msg), conn);
|
|
|
|
|
break;
|
|
|
|
|
case Message::kExecuteRpc:
|
|
|
|
|
ProcessIncomingExecuteRpc(std::move(msg), conn, std::move(conn_weak));
|
|
|
|
|
break;
|
|
|
|
|
case Message::kRpcResponse:
|
|
|
|
|
ProcessIncomingRpcResponse(std::move(msg), conn);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
void Storage::ProcessIncomingEntryAssign(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
StringRef name = msg->str();
|
|
|
|
|
Entry* entry;
|
|
|
|
|
bool may_need_update = false;
|
|
|
|
|
if (m_server) {
|
|
|
|
|
// if we're a server, id=0xffff requests are requests for an id
|
|
|
|
|
// to be assigned, and we need to send the new assignment back to
|
|
|
|
|
// the sender as well as all other connections.
|
|
|
|
|
if (id == 0xffff) {
|
|
|
|
|
entry = GetOrNew(name);
|
|
|
|
|
// see if it was already assigned; ignore if so.
|
|
|
|
|
if (entry->id != 0xffff) return;
|
|
|
|
|
|
|
|
|
|
entry->flags = msg->flags();
|
|
|
|
|
SetEntryValueImpl(entry, msg->value(), lock, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id >= m_idmap.size() || !m_idmap[id]) {
|
|
|
|
|
// ignore arbitrary entry assignments
|
|
|
|
|
// this can happen due to e.g. assignment to deleted entry
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("server: received assignment to unknown entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
entry = m_idmap[id];
|
|
|
|
|
} else {
|
|
|
|
|
// clients simply accept new assignments
|
|
|
|
|
if (id == 0xffff) {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("client: received entry assignment request?");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (id >= m_idmap.size()) m_idmap.resize(id + 1);
|
|
|
|
|
entry = m_idmap[id];
|
|
|
|
|
if (!entry) {
|
|
|
|
|
// create local
|
2017-10-02 13:06:39 -07:00
|
|
|
entry = GetOrNew(name);
|
2017-08-13 08:20:28 -07:00
|
|
|
entry->id = id;
|
|
|
|
|
m_idmap[id] = entry;
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value) {
|
2017-08-13 08:20:28 -07:00
|
|
|
// didn't exist at all (rather than just being a response to a
|
|
|
|
|
// id assignment request)
|
|
|
|
|
entry->value = msg->value();
|
|
|
|
|
entry->flags = msg->flags();
|
|
|
|
|
|
|
|
|
|
// notify
|
|
|
|
|
m_notifier.NotifyEntry(entry->local_id, name, entry->value,
|
|
|
|
|
NT_NOTIFY_NEW);
|
2015-07-31 13:21:19 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2017-08-13 08:20:28 -07:00
|
|
|
may_need_update = true; // we may need to send an update message
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// if the received flags don't match what we sent, we most likely
|
|
|
|
|
// updated flags locally in the interim; send flags update message.
|
|
|
|
|
if (msg->flags() != entry->flags) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
auto outmsg = Message::FlagsUpdate(id, entry->flags);
|
2015-07-29 23:45:04 -07:00
|
|
|
lock.unlock();
|
2017-08-13 08:20:28 -07:00
|
|
|
dispatcher->QueueOutgoing(outmsg, nullptr, nullptr);
|
|
|
|
|
lock.lock();
|
2015-07-29 23:45:04 -07:00
|
|
|
}
|
2017-08-13 08:20:28 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// common client and server handling
|
|
|
|
|
|
|
|
|
|
// already exists; ignore if sequence number not higher than local
|
|
|
|
|
SequenceNumber seq_num(msg->seq_num_uid());
|
|
|
|
|
if (seq_num < entry->seq_num) {
|
|
|
|
|
if (may_need_update) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
auto outmsg =
|
|
|
|
|
Message::EntryUpdate(entry->id, entry->seq_num.value(), entry->value);
|
|
|
|
|
lock.unlock();
|
|
|
|
|
dispatcher->QueueOutgoing(outmsg, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-25 11:54:17 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// sanity check: name should match id
|
|
|
|
|
if (msg->str() != entry->name) {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("entry assignment for same id with different name?");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-08-19 19:09:25 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
unsigned int notify_flags = NT_NOTIFY_UPDATE;
|
2015-08-19 19:09:25 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// don't update flags from a <3.0 remote (not part of message)
|
|
|
|
|
// don't update flags if this is a server response to a client id request
|
|
|
|
|
if (!may_need_update && conn->proto_rev() >= 0x0300) {
|
|
|
|
|
// update persistent dirty flag if persistent flag changed
|
|
|
|
|
if ((entry->flags & NT_PERSISTENT) != (msg->flags() & NT_PERSISTENT))
|
|
|
|
|
m_persistent_dirty = true;
|
|
|
|
|
if (entry->flags != msg->flags()) notify_flags |= NT_NOTIFY_FLAGS;
|
|
|
|
|
entry->flags = msg->flags();
|
|
|
|
|
}
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// update persistent dirty flag if the value changed and it's persistent
|
|
|
|
|
if (entry->IsPersistent() && *entry->value != *msg->value())
|
|
|
|
|
m_persistent_dirty = true;
|
|
|
|
|
|
|
|
|
|
// update local
|
|
|
|
|
entry->value = msg->value();
|
|
|
|
|
entry->seq_num = seq_num;
|
|
|
|
|
|
|
|
|
|
// notify
|
|
|
|
|
m_notifier.NotifyEntry(entry->local_id, name, entry->value, notify_flags);
|
|
|
|
|
|
|
|
|
|
// broadcast to all other connections (note for client there won't
|
|
|
|
|
// be any other connections, so don't bother)
|
|
|
|
|
if (m_server && m_dispatcher) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
auto outmsg = Message::EntryAssign(entry->name, id, msg->seq_num_uid(),
|
|
|
|
|
msg->value(), entry->flags);
|
|
|
|
|
lock.unlock();
|
|
|
|
|
dispatcher->QueueOutgoing(outmsg, nullptr, conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-02 21:47:01 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
void Storage::ProcessIncomingEntryUpdate(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
if (id >= m_idmap.size() || !m_idmap[id]) {
|
|
|
|
|
// ignore arbitrary entry updates;
|
|
|
|
|
// this can happen due to deleted entries
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received update to unknown entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Entry* entry = m_idmap[id];
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// ignore if sequence number not higher than local
|
|
|
|
|
SequenceNumber seq_num(msg->seq_num_uid());
|
|
|
|
|
if (seq_num <= entry->seq_num) return;
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// update local
|
|
|
|
|
entry->value = msg->value();
|
|
|
|
|
entry->seq_num = seq_num;
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// update persistent dirty flag if it's a persistent value
|
|
|
|
|
if (entry->IsPersistent()) m_persistent_dirty = true;
|
2015-08-19 19:09:25 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// notify
|
|
|
|
|
m_notifier.NotifyEntry(entry->local_id, entry->name, entry->value,
|
|
|
|
|
NT_NOTIFY_UPDATE);
|
2015-08-02 21:47:01 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// broadcast to all other connections (note for client there won't
|
|
|
|
|
// be any other connections, so don't bother)
|
|
|
|
|
if (m_server && m_dispatcher) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
lock.unlock();
|
|
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-19 19:09:25 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
void Storage::ProcessIncomingFlagsUpdate(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
if (id >= m_idmap.size() || !m_idmap[id]) {
|
|
|
|
|
// ignore arbitrary entry updates;
|
|
|
|
|
// this can happen due to deleted entries
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received flags update to unknown entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-25 11:54:17 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// update local
|
|
|
|
|
SetEntryFlagsImpl(m_idmap[id], msg->flags(), lock, false);
|
2015-09-25 11:54:17 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// broadcast to all other connections (note for client there won't
|
|
|
|
|
// be any other connections, so don't bother)
|
|
|
|
|
if (m_server && m_dispatcher) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
lock.unlock();
|
|
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-29 23:45:04 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
void Storage::ProcessIncomingEntryDelete(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
if (id >= m_idmap.size() || !m_idmap[id]) {
|
|
|
|
|
// ignore arbitrary entry updates;
|
|
|
|
|
// this can happen due to deleted entries
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received delete to unknown entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-25 11:54:17 -07:00
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
// update local
|
2017-09-30 22:55:30 -07:00
|
|
|
DeleteEntryImpl(m_idmap[id], lock, false);
|
2017-08-13 08:20:28 -07:00
|
|
|
|
|
|
|
|
// broadcast to all other connections (note for client there won't
|
|
|
|
|
// be any other connections, so don't bother)
|
|
|
|
|
if (m_server && m_dispatcher) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
lock.unlock();
|
|
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::ProcessIncomingClearEntries(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
// update local
|
|
|
|
|
DeleteAllEntriesImpl(false);
|
|
|
|
|
|
|
|
|
|
// broadcast to all other connections (note for client there won't
|
|
|
|
|
// be any other connections, so don't bother)
|
|
|
|
|
if (m_server && m_dispatcher) {
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
lock.unlock();
|
|
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, conn);
|
2015-07-29 23:45:04 -07:00
|
|
|
}
|
2015-07-29 20:33:13 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-13 08:20:28 -07:00
|
|
|
void Storage::ProcessIncomingExecuteRpc(
|
2017-09-04 22:01:59 -07:00
|
|
|
std::shared_ptr<Message> msg, INetworkConnection* conn,
|
|
|
|
|
std::weak_ptr<INetworkConnection> conn_weak) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (!m_server) return; // only process on server
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
if (id >= m_idmap.size() || !m_idmap[id]) {
|
|
|
|
|
// ignore call to non-existent RPC
|
|
|
|
|
// this can happen due to deleted entries
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received RPC call to unknown entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Entry* entry = m_idmap[id];
|
|
|
|
|
if (!entry->value || !entry->value->IsRpc()) {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received RPC call to non-RPC entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ConnectionInfo conn_info;
|
|
|
|
|
auto c = conn_weak.lock();
|
|
|
|
|
if (c) {
|
|
|
|
|
conn_info = c->info();
|
|
|
|
|
} else {
|
|
|
|
|
conn_info.remote_id = "";
|
|
|
|
|
conn_info.remote_ip = "";
|
|
|
|
|
conn_info.remote_port = 0;
|
|
|
|
|
conn_info.last_update = 0;
|
|
|
|
|
conn_info.protocol_version = 0;
|
|
|
|
|
}
|
|
|
|
|
unsigned int call_uid = msg->seq_num_uid();
|
|
|
|
|
m_rpc_server.ProcessRpc(
|
|
|
|
|
entry->local_id, call_uid, entry->name, msg->str(), conn_info,
|
|
|
|
|
[=](StringRef result) {
|
|
|
|
|
auto c = conn_weak.lock();
|
|
|
|
|
if (c) c->QueueOutgoing(Message::RpcResponse(id, call_uid, result));
|
|
|
|
|
},
|
|
|
|
|
entry->rpc_uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::ProcessIncomingRpcResponse(std::shared_ptr<Message> msg,
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection* conn) {
|
2017-08-13 08:20:28 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (m_server) return; // only process on client
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
if (id >= m_idmap.size() || !m_idmap[id]) {
|
|
|
|
|
// ignore response to non-existent RPC
|
|
|
|
|
// this can happen due to deleted entries
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received rpc response to unknown entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Entry* entry = m_idmap[id];
|
|
|
|
|
if (!entry->value || !entry->value->IsRpc()) {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
DEBUG("received RPC response to non-RPC entry");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_rpc_results.insert(std::make_pair(
|
|
|
|
|
RpcIdPair{entry->local_id, msg->seq_num_uid()}, msg->str()));
|
|
|
|
|
m_rpc_results_cond.notify_all();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-31 20:32:52 -07:00
|
|
|
void Storage::GetInitialAssignments(
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection& conn, std::vector<std::shared_ptr<Message>>* msgs) {
|
2015-07-31 20:32:52 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2017-09-04 22:01:59 -07:00
|
|
|
conn.set_state(INetworkConnection::kSynchronized);
|
2015-07-31 20:32:52 -07:00
|
|
|
for (auto& i : m_entries) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = i.getValue();
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value) continue;
|
2015-07-31 20:32:52 -07:00
|
|
|
msgs->emplace_back(Message::EntryAssign(i.getKey(), entry->id,
|
|
|
|
|
entry->seq_num.value(),
|
|
|
|
|
entry->value, entry->flags));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::ApplyInitialAssignments(
|
2017-09-04 22:01:59 -07:00
|
|
|
INetworkConnection& conn, llvm::ArrayRef<std::shared_ptr<Message>> msgs,
|
2015-07-31 23:56:06 -07:00
|
|
|
bool new_server, std::vector<std::shared_ptr<Message>>* out_msgs) {
|
2015-07-31 20:32:52 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (m_server) return; // should not do this on server
|
|
|
|
|
|
2017-09-04 22:01:59 -07:00
|
|
|
conn.set_state(INetworkConnection::kSynchronized);
|
2015-07-31 23:56:06 -07:00
|
|
|
|
2015-07-31 20:32:52 -07:00
|
|
|
std::vector<std::shared_ptr<Message>> update_msgs;
|
|
|
|
|
|
|
|
|
|
// clear existing id's
|
|
|
|
|
for (auto& i : m_entries) i.getValue()->id = 0xffff;
|
|
|
|
|
|
|
|
|
|
// clear existing idmap
|
|
|
|
|
m_idmap.resize(0);
|
|
|
|
|
|
|
|
|
|
// apply assignments
|
|
|
|
|
for (auto& msg : msgs) {
|
|
|
|
|
if (!msg->Is(Message::kEntryAssign)) {
|
|
|
|
|
DEBUG("client: received non-entry assignment request?");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int id = msg->id();
|
|
|
|
|
if (id == 0xffff) {
|
|
|
|
|
DEBUG("client: received entry assignment request?");
|
|
|
|
|
continue;
|
2015-07-31 13:21:19 -07:00
|
|
|
}
|
2015-07-31 20:32:52 -07:00
|
|
|
|
|
|
|
|
SequenceNumber seq_num(msg->seq_num_uid());
|
|
|
|
|
StringRef name = msg->str();
|
|
|
|
|
|
2017-10-02 13:06:39 -07:00
|
|
|
Entry* entry = GetOrNew(name);
|
|
|
|
|
if (!entry->value) {
|
2015-07-31 20:32:52 -07:00
|
|
|
// doesn't currently exist
|
|
|
|
|
entry->value = msg->value();
|
|
|
|
|
entry->flags = msg->flags();
|
|
|
|
|
entry->seq_num = seq_num;
|
2015-09-11 19:18:50 -07:00
|
|
|
// notify
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, name, entry->value,
|
|
|
|
|
NT_NOTIFY_NEW);
|
2015-07-31 20:32:52 -07:00
|
|
|
} else {
|
2017-08-13 10:11:29 -07:00
|
|
|
// if we have written the value locally and the value is not persistent,
|
|
|
|
|
// then we don't update the local value and instead send it back to the
|
|
|
|
|
// server as an update message
|
|
|
|
|
if (entry->local_write && !entry->IsPersistent()) {
|
2015-07-31 20:32:52 -07:00
|
|
|
update_msgs.emplace_back(Message::EntryUpdate(
|
|
|
|
|
entry->id, entry->seq_num.value(), entry->value));
|
|
|
|
|
} else {
|
|
|
|
|
entry->value = msg->value();
|
|
|
|
|
entry->seq_num = seq_num;
|
2015-09-25 11:54:17 -07:00
|
|
|
unsigned int notify_flags = NT_NOTIFY_UPDATE;
|
2015-07-31 20:32:52 -07:00
|
|
|
// don't update flags from a <3.0 remote (not part of message)
|
2015-09-25 11:54:17 -07:00
|
|
|
if (conn.proto_rev() >= 0x0300) {
|
|
|
|
|
if (entry->flags != msg->flags()) notify_flags |= NT_NOTIFY_FLAGS;
|
|
|
|
|
entry->flags = msg->flags();
|
|
|
|
|
}
|
2015-09-11 19:18:50 -07:00
|
|
|
// notify
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, name, entry->value,
|
|
|
|
|
notify_flags);
|
2015-07-31 20:32:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set id and save to idmap
|
|
|
|
|
entry->id = id;
|
2016-11-03 21:03:45 -07:00
|
|
|
if (id >= m_idmap.size()) m_idmap.resize(id + 1);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_idmap[id] = entry;
|
2015-07-31 20:32:52 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-13 10:11:29 -07:00
|
|
|
// delete or generate assign messages for unassigned local entries
|
|
|
|
|
DeleteAllEntriesImpl(false, [&](Entry* entry) -> bool {
|
|
|
|
|
// was assigned by the server, don't delete
|
|
|
|
|
if (entry->id != 0xffff) return false;
|
|
|
|
|
// if we have written the value locally, we send an assign message to the
|
|
|
|
|
// server instead of deleting
|
|
|
|
|
if (entry->local_write) {
|
|
|
|
|
out_msgs->emplace_back(
|
|
|
|
|
Message::EntryAssign(entry->name, entry->id, entry->seq_num.value(),
|
|
|
|
|
entry->value, entry->flags));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// otherwise delete
|
|
|
|
|
return true;
|
|
|
|
|
});
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto dispatcher = m_dispatcher;
|
2015-07-31 20:32:52 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
for (auto& msg : update_msgs)
|
|
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, nullptr);
|
2015-07-26 20:41:48 -07:00
|
|
|
}
|
|
|
|
|
|
2015-07-31 13:21:19 -07:00
|
|
|
std::shared_ptr<Value> Storage::GetEntryValue(StringRef name) const {
|
2015-07-18 01:29:51 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
auto i = m_entries.find(name);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (i == m_entries.end()) return nullptr;
|
|
|
|
|
return i->getValue()->value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Value> Storage::GetEntryValue(unsigned int local_id) const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return nullptr;
|
|
|
|
|
return m_localmap[local_id]->value;
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-03 21:03:45 -07:00
|
|
|
bool Storage::SetDefaultEntryValue(StringRef name,
|
2016-07-13 00:31:03 -07:00
|
|
|
std::shared_ptr<Value> value) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (name.empty()) return false;
|
|
|
|
|
if (!value) return false;
|
2016-07-13 00:31:03 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = GetOrNew(name);
|
2016-11-03 21:03:45 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
// we return early if value already exists; if types match return true
|
|
|
|
|
if (entry->value) return entry->value->type() == value->type();
|
2016-07-13 00:31:03 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
SetEntryValueImpl(entry, value, lock, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-07-13 00:31:03 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
bool Storage::SetDefaultEntryValue(unsigned int local_id,
|
|
|
|
|
std::shared_ptr<Value> value) {
|
|
|
|
|
if (!value) return false;
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return false;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
2016-07-13 00:31:03 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
// we return early if value already exists; if types match return true
|
|
|
|
|
if (entry->value) return entry->value->type() == value->type();
|
|
|
|
|
|
|
|
|
|
SetEntryValueImpl(entry, value, lock, true);
|
2016-07-13 00:31:03 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 01:29:51 -07:00
|
|
|
bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
|
|
|
|
|
if (name.empty()) return true;
|
|
|
|
|
if (!value) return true;
|
2015-07-31 13:21:19 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = GetOrNew(name);
|
|
|
|
|
|
|
|
|
|
if (entry->value && entry->value->type() != value->type())
|
|
|
|
|
return false; // error on type mismatch
|
|
|
|
|
|
|
|
|
|
SetEntryValueImpl(entry, value, lock, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Storage::SetEntryValue(unsigned int local_id,
|
|
|
|
|
std::shared_ptr<Value> value) {
|
|
|
|
|
if (!value) return true;
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return true;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
|
|
|
|
|
if (entry->value && entry->value->type() != value->type())
|
2015-07-18 01:29:51 -07:00
|
|
|
return false; // error on type mismatch
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
|
|
|
|
|
SetEntryValueImpl(entry, value, lock, true);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::SetEntryValueImpl(Entry* entry, std::shared_ptr<Value> value,
|
|
|
|
|
std::unique_lock<std::mutex>& lock,
|
|
|
|
|
bool local) {
|
|
|
|
|
if (!value) return;
|
|
|
|
|
auto old_value = entry->value;
|
2015-07-31 13:48:33 -07:00
|
|
|
entry->value = value;
|
2015-07-31 13:21:19 -07:00
|
|
|
|
|
|
|
|
// if we're the server, assign an id if it doesn't have one
|
2015-07-31 13:48:33 -07:00
|
|
|
if (m_server && entry->id == 0xffff) {
|
2015-07-31 13:21:19 -07:00
|
|
|
unsigned int id = m_idmap.size();
|
2015-07-31 13:48:33 -07:00
|
|
|
entry->id = id;
|
2015-07-31 13:21:19 -07:00
|
|
|
m_idmap.push_back(entry);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 19:09:25 -07:00
|
|
|
// update persistent dirty flag if value changed and it's persistent
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (entry->IsPersistent() && (!old_value || *old_value != *value))
|
|
|
|
|
m_persistent_dirty = true;
|
|
|
|
|
|
|
|
|
|
// notify
|
|
|
|
|
if (!old_value)
|
|
|
|
|
m_notifier.NotifyEntry(entry->local_id, entry->name, value,
|
|
|
|
|
NT_NOTIFY_NEW | (local ? NT_NOTIFY_LOCAL : 0));
|
|
|
|
|
else if (*old_value != *value)
|
|
|
|
|
m_notifier.NotifyEntry(entry->local_id, entry->name, value,
|
|
|
|
|
NT_NOTIFY_UPDATE | (local ? NT_NOTIFY_LOCAL : 0));
|
2015-10-08 00:04:38 -07:00
|
|
|
|
2017-08-13 10:11:29 -07:00
|
|
|
// remember local changes
|
|
|
|
|
if (local) entry->local_write = true;
|
|
|
|
|
|
2015-07-31 13:21:19 -07:00
|
|
|
// generate message
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!m_dispatcher || (!local && !m_server)) return;
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
|
|
|
|
if (!old_value || old_value->type() != value->type()) {
|
|
|
|
|
if (local) ++entry->seq_num;
|
|
|
|
|
auto msg = Message::EntryAssign(
|
|
|
|
|
entry->name, entry->id, entry->seq_num.value(), value, entry->flags);
|
2015-07-31 13:21:19 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, nullptr);
|
2015-07-31 13:21:19 -07:00
|
|
|
} else if (*old_value != *value) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (local) ++entry->seq_num;
|
2015-07-31 13:21:19 -07:00
|
|
|
// don't send an update if we don't have an assigned id yet
|
2015-07-31 13:48:33 -07:00
|
|
|
if (entry->id != 0xffff) {
|
2016-11-03 21:03:45 -07:00
|
|
|
auto msg = Message::EntryUpdate(entry->id, entry->seq_num.value(), value);
|
2015-07-31 13:21:19 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, nullptr);
|
2015-07-31 13:21:19 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr<Value> value) {
|
|
|
|
|
if (name.empty()) return;
|
|
|
|
|
if (!value) return;
|
2015-07-31 13:21:19 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = GetOrNew(name);
|
2015-07-31 13:21:19 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
SetEntryValueImpl(entry, value, lock, true);
|
|
|
|
|
}
|
2015-08-19 19:09:25 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
void Storage::SetEntryTypeValue(unsigned int local_id,
|
|
|
|
|
std::shared_ptr<Value> value) {
|
|
|
|
|
if (!value) return;
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
if (!entry) return;
|
2015-10-08 00:04:38 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
SetEntryValueImpl(entry, value, lock, true);
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::SetEntryFlags(StringRef name, unsigned int flags) {
|
2015-07-19 17:50:31 -07:00
|
|
|
if (name.empty()) return;
|
2015-07-31 13:21:19 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2015-07-26 09:27:23 -07:00
|
|
|
auto i = m_entries.find(name);
|
|
|
|
|
if (i == m_entries.end()) return;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
SetEntryFlagsImpl(i->getValue(), flags, lock, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::SetEntryFlags(unsigned int id_local, unsigned int flags) {
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (id_local >= m_localmap.size()) return;
|
|
|
|
|
SetEntryFlagsImpl(m_localmap[id_local].get(), flags, lock, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::SetEntryFlagsImpl(Entry* entry, unsigned int flags,
|
|
|
|
|
std::unique_lock<std::mutex>& lock,
|
|
|
|
|
bool local) {
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value || entry->flags == flags) return;
|
2015-08-19 19:09:25 -07:00
|
|
|
|
|
|
|
|
// update persistent dirty flag if persistent flag changed
|
|
|
|
|
if ((entry->flags & NT_PERSISTENT) != (flags & NT_PERSISTENT))
|
|
|
|
|
m_persistent_dirty = true;
|
|
|
|
|
|
2015-07-31 13:48:33 -07:00
|
|
|
entry->flags = flags;
|
2015-07-31 13:21:19 -07:00
|
|
|
|
2015-10-08 00:04:38 -07:00
|
|
|
// notify
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, entry->name, entry->value,
|
|
|
|
|
NT_NOTIFY_FLAGS | (local ? NT_NOTIFY_LOCAL : 0));
|
2015-10-08 00:04:38 -07:00
|
|
|
|
2015-07-31 13:21:19 -07:00
|
|
|
// generate message
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!local || !m_dispatcher) return;
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
2015-07-31 13:48:33 -07:00
|
|
|
unsigned int id = entry->id;
|
2015-07-31 13:21:19 -07:00
|
|
|
// don't send an update if we don't have an assigned id yet
|
|
|
|
|
if (id != 0xffff) {
|
|
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(Message::FlagsUpdate(id, flags), nullptr,
|
|
|
|
|
nullptr);
|
2015-07-19 16:02:21 -07:00
|
|
|
}
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int Storage::GetEntryFlags(StringRef name) const {
|
2015-07-31 13:21:19 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
auto i = m_entries.find(name);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (i == m_entries.end()) return 0;
|
|
|
|
|
return i->getValue()->flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int Storage::GetEntryFlags(unsigned int local_id) const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return 0;
|
|
|
|
|
return m_localmap[local_id]->flags;
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::DeleteEntry(StringRef name) {
|
2015-07-31 13:21:19 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2015-07-19 18:10:26 -07:00
|
|
|
auto i = m_entries.find(name);
|
|
|
|
|
if (i == m_entries.end()) return;
|
2017-09-30 22:55:30 -07:00
|
|
|
DeleteEntryImpl(i->getValue(), lock, true);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Storage::DeleteEntry(unsigned int local_id) {
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return;
|
2017-09-30 22:55:30 -07:00
|
|
|
DeleteEntryImpl(m_localmap[local_id].get(), lock, true);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-30 22:55:30 -07:00
|
|
|
void Storage::DeleteEntryImpl(Entry* entry, std::unique_lock<std::mutex>& lock,
|
|
|
|
|
bool local) {
|
2015-07-31 13:48:33 -07:00
|
|
|
unsigned int id = entry->id;
|
2015-08-19 19:09:25 -07:00
|
|
|
|
2017-09-30 22:55:30 -07:00
|
|
|
// Erase entry from id mapping.
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (id < m_idmap.size()) m_idmap[id] = nullptr;
|
|
|
|
|
|
2017-08-13 10:11:29 -07:00
|
|
|
// empty the value and reset id and local_write flag
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
std::shared_ptr<Value> old_value;
|
|
|
|
|
old_value.swap(entry->value);
|
|
|
|
|
entry->id = 0xffff;
|
2017-08-13 10:11:29 -07:00
|
|
|
entry->local_write = false;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
|
|
|
|
|
// remove RPC if there was one
|
|
|
|
|
if (entry->rpc_uid != UINT_MAX) {
|
|
|
|
|
m_rpc_server.RemoveRpc(entry->rpc_uid);
|
|
|
|
|
entry->rpc_uid = UINT_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 19:09:25 -07:00
|
|
|
// update persistent dirty flag if it's a persistent value
|
|
|
|
|
if (entry->IsPersistent()) m_persistent_dirty = true;
|
|
|
|
|
|
2017-10-02 13:06:39 -07:00
|
|
|
// reset flags
|
|
|
|
|
entry->flags = 0;
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!old_value) return; // was not previously assigned
|
2015-07-31 13:21:19 -07:00
|
|
|
|
2015-10-08 00:04:38 -07:00
|
|
|
// notify
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, entry->name, old_value,
|
|
|
|
|
NT_NOTIFY_DELETE | (local ? NT_NOTIFY_LOCAL : 0));
|
2015-10-08 00:04:38 -07:00
|
|
|
|
2015-07-31 13:21:19 -07:00
|
|
|
// if it had a value, generate message
|
|
|
|
|
// don't send an update if we don't have an assigned id yet
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (local && id != 0xffff) {
|
|
|
|
|
if (!m_dispatcher) return;
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
2015-07-31 13:21:19 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(Message::EntryDelete(id), nullptr, nullptr);
|
2015-07-31 13:21:19 -07:00
|
|
|
}
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-13 10:11:29 -07:00
|
|
|
template <typename F>
|
|
|
|
|
void Storage::DeleteAllEntriesImpl(bool local, F should_delete) {
|
2016-06-17 22:33:02 -07:00
|
|
|
for (auto& i : m_entries) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = i.getValue();
|
2017-10-02 13:06:39 -07:00
|
|
|
if (entry->value && should_delete(entry)) {
|
2016-06-17 22:33:02 -07:00
|
|
|
// notify it's being deleted
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, i.getKey(), entry->value,
|
|
|
|
|
NT_NOTIFY_DELETE | (local ? NT_NOTIFY_LOCAL : 0));
|
2016-06-17 22:33:02 -07:00
|
|
|
// remove it from idmap
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (entry->id < m_idmap.size()) m_idmap[entry->id] = nullptr;
|
|
|
|
|
entry->id = 0xffff;
|
2017-08-13 10:11:29 -07:00
|
|
|
entry->local_write = false;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
entry->value.reset();
|
|
|
|
|
continue;
|
2016-06-17 22:33:02 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-13 10:11:29 -07:00
|
|
|
void Storage::DeleteAllEntriesImpl(bool local) {
|
|
|
|
|
// only delete non-persistent values
|
|
|
|
|
DeleteAllEntriesImpl(local,
|
|
|
|
|
[](Entry* entry) { return !entry->IsPersistent(); });
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 01:29:51 -07:00
|
|
|
void Storage::DeleteAllEntries() {
|
2015-07-31 13:21:19 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
2015-07-19 18:10:26 -07:00
|
|
|
if (m_entries.empty()) return;
|
2015-07-31 13:21:19 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
DeleteAllEntriesImpl(true);
|
2015-10-08 00:04:38 -07:00
|
|
|
|
|
|
|
|
// generate message
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!m_dispatcher) return;
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
2015-10-08 00:04:38 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(Message::ClearEntries(), nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-02 13:06:39 -07:00
|
|
|
Storage::Entry* Storage::GetOrNew(StringRef name) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto& entry = m_entries[name];
|
|
|
|
|
if (!entry) {
|
|
|
|
|
m_localmap.emplace_back(new Entry(name));
|
|
|
|
|
entry = m_localmap.back().get();
|
|
|
|
|
entry->local_id = m_localmap.size() - 1;
|
|
|
|
|
}
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int Storage::GetEntry(StringRef name) {
|
|
|
|
|
if (name.empty()) return UINT_MAX;
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
return GetOrNew(name)->local_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<unsigned int> Storage::GetEntries(StringRef prefix,
|
|
|
|
|
unsigned int types) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
std::vector<unsigned int> ids;
|
|
|
|
|
for (auto& i : m_entries) {
|
|
|
|
|
Entry* entry = i.getValue();
|
2017-10-02 13:06:39 -07:00
|
|
|
auto value = entry->value.get();
|
|
|
|
|
if (!value || !i.getKey().startswith(prefix)) continue;
|
|
|
|
|
if (types != 0 && (types & value->type()) == 0) continue;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
ids.push_back(entry->local_id);
|
|
|
|
|
}
|
|
|
|
|
return ids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntryInfo Storage::GetEntryInfo(int inst, unsigned int local_id) const {
|
|
|
|
|
EntryInfo info;
|
|
|
|
|
info.entry = 0;
|
|
|
|
|
info.type = NT_UNASSIGNED;
|
|
|
|
|
info.flags = 0;
|
|
|
|
|
info.last_change = 0;
|
|
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return info;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
if (!entry->value) return info;
|
|
|
|
|
|
|
|
|
|
info.entry = Handle(inst, local_id, Handle::kEntry);
|
|
|
|
|
info.name = entry->name;
|
|
|
|
|
info.type = entry->value->type();
|
|
|
|
|
info.flags = entry->flags;
|
|
|
|
|
info.last_change = entry->value->last_change();
|
|
|
|
|
return info;
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
std::string Storage::GetEntryName(unsigned int local_id) const {
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return std::string{};
|
|
|
|
|
return m_localmap[local_id]->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NT_Type Storage::GetEntryType(unsigned int local_id) const {
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return NT_UNASSIGNED;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
if (!entry->value) return NT_UNASSIGNED;
|
|
|
|
|
return entry->value->type();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long long Storage::GetEntryLastChange(unsigned int local_id) const {
|
|
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
if (local_id >= m_localmap.size()) return 0;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
if (!entry->value) return 0;
|
|
|
|
|
return entry->value->last_change();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<EntryInfo> Storage::GetEntryInfo(int inst, StringRef prefix,
|
2015-07-18 01:29:51 -07:00
|
|
|
unsigned int types) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
std::vector<EntryInfo> infos;
|
|
|
|
|
for (auto& i : m_entries) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = i.getValue();
|
2017-10-02 13:06:39 -07:00
|
|
|
auto value = entry->value.get();
|
|
|
|
|
if (!value || !i.getKey().startswith(prefix)) continue;
|
2015-07-19 19:42:13 -07:00
|
|
|
if (types != 0 && (types & value->type()) == 0) continue;
|
2015-07-18 01:29:51 -07:00
|
|
|
EntryInfo info;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
info.entry = Handle(inst, entry->local_id, Handle::kEntry);
|
2015-07-18 01:29:51 -07:00
|
|
|
info.name = i.getKey();
|
2015-07-19 16:02:21 -07:00
|
|
|
info.type = value->type();
|
2015-07-31 13:48:33 -07:00
|
|
|
info.flags = entry->flags;
|
2015-07-19 16:02:21 -07:00
|
|
|
info.last_change = value->last_change();
|
2015-07-18 01:29:51 -07:00
|
|
|
infos.push_back(std::move(info));
|
|
|
|
|
}
|
|
|
|
|
return infos;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-30 23:25:45 -07:00
|
|
|
unsigned int Storage::AddListener(
|
|
|
|
|
StringRef prefix,
|
|
|
|
|
std::function<void(const EntryNotification& event)> callback,
|
|
|
|
|
unsigned int flags) const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int uid = m_notifier.Add(callback, prefix, flags);
|
|
|
|
|
// perform immediate notifications
|
|
|
|
|
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0) {
|
|
|
|
|
for (auto& i : m_entries) {
|
|
|
|
|
Entry* entry = i.getValue();
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value || !i.getKey().startswith(prefix)) continue;
|
2017-09-30 23:25:45 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, i.getKey(), entry->value,
|
|
|
|
|
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW, uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int Storage::AddListener(
|
|
|
|
|
unsigned int local_id,
|
|
|
|
|
std::function<void(const EntryNotification& event)> callback,
|
|
|
|
|
unsigned int flags) const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int uid = m_notifier.Add(callback, local_id, flags);
|
|
|
|
|
// perform immediate notifications
|
|
|
|
|
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0 &&
|
|
|
|
|
local_id < m_localmap.size()) {
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
if (entry->value) {
|
|
|
|
|
m_notifier.NotifyEntry(local_id, entry->name, entry->value,
|
|
|
|
|
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW, uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int Storage::AddPolledListener(unsigned int poller, StringRef prefix,
|
|
|
|
|
unsigned int flags) const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int uid = m_notifier.AddPolled(poller, prefix, flags);
|
|
|
|
|
// perform immediate notifications
|
|
|
|
|
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0) {
|
|
|
|
|
for (auto& i : m_entries) {
|
|
|
|
|
if (!i.getKey().startswith(prefix)) continue;
|
|
|
|
|
Entry* entry = i.getValue();
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value) continue;
|
2017-09-30 23:25:45 -07:00
|
|
|
m_notifier.NotifyEntry(entry->local_id, i.getKey(), entry->value,
|
|
|
|
|
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW, uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int Storage::AddPolledListener(unsigned int poller,
|
|
|
|
|
unsigned int local_id,
|
|
|
|
|
unsigned int flags) const {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
unsigned int uid = m_notifier.AddPolled(poller, local_id, flags);
|
|
|
|
|
// perform immediate notifications
|
|
|
|
|
if ((flags & NT_NOTIFY_IMMEDIATE) != 0 && (flags & NT_NOTIFY_NEW) != 0 &&
|
|
|
|
|
local_id < m_localmap.size()) {
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
|
|
|
|
// if no value, don't notify
|
|
|
|
|
if (entry->value) {
|
|
|
|
|
m_notifier.NotifyEntry(local_id, entry->name, entry->value,
|
|
|
|
|
NT_NOTIFY_IMMEDIATE | NT_NOTIFY_NEW, uid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 19:09:25 -07:00
|
|
|
bool Storage::GetPersistentEntries(
|
|
|
|
|
bool periodic,
|
|
|
|
|
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
|
|
|
|
|
const {
|
2015-07-18 01:29:51 -07:00
|
|
|
// copy values out of storage as quickly as possible so lock isn't held
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
2015-08-19 19:09:25 -07:00
|
|
|
// for periodic, don't re-save unless something has changed
|
|
|
|
|
if (periodic && !m_persistent_dirty) return false;
|
|
|
|
|
m_persistent_dirty = false;
|
|
|
|
|
entries->reserve(m_entries.size());
|
2015-07-18 01:29:51 -07:00
|
|
|
for (auto& i : m_entries) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
Entry* entry = i.getValue();
|
2015-07-18 01:29:51 -07:00
|
|
|
// only write persistent-flagged values
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value || !entry->IsPersistent()) continue;
|
2015-08-19 19:09:25 -07:00
|
|
|
entries->emplace_back(i.getKey(), entry->value);
|
2015-07-18 01:29:51 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-01 09:13:43 -07:00
|
|
|
// sort in name order
|
|
|
|
|
std::sort(entries->begin(), entries->end(),
|
|
|
|
|
[](const std::pair<std::string, std::shared_ptr<Value>>& a,
|
|
|
|
|
const std::pair<std::string, std::shared_ptr<Value>>& b) {
|
|
|
|
|
return a.first < b.first;
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Storage::GetEntries(
|
|
|
|
|
StringRef prefix,
|
|
|
|
|
std::vector<std::pair<std::string, std::shared_ptr<Value>>>* entries)
|
|
|
|
|
const {
|
|
|
|
|
// copy values out of storage as quickly as possible so lock isn't held
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
entries->reserve(m_entries.size());
|
|
|
|
|
for (auto& i : m_entries) {
|
|
|
|
|
Entry* entry = i.getValue();
|
|
|
|
|
// only write values with given prefix
|
2017-10-02 13:06:39 -07:00
|
|
|
if (!entry->value || !i.getKey().startswith(prefix)) continue;
|
2017-10-01 09:13:43 -07:00
|
|
|
entries->emplace_back(i.getKey(), entry->value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 21:10:20 -07:00
|
|
|
// sort in name order
|
2015-08-19 19:09:25 -07:00
|
|
|
std::sort(entries->begin(), entries->end(),
|
|
|
|
|
[](const std::pair<std::string, std::shared_ptr<Value>>& a,
|
|
|
|
|
const std::pair<std::string, std::shared_ptr<Value>>& b) {
|
|
|
|
|
return a.first < b.first;
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-07-19 21:10:20 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
void Storage::CreateRpc(unsigned int local_id, StringRef def,
|
|
|
|
|
unsigned int rpc_uid) {
|
2015-08-13 13:12:15 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (local_id >= m_localmap.size()) return;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
2015-08-13 13:12:15 -07:00
|
|
|
|
|
|
|
|
auto old_value = entry->value;
|
|
|
|
|
auto value = Value::MakeRpc(def);
|
|
|
|
|
entry->value = value;
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
// set up the RPC info
|
|
|
|
|
entry->rpc_uid = rpc_uid;
|
2015-08-13 13:12:15 -07:00
|
|
|
|
|
|
|
|
if (old_value && *old_value == *value) return;
|
|
|
|
|
|
|
|
|
|
// assign an id if it doesn't have one
|
|
|
|
|
if (entry->id == 0xffff) {
|
|
|
|
|
unsigned int id = m_idmap.size();
|
|
|
|
|
entry->id = id;
|
|
|
|
|
m_idmap.push_back(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// generate message
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!m_dispatcher) return;
|
|
|
|
|
auto dispatcher = m_dispatcher;
|
2015-08-13 13:12:15 -07:00
|
|
|
if (!old_value || old_value->type() != value->type()) {
|
|
|
|
|
++entry->seq_num;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto msg = Message::EntryAssign(
|
|
|
|
|
entry->name, entry->id, entry->seq_num.value(), value, entry->flags);
|
2015-08-13 13:12:15 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, nullptr);
|
2015-08-13 13:12:15 -07:00
|
|
|
} else {
|
|
|
|
|
++entry->seq_num;
|
|
|
|
|
auto msg = Message::EntryUpdate(entry->id, entry->seq_num.value(), value);
|
|
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, nullptr);
|
2015-08-13 13:12:15 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
unsigned int Storage::CallRpc(unsigned int local_id, StringRef params) {
|
2015-08-13 13:12:15 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (local_id >= m_localmap.size()) return 0;
|
|
|
|
|
Entry* entry = m_localmap[local_id].get();
|
2015-08-13 13:12:15 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!entry->value || !entry->value->IsRpc()) return 0;
|
2015-08-13 13:12:15 -07:00
|
|
|
|
|
|
|
|
++entry->rpc_call_uid;
|
|
|
|
|
if (entry->rpc_call_uid > 0xffff) entry->rpc_call_uid = 0;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
unsigned int call_uid = entry->rpc_call_uid;
|
|
|
|
|
|
|
|
|
|
auto msg = Message::ExecuteRpc(entry->id, call_uid, params);
|
|
|
|
|
StringRef name{entry->name};
|
|
|
|
|
|
2015-08-13 13:12:15 -07:00
|
|
|
if (m_server) {
|
|
|
|
|
// RPCs are unlikely to be used locally on the server, but handle it
|
|
|
|
|
// gracefully anyway.
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto rpc_uid = entry->rpc_uid;
|
2015-08-13 13:12:15 -07:00
|
|
|
lock.unlock();
|
2016-10-03 10:04:30 -07:00
|
|
|
ConnectionInfo conn_info;
|
|
|
|
|
conn_info.remote_id = "Server";
|
|
|
|
|
conn_info.remote_ip = "localhost";
|
|
|
|
|
conn_info.remote_port = 0;
|
|
|
|
|
conn_info.last_update = wpi::Now();
|
|
|
|
|
conn_info.protocol_version = 0x0300;
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
unsigned int call_uid = msg->seq_num_uid();
|
|
|
|
|
m_rpc_server.ProcessRpc(local_id, call_uid, name, msg->str(), conn_info,
|
|
|
|
|
[=](StringRef result) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
|
|
m_rpc_results.insert(std::make_pair(
|
|
|
|
|
RpcIdPair{local_id, call_uid}, result));
|
|
|
|
|
m_rpc_results_cond.notify_all();
|
|
|
|
|
},
|
|
|
|
|
rpc_uid);
|
2015-08-13 13:12:15 -07:00
|
|
|
} else {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto dispatcher = m_dispatcher;
|
2015-08-13 13:12:15 -07:00
|
|
|
lock.unlock();
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
dispatcher->QueueOutgoing(msg, nullptr, nullptr);
|
2015-08-13 13:12:15 -07:00
|
|
|
}
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
return call_uid;
|
2015-08-13 13:12:15 -07:00
|
|
|
}
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
bool Storage::GetRpcResult(unsigned int local_id, unsigned int call_uid,
|
2016-08-15 20:24:07 -07:00
|
|
|
std::string* result) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
bool timed_out = false;
|
|
|
|
|
return GetRpcResult(local_id, call_uid, result, -1, &timed_out);
|
2016-08-15 20:24:07 -07:00
|
|
|
}
|
|
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
bool Storage::GetRpcResult(unsigned int local_id, unsigned int call_uid,
|
|
|
|
|
std::string* result, double timeout,
|
|
|
|
|
bool* timed_out) {
|
2015-08-13 13:12:15 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
|
|
|
|
|
RpcIdPair call_pair{local_id, call_uid};
|
|
|
|
|
|
2016-08-16 23:31:02 -07:00
|
|
|
// only allow one blocking call per rpc call uid
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (!m_rpc_blocking_calls.insert(call_pair).second) return false;
|
|
|
|
|
|
2016-09-30 12:41:52 -07:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1900
|
2016-11-03 21:03:45 -07:00
|
|
|
auto timeout_time = std::chrono::steady_clock::now() +
|
|
|
|
|
std::chrono::duration<int64_t, std::nano>(
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
static_cast<int64_t>(timeout * 1e9));
|
2016-09-30 12:41:52 -07:00
|
|
|
#else
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto timeout_time =
|
|
|
|
|
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
2016-09-30 12:41:52 -07:00
|
|
|
#endif
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
*timed_out = false;
|
2015-08-13 13:12:15 -07:00
|
|
|
for (;;) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto i = m_rpc_results.find(call_pair);
|
2015-08-13 13:12:15 -07:00
|
|
|
if (i == m_rpc_results.end()) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (timeout == 0 || m_terminating) {
|
|
|
|
|
m_rpc_blocking_calls.erase(call_pair);
|
2016-08-19 21:48:30 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (timeout < 0) {
|
2016-08-15 20:24:07 -07:00
|
|
|
m_rpc_results_cond.wait(lock);
|
|
|
|
|
} else {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
auto cond_timed_out = m_rpc_results_cond.wait_until(lock, timeout_time);
|
|
|
|
|
if (cond_timed_out == std::cv_status::timeout) {
|
|
|
|
|
m_rpc_blocking_calls.erase(call_pair);
|
|
|
|
|
*timed_out = true;
|
2016-08-16 23:31:02 -07:00
|
|
|
return false;
|
2016-08-15 20:24:07 -07:00
|
|
|
}
|
2016-09-02 19:28:59 -07:00
|
|
|
}
|
|
|
|
|
// if element does not exist, we have been canceled
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
if (m_rpc_blocking_calls.count(call_pair) == 0) {
|
2016-09-02 19:28:59 -07:00
|
|
|
return false;
|
2016-08-15 20:24:07 -07:00
|
|
|
}
|
2016-08-15 22:46:49 -07:00
|
|
|
if (m_terminating) {
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_rpc_blocking_calls.erase(call_pair);
|
2016-08-15 22:46:49 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-08-13 13:12:15 -07:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result->swap(i->getSecond());
|
2016-08-15 22:46:49 -07:00
|
|
|
// safe to erase even if id does not exist
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_rpc_blocking_calls.erase(call_pair);
|
2015-08-13 13:12:15 -07:00
|
|
|
m_rpc_results.erase(i);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-16 23:31:45 -07:00
|
|
|
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
void Storage::CancelRpcResult(unsigned int local_id, unsigned int call_uid) {
|
2016-08-16 23:31:45 -07:00
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
|
|
// safe to erase even if id does not exist
|
Implement independent instances.
Previously, most of the classes were implemented as singletons so only one
instance was possible.
This change adds an instance handle-based API. In Java, this API is located
in a different package than the old API (edu.wpi.first.networktables).
Backwards compatibility with ITable and the old NetworkTable API is largely
maintained, but a handful of classes have moved to the new package in Java
(ConnectionInfo and PersistentException), and the old JNI has been completed
replaced.
Also:
- Move SetTeam implementation to Dispatcher.
- Consistently pass time through Java and C++ Value API.
- Rename nt_Value.h to NetworkTableValue.h for consistency with Java.
- Improve documentation
- Make C++ and Java APIs more consistent
- Document RPC functions and support RPC in Java.
- Add polling features for entry and connection listeners and use them to
move callback threads to Java level.
- Remove thread start and stop hooks (as polling is available).
- Make Notifiers, RpcServer, Dispatcher, and Storage mockable.
- Set NOTIFY_NEW on immediate entry notifications.
- Make GetTable("/") and GetTable("") equivalent.
- Generate local notification for flags update when loading persistent file.
And many unit test updates/changes:
- Use InitGoogleMock instead of InitGoogleTest in test main.
- Move test printers to TestPrinter.h/cpp.
- Provide printers for StringRef, EntryNotifier, and Handle.
- StorageTest: Check notifications.
- Add entry notifier unit tests.
- Storage: Add test for incoming entry assignment.
- Update connection listener tests.
- Add entry listener unit tests.
Fixes #11, #140, #189, #190, #192, #193, #221
2017-04-23 10:26:17 -07:00
|
|
|
m_rpc_blocking_calls.erase(RpcIdPair{local_id, call_uid});
|
2016-08-16 23:31:45 -07:00
|
|
|
m_rpc_results_cond.notify_all();
|
|
|
|
|
}
|