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

Variables

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