MoveIt Pro API
Core Behaviors for MoveIt Pro
Loading...
Searching...
No Matches
moveit_pro::behaviors::PersistentPublisherCache Class Reference

Topic-keyed cache of publishers whose latched samples must outlive the Behavior instance that created them. More...

#include <behavior_context.hpp>

Public Member Functions

template<typename Factory >
std::shared_ptr< rclcpp::PublisherBase > getOrCreate (const std::string &topic, Factory &&factory)
 Return the publisher for topic, creating it via factory if absent.
 
std::shared_ptr< rclcpp::PublisherBase > get (std::string_view topic) const
 Return the publisher stored for topic, or nullptr if none.
 
void clear ()
 Drop all publishers, destroying their writers so DDS retracts any latched samples (e.g. when the user clears the scene snapshot).
 

Detailed Description

Topic-keyed cache of publishers whose latched samples must outlive the Behavior instance that created them.

A Behavior's publishers are destroyed when its tree is torn down at the end of an Objective run, taking any transient_local latched sample with them. A publisher stored here lives as long as the owning BehaviorContext, so a UI that subscribes or reconnects after the run still receives the latched sample. The cache only grows: entries are added per distinct topic and released only by clear() or destruction, so callers should use a stable topic rather than a per-tick unique one. Thread-safe.

Member Function Documentation

◆ clear()

void moveit_pro::behaviors::PersistentPublisherCache::clear ( )

Drop all publishers, destroying their writers so DDS retracts any latched samples (e.g. when the user clears the scene snapshot).

◆ get()

std::shared_ptr< rclcpp::PublisherBase > moveit_pro::behaviors::PersistentPublisherCache::get ( std::string_view  topic) const

Return the publisher stored for topic, or nullptr if none.

◆ getOrCreate()

template<typename Factory >
std::shared_ptr< rclcpp::PublisherBase > moveit_pro::behaviors::PersistentPublisherCache::getOrCreate ( const std::string &  topic,
Factory &&  factory 
)
inline

Return the publisher for topic, creating it via factory if absent.

The lookup-and-create is atomic under the cache lock, so concurrent callers on the same topic share one publisher (no lost-publish race) and factory runs at most once per topic. factory runs while the lock is held and must not call back into this cache (it is not reentrant).


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