SMACC2
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
smacc2::components::CpTopicSubscriber< MessageType > Class Template Reference

#include <cp_topic_subscriber.hpp>

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

Public Types

typedef MessageType TMessageType
 

Public Member Functions

 CpTopicSubscriber ()
 
 CpTopicSubscriber (std::string topicname)
 
virtual ~CpTopicSubscriber ()
 
template<typename T >
boost::signals2::connection onMessageReceived (void(T::*callback)(const MessageType &), T *object)
 
template<typename T >
boost::signals2::connection onFirstMessageReceived (void(T::*callback)(const MessageType &), T *object)
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
void onInitialize () override
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Public Attributes

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

Private Member Functions

void messageCallback (const MessageType &msg)
 

Private Attributes

rclcpp::Subscription< MessageType >::SharedPtr sub_
 
bool firstMessage_
 
bool initialized_
 
std::string topicName_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
virtual void onInitialize ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 
ISmaccStateMachinegetStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

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

Definition at line 34 of file cp_topic_subscriber.hpp.

Member Typedef Documentation

◆ TMessageType

template<typename MessageType >
typedef MessageType smacc2::components::CpTopicSubscriber< MessageType >::TMessageType

Definition at line 39 of file cp_topic_subscriber.hpp.

Constructor & Destructor Documentation

◆ CpTopicSubscriber() [1/2]

template<typename MessageType >
smacc2::components::CpTopicSubscriber< MessageType >::CpTopicSubscriber ( )
inline

◆ CpTopicSubscriber() [2/2]

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

◆ ~CpTopicSubscriber()

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

Definition at line 45 of file cp_topic_subscriber.hpp.

45{}

Member Function Documentation

◆ messageCallback()

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

Definition at line 113 of file cp_topic_subscriber.hpp.

114 {
115 if (firstMessage_)
116 {
119 firstMessage_ = false;
120 }
121
122 postMessageEvent(msg);
124 }
std::function< void(const MessageType &)> postMessageEvent
std::function< void(const MessageType &)> postInitialMessageEvent
smacc2::SmaccSignal< void(const MessageType &)> onFirstMessageReceived_
smacc2::SmaccSignal< void(const MessageType &)> onMessageReceived_

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

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

Here is the caller graph for this function:

◆ onFirstMessageReceived()

template<typename MessageType >
template<typename T >
boost::signals2::connection smacc2::components::CpTopicSubscriber< MessageType >::onFirstMessageReceived ( void(T::*)(const MessageType &)  callback,
T object 
)
inline

Definition at line 61 of file cp_topic_subscriber.hpp.

63 {
66 }
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)
void callback(const image_tools::ROSCvMatContainer &img)

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

Here is the call graph for this function:

◆ onInitialize()

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

Reimplemented from smacc2::ISmaccComponent.

Definition at line 84 of file cp_topic_subscriber.hpp.

85 {
86 if (!initialized_)
87 {
88 firstMessage_ = true;
89
90 if (!queueSize) queueSize = 1;
91
92 RCLCPP_INFO_STREAM(
93 getLogger(), "[" << this->getName() << "] Subscribing to topic: " << topicName_);
94
95 rclcpp::SensorDataQoS qos;
96 if (queueSize) qos.keep_last(*queueSize);
97
98 std::function<void(typename MessageType::SharedPtr)> fn = [this](auto msg) {
99 this->messageCallback(*msg);
100 };
101
102 sub_ = this->getNode()->template create_subscription<MessageType>(topicName_, qos, fn);
103 this->initialized_ = true;
104 }
105 }
rclcpp::Logger getLogger()
virtual std::string getName() const
rclcpp::Node::SharedPtr getNode()
rclcpp::Subscription< MessageType >::SharedPtr sub_
void messageCallback(const MessageType &msg)

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

Here is the call graph for this function:

◆ onMessageReceived()

template<typename MessageType >
template<typename T >
boost::signals2::connection smacc2::components::CpTopicSubscriber< MessageType >::onMessageReceived ( void(T::*)(const MessageType &)  callback,
T object 
)
inline

Definition at line 54 of file cp_topic_subscriber.hpp.

56 {
58 }

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

Referenced by sm_autoware_avp::clients::ClAutoware::onInitialize().

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

◆ onOrthogonalAllocation()

template<typename MessageType >
template<typename TOrthogonal , typename TSourceObject >
void smacc2::components::CpTopicSubscriber< MessageType >::onOrthogonalAllocation ( )
inline

Definition at line 69 of file cp_topic_subscriber.hpp.

70 {
71 this->postMessageEvent = [=](auto msg) {
72 auto event = new EvTopicMessage<TSourceObject, TOrthogonal, MessageType>();
73 event->msgData = msg;
74 this->postEvent(event);
75 };
76
77 this->postInitialMessageEvent = [=](auto msg) {
78 auto event = new EvTopicInitialMessage<TSourceObject, TOrthogonal, MessageType>();
79 event->msgData = msg;
80 this->postEvent(event);
81 };
82 }

References smacc2::ISmaccComponent::postEvent().

Here is the call graph for this function:

Member Data Documentation

◆ firstMessage_

template<typename MessageType >
bool smacc2::components::CpTopicSubscriber< MessageType >::firstMessage_
private

◆ initialized_

template<typename MessageType >
bool smacc2::components::CpTopicSubscriber< MessageType >::initialized_
private

◆ onFirstMessageReceived_

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

◆ onMessageReceived_

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

◆ postInitialMessageEvent

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

◆ postMessageEvent

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

◆ queueSize

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

◆ sub_

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

◆ topicName_

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

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