Publisher#
agnocast::Publisher<MessageT>#
Extends: agnocast::PublisherBase
Zero-copy publisher that allocates messages in shared memory. Use borrow_loaned_message() to obtain a message, populate its fields, then call publish() to transfer it to subscribers without copying.
Example:
// Create a publisher (Stage 1, with rclcpp::Node)
auto pub = agnocast::create_publisher<MyMsg>(this, "/topic", 10);
// Borrow, populate, publish
auto msg = pub->borrow_loaned_message();
msg->data = 42;
pub->publish(std::move(msg)); // msg is invalidated after this
borrow_loaned_message()#
agnocast::ipc_shared_ptr<MessageT> Publisher::borrow_loaned_message()
Allocate a new default-constructed message in shared memory. The caller must either pass the returned pointer to publish() or let it go out of scope (which frees the memory).
| Template Parameter | Description |
|---|---|
MessageT |
ROS message type. |
| Returns | Owned pointer to the newly allocated message in shared memory. |
publish()#
void Publisher::publish(agnocast::ipc_shared_ptr<MessageT> &&message)
Publish a message via zero-copy IPC. Ownership is transferred: after this call, the passed-in ipc_shared_ptr and all copies sharing its control block are invalidated — dereferencing them calls std::terminate().
| Template Parameter | Description |
|---|---|
MessageT |
ROS message type. |
| Parameter | Description |
|---|---|
message |
Message obtained from borrow_loaned_message(). Must be moved in. |