nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
nros::Publisher< M > Class Template Reference

#include <publisher.hpp>

Classes

class  Loan
 

Public Member Functions

Result assert_liveliness ()
 
const charget_topic_name () const
 Get the topic name.
 
bool is_valid () const
 Check if the publisher is initialized and valid.
 
Expected< Loanloan (size_t requested_len)
 
Result on_liveliness_lost (nros_cpp_publisher_count_cb_t cb, void *user_context=nullptr)
 Register a callback for liveliness-lost events on this publisher.
 
Result on_offered_deadline_missed (uint32_t deadline_ms, nros_cpp_publisher_count_cb_t cb, void *user_context=nullptr)
 
Publisheroperator= (Publisher &&other)
 
Result publish (const M &msg)
 
Result publish_raw (const uint8_t *data, size_t len)
 Publish raw CDR bytes.
 
template<typename W >
Result publish_streamed (size_t total_len, W &&writer)
 
 Publisher ()
 
 Publisher (Publisher &&other)
 
 ~Publisher ()
 Destructor — releases publisher resources.
 

Friends

class Node
 

Detailed Description

template<typename M>
class nros::Publisher< M >

Typed publisher for a ROS 2 topic.

Mirrors rclcpp::Publisher<M>. The message type M must provide TYPE_NAME, TYPE_HASH, and ffi_publish() (generated by codegen).

Raw CDR publishing is always available via publish_raw().

Inline storage holds the runtime publisher handle directly (NROS_PUBLISHER_SIZE bytes; size auto-derived from the runtime). Topic name metadata lives C++-side in topic_name_, avoiding a runtime hop for get_topic_name().

Usage:

NROS_TRY(node.create_publisher(pub, "/chatter"));
pub.publish_raw(cdr_data, cdr_len);
Definition future.hpp:40
#define NROS_TRY(expr)
Definition result.hpp:90

Constructor & Destructor Documentation

◆ ~Publisher()

template<typename M >
nros::Publisher< M >::~Publisher ( )
inline

Destructor — releases publisher resources.

◆ Publisher() [1/2]

template<typename M >
nros::Publisher< M >::Publisher ( Publisher< M > &&  other)
inline

◆ Publisher() [2/2]

template<typename M >
nros::Publisher< M >::Publisher ( )
inline

Default constructor — creates an uninitialized publisher. Use Node::create_publisher() to initialize.

Member Function Documentation

◆ assert_liveliness()

template<typename M >
Result nros::Publisher< M >::assert_liveliness ( )
inline

Phase 108.B.7 — manually assert liveliness. Required for publishers configured with LivelinessManualByTopic / ManualByNode; no-op for Automatic / None.

◆ get_topic_name()

template<typename M >
const char * nros::Publisher< M >::get_topic_name ( ) const
inline

Get the topic name.

◆ is_valid()

template<typename M >
bool nros::Publisher< M >::is_valid ( ) const
inline

Check if the publisher is initialized and valid.

◆ loan()

template<typename M >
Expected< Loan > nros::Publisher< M >::loan ( size_t  requested_len)
inline

Loan a writable slot of at least requested_len bytes. The returned Loan is RAII: call commit(actual_len) to send, discard() to abandon, or let it drop (auto-discard).

◆ on_liveliness_lost()

template<typename M >
Result nros::Publisher< M >::on_liveliness_lost ( nros_cpp_publisher_count_cb_t  cb,
void user_context = nullptr 
)
inline

Register a callback for liveliness-lost events on this publisher.

◆ on_offered_deadline_missed()

template<typename M >
Result nros::Publisher< M >::on_offered_deadline_missed ( uint32_t  deadline_ms,
nros_cpp_publisher_count_cb_t  cb,
void user_context = nullptr 
)
inline

Register a callback for offered-deadline-missed events on this publisher.

◆ operator=()

template<typename M >
Publisher & nros::Publisher< M >::operator= ( Publisher< M > &&  other)
inline

◆ publish()

template<typename M >
Result nros::Publisher< M >::publish ( const M msg)
inline

Publish a typed message.

Calls the codegen-generated M::ffi_publish() which serializes the message to CDR and publishes it.

◆ publish_raw()

template<typename M >
Result nros::Publisher< M >::publish_raw ( const uint8_t data,
size_t  len 
)
inline

Publish raw CDR bytes.

◆ publish_streamed()

template<typename M >
template<typename W >
Result nros::Publisher< M >::publish_streamed ( size_t  total_len,
W &&  writer 
)
inline

Phase 124.E.1 — streamed publish.

total_len declares the full payload size; writer is invoked one or more times with a writable chunk and must return the bytes written. The runtime/backend allocates total_len bytes (in the outbound buffer when the backend natively streams, otherwise in a stack staging buffer capped at ~4 KiB) and drains the closure until full.

writer signature: size_t(uint8_t* chunk, size_t cap).

Friends And Related Symbol Documentation

◆ Node

template<typename M >
friend class Node
friend

The documentation for this class was generated from the following files: