24class BooleanArrayTopic;
26class DoubleArrayTopic;
30class IntegerArrayTopic;
33template <wpi::ProtobufSerializable T>
36class StringArrayTopic;
38template <
typename T,
typename... I>
40class StructArrayTopic;
41template <
typename T,
typename... I>
124 explicit operator bool()
const {
return m_handle != 0; }
150 if (inst.m_handle != 0) {
265 template <wpi::ProtobufSerializable T>
277 template <
typename T,
typename... I>
290 template <
typename T,
typename... I>
306 return {handles.begin(), handles.end()};
321 return {handles.begin(), handles.end()};
336 std::vector<Topic>
GetTopics(std::string_view prefix,
unsigned int types) {
338 return {handles.begin(), handles.end()};
353 std::span<std::string_view> types) {
355 return {handles.begin(), handles.end()};
366 return ::nt::GetTopicInfo(m_handle,
"", 0);
381 return ::nt::GetTopicInfo(m_handle, prefix, 0);
398 unsigned int types) {
399 return ::nt::GetTopicInfo(m_handle, prefix, types);
415 std::span<std::string_view> types) {
416 return ::nt::GetTopicInfo(m_handle, prefix, types);
435 std::shared_ptr<NetworkTable>
GetTable(std::string_view key)
const;
462 return ::nt::WaitForListenerQueue(m_handle, timeout);
476 return ::nt::AddListener(
479 std::move(callback));
495 return ::nt::AddListener(
498 std::move(callback));
576 return ::nt::AddListener(m_handle, prefixes, eventMask,
577 std::move(listener));
617 void StartServer(std::string_view persist_filename =
"networktables.json",
618 const char* listen_address =
"",
660 void SetServer(std::string_view server_name,
unsigned int port = 0) {
671 std::span<
const std::pair<std::string_view, unsigned int>> servers) {
682 void SetServer(std::span<const std::string_view> servers,
683 unsigned int port = 0);
739 return ::nt::GetConnections(m_handle);
761 return ::nt::GetServerTimeOffset(m_handle);
782 std::string_view prefix,
783 std::string_view logPrefix) {
784 return ::nt::StartEntryDataLog(m_handle, log, prefix, logPrefix);
805 std::string_view name) {
806 return ::nt::StartConnectionDataLog(m_handle, log, name);
839 return ::nt::AddLogger(m_handle, minLevel, maxLevel, std::move(func));
859 return ::nt::HasSchema(m_handle, name);
876 void AddSchema(std::string_view name, std::string_view type,
877 std::span<const uint8_t> schema) {
895 void AddSchema(std::string_view name, std::string_view type,
896 std::string_view schema) {
902#pragma clang diagnostic push
903#pragma clang diagnostic ignored "-Wunused-lambda-capture"
913 template <wpi::ProtobufSerializable T>
916 [
this](
auto typeString) {
return HasSchema(typeString); },
917 [
this](
auto typeString,
auto schema) {
918 AddSchema(typeString,
"proto:FileDescriptorProto", schema);
929 template <
typename T,
typename... I>
933 [
this](
auto typeString,
auto schema) {
934 AddSchema(typeString,
"structschema", schema);
940#pragma clang diagnostic pop
NetworkTables BooleanArray topic.
Definition BooleanArrayTopic.h:296
NetworkTables Boolean topic.
Definition BooleanTopic.h:235
NetworkTables DoubleArray topic.
Definition DoubleArrayTopic.h:296
NetworkTables Double topic.
Definition DoubleTopic.h:235
NetworkTables FloatArray topic.
Definition FloatArrayTopic.h:296
NetworkTables Float topic.
Definition FloatTopic.h:235
NetworkTables IntegerArray topic.
Definition IntegerArrayTopic.h:296
NetworkTables Integer topic.
Definition IntegerTopic.h:235
Subscribe to multiple topics based on one or more topic name prefixes.
Definition MultiSubscriber.h:20
NetworkTables Entry.
Definition NetworkTableEntry.h:31
NetworkTables Instance.
Definition NetworkTableInstance.h:68
void StartClient4(std::string_view identity)
Starts a NT4 client.
Definition NetworkTableInstance.h:645
static NetworkTableInstance Create()
Create an instance.
Definition NetworkTableInstance.h:140
IntegerArrayTopic GetIntegerArrayTopic(std::string_view name) const
Gets an integer array topic.
NetworkMode
Client/server mode flag values (as returned by GetNetworkMode()).
Definition NetworkTableInstance.h:74
@ kNetModeClient4
Definition NetworkTableInstance.h:78
@ kNetModeServer
Definition NetworkTableInstance.h:76
@ kNetModeLocal
Definition NetworkTableInstance.h:79
@ kNetModeClient3
Definition NetworkTableInstance.h:77
@ kNetModeNone
Definition NetworkTableInstance.h:75
BooleanTopic GetBooleanTopic(std::string_view name) const
Gets a boolean topic.
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix, std::span< std::string_view > types)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:414
FloatTopic GetFloatTopic(std::string_view name) const
Gets a float topic.
std::vector< Topic > GetTopics(std::string_view prefix, unsigned int types)
Get Published Topics.
Definition NetworkTableInstance.h:336
bool IsConnected() const
Return whether or not the instance is connected to another node.
Definition NetworkTableInstance.h:747
NT_Listener AddListener(const NetworkTableEntry &entry, int eventMask, ListenerCallback listener)
Add a listener for changes on an entry.
NT_Listener AddConnectionListener(bool immediate_notify, ListenerCallback callback) const
Add a connection listener.
Definition NetworkTableInstance.h:474
void StartLocal()
Starts local-only operation.
Definition NetworkTableInstance.h:599
StructTopic< T, I... > GetStructTopic(std::string_view name, I... info) const
Gets a raw struct serialized value topic.
Definition NetworkTableInstance.h:279
bool WaitForListenerQueue(double timeout)
Wait for the listener queue to be empty.
Definition NetworkTableInstance.h:461
DoubleArrayTopic GetDoubleArrayTopic(std::string_view name) const
Gets a double array topic.
StructArrayTopic< T, I... > GetStructArrayTopic(std::string_view name, I... info) const
Gets a raw struct serialized array topic.
Definition NetworkTableInstance.h:292
NT_Listener AddListener(std::span< const std::string_view > prefixes, int eventMask, ListenerCallback listener)
Add a listener for changes to topics with names that start with any of the given prefixes.
Definition NetworkTableInstance.h:574
NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel, ListenerCallback func)
Add logger callback function.
Definition NetworkTableInstance.h:837
void StartDSClient(unsigned int port=0)
Starts requesting server address from Driver Station.
Definition NetworkTableInstance.h:709
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:380
NT_Listener AddListener(MultiSubscriber &subscriber, int eventMask, ListenerCallback listener)
Add a listener for changes on a subscriber.
void FlushLocal() const
Flushes all updated values immediately to the local client/server.
Definition NetworkTableInstance.h:722
StringArrayTopic GetStringArrayTopic(std::string_view name) const
Gets a string array topic.
FloatArrayTopic GetFloatArrayTopic(std::string_view name) const
Gets a float array topic.
NT_ConnectionDataLogger StartConnectionDataLog(wpi::log::DataLog &log, std::string_view name)
Starts logging connection changes to a DataLog.
Definition NetworkTableInstance.h:804
ProtobufTopic< T > GetProtobufTopic(std::string_view name) const
Gets a protobuf serialized value topic.
Definition NetworkTableInstance.h:266
unsigned int GetNetworkMode() const
Get the current network mode.
Definition NetworkTableInstance.h:592
NT_Inst GetHandle() const
Gets the native handle for the entry.
Definition NetworkTableInstance.h:161
static constexpr unsigned int kDefaultPort4
The default port that network tables operates on for NT4.
Definition NetworkTableInstance.h:105
NT_DataLogger StartEntryDataLog(wpi::log::DataLog &log, std::string_view prefix, std::string_view logPrefix)
Starts logging entry changes to a DataLog.
Definition NetworkTableInstance.h:781
bool HasSchema(std::string_view name) const
Returns whether there is a data schema already registered with the given name.
Definition NetworkTableInstance.h:858
NetworkTableEntry GetEntry(std::string_view name)
Gets the entry for a key.
Definition NetworkTableInstance.h:425
NT_Listener AddListener(Subscriber &subscriber, unsigned int eventMask, ListenerCallback listener)
Add a listener for changes on a subscriber.
BooleanArrayTopic GetBooleanArrayTopic(std::string_view name) const
Gets a boolean array topic.
StringTopic GetStringTopic(std::string_view name) const
Gets a string topic.
void SetServer(std::string_view server_name, unsigned int port=0)
Sets server address and port for client (without restarting client).
Definition NetworkTableInstance.h:660
static constexpr unsigned int kDefaultPort3
The default port that network tables operates on for NT3.
Definition NetworkTableInstance.h:100
static void RemoveListener(NT_Listener listener)
Remove a listener.
Definition NetworkTableInstance.h:447
NetworkTableInstance() noexcept=default
Construct invalid instance.
void StopServer()
Stops the server if it is running.
Definition NetworkTableInstance.h:627
void AddStructSchema(const I &... info)
Registers a struct schema.
Definition NetworkTableInstance.h:931
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix, unsigned int types)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:397
void SetServerTeam(unsigned int team, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
Definition NetworkTableInstance.h:692
bool operator==(const NetworkTableInstance &) const =default
Equality operator.
void StopDSClient()
Stops requesting server address from Driver Station.
Definition NetworkTableInstance.h:716
static void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
Definition NetworkTableInstance.h:814
LogLevel
Logging levels (as used by SetLogger()).
Definition NetworkTableInstance.h:85
@ kLogInfo
Definition NetworkTableInstance.h:89
@ kLogError
Definition NetworkTableInstance.h:87
@ kLogWarning
Definition NetworkTableInstance.h:88
@ kLogDebug4
Definition NetworkTableInstance.h:94
@ kLogDebug3
Definition NetworkTableInstance.h:93
@ kLogCritical
Definition NetworkTableInstance.h:86
@ kLogDebug
Definition NetworkTableInstance.h:90
@ kLogDebug1
Definition NetworkTableInstance.h:91
@ kLogDebug2
Definition NetworkTableInstance.h:92
void AddSchema(std::string_view name, std::string_view type, std::span< const uint8_t > schema)
Registers a data schema.
Definition NetworkTableInstance.h:876
void Disconnect()
Disconnects the client if it's running and connected.
Definition NetworkTableInstance.h:700
void Flush() const
Flushes all updated values immediately to the network.
Definition NetworkTableInstance.h:730
void AddProtobufSchema(wpi::ProtobufMessage< T > &msg)
Registers a protobuf schema.
Definition NetworkTableInstance.h:914
NT_Listener AddListener(Topic topic, unsigned int eventMask, ListenerCallback listener)
Add a listener for changes on a particular topic.
std::shared_ptr< NetworkTable > GetTable(std::string_view key) const
Gets the table with the specified key.
NT_Listener AddTimeSyncListener(bool immediate_notify, ListenerCallback callback) const
Add a time synchronization listener.
Definition NetworkTableInstance.h:493
RawTopic GetRawTopic(std::string_view name) const
Gets a raw topic.
static void Destroy(NetworkTableInstance &inst)
Destroys an instance (note: this has global effect).
Definition NetworkTableInstance.h:149
std::vector< TopicInfo > GetTopicInfo()
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:365
DoubleTopic GetDoubleTopic(std::string_view name) const
Gets a double topic.
Topic GetTopic(std::string_view name) const
Gets a "generic" (untyped) topic.
void StartServer(std::string_view persist_filename="networktables.json", const char *listen_address="", unsigned int port3=kDefaultPort3, unsigned int port4=kDefaultPort4)
Starts a server using the specified filename, listening address, and port.
Definition NetworkTableInstance.h:617
void StopLocal()
Stops local-only operation.
Definition NetworkTableInstance.h:605
std::vector< ConnectionInfo > GetConnections() const
Get information on the currently established network connections.
Definition NetworkTableInstance.h:738
std::vector< Topic > GetTopics(std::string_view prefix)
Get Published Topics.
Definition NetworkTableInstance.h:319
void StopClient()
Stops the client if it is running.
Definition NetworkTableInstance.h:652
std::optional< int64_t > GetServerTimeOffset() const
Get the time offset between server time and local time.
Definition NetworkTableInstance.h:760
void SetServer(std::span< const std::pair< std::string_view, unsigned int > > servers)
Sets server addresses and ports for client (without restarting client).
Definition NetworkTableInstance.h:670
IntegerTopic GetIntegerTopic(std::string_view name) const
Gets an integer topic.
std::vector< Topic > GetTopics()
Get Published Topics.
Definition NetworkTableInstance.h:304
std::vector< Topic > GetTopics(std::string_view prefix, std::span< std::string_view > types)
Get Published Topics.
Definition NetworkTableInstance.h:352
void SetServer(std::span< const std::string_view > servers, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
static NetworkTableInstance GetDefault()
Get global default instance.
Definition NetworkTableInstance.h:131
static void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
Definition NetworkTableInstance.h:792
void StartClient3(std::string_view identity)
Starts a NT3 client.
Definition NetworkTableInstance.h:635
void AddSchema(std::string_view name, std::string_view type, std::string_view schema)
Registers a data schema.
Definition NetworkTableInstance.h:895
NetworkTables protobuf-encoded value topic.
Definition NetworkTable.h:36
NetworkTables Raw topic.
Definition RawTopic.h:296
NetworkTables StringArray topic.
Definition StringArrayTopic.h:235
NetworkTables String topic.
Definition StringTopic.h:298
NetworkTables struct-encoded value array topic.
Definition NetworkTable.h:42
NetworkTables struct-encoded value topic.
Definition NetworkTable.h:45
NetworkTables subscriber.
Definition Topic.h:321
NetworkTables Topic.
Definition Topic.h:28
Ease of use wrapper to make nanopb streams more opaque to the user.
Definition Protobuf.h:307
void ForEachProtobufDescriptor(function_ref< bool(std::string_view filename)> exists, function_ref< void(std::string_view filename, std::span< const uint8_t > descriptor)> fn)
Loops over all protobuf descriptors including nested/referenced descriptors.
Definition Protobuf.h:383
A data log for high-speed writing of data values.
Definition DataLog.h:70
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.h:69
NT_Handle NT_ConnectionDataLogger
Definition ntcore_c.h:35
NT_Handle NT_Listener
Definition ntcore_c.h:39
#define NT_DEFAULT_PORT3
Default network tables port number (NT3)
Definition ntcore_c.h:47
NT_Handle NT_Inst
Definition ntcore_c.h:38
#define NT_DEFAULT_PORT4
Default network tables port number (NT4)
Definition ntcore_c.h:50
NT_Handle NT_DataLogger
Definition ntcore_c.h:36
@ NT_LOG_DEBUG4
Definition ntcore_c.h:86
@ NT_LOG_WARNING
Definition ntcore_c.h:80
@ NT_LOG_INFO
Definition ntcore_c.h:81
@ NT_LOG_DEBUG2
Definition ntcore_c.h:84
@ NT_LOG_DEBUG
Definition ntcore_c.h:82
@ NT_LOG_CRITICAL
Definition ntcore_c.h:78
@ NT_LOG_ERROR
Definition ntcore_c.h:79
@ NT_LOG_DEBUG3
Definition ntcore_c.h:85
@ NT_LOG_DEBUG1
Definition ntcore_c.h:83
@ NT_NET_MODE_LOCAL
Definition ntcore_c.h:96
@ NT_NET_MODE_CLIENT4
Definition ntcore_c.h:94
@ NT_NET_MODE_CLIENT3
Definition ntcore_c.h:93
@ NT_NET_MODE_SERVER
Definition ntcore_c.h:92
@ NT_NET_MODE_NONE
Definition ntcore_c.h:91
@ NT_EVENT_TIMESYNC
Time synchronized with server.
Definition ntcore_c.h:127
@ NT_EVENT_CONNECTION
Any connection event (connect or disconnect).
Definition ntcore_c.h:109
@ NT_EVENT_IMMEDIATE
Initial listener addition.
Definition ntcore_c.h:103
void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
NT_Inst CreateInstance()
Create an instance.
NT_Inst GetDefaultInstance()
Get default instance.
void DestroyInstance(NT_Inst inst)
Destroy an instance.
std::function< void(const Event &)> ListenerCallback
Definition ntcore_cpp.h:899
void RemoveListener(NT_Listener listener)
Removes a listener.
void StartClient4(NT_Inst inst, std::string_view identity)
Starts a NT4 client.
void Disconnect(NT_Inst inst)
Disconnects the client if it's running and connected.
void StopLocal(NT_Inst inst)
Stops local-only operation.
void StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
void StopServer(NT_Inst inst)
Stops the server if it is running.
void StartLocal(NT_Inst inst)
Starts local-only operation.
void Flush(NT_Inst inst)
Flush to network.
void StartClient3(NT_Inst inst, std::string_view identity)
Starts a NT3 client.
void SetServer(NT_Inst inst, std::string_view server_name, unsigned int port)
Sets server address and port for client (without restarting client).
void StartDSClient(NT_Inst inst, unsigned int port)
Starts requesting server address from Driver Station.
void StopClient(NT_Inst inst)
Stops the client if it is running.
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
void FlushLocal(NT_Inst inst)
Flush local updates.
void StartServer(NT_Inst inst, std::string_view persist_filename, std::string_view listen_address, unsigned int port3, unsigned int port4)
Starts a server using the specified filename, listening address, and port.
void AddSchema(NT_Inst inst, std::string_view name, std::string_view type, std::span< const uint8_t > schema)
Registers a data schema.
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
std::vector< NT_Topic > GetTopics(NT_Inst inst, std::string_view prefix, unsigned int types)
Get Published Topics.
NetworkTables (ntcore) namespace.
Definition ntcore_cpp.h:36
void ForEachStructSchema(std::invocable< std::string_view, std::string_view > auto fn, const I &... info)
Definition Struct.h:424