WPILibC++ 2023.4.3-108-ge5452e3
Topic Functions

Functions

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< TopicInfont::GetTopicInfo (NT_Inst inst, std::string_view prefix, unsigned int types)
 Get Topic Information about multiple topics. More...
 
std::vector< TopicInfont::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...
 
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...
 

Detailed Description

Function Documentation

◆ DeleteTopicProperty()

void nt::DeleteTopicProperty ( NT_Topic  topic,
std::string_view  name 
)

Deletes a property.

Has no effect if the property does not exist.

Parameters
topictopic handle
nameproperty name

◆ GetEntry()

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.

Parameters
topictopic handle
typetype
typeStrtype string
optionspublish options
Returns
Entry handle

◆ GetTopic()

NT_Topic nt::GetTopic ( NT_Inst  inst,
std::string_view  name 
)

Gets Topic Handle.

Returns topic handle.

Parameters
instinstance handle
nametopic name
Returns
Topic handle.

◆ GetTopicExists()

bool nt::GetTopicExists ( NT_Handle  handle)

Determine if topic exists (e.g.

has at least one publisher).

Parameters
handleTopic, entry, or subscriber handle.
Returns
True if topic exists.

◆ GetTopicFromHandle()

NT_Topic nt::GetTopicFromHandle ( NT_Handle  pubsubentry)

Gets the topic handle from an entry/subscriber/publisher handle.

Parameters
pubsubentryentry/subscriber/publisher handle
Returns
Topic handle

◆ GetTopicInfo() [1/3]

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.

Returns an array of topic information (handle, name, type, and properties). The results are optionally filtered by string prefix and type to only return a subset of all topics.

Parameters
instinstance handle
prefixname required prefix; only topics whose name starts with this string are returned
typesarray of type strings
Returns
Array of topic information.

◆ GetTopicInfo() [2/3]

std::vector< TopicInfo > nt::GetTopicInfo ( NT_Inst  inst,
std::string_view  prefix,
unsigned int  types 
)

Get Topic Information about multiple topics.

Returns an array of topic information (handle, name, type, and properties). The results are optionally filtered by string prefix and type to only return a subset of all topics.

Parameters
instinstance handle
prefixname required prefix; only topics whose name starts with this string are returned
typesbitmask of NT_Type values; 0 is treated specially as a "don't care"
Returns
Array of topic information.

◆ GetTopicInfo() [3/3]

TopicInfo nt::GetTopicInfo ( NT_Topic  topic)

Gets Topic Information.

Returns information about a topic (name, type, and properties).

Parameters
topichandle
Returns
Topic information.

◆ GetTopicName()

std::string nt::GetTopicName ( NT_Topic  topic)

Gets the name of the specified topic.

Returns an empty string if the handle is invalid.

Parameters
topictopic handle
Returns
Topic name

◆ GetTopicPersistent()

bool nt::GetTopicPersistent ( NT_Topic  topic)

Gets the persistent property of a topic.

If true, the server retains the topic even when there are no publishers.

Parameters
topictopic handle
Returns
persistent property value

◆ GetTopicProperties()

wpi::json nt::GetTopicProperties ( NT_Topic  topic)

Gets all topic properties as a JSON object.

Each key in the object is the property name, and the corresponding value is the property value.

Parameters
topictopic handle
Returns
JSON object

◆ GetTopicProperty()

wpi::json nt::GetTopicProperty ( NT_Topic  topic,
std::string_view  name 
)

Gets the current value of a property (as a JSON object).

Parameters
topictopic handle
nameproperty name
Returns
JSON object; null object if the property does not exist.

◆ GetTopicRetained()

bool nt::GetTopicRetained ( NT_Topic  topic)

Gets the retained property of a topic.

Parameters
topictopic handle
Returns
retained property value

◆ GetTopics() [1/2]

std::vector< NT_Topic > nt::GetTopics ( NT_Inst  inst,
std::string_view  prefix,
std::span< const std::string_view types 
)

Get Published Topics.

Returns an array of topic handles. The results are optionally filtered by string prefix and type to only return a subset of all topics.

Parameters
instinstance handle
prefixname required prefix; only topics whose name starts with this string are returned
typesarray of type strings
Returns
Array of topic handles.

◆ GetTopics() [2/2]

std::vector< NT_Topic > nt::GetTopics ( NT_Inst  inst,
std::string_view  prefix,
unsigned int  types 
)

Get Published Topics.

Returns an array of topic handles. The results are optionally filtered by string prefix and type to only return a subset of all topics.

Parameters
instinstance handle
prefixname required prefix; only topics whose name starts with this string are returned
typesbitmask of NT_Type values; 0 is treated specially as a "don't care"
Returns
Array of topic handles.

◆ GetTopicType()

NT_Type nt::GetTopicType ( NT_Topic  topic)

Gets the type for the specified topic, or unassigned if non existent.

Parameters
topictopic handle
Returns
Topic type

◆ GetTopicTypeString()

std::string nt::GetTopicTypeString ( NT_Topic  topic)

Gets the type string for the specified topic, or empty string if non existent.

This may have more information than the numeric type (especially for raw values).

Parameters
topictopic handle
Returns
Topic type string

◆ Publish()

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.

Parameters
topictopic handle
typetype
typeStrtype string
optionspublish options
Returns
Publisher handle

◆ PublishEx()

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.

Parameters
topictopic handle
typetype
typeStrtype string
propertiesinitial properties
optionspublish options
Returns
Publisher handle

◆ Release()

void nt::Release ( NT_Handle  pubsubentry)

Stops entry/subscriber/publisher.

Parameters
pubsubentryentry/subscriber/publisher handle

◆ ReleaseEntry()

void nt::ReleaseEntry ( NT_Entry  entry)

Stops entry subscriber/publisher.

Parameters
entryentry handle

◆ SetTopicPersistent()

void nt::SetTopicPersistent ( NT_Topic  topic,
bool  value 
)

Sets the persistent property of a topic.

If true, the stored value is persistent through server restarts.

Parameters
topictopic handle
valueTrue for persistent, false for not persistent.

◆ SetTopicProperties()

bool nt::SetTopicProperties ( NT_Topic  topic,
const wpi::json update 
)

Updates multiple topic properties.

Each key in the passed-in object is the name of the property to add/update, and the corresponding value is the property value to set for that property. Null values result in deletion of the corresponding property.

Parameters
topictopic handle
updateJSON object with keys to add/update/delete
Returns
False if update is not a JSON object

◆ SetTopicProperty()

void nt::SetTopicProperty ( NT_Topic  topic,
std::string_view  name,
const wpi::json value 
)

Sets a property value.

Parameters
topictopic handle
nameproperty name
valueproperty value

◆ SetTopicRetained()

void nt::SetTopicRetained ( NT_Topic  topic,
bool  value 
)

Sets the retained property of a topic.

Parameters
topictopic handle
valuenew retained property value

◆ Subscribe()

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.

Parameters
topictopic handle
typeexpected type
typeStrexpected type string
optionssubscription options
Returns
Subscriber handle

◆ Unpublish()

void nt::Unpublish ( NT_Handle  pubentry)

Stops publisher.

Parameters
pubentrypublisher/entry handle

◆ Unsubscribe()

void nt::Unsubscribe ( NT_Subscriber  sub)

Stops subscriber.

Parameters
subsubscriber handle