SMACC2
Loading...
Searching...
No Matches
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)
 
const std::vector< std::shared_ptr< ISmaccComponent > > & iterateComponents () const
 
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 127 of file smacc_subscriber_client.hpp.

128 {
129 if (firstMessage_)
130 {
133 firstMessage_ = false;
134 }
135
136 postMessageEvent(msg);
138 }
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 {
70 onFirstMessageReceived_, callback, object);
71 }
ISmaccStateMachine * getStateMachine()
boost::signals2::connection createSignalConnection(TSmaccSignal &signal, TMemberFunctionPrototype callback, TSmaccObjectType *object)

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

Definition at line 94 of file smacc_subscriber_client.hpp.

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

Definition at line 59 of file smacc_subscriber_client.hpp.

61 {
62 return this->getStateMachine()->createSignalConnection(onMessageReceived_, callback, object);
63 }

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

Referenced by smacc2::client_behaviors::CbSubscriptionCallbackBase< TMsg >::onEntry(), and cl_multirole_sensor::ClMultiroleSensor< MessageType >::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::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 {
79 auto event = new EvTopicMessage<TSourceObject, TOrthogonal>();
80 event->msgData = msg;
81 this->postEvent(event);
82 };
83
84 // initial ros topic message received smacc event callback
85 this->postInitialMessageEvent = [this](auto msg)
86 {
87 auto event = new EvTopicInitialMessage<TSourceObject, TOrthogonal>();
88 event->msgData = msg;
89 this->postEvent(event);
90 };
91 }

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: