32template <wpi::util::ProtobufSerializable T>
37template <
typename T,
typename... I>
38 requires wpi::util::StructSerializable<T, I...>
40template <
typename T,
typename... I>
41 requires wpi::util::StructSerializable<T, I...>
117 explicit operator bool()
const {
return m_handle != 0; }
143 if (inst.m_handle != 0) {
258 template <wpi::util::ProtobufSerializable T>
270 template <
typename T,
typename... I>
283 template <
typename T,
typename... I>
299 return {handles.begin(), handles.end()};
314 return {handles.begin(), handles.end()};
329 std::vector<Topic>
GetTopics(std::string_view prefix,
unsigned int types) {
331 return {handles.begin(), handles.end()};
346 std::span<std::string_view> types) {
348 return {handles.begin(), handles.end()};
359 return ::wpi::nt::GetTopicInfo(m_handle,
"", 0);
374 return ::wpi::nt::GetTopicInfo(m_handle, prefix, 0);
391 unsigned int types) {
392 return ::wpi::nt::GetTopicInfo(m_handle, prefix, types);
408 std::span<std::string_view> types) {
409 return ::wpi::nt::GetTopicInfo(m_handle, prefix, types);
428 std::shared_ptr<NetworkTable>
GetTable(std::string_view key)
const;
455 return ::wpi::nt::WaitForListenerQueue(m_handle, timeout);
469 return ::wpi::nt::AddListener(
472 std::move(callback));
488 return ::wpi::nt::AddListener(
491 std::move(callback));
569 return ::wpi::nt::AddListener(m_handle, prefixes, eventMask,
570 std::move(listener));
586 return ::wpi::nt::GetNetworkMode(m_handle);
615 void StartServer(std::string_view persist_filename =
"networktables.json",
616 std::string_view listen_address =
"",
617 std::string_view mdns_service =
"",
649 void SetServer(std::string_view server_name,
unsigned int port = 0) {
660 std::span<
const std::pair<std::string_view, unsigned int>> servers) {
671 void SetServer(std::span<const std::string_view> servers,
672 unsigned int port = 0);
728 return ::wpi::nt::GetConnections(m_handle);
736 bool IsConnected()
const { return ::wpi::nt::IsConnected(m_handle); }
750 return ::wpi::nt::GetServerTimeOffset(m_handle);
771 std::string_view prefix,
772 std::string_view logPrefix) {
773 return ::wpi::nt::StartEntryDataLog(m_handle,
log, prefix, logPrefix);
794 std::string_view
name) {
795 return ::wpi::nt::StartConnectionDataLog(m_handle,
log,
name);
828 return ::wpi::nt::AddLogger(m_handle, minLevel, maxLevel, std::move(func));
848 return ::wpi::nt::HasSchema(m_handle,
name);
866 std::span<const uint8_t> schema) {
885 std::string_view schema) {
891#pragma clang diagnostic push
892#pragma clang diagnostic ignored "-Wunused-lambda-capture"
902 template <wpi::util::ProtobufSerializable T>
905 [
this](
auto typeString) {
return HasSchema(typeString); },
906 [
this](
auto typeString,
auto schema) {
907 AddSchema(typeString,
"proto:FileDescriptorProto", schema);
918 template <
typename T,
typename... I>
922 [
this](
auto typeString,
auto schema) {
923 AddSchema(typeString,
"structschema", schema);
929#pragma clang diagnostic pop
@ name
Definition base.h:690
A data log for high-speed writing of data values.
Definition DataLog.hpp:69
NetworkTables BooleanArray topic.
Definition BooleanArrayTopic.hpp:296
NetworkTables Boolean topic.
Definition BooleanTopic.hpp:235
NetworkTables DoubleArray topic.
Definition DoubleArrayTopic.hpp:296
NetworkTables Double topic.
Definition DoubleTopic.hpp:235
NetworkTables FloatArray topic.
Definition FloatArrayTopic.hpp:296
NetworkTables Float topic.
Definition FloatTopic.hpp:235
NetworkTables IntegerArray topic.
Definition IntegerArrayTopic.hpp:296
NetworkTables Integer topic.
Definition IntegerTopic.hpp:235
Subscribe to multiple topics based on one or more topic name prefixes.
Definition MultiSubscriber.hpp:20
NetworkTables Entry.
Definition NetworkTableEntry.hpp:31
void StartServer(std::string_view persist_filename="networktables.json", std::string_view listen_address="", std::string_view mdns_service="", unsigned int port=kDefaultPort)
Starts a server using the specified filename, listening address, and port.
Definition NetworkTableInstance.hpp:615
bool WaitForListenerQueue(double timeout)
Wait for the listener queue to be empty.
Definition NetworkTableInstance.hpp:454
static void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
Definition NetworkTableInstance.hpp:803
void SetServer(std::span< const std::string_view > servers, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
void AddSchema(std::string_view name, std::string_view type, std::span< const uint8_t > schema)
Registers a data schema.
Definition NetworkTableInstance.hpp:865
Topic GetTopic(std::string_view name) const
Gets a "generic" (untyped) topic.
NT_Listener AddListener(Subscriber &subscriber, unsigned int eventMask, ListenerCallback listener)
Add a listener for changes on a subscriber.
void SetServerTeam(unsigned int team, unsigned int port=0)
Sets server addresses and port for client (without restarting client).
Definition NetworkTableInstance.hpp:681
static constexpr unsigned int kDefaultPort
The default port that network tables operates on.
Definition NetworkTableInstance.hpp:98
std::vector< Topic > GetTopics()
Get Published Topics.
Definition NetworkTableInstance.hpp:297
StringArrayTopic GetStringArrayTopic(std::string_view name) const
Gets a string array topic.
BooleanTopic GetBooleanTopic(std::string_view name) const
Gets a boolean topic.
void Disconnect()
Disconnects the client if it's running and connected.
Definition NetworkTableInstance.hpp:689
bool operator==(const NetworkTableInstance &) const =default
Equality operator.
NT_Listener AddListener(const NetworkTableEntry &entry, int eventMask, ListenerCallback listener)
Add a listener for changes on an entry.
void AddStructSchema(const I &... info)
Registers a struct schema.
Definition NetworkTableInstance.hpp:920
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.hpp:659
NT_Listener AddConnectionListener(bool immediate_notify, ListenerCallback callback) const
Add a connection listener.
Definition NetworkTableInstance.hpp:467
void StartClient(std::string_view identity)
Starts a client.
Definition NetworkTableInstance.hpp:634
NetworkMode
Client/server mode flag values (as returned by GetNetworkMode()).
Definition NetworkTableInstance.hpp:73
@ kNetModeClient
Definition NetworkTableInstance.hpp:76
@ kNetModeLocal
Definition NetworkTableInstance.hpp:77
@ kNetModeNone
Definition NetworkTableInstance.hpp:74
@ kNetModeServer
Definition NetworkTableInstance.hpp:75
void StopServer()
Stops the server if it is running.
Definition NetworkTableInstance.hpp:626
DoubleTopic GetDoubleTopic(std::string_view name) const
Gets a double topic.
void StopClient()
Stops the client if it is running.
Definition NetworkTableInstance.hpp:641
FloatArrayTopic GetFloatArrayTopic(std::string_view name) const
Gets a float array topic.
FloatTopic GetFloatTopic(std::string_view name) const
Gets a float topic.
std::vector< Topic > GetTopics(std::string_view prefix)
Get Published Topics.
Definition NetworkTableInstance.hpp:312
NT_Inst GetHandle() const
Gets the native handle for the entry.
Definition NetworkTableInstance.hpp:154
std::vector< TopicInfo > GetTopicInfo()
Get Topic Information about multiple topics.
Definition NetworkTableInstance.hpp:358
void Flush() const
Flushes all updated values immediately to the network.
Definition NetworkTableInstance.hpp:719
static void RemoveListener(NT_Listener listener)
Remove a listener.
Definition NetworkTableInstance.hpp:440
NT_Listener AddLogger(unsigned int minLevel, unsigned int maxLevel, ListenerCallback func)
Add logger callback function.
Definition NetworkTableInstance.hpp:826
DoubleArrayTopic GetDoubleArrayTopic(std::string_view name) const
Gets a double array topic.
std::shared_ptr< NetworkTable > GetTable(std::string_view key) const
Gets the table with the specified key.
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix, std::span< std::string_view > types)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.hpp:407
static void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
Definition NetworkTableInstance.hpp:781
NetworkTableInstance() noexcept=default
Construct invalid instance.
IntegerTopic GetIntegerTopic(std::string_view name) const
Gets an integer topic.
ProtobufTopic< T > GetProtobufTopic(std::string_view name) const
Gets a protobuf serialized value topic.
Definition NetworkTableInstance.hpp:259
StructTopic< T, I... > GetStructTopic(std::string_view name, I... info) const
Gets a raw struct serialized value topic.
Definition NetworkTableInstance.hpp:272
unsigned int GetNetworkMode() const
Get the current network mode.
Definition NetworkTableInstance.hpp:585
StringTopic GetStringTopic(std::string_view name) const
Gets a string topic.
NT_DataLogger StartEntryDataLog(wpi::log::DataLog &log, std::string_view prefix, std::string_view logPrefix)
Starts logging entry changes to a DataLog.
Definition NetworkTableInstance.hpp:770
std::vector< ConnectionInfo > GetConnections() const
Get information on the currently established network connections.
Definition NetworkTableInstance.hpp:727
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.hpp:373
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.hpp:567
std::vector< Topic > GetTopics(std::string_view prefix, unsigned int types)
Get Published Topics.
Definition NetworkTableInstance.hpp:329
void StopLocal()
Stops local-only operation.
Definition NetworkTableInstance.hpp:600
void StartLocal()
Starts local-only operation.
Definition NetworkTableInstance.hpp:594
bool HasSchema(std::string_view name) const
Returns whether there is a data schema already registered with the given name.
Definition NetworkTableInstance.hpp:847
static void Destroy(NetworkTableInstance &inst)
Destroys an instance (note: this has global effect).
Definition NetworkTableInstance.hpp:142
NetworkTableEntry GetEntry(std::string_view name)
Gets the entry for a key.
Definition NetworkTableInstance.hpp:418
NT_Listener AddTimeSyncListener(bool immediate_notify, ListenerCallback callback) const
Add a time synchronization listener.
Definition NetworkTableInstance.hpp:486
RawTopic GetRawTopic(std::string_view name) const
Gets a raw topic.
void AddSchema(std::string_view name, std::string_view type, std::string_view schema)
Registers a data schema.
Definition NetworkTableInstance.hpp:884
NT_ConnectionDataLogger StartConnectionDataLog(wpi::log::DataLog &log, std::string_view name)
Starts logging connection changes to a DataLog.
Definition NetworkTableInstance.hpp:793
static NetworkTableInstance GetDefault()
Get global default instance.
Definition NetworkTableInstance.hpp:124
bool IsConnected() const
Return whether or not the instance is connected to another node.
Definition NetworkTableInstance.hpp:736
void StartDSClient(unsigned int port=0)
Starts requesting server address from Driver Station.
Definition NetworkTableInstance.hpp:698
NT_Listener AddListener(MultiSubscriber &subscriber, int eventMask, ListenerCallback listener)
Add a listener for changes on a subscriber.
BooleanArrayTopic GetBooleanArrayTopic(std::string_view name) const
Gets a boolean array topic.
static NetworkTableInstance Create()
Create an instance.
Definition NetworkTableInstance.hpp:133
void SetServer(std::string_view server_name, unsigned int port=0)
Sets server address and port for client (without restarting client).
Definition NetworkTableInstance.hpp:649
NT_Listener AddListener(Topic topic, unsigned int eventMask, ListenerCallback listener)
Add a listener for changes on a particular topic.
IntegerArrayTopic GetIntegerArrayTopic(std::string_view name) const
Gets an integer array topic.
LogLevel
Logging levels (as used by SetLogger()).
Definition NetworkTableInstance.hpp:83
@ kLogCritical
Definition NetworkTableInstance.hpp:84
@ kLogDebug3
Definition NetworkTableInstance.hpp:91
@ kLogDebug2
Definition NetworkTableInstance.hpp:90
@ kLogError
Definition NetworkTableInstance.hpp:85
@ kLogDebug
Definition NetworkTableInstance.hpp:88
@ kLogInfo
Definition NetworkTableInstance.hpp:87
@ kLogWarning
Definition NetworkTableInstance.hpp:86
@ kLogDebug4
Definition NetworkTableInstance.hpp:92
@ kLogDebug1
Definition NetworkTableInstance.hpp:89
StructArrayTopic< T, I... > GetStructArrayTopic(std::string_view name, I... info) const
Gets a raw struct serialized array topic.
Definition NetworkTableInstance.hpp:285
std::vector< TopicInfo > GetTopicInfo(std::string_view prefix, unsigned int types)
Get Topic Information about multiple topics.
Definition NetworkTableInstance.hpp:390
void StopDSClient()
Stops requesting server address from Driver Station.
Definition NetworkTableInstance.hpp:705
std::optional< int64_t > GetServerTimeOffset() const
Get the time offset between server time and local time.
Definition NetworkTableInstance.hpp:749
void AddProtobufSchema(wpi::util::ProtobufMessage< T > &msg)
Registers a protobuf schema.
Definition NetworkTableInstance.hpp:903
std::vector< Topic > GetTopics(std::string_view prefix, std::span< std::string_view > types)
Get Published Topics.
Definition NetworkTableInstance.hpp:345
void FlushLocal() const
Flushes all updated values immediately to the local client/server.
Definition NetworkTableInstance.hpp:711
NetworkTables protobuf-encoded value topic.
Definition ProtobufTopic.hpp:336
NetworkTables Raw topic.
Definition RawTopic.hpp:296
NetworkTables StringArray topic.
Definition StringArrayTopic.hpp:235
NetworkTables String topic.
Definition StringTopic.hpp:298
NetworkTables struct-encoded value array topic.
Definition StructArrayTopic.hpp:466
NetworkTables struct-encoded value topic.
Definition StructTopic.hpp:372
NetworkTables subscriber.
Definition Topic.hpp:320
NetworkTables Topic.
Definition Topic.hpp:27
Ease of use wrapper to make nanopb streams more opaque to the user.
Definition Protobuf.hpp:308
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.hpp:384
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.hpp: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:124
@ NT_EVENT_CONNECTION
Any connection event (connect or disconnect).
Definition ntcore_c.h:106
@ NT_EVENT_IMMEDIATE
Initial listener addition.
Definition ntcore_c.h:100
void StopConnectionDataLog(NT_ConnectionDataLogger logger)
Stops logging connection changes to a DataLog.
void StopEntryDataLog(NT_DataLogger logger)
Stops logging entry changes to a DataLog.
void DestroyInstance(NT_Inst inst)
Destroy an instance.
NT_Inst CreateInstance()
Create an instance.
NT_Inst GetDefaultInstance()
Get default instance.
void RemoveListener(NT_Listener listener)
Removes a listener.
std::function< void(const Event &)> ListenerCallback
Definition ntcore_cpp.hpp:897
void StartLocal(NT_Inst inst)
Starts local-only operation.
void SetServer(NT_Inst inst, std::string_view server_name, unsigned int port)
Sets server address and port for client (without restarting client).
void StopLocal(NT_Inst inst)
Stops local-only operation.
void StartClient(NT_Inst inst, std::string_view identity)
Starts a client.
void StartDSClient(NT_Inst inst, unsigned int port)
Starts requesting server address from Driver Station.
void FlushLocal(NT_Inst inst)
Flush local updates.
void StopClient(NT_Inst inst)
Stops the client if it is running.
void Flush(NT_Inst inst)
Flush to network.
void SetServerTeam(NT_Inst inst, unsigned int team, unsigned int port)
Sets server addresses and port for client (without restarting client).
void StopServer(NT_Inst inst)
Stops the server if it is running.
void StartServer(NT_Inst inst, std::string_view persist_filename, std::string_view listen_address, std::string_view mdns_service, unsigned int port)
Starts a server using the specified filename, listening address, and port.
void StopDSClient(NT_Inst inst)
Stops requesting server address from Driver Station.
void Disconnect(NT_Inst inst)
Disconnects the client if it's running and connected.
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.
Definition DataLogReader.hpp:17
NetworkTables (ntcore) namespace.
Definition NTSendable.hpp:9
void ForEachStructSchema(std::invocable< std::string_view, std::string_view > auto fn, const I &... info)
Definition Struct.hpp:424