[ntcore] Add DataLog support

This commit is contained in:
Peter Johnson
2021-12-12 20:09:57 -08:00
parent 9b500df0d9
commit 02a804f1c5
16 changed files with 654 additions and 20 deletions

View File

@@ -505,6 +505,52 @@ class NetworkTableInstance final {
/** @} */
/**
* @{
* @name Data Logger Functions
*/
/**
* Starts logging entry changes to a DataLog.
*
* @param log data log object; lifetime must extend until StopEntryDataLog is
* called or the instance is destroyed
* @param prefix only store entries with names that start with this prefix;
* the prefix is not included in the data log entry name
* @param logPrefix prefix to add to data log entry names
* @return Data logger handle
*/
NT_DataLogger StartEntryDataLog(wpi::log::DataLog& log,
std::string_view prefix,
std::string_view logPrefix);
/**
* Stops logging entry changes to a DataLog.
*
* @param logger data logger handle
*/
static void StopEntryDataLog(NT_DataLogger logger);
/**
* Starts logging connection changes to a DataLog.
*
* @param log data log object; lifetime must extend until
* StopConnectionDataLog is called or the instance is destroyed
* @param name data log entry name
* @return Data logger handle
*/
NT_ConnectionDataLogger StartConnectionDataLog(wpi::log::DataLog& log,
std::string_view name);
/**
* Stops logging connection changes to a DataLog.
*
* @param logger data logger handle
*/
static void StopConnectionDataLog(NT_ConnectionDataLogger logger);
/** @} */
/**
* @{
* @name Logger Functions

View File

@@ -10,6 +10,7 @@
#include <vector>
#include "networktables/NetworkTableInstance.h"
#include "ntcore_cpp.h"
namespace nt {
@@ -192,6 +193,26 @@ inline const char* NetworkTableInstance::LoadEntries(
return ::nt::LoadEntries(m_handle, filename, prefix, warn);
}
inline NT_DataLogger NetworkTableInstance::StartEntryDataLog(
wpi::log::DataLog& log, std::string_view prefix,
std::string_view logPrefix) {
return ::nt::StartEntryDataLog(m_handle, log, prefix, logPrefix);
}
inline void NetworkTableInstance::StopEntryDataLog(NT_DataLogger logger) {
::nt::StopEntryDataLog(logger);
}
inline NT_ConnectionDataLogger NetworkTableInstance::StartConnectionDataLog(
wpi::log::DataLog& log, std::string_view name) {
return ::nt::StartConnectionDataLog(m_handle, log, name);
}
inline void NetworkTableInstance::StopConnectionDataLog(
NT_ConnectionDataLogger logger) {
::nt::StopConnectionDataLog(logger);
}
inline NT_Logger NetworkTableInstance::AddLogger(
std::function<void(const LogMessage& msg)> func, unsigned int min_level,
unsigned int max_level) {

View File

@@ -29,8 +29,10 @@ extern "C" {
typedef int NT_Bool;
typedef unsigned int NT_Handle;
typedef NT_Handle NT_ConnectionDataLogger;
typedef NT_Handle NT_ConnectionListener;
typedef NT_Handle NT_ConnectionListenerPoller;
typedef NT_Handle NT_DataLogger;
typedef NT_Handle NT_Entry;
typedef NT_Handle NT_EntryListener;
typedef NT_Handle NT_EntryListenerPoller;

View File

@@ -20,6 +20,10 @@
#include "networktables/NetworkTableValue.h"
namespace wpi::log {
class DataLog;
} // namespace wpi::log
/** NetworkTables (ntcore) namespace */
namespace nt {
@@ -1233,6 +1237,55 @@ uint64_t Now();
/** @} */
/**
* @defgroup ntcore_data_logger_func Data Logger Functions
* @{
*/
/**
* Starts logging entry changes to a DataLog.
*
* @param inst instance handle
* @param log data log object; lifetime must extend until StopEntryDataLog is
* called or the instance is destroyed
* @param prefix only store entries with names that start with this prefix;
* the prefix is not included in the data log entry name
* @param logPrefix prefix to add to data log entry names
* @return Data logger handle
*/
NT_DataLogger StartEntryDataLog(NT_Inst inst, wpi::log::DataLog& log,
std::string_view prefix,
std::string_view logPrefix);
/**
* Stops logging entry changes to a DataLog.
*
* @param logger data logger handle
*/
void StopEntryDataLog(NT_DataLogger logger);
/**
* Starts logging connection changes to a DataLog.
*
* @param inst instance handle
* @param log data log object; lifetime must extend until StopConnectionDataLog
* is called or the instance is destroyed
* @param name data log entry name
* @return Data logger handle
*/
NT_ConnectionDataLogger StartConnectionDataLog(NT_Inst inst,
wpi::log::DataLog& log,
std::string_view name);
/**
* Stops logging connection changes to a DataLog.
*
* @param logger data logger handle
*/
void StopConnectionDataLog(NT_ConnectionDataLogger logger);
/** @} */
/**
* @defgroup ntcore_logger_func Logger Functions
* @{