SMACC2
Loading...
Searching...
No Matches
smacc2::client_core_components::CpTopicSubscriber< MessageType > Class Template Reference

#include <cp_topic_subscriber.hpp>

Inheritance diagram for smacc2::client_core_components::CpTopicSubscriber< MessageType >:
Inheritance graph
Collaboration diagram for smacc2::client_core_components::CpTopicSubscriber< MessageType >:
Collaboration graph

Public Types

typedef MessageType TMessageType
 

Public Member Functions

 CpTopicSubscriber ()
 
 CpTopicSubscriber (std::string topicname)
 
 CpTopicSubscriber (std::string topicname, const rclcpp::QoS &qos)
 
virtual ~CpTopicSubscriber ()
 
template<typename T >
smacc2::SmaccSignalConnection onMessageReceived (void(T::*callback)(const MessageType &), T *object)
 
template<typename T >
smacc2::SmaccSignalConnection onFirstMessageReceived (void(T::*callback)(const MessageType &), T *object)
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
void onInitialize () override
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
 ISmaccComponent (const ISmaccComponent &)=delete
 
ISmaccComponent & operator= (const ISmaccComponent &)=delete
 
 ISmaccComponent (ISmaccComponent &&)=delete
 
ISmaccComponent & operator= (ISmaccComponent &&)=delete
 
virtual std::string getName () const
 

Public Attributes

std::optional< int > queueSize
 
std::function< void(const MessageType &)> postMessageEvent
 
std::function< void(const MessageType &)> postInitialMessageEvent
 
smacc2::SmaccSignal< void(const MessageType &)> onFirstMessageReceived_
 
smacc2::SmaccSignal< void(const MessageType &)> onMessageReceived_
 

Private Member Functions

void messageCallback (const MessageType &msg)
 

Private Attributes

std::optional< rclcpp::QoS > qos_
 
rclcpp::Subscription< MessageType >::SharedPtr sub_
 
bool firstMessage_ = true
 
bool initialized_
 
std::string topicName_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (const std::string &name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_ = nullptr
 
ISmaccClient * owner_ = nullptr
 

Detailed Description

template<typename MessageType>
class smacc2::client_core_components::CpTopicSubscriber< MessageType >

Definition at line 34 of file cp_topic_subscriber.hpp.

Member Typedef Documentation

◆ TMessageType

template<typename MessageType >
MessageType smacc2::client_core_components::CpTopicSubscriber< MessageType >::TMessageType

Definition at line 39 of file cp_topic_subscriber.hpp.

Constructor & Destructor Documentation

◆ CpTopicSubscriber() [1/3]

◆ CpTopicSubscriber() [2/3]

template<typename MessageType >
smacc2::client_core_components::CpTopicSubscriber< MessageType >::CpTopicSubscriber ( std::string topicname)
inline

Definition at line 43 of file cp_topic_subscriber.hpp.

43 : initialized_(false), topicName_(std::move(topicname))
44 {
45 }

◆ CpTopicSubscriber() [3/3]

template<typename MessageType >
smacc2::client_core_components::CpTopicSubscriber< MessageType >::CpTopicSubscriber ( std::string topicname,
const rclcpp::QoS & qos )
inline

Definition at line 49 of file cp_topic_subscriber.hpp.

50 : qos_(qos), initialized_(false), topicName_(std::move(topicname))
51 {
52 }

◆ ~CpTopicSubscriber()

template<typename MessageType >
virtual smacc2::client_core_components::CpTopicSubscriber< MessageType >::~CpTopicSubscriber ( )
inlinevirtual

Definition at line 54 of file cp_topic_subscriber.hpp.

54{}

Member Function Documentation

◆ messageCallback()

template<typename MessageType >
void smacc2::client_core_components::CpTopicSubscriber< MessageType >::messageCallback ( const MessageType & msg)
inlineprivate

Definition at line 134 of file cp_topic_subscriber.hpp.

135 {
136 if (firstMessage_)
137 {
140 firstMessage_ = false;
141 }
142
143 postMessageEvent(msg);
145 }
smacc2::SmaccSignal< void(const MessageType &)> onFirstMessageReceived_
smacc2::SmaccSignal< void(const MessageType &)> onMessageReceived_
std::function< void(const MessageType &)> postInitialMessageEvent
std::function< void(const MessageType &)> postMessageEvent

References smacc2::client_core_components::CpTopicSubscriber< MessageType >::firstMessage_, smacc2::client_core_components::CpTopicSubscriber< MessageType >::onFirstMessageReceived_, smacc2::client_core_components::CpTopicSubscriber< MessageType >::onMessageReceived_, smacc2::client_core_components::CpTopicSubscriber< MessageType >::postInitialMessageEvent, and smacc2::client_core_components::CpTopicSubscriber< MessageType >::postMessageEvent.

Referenced by smacc2::client_core_components::CpTopicSubscriber< MessageType >::onInitialize().

Here is the caller graph for this function:

◆ onFirstMessageReceived()

template<typename MessageType >
template<typename T >
smacc2::SmaccSignalConnection smacc2::client_core_components::CpTopicSubscriber< MessageType >::onFirstMessageReceived ( void(T::* callback )(const MessageType &),
T * object )
inline

Definition at line 72 of file cp_topic_subscriber.hpp.

74 {
76 onFirstMessageReceived_, callback, object);
77 }
ISmaccStateMachine * getStateMachine()
smacc2::SmaccSignalConnection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)

References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

Referenced by cl_generic_sensor::CbDefaultGenericSensorBehavior< ClientType >::onStateOrthogonalAllocation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onInitialize()

template<typename MessageType >
void smacc2::client_core_components::CpTopicSubscriber< MessageType >::onInitialize ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 98 of file cp_topic_subscriber.hpp.

99 {
100 if (!initialized_)
101 {
102 firstMessage_ = true;
103
104 RCLCPP_INFO_STREAM(
105 getLogger(), "[" << this->getName() << "] Subscribing to topic: " << topicName_);
106
107 rclcpp::QoS qos = rclcpp::SensorDataQoS();
108 if (qos_)
109 {
110 qos = *qos_;
111 if (queueSize) qos.keep_last(*queueSize);
112 }
113 else
114 {
115 if (!queueSize) queueSize = 1;
116 qos.keep_last(*queueSize);
117 }
118
119 std::function<void(typename MessageType::SharedPtr)> fn = [this](auto msg)
120 { this->messageCallback(*msg); };
121
122 sub_ = this->getNode()->template create_subscription<MessageType>(topicName_, qos, fn);
123 this->initialized_ = true;
124 }
125 }
virtual std::string getName() const
rclcpp::Logger getLogger() const
rclcpp::Node::SharedPtr getNode()
rclcpp::Subscription< MessageType >::SharedPtr sub_

References smacc2::client_core_components::CpTopicSubscriber< MessageType >::firstMessage_, smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::ISmaccComponent::getNode(), smacc2::client_core_components::CpTopicSubscriber< MessageType >::initialized_, smacc2::client_core_components::CpTopicSubscriber< MessageType >::messageCallback(), smacc2::client_core_components::CpTopicSubscriber< MessageType >::qos_, smacc2::client_core_components::CpTopicSubscriber< MessageType >::queueSize, smacc2::client_core_components::CpTopicSubscriber< MessageType >::sub_, and smacc2::client_core_components::CpTopicSubscriber< MessageType >::topicName_.

Here is the call graph for this function:

◆ onMessageReceived()

◆ onStateOrthogonalAllocation()

template<typename MessageType >
template<typename TOrthogonal , typename TSourceObject >
void smacc2::client_core_components::CpTopicSubscriber< MessageType >::onStateOrthogonalAllocation ( )
inline

Definition at line 80 of file cp_topic_subscriber.hpp.

81 {
82 this->postMessageEvent = [=](auto msg)
83 {
85 event->msgData = msg;
86 this->postEvent(event);
87 };
88
89 this->postInitialMessageEvent = [=](auto msg)
90 {
91 auto event =
93 event->msgData = msg;
94 this->postEvent(event);
95 };
96 }
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)

References smacc2::makeEvent(), and smacc2::ISmaccComponent::postEvent().

Here is the call graph for this function:

Member Data Documentation

◆ firstMessage_

◆ initialized_

◆ onFirstMessageReceived_

template<typename MessageType >
smacc2::SmaccSignal<void(const MessageType &)> smacc2::client_core_components::CpTopicSubscriber< MessageType >::onFirstMessageReceived_

◆ onMessageReceived_

template<typename MessageType >
smacc2::SmaccSignal<void(const MessageType &)> smacc2::client_core_components::CpTopicSubscriber< MessageType >::onMessageReceived_

◆ postInitialMessageEvent

template<typename MessageType >
std::function<void(const MessageType &)> smacc2::client_core_components::CpTopicSubscriber< MessageType >::postInitialMessageEvent

◆ postMessageEvent

template<typename MessageType >
std::function<void(const MessageType &)> smacc2::client_core_components::CpTopicSubscriber< MessageType >::postMessageEvent

◆ qos_

template<typename MessageType >
std::optional<rclcpp::QoS> smacc2::client_core_components::CpTopicSubscriber< MessageType >::qos_
private

◆ queueSize

template<typename MessageType >
std::optional<int> smacc2::client_core_components::CpTopicSubscriber< MessageType >::queueSize

◆ sub_

template<typename MessageType >
rclcpp::Subscription<MessageType>::SharedPtr smacc2::client_core_components::CpTopicSubscriber< MessageType >::sub_
private

◆ topicName_

template<typename MessageType >
std::string smacc2::client_core_components::CpTopicSubscriber< MessageType >::topicName_
private

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