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
This commit is contained in:
Peter Johnson
2017-04-23 10:26:17 -07:00
parent 8125a179fb
commit 5ab20bb27c
118 changed files with 15638 additions and 4640 deletions

View File

@@ -17,22 +17,26 @@
using namespace nt;
ATOMIC_STATIC_INIT(DsClient)
class DsClient::Thread : public wpi::SafeThread {
public:
Thread(unsigned int port) : m_port(port) {}
Thread(Dispatcher& dispatcher, wpi::Logger& logger, unsigned int port)
: m_dispatcher(dispatcher), m_logger(logger), m_port(port) {}
void Main();
Dispatcher& m_dispatcher;
wpi::Logger& m_logger;
unsigned int m_port;
std::unique_ptr<wpi::NetworkStream> m_stream;
};
DsClient::DsClient(Dispatcher& dispatcher, wpi::Logger& logger)
: m_dispatcher(dispatcher), m_logger(logger) {}
void DsClient::Start(unsigned int port) {
auto thr = m_owner.GetThread();
if (!thr)
m_owner.Start(new Thread(port));
m_owner.Start(new Thread(m_dispatcher, m_logger, port));
else
thr->m_port = port;
}
@@ -122,7 +126,7 @@ void DsClient::Thread::Main() {
// If zero, clear the server override
if (ip == 0) {
Dispatcher::GetInstance().ClearServerOverride();
m_dispatcher.ClearServerOverride();
oldip = 0;
continue;
}
@@ -137,14 +141,14 @@ void DsClient::Thread::Main() {
os << ((ip >> 24) & 0xff) << "." << ((ip >> 16) & 0xff) << "."
<< ((ip >> 8) & 0xff) << "." << (ip & 0xff);
INFO("client: DS overriding server IP to " << os.str());
Dispatcher::GetInstance().SetServerOverride(json.c_str(), port);
m_dispatcher.SetServerOverride(json.c_str(), port);
}
// We disconnected from the DS, clear the server override
Dispatcher::GetInstance().ClearServerOverride();
m_dispatcher.ClearServerOverride();
oldip = 0;
}
done:
Dispatcher::GetInstance().ClearServerOverride();
m_dispatcher.ClearServerOverride();
}