Skip to main content

PersistentPublisherCache Class

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

Declaration

class moveit_pro::behaviors::PersistentPublisherCache { ... }

Included Headers

#include <behavior_context.hpp>

Public Member Functions Index

template <typename Factory>
auto getOrCreate (const std::string &topic, Factory &&factory) -> std::shared_ptr< rclcpp::PublisherBase >

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

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

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

voidclear ()

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

Private Member Attributes Index

std::mutexmutex_
std::unordered_map< std::string, std::shared_ptr< rclcpp::PublisherBase >, moveit_pro_types::StringHash, std::equal_to<> >publishers_

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.

Definition at line 54 of file behavior_context.hpp.

Public Member Functions

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).

Declaration at line 80 of file behavior_context.hpp, definition at line 26 of file behavior_context.cpp.

get()

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

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

Declaration at line 76 of file behavior_context.hpp, definition at line 19 of file behavior_context.cpp.

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).

Definition at line 64 of file behavior_context.hpp.

Private Member Attributes

mutex_

std::mutex moveit_pro::behaviors::PersistentPublisherCache::mutex_
mutable

Definition at line 83 of file behavior_context.hpp.

publishers_

std::unordered_map<std::string, std::shared_ptr<rclcpp::PublisherBase>, moveit_pro_types::StringHash, std::equal_to<> > moveit_pro::behaviors::PersistentPublisherCache::publishers_

Definition at line 85 of file behavior_context.hpp.


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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.9.8.