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
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-05-13 17:09:56 -07:00
|
|
|
/* Copyright (c) 2015-2018 FIRST. All Rights Reserved. */
|
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
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2017-08-19 23:08:27 -07:00
|
|
|
#ifndef NTCORE_LOGGERIMPL_H_
|
|
|
|
|
#define NTCORE_LOGGERIMPL_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 "CallbackManager.h"
|
|
|
|
|
#include "Handle.h"
|
2017-08-19 23:08:27 -07:00
|
|
|
#include "ntcore_cpp.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
|
|
|
|
|
|
|
|
namespace nt {
|
|
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
|
|
|
|
|
struct LoggerListenerData
|
|
|
|
|
: public ListenerData<std::function<void(const LogMessage& msg)>> {
|
|
|
|
|
LoggerListenerData() = default;
|
|
|
|
|
LoggerListenerData(std::function<void(const LogMessage& msg)> callback_,
|
|
|
|
|
unsigned int min_level_, unsigned int max_level_)
|
|
|
|
|
: ListenerData(callback_), min_level(min_level_), max_level(max_level_) {}
|
|
|
|
|
LoggerListenerData(unsigned int poller_uid_, unsigned int min_level_,
|
|
|
|
|
unsigned int max_level_)
|
|
|
|
|
: ListenerData(poller_uid_),
|
|
|
|
|
min_level(min_level_),
|
|
|
|
|
max_level(max_level_) {}
|
|
|
|
|
|
|
|
|
|
unsigned int min_level;
|
|
|
|
|
unsigned int max_level;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LoggerThread
|
|
|
|
|
: public CallbackThread<LoggerThread, LogMessage, LoggerListenerData> {
|
|
|
|
|
public:
|
2017-08-19 23:08:27 -07:00
|
|
|
explicit LoggerThread(int inst) : m_inst(inst) {}
|
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 Matches(const LoggerListenerData& listener, const LogMessage& data) {
|
|
|
|
|
return data.level >= listener.min_level && data.level <= listener.max_level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetListener(LogMessage* data, unsigned int listener_uid) {
|
|
|
|
|
data->logger = Handle(m_inst, listener_uid, Handle::kLogger).handle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DoCallback(std::function<void(const LogMessage& msg)> callback,
|
|
|
|
|
const LogMessage& data) {
|
|
|
|
|
callback(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int m_inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
|
|
|
|
|
|
class LoggerImpl : public CallbackManager<LoggerImpl, impl::LoggerThread> {
|
|
|
|
|
friend class LoggerTest;
|
|
|
|
|
friend class CallbackManager<LoggerImpl, impl::LoggerThread>;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit LoggerImpl(int inst);
|
|
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
|
|
|
|
|
|
unsigned int Add(std::function<void(const LogMessage& msg)> callback,
|
|
|
|
|
unsigned int min_level, unsigned int max_level);
|
|
|
|
|
unsigned int AddPolled(unsigned int poller_uid, unsigned int min_level,
|
|
|
|
|
unsigned int max_level);
|
|
|
|
|
|
|
|
|
|
unsigned int GetMinLevel();
|
|
|
|
|
|
|
|
|
|
void Log(unsigned int level, const char* file, unsigned int line,
|
|
|
|
|
const char* msg);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace nt
|
|
|
|
|
|
2017-08-19 23:08:27 -07:00
|
|
|
#endif // NTCORE_LOGGERIMPL_H_
|