WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
ntcore_cpp.h File Reference
#include <stdint.h>
#include <cassert>
#include <functional>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include <variant>
#include <vector>
#include <wpi/json_fwd.h>
#include "networktables/NetworkTableValue.h"
#include "ntcore_c.h"
#include "ntcore_cpp_types.h"

Go to the source code of this file.

Classes

struct  nt::EventFlags
 Event notification flags. More...
 
struct  nt::TopicInfo
 NetworkTables Topic Information. More...
 
struct  nt::ConnectionInfo
 NetworkTables Connection Information. More...
 
class  nt::ValueEventData
 NetworkTables Value Event Data. More...
 
class  nt::LogMessage
 NetworkTables log message. More...
 
class  nt::TimeSyncEventData
 NetworkTables time sync event data. More...
 
class  nt::Event
 NetworkTables event. More...
 
struct  nt::PubSubOptions
 NetworkTables publish/subscribe options. More...
 
struct  nt::meta::SubscriberOptions
 Subscriber options. More...
 
struct  nt::meta::TopicPublisher
 Topic publisher (as published via $pub$<topic>). More...
 
struct  nt::meta::TopicSubscriber
 Topic subscriber (as published via $sub$<topic>). More...
 
struct  nt::meta::ClientPublisher
 Client publisher (as published via $clientpub$<client> or $serverpub). More...
 
struct  nt::meta::ClientSubscriber
 Client subscriber (as published via $clientsub$<client> or $serversub). More...
 
struct  nt::meta::Client
 Client (as published via $clients). More...
 

Namespaces

namespace  wpi
 Foonathan namespace.
 
namespace  wpi::log
 
namespace  nt
 NetworkTables (ntcore) namespace.
 
namespace  nt::meta
 NetworkTables meta-topic decoding functions.
 

Typedefs

using nt::ListenerCallback = std::function<void(const Event&)>
 

Functions

NT_Inst nt::GetDefaultInstance ()
 Get default instance.
 
NT_Inst nt::CreateInstance ()
 Create an instance.
 
void nt::ResetInstance (NT_Inst inst)
 Reset the internals of an instance.
 
void nt::DestroyInstance (NT_Inst inst)
 Destroy an instance.
 
NT_Inst nt::GetInstanceFromHandle (NT_Handle handle)
 Get instance handle from another handle.
 
NT_Entry nt::GetEntry (NT_Inst inst, std::string_view name)
 Get Entry Handle.
 
std::string nt::GetEntryName (NT_Entry entry)
 Gets the name of the specified entry.
 
NT_Type nt::GetEntryType (NT_Entry entry)
 Gets the type for the specified entry, or unassigned if non existent.
 
int64_t nt::GetEntryLastChange (NT_Handle subentry)
 Gets the last time the entry was changed.
 
Value nt::GetEntryValue (NT_Handle subentry)
 Get Entry Value.
 
bool nt::SetDefaultEntryValue (NT_Entry entry, const Value &value)
 Set Default Entry Value.
 
bool nt::SetEntryValue (NT_Entry entry, const Value &value)
 Set Entry Value.
 
void nt::SetEntryFlags (NT_Entry entry, unsigned int flags)
 Set Entry Flags.
 
unsigned int nt::GetEntryFlags (NT_Entry entry)
 Get Entry Flags.
 
std::vector< Valuent::ReadQueueValue (NT_Handle subentry)
 Read Entry Queue.
 
std::vector< Valuent::ReadQueueValue (NT_Handle subentry, unsigned int types)
 Read Entry Queue.
 
std::vector< NT_Topicnt::GetTopics (NT_Inst inst, std::string_view prefix, unsigned int types)
 Get Published Topics.
 
std::vector< NT_Topicnt::GetTopics (NT_Inst inst, std::string_view prefix, std::span< const std::string_view > types)
 Get Published Topics.
 
std::vector< TopicInfont::GetTopicInfo (NT_Inst inst, std::string_view prefix, unsigned int types)
 Get Topic Information about multiple topics.
 
std::vector< TopicInfont::GetTopicInfo (NT_Inst inst, std::string_view prefix, std::span< const std::string_view > types)
 Get Topic Information about multiple topics.
 
TopicInfo nt::GetTopicInfo (NT_Topic topic)
 Gets Topic Information.
 
NT_Topic nt::GetTopic (NT_Inst inst, std::string_view name)
 Gets Topic Handle.
 
std::string nt::GetTopicName (NT_Topic topic)
 Gets the name of the specified topic.
 
NT_Type nt::GetTopicType (NT_Topic topic)
 Gets the type for the specified topic, or unassigned if non existent.
 
std::string nt::GetTopicTypeString (NT_Topic topic)
 Gets the type string for the specified topic, or empty string if non existent.
 
void nt::SetTopicPersistent (NT_Topic topic, bool value)
 Sets the persistent property of a topic.
 
bool nt::GetTopicPersistent (NT_Topic topic)
 Gets the persistent property of a topic.
 
void nt::SetTopicRetained (NT_Topic topic, bool value)
 Sets the retained property of a topic.
 
bool nt::GetTopicRetained (NT_Topic topic)
 Gets the retained property of a topic.
 
void nt::SetTopicCached (NT_Topic topic, bool value)
 Sets the cached property of a topic.
 
bool nt::GetTopicCached (NT_Topic topic)
 Gets the cached property of a topic.
 
bool nt::GetTopicExists (NT_Handle handle)
 Determine if topic exists (e.g.
 
wpi::json nt::GetTopicProperty (NT_Topic topic, std::string_view name)
 Gets the current value of a property (as a JSON object).
 
void nt::SetTopicProperty (NT_Topic topic, std::string_view name, const wpi::json &value)
 Sets a property value.
 
void nt::DeleteTopicProperty (NT_Topic topic, std::string_view name)
 Deletes a property.
 
wpi::json nt::GetTopicProperties (NT_Topic topic)
 Gets all topic properties as a JSON object.
 
bool nt::SetTopicProperties (NT_Topic topic, const wpi::json &update)
 Updates multiple topic properties.
 
NT_Subscriber nt::Subscribe (NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
 Creates a new subscriber to value changes on a topic.
 
void nt::Unsubscribe (NT_Subscriber sub)
 Stops subscriber.
 
NT_Publisher nt::Publish (NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
 Creates a new publisher to a topic.
 
NT_Publisher nt::PublishEx (NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
 Creates a new publisher to a topic.
 
void nt::Unpublish (NT_Handle pubentry)
 Stops publisher.
 
NT_Entry nt::GetEntry (NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=kDefaultPubSubOptions)
 Creates a new entry (subscriber and weak publisher) to a topic.
 
void nt::ReleaseEntry (NT_Entry entry)
 Stops entry subscriber/publisher.
 
void nt::Release (NT_Handle pubsubentry)
 Stops entry/subscriber/publisher.
 
NT_Topic nt::GetTopicFromHandle (NT_Handle pubsubentry)
 Gets the topic handle from an entry/subscriber/publisher handle.
 
NT_MultiSubscriber nt::SubscribeMultiple (NT_Inst inst, std::span< const std::string_view > prefixes, const PubSubOptions &options=kDefaultPubSubOptions)
 Subscribes to multiple topics based on one or more topic name prefixes.
 
void nt::UnsubscribeMultiple (NT_MultiSubscriber sub)
 Unsubscribes a multi-subscriber.
 
NT_ListenerPoller nt::CreateListenerPoller (NT_Inst inst)
 Creates a listener poller.
 
void nt::DestroyListenerPoller (NT_ListenerPoller poller)
 Destroys a listener poller.
 
std::vector< Eventnt::ReadListenerQueue (NT_ListenerPoller poller)
 Read notifications.
 
void nt::RemoveListener (NT_Listener listener)
 Removes a listener.
 
bool nt::WaitForListenerQueue (NT_Handle handle, double timeout)
 Wait for the listener queue to be empty.
 
NT_Listener nt::AddListener (NT_Inst inst, std::span< const std::string_view > prefixes, unsigned int mask, ListenerCallback callback)
 Create a listener for changes to topics with names that start with any of the given prefixes.
 
NT_Listener nt::AddListener (NT_Handle handle, unsigned int mask, ListenerCallback callback)
 Create a listener.
 
NT_Listener nt::AddPolledListener (NT_ListenerPoller poller, std::span< const std::string_view > prefixes, unsigned int mask)
 Creates a polled listener.
 
NT_Listener nt::AddPolledListener (NT_ListenerPoller poller, NT_Handle handle, unsigned int mask)
 Creates a polled listener.
 
unsigned int nt::GetNetworkMode (NT_Inst inst)
 Get the current network mode.
 
void nt::StartLocal (NT_Inst inst)
 Starts local-only operation.
 
void nt::StopLocal (NT_Inst inst)
 Stops local-only operation.
 
void nt::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 nt::StopServer (NT_Inst inst)
 Stops the server if it is running.
 
void nt::StartClient3 (NT_Inst inst, std::string_view identity)
 Starts a NT3 client.
 
void nt::StartClient4 (NT_Inst inst, std::string_view identity)
 Starts a NT4 client.
 
void nt::StopClient (NT_Inst inst)
 Stops the client if it is running.
 
void nt::SetServer (NT_Inst inst, std::string_view server_name, unsigned int port)
 Sets server address and port for client (without restarting client).
 
void nt::SetServer (NT_Inst inst, std::span< const std::pair< std::string_view, unsigned int > > servers)
 Sets server addresses for client (without restarting client).
 
void nt::SetServerTeam (NT_Inst inst, unsigned int team, unsigned int port)
 Sets server addresses and port for client (without restarting client).
 
void nt::Disconnect (NT_Inst inst)
 Disconnects the client if it's running and connected.
 
void nt::StartDSClient (NT_Inst inst, unsigned int port)
 Starts requesting server address from Driver Station.
 
void nt::StopDSClient (NT_Inst inst)
 Stops requesting server address from Driver Station.
 
void nt::FlushLocal (NT_Inst inst)
 Flush local updates.
 
void nt::Flush (NT_Inst inst)
 Flush to network.
 
std::vector< ConnectionInfont::GetConnections (NT_Inst inst)
 Get information on the currently established network connections.
 
bool nt::IsConnected (NT_Inst inst)
 Return whether or not the instance is connected to another node.
 
std::optional< int64_t > nt::GetServerTimeOffset (NT_Inst inst)
 Get the time offset between server time and local time.
 
int64_t nt::Now ()
 Returns monotonic current time in 1 us increments.
 
void nt::SetNow (int64_t timestamp)
 Sets the current timestamp used for timestamping values that do not provide a timestamp (e.g.
 
NT_Type nt::GetTypeFromString (std::string_view typeString)
 Turns a type string into a type enum value.
 
std::string_view nt::GetStringFromType (NT_Type type)
 Turns a type enum value into a type string.
 
NT_DataLogger nt::StartEntryDataLog (NT_Inst inst, wpi::log::DataLog &log, std::string_view prefix, std::string_view logPrefix)
 Starts logging entry changes to a DataLog.
 
void nt::StopEntryDataLog (NT_DataLogger logger)
 Stops logging entry changes to a DataLog.
 
NT_ConnectionDataLogger nt::StartConnectionDataLog (NT_Inst inst, wpi::log::DataLog &log, std::string_view name)
 Starts logging connection changes to a DataLog.
 
void nt::StopConnectionDataLog (NT_ConnectionDataLogger logger)
 Stops logging connection changes to a DataLog.
 
NT_Listener nt::AddLogger (NT_Inst inst, unsigned int min_level, unsigned int max_level, ListenerCallback func)
 Add logger callback function.
 
NT_Listener nt::AddPolledLogger (NT_ListenerPoller poller, unsigned int min_level, unsigned int max_level)
 Set the log level for a log poller.
 
bool nt::HasSchema (NT_Inst inst, std::string_view name)
 Returns whether there is a data schema already registered with the given name.
 
void nt::AddSchema (NT_Inst inst, std::string_view name, std::string_view type, std::span< const uint8_t > schema)
 Registers a data schema.
 
void nt::AddSchema (NT_Inst inst, std::string_view name, std::string_view type, std::string_view schema)
 Registers a data schema.
 
std::optional< std::vector< TopicPublisher > > nt::meta::DecodeTopicPublishers (std::span< const uint8_t > data)
 Decodes $pub$<topic> meta-topic data.
 
std::optional< std::vector< TopicSubscriber > > nt::meta::DecodeTopicSubscribers (std::span< const uint8_t > data)
 Decodes $sub$<topic> meta-topic data.
 
std::optional< std::vector< ClientPublisher > > nt::meta::DecodeClientPublishers (std::span< const uint8_t > data)
 Decodes $clientpub$<topic> meta-topic data.
 
std::optional< std::vector< ClientSubscriber > > nt::meta::DecodeClientSubscribers (std::span< const uint8_t > data)
 Decodes $clientsub$<topic> meta-topic data.
 
std::optional< std::vector< Client > > nt::meta::DecodeClients (std::span< const uint8_t > data)
 Decodes $clients meta-topic data.
 

Variables

constexpr PubSubOptions nt::kDefaultPubSubOptions
 Default publish/subscribe options.