24class BooleanArrayTopic;
26class DoubleArrayTopic;
30class IntegerArrayTopic;
33template <wpi::ProtobufSerializable T>
36class StringArrayTopic;
38template <
typename T,
typename... I>
40class StructArrayTopic;
41template <
typename T,
typename... I>
118 explicit operator bool()
const {
return m_handle != 0; }
144 if (inst.m_handle != 0) {
259 template <wpi::ProtobufSerializable T>
271 template <
typename T,
typename... I>
284 template <
typename T,
typename... I>
300 return {handles.begin(), handles.end()};
315 return {handles.begin(), handles.end()};
330 std::vector<Topic>
GetTopics(std::string_view prefix,
unsigned int types) {
332 return {handles.begin(), handles.end()};
347 std::span<std::string_view> types) {
349 return {handles.begin(), handles.end()};
360 return ::nt::GetTopicInfo(m_handle,
"", 0);
375 return ::nt::GetTopicInfo(m_handle, prefix, 0);
392 unsigned int types) {
393 return ::nt::GetTopicInfo(m_handle, prefix, types);
409 std::span<std::string_view> types) {
410 return ::nt::GetTopicInfo(m_handle, prefix, types);
429 std::shared_ptr<NetworkTable>
GetTable(std::string_view key)
const;
456 return ::nt::WaitForListenerQueue(m_handle, timeout);
470 return ::nt::AddListener(
473 std::move(callback));
489 return ::nt::AddListener(
492 std::move(callback));
570 return ::nt::AddListener(m_handle, prefixes, eventMask,
571 std::move(listener));
611 void StartServer(std::string_view persist_filename =
"networktables.json",
612 const char* listen_address =
"",
643 void SetServer(std::string_view server_name,
unsigned int port = 0) {
654 std::span<
const std::pair<std::string_view, unsigned int>> servers) {
665 void SetServer(std::span<const std::string_view> servers,
666 unsigned int port = 0);
722 return ::nt::GetConnections(m_handle);
744 return ::nt::GetServerTimeOffset(m_handle);
765 std::string_view prefix,
766 std::string_view logPrefix) {
767 return ::nt::StartEntryDataLog(m_handle, log, prefix, logPrefix);
788 std::string_view name) {
789 return ::nt::StartConnectionDataLog(m_handle, log, name);
822 return ::nt::AddLogger(m_handle, minLevel, maxLevel, std::move(func));
842 return ::nt::HasSchema(m_handle, name);
859 void AddSchema(std::string_view name, std::string_view type,
860 std::span<const uint8_t> schema) {
878 void AddSchema(std::string_view name, std::string_view type,
879 std::string_view schema) {
885#pragma clang diagnostic push
886#pragma clang diagnostic ignored "-Wunused-lambda-capture"
896 template <wpi::ProtobufSerializable T>
899 [
this](
auto typeString) {
return HasSchema(typeString); },
900 [
this](
auto typeString,
auto schema) {
901 AddSchema(typeString,
"proto:FileDescriptorProto", schema);
912 template <
typename T,
typename... I>
916 [
this](
auto typeString,
auto schema) {
917 AddSchema(typeString,
"structschema", schema);
923#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
static NetworkTableInstance Create()
Create an instance.
Definition NetworkTableInstance.h:134
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
@ kNetModeClient
Definition NetworkTableInstance.h:77
@ kNetModeServer
Definition NetworkTableInstance.h:76
@ kNetModeLocal
Definition NetworkTableInstance.h:78
@ 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:408
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:330
bool IsConnected() const
Return whether or not the instance is connected to another node.
Definition NetworkTableInstance.h:730
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:468
void StartLocal()
Starts local-only operation.
Definition NetworkTableInstance.h:593
StructTopic< T, I... > GetStructTopic(std::string_view name, I... info) const
Gets a raw struct serialized value topic.
Definition NetworkTableInstance.h:273
bool WaitForListenerQueue(double timeout)
Wait for the listener queue to be empty.
Definition NetworkTableInstance.h:455
static constexpr unsigned int kDefaultPort
The default port that network tables operates on.
Definition NetworkTableInstance.h:99
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:286
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:568
NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel, ListenerCallback func)
Add logger callback function.
Definition NetworkTableInstance.h:820
void StartDSClient(unsigned int port=0)
Starts requesting server address from Driver Station.
Definition NetworkTableInstance.h:692
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:374
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:705
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:787
ProtobufTopic< T > GetProtobufTopic(std::string_view name) const
Gets a protobuf serialized value topic.
Definition NetworkTableInstance.h:260
unsigned int GetNetworkMode() const
Get the current network mode.
Definition NetworkTableInstance.h:586
NT_Inst GetHandle() const
Gets the native handle for the entry.
Definition NetworkTableInstance.h:155
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:764
bool HasSchema(std::string_view name) const
Returns whether there is a data schema already registered with the given name.
Definition NetworkTableInstance.h:841
NetworkTableEntry GetEntry(std::string_view name)
Gets the entry for a key.
Definition NetworkTableInstance.h:419
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:643
static void RemoveListener(NT_Listener listener)
Remove a listener.
Definition NetworkTableInstance.h:441
void StartServer(std::string_view persist_filename="networktables.json", const char *listen_address="", unsigned int port=kDefaultPort)
Starts a server using the specified filename, listening address, and port.
Definition NetworkTableInstance.h:611
NetworkTableInstance() noexcept=default
Construct invalid instance.
void StopServer()
Stops the server if it is running.
Definition NetworkTableInstance.h:620
void AddStructSchema(const I &... info)
Registers a struct schema.
Definition NetworkTableInstance.h:914
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix, unsigned int types)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:391
void SetServerTeam(unsigned int team, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
Definition NetworkTableInstance.h:675
bool operator==(const NetworkTableInstance &) const =default
Equality operator.
void StopDSClient()
Stops requesting server address from Driver Station.
Definition NetworkTableInstance.h:699
static void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
Definition NetworkTableInstance.h:797
LogLevel
Logging levels (as used by SetLogger()).
Definition NetworkTableInstance.h:84
@ kLogInfo
Definition NetworkTableInstance.h:88
@ kLogError
Definition NetworkTableInstance.h:86
@ kLogWarning
Definition NetworkTableInstance.h:87
@ kLogDebug4
Definition NetworkTableInstance.h:93
@ kLogDebug3
Definition NetworkTableInstance.h:92
@ kLogCritical
Definition NetworkTableInstance.h:85
@ kLogDebug
Definition NetworkTableInstance.h:89
@ kLogDebug1
Definition NetworkTableInstance.h:90
@ kLogDebug2
Definition NetworkTableInstance.h:91
void AddSchema(std::string_view name, std::string_view type, std::span< const uint8_t > schema)
Registers a data schema.
Definition NetworkTableInstance.h:859
void Disconnect()
Disconnects the client if it's running and connected.
Definition NetworkTableInstance.h:683
void Flush() const
Flushes all updated values immediately to the network.
Definition NetworkTableInstance.h:713
void AddProtobufSchema(wpi::ProtobufMessage< T > &msg)
Registers a protobuf schema.
Definition NetworkTableInstance.h:897
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:487
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:143
std::vector< TopicInfo > GetTopicInfo()
Get Topic Information about multiple topics.
Definition NetworkTableInstance.h:359
DoubleTopic GetDoubleTopic(std::string_view name) const
Gets a double topic.
Topic GetTopic(std::string_view name) const
Gets a "generic" (untyped) topic.
void StopLocal()
Stops local-only operation.
Definition NetworkTableInstance.h:599
void StartClient(std::string_view identity)
Starts a client.
Definition NetworkTableInstance.h:628
std::vector< ConnectionInfo > GetConnections() const
Get information on the currently established network connections.
Definition NetworkTableInstance.h:721
std::vector< Topic > GetTopics(std::string_view prefix)
Get Published Topics.
Definition NetworkTableInstance.h:313
void StopClient()
Stops the client if it is running.
Definition NetworkTableInstance.h:635
std::optional< int64_t > GetServerTimeOffset() const
Get the time offset between server time and local time.
Definition NetworkTableInstance.h:743
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:653
IntegerTopic GetIntegerTopic(std::string_view name) const
Gets an integer topic.
std::vector< Topic > GetTopics()
Get Published Topics.
Definition NetworkTableInstance.h:298
std::vector< Topic > GetTopics(std::string_view prefix, std::span< std::string_view > types)
Get Published Topics.
Definition NetworkTableInstance.h:346
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:125
static void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
Definition NetworkTableInstance.h:775
void AddSchema(std::string_view name, std::string_view type, std::string_view schema)
Registers a data schema.
Definition NetworkTableInstance.h:878
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
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
NT_Handle NT_Inst
Definition ntcore_c.h:38
#define NT_DEFAULT_PORT
Default network tables port number.
Definition ntcore_c.h:47
NT_Handle NT_DataLogger
Definition ntcore_c.h:36
@ NT_LOG_DEBUG4
Definition ntcore_c.h:83
@ NT_LOG_WARNING
Definition ntcore_c.h:77
@ NT_LOG_INFO
Definition ntcore_c.h:78
@ NT_LOG_DEBUG2
Definition ntcore_c.h:81
@ NT_LOG_DEBUG
Definition ntcore_c.h:79
@ NT_LOG_CRITICAL
Definition ntcore_c.h:75
@ NT_LOG_ERROR
Definition ntcore_c.h:76
@ NT_LOG_DEBUG3
Definition ntcore_c.h:82
@ NT_LOG_DEBUG1
Definition ntcore_c.h:80
@ NT_NET_MODE_LOCAL
Definition ntcore_c.h:92
@ NT_NET_MODE_CLIENT
Definition ntcore_c.h:90
@ NT_NET_MODE_SERVER
Definition ntcore_c.h:89
@ NT_NET_MODE_NONE
Definition ntcore_c.h:88
@ NT_EVENT_TIMESYNC
Time synchronized with server.
Definition ntcore_c.h:123
@ NT_EVENT_CONNECTION
Any connection event (connect or disconnect).
Definition ntcore_c.h:105
@ NT_EVENT_IMMEDIATE
Initial listener addition.
Definition ntcore_c.h:99
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 Disconnect(NT_Inst inst)
Disconnects the client if it's running and connected.
void StartServer(NT_Inst inst, std::string_view persist_filename, std::string_view listen_address, unsigned int port)
Starts a server using the specified filename, listening address, and port.
void StopLocal(NT_Inst inst)
Stops local-only operation.
void StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
void StartClient(NT_Inst inst, std::string_view identity)
Starts a client.
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 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 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