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

#include <smacc_subscriber_client.hpp>

Inheritance diagram for smacc2::client_bases::SmaccSubscriberClient< MessageType >:
Inheritance graph
Collaboration diagram for smacc2::client_bases::SmaccSubscriberClient< MessageType >:
Collaboration graph

Public Types

typedef MessageType TMessageType
 

Public Member Functions

 SmaccSubscriberClient ()
 
 SmaccSubscriberClient (std::string topicname)
 
virtual ~SmaccSubscriberClient ()
 
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 ()
 
- Public Member Functions inherited from smacc2::ISmaccClient
 ISmaccClient ()
 
virtual ~ISmaccClient ()
 
virtual void onInitialize ()
 
virtual std::string getName () const
 
template<typename TComponent >
TComponent * getComponent ()
 
template<typename TComponent >
TComponent * getComponent (std::string name)
 
template<typename TComponent >
TComponent * getComponent (int index)
 
virtual smacc2::introspection::TypeInfo::Ptr getType ()
 
ISmaccStateMachinegetStateMachine ()
 
template<typename TSmaccSignal , typename T >
void connectSignal (TSmaccSignal &signal, void(T::*callback)(), T *object)
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
void getComponents (std::vector< std::shared_ptr< ISmaccComponent > > &components)
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 

Public Attributes

std::optional< std::string > topicName
 
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
 

Protected Member Functions

void onInitialize () override
 
- Protected Member Functions inherited from smacc2::ISmaccClient
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 

Private Member Functions

void messageCallback (const MessageType &msg)
 

Private Attributes

rclcpp::Subscription< MessageType >::SharedPtr sub_
 
bool firstMessage_
 
bool initialized_
 

Additional Inherited Members

- Protected Attributes inherited from smacc2::ISmaccClient
std::map< ComponentKey, std::shared_ptr< smacc2::ISmaccComponent > > components_
 

Detailed Description

template<typename MessageType>
class smacc2::client_bases::SmaccSubscriberClient< MessageType >

Definition at line 38 of file smacc_subscriber_client.hpp.

Member Typedef Documentation

◆ TMessageType

template<typename MessageType >
typedef MessageType smacc2::client_bases::SmaccSubscriberClient< MessageType >::TMessageType

Definition at line 44 of file smacc_subscriber_client.hpp.

Constructor & Destructor Documentation

◆ SmaccSubscriberClient() [1/2]

template<typename MessageType >
smacc2::client_bases::SmaccSubscriberClient< MessageType >::SmaccSubscriberClient ( )
inline

◆ SmaccSubscriberClient() [2/2]

template<typename MessageType >
smacc2::client_bases::SmaccSubscriberClient< MessageType >::SmaccSubscriberClient ( std::string  topicname)
inline

◆ ~SmaccSubscriberClient()

template<typename MessageType >
virtual smacc2::client_bases::SmaccSubscriberClient< MessageType >::~SmaccSubscriberClient ( )
inlinevirtual

Definition at line 50 of file smacc_subscriber_client.hpp.

50{}

Member Function Documentation

◆ messageCallback()

template<typename MessageType >
void smacc2::client_bases::SmaccSubscriberClient< MessageType >::messageCallback ( const MessageType &  msg)
inlineprivate

Definition at line 126 of file smacc_subscriber_client.hpp.

127 {
128 if (firstMessage_)
129 {
132 firstMessage_ = false;
133 }
134
135 postMessageEvent(msg);
137 }
std::function< void(const MessageType &)> postMessageEvent
std::function< void(const MessageType &)> postInitialMessageEvent
smacc2::SmaccSignal< void(const MessageType &)> onMessageReceived_
smacc2::SmaccSignal< void(const MessageType &)> onFirstMessageReceived_

References smacc2::client_bases::SmaccSubscriberClient< MessageType >::firstMessage_, smacc2::client_bases::SmaccSubscriberClient< MessageType >::onFirstMessageReceived_, smacc2::client_bases::SmaccSubscriberClient< MessageType >::onMessageReceived_, smacc2::client_bases::SmaccSubscriberClient< MessageType >::postInitialMessageEvent, and smacc2::client_bases::SmaccSubscriberClient< MessageType >::postMessageEvent.

Referenced by smacc2::client_bases::SmaccSubscriberClient< MessageType >::onInitialize().

Here is the caller graph for this function:

◆ onFirstMessageReceived()

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

Definition at line 66 of file smacc_subscriber_client.hpp.

68 {
71 }
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::ISmaccClient::getStateMachine().

Here is the call graph for this function:

◆ onInitialize()

template<typename MessageType >
void smacc2::client_bases::SmaccSubscriberClient< MessageType >::onInitialize ( )
inlineoverrideprotectedvirtual

Reimplemented from smacc2::ISmaccClient.

Reimplemented in cl_multirole_sensor::ClMultiroleSensor< MessageType >, cl_multirole_sensor::ClMultiroleSensor< sensor_msgs::msg::LaserScan >, and cl_multirole_sensor::ClMultiroleSensor< sensor_msgs::msg::Temperature >.

Definition at line 92 of file smacc_subscriber_client.hpp.

93 {
94 if (!initialized_)
95 {
96 firstMessage_ = true;
97
98 if (!queueSize) queueSize = 1;
99
100 if (!topicName)
101 {
102 RCLCPP_ERROR(getLogger(), "topic client with no topic name set. Skipping subscribing");
103 }
104 else
105 {
106 RCLCPP_INFO_STREAM(
107 getLogger(), "[" << this->getName() << "] Subscribing to topic: " << *topicName);
108
109 rclcpp::SensorDataQoS qos;
110 if (queueSize) qos.keep_last(*queueSize);
111
112 std::function<void(typename MessageType::SharedPtr)> fn = [this](auto msg) {
113 this->messageCallback(*msg);
114 };
115 sub_ = getNode()->create_subscription<MessageType>(*topicName, qos, fn);
116 this->initialized_ = true;
117 }
118 }
119 }
rclcpp::Node::SharedPtr getNode()
Definition: client.cpp:60
virtual std::string getName() const
Definition: client.cpp:42
rclcpp::Logger getLogger()
rclcpp::Subscription< MessageType >::SharedPtr sub_

References smacc2::client_bases::SmaccSubscriberClient< MessageType >::firstMessage_, smacc2::ISmaccClient::getLogger(), smacc2::ISmaccClient::getName(), smacc2::ISmaccClient::getNode(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::initialized_, smacc2::client_bases::SmaccSubscriberClient< MessageType >::messageCallback(), smacc2::client_bases::SmaccSubscriberClient< MessageType >::queueSize, smacc2::client_bases::SmaccSubscriberClient< MessageType >::sub_, and smacc2::client_bases::SmaccSubscriberClient< MessageType >::topicName.

Referenced by cl_multirole_sensor::ClMultiroleSensor< MessageType >::onInitialize().

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

◆ onMessageReceived()

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

◆ onOrthogonalAllocation()

template<typename MessageType >
template<typename TOrthogonal , typename TSourceObject >
void smacc2::client_bases::SmaccSubscriberClient< MessageType >::onOrthogonalAllocation ( )
inline

Definition at line 74 of file smacc_subscriber_client.hpp.

75 {
76 // ros topic message received smacc event callback
77 this->postMessageEvent = [this](auto msg) {
78 auto event = new EvTopicMessage<TSourceObject, TOrthogonal>();
79 event->msgData = msg;
80 this->postEvent(event);
81 };
82
83 // initial ros topic message received smacc event callback
84 this->postInitialMessageEvent = [this](auto msg) {
85 auto event = new EvTopicInitialMessage<TSourceObject, TOrthogonal>();
86 event->msgData = msg;
87 this->postEvent(event);
88 };
89 }

References smacc2::ISmaccClient::postEvent().

Here is the call graph for this function:

Member Data Documentation

◆ firstMessage_

template<typename MessageType >
bool smacc2::client_bases::SmaccSubscriberClient< MessageType >::firstMessage_
private

◆ initialized_

template<typename MessageType >
bool smacc2::client_bases::SmaccSubscriberClient< MessageType >::initialized_
private

◆ onFirstMessageReceived_

template<typename MessageType >
smacc2::SmaccSignal<void(const MessageType &)> smacc2::client_bases::SmaccSubscriberClient< MessageType >::onFirstMessageReceived_

◆ onMessageReceived_

template<typename MessageType >
smacc2::SmaccSignal<void(const MessageType &)> smacc2::client_bases::SmaccSubscriberClient< MessageType >::onMessageReceived_

◆ postInitialMessageEvent

template<typename MessageType >
std::function<void(const MessageType &)> smacc2::client_bases::SmaccSubscriberClient< MessageType >::postInitialMessageEvent

◆ postMessageEvent

template<typename MessageType >
std::function<void(const MessageType &)> smacc2::client_bases::SmaccSubscriberClient< MessageType >::postMessageEvent

◆ queueSize

template<typename MessageType >
std::optional<int> smacc2::client_bases::SmaccSubscriberClient< MessageType >::queueSize

◆ sub_

template<typename MessageType >
rclcpp::Subscription<MessageType>::SharedPtr smacc2::client_bases::SmaccSubscriberClient< MessageType >::sub_
private

◆ topicName

template<typename MessageType >
std::optional<std::string> smacc2::client_bases::SmaccSubscriberClient< MessageType >::topicName

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