SMACC2
Loading...
Searching...
No Matches
smacc2::client_behaviors::CbServiceCall< ServiceType > Class Template Reference

#include <cb_call_service.hpp>

Inheritance diagram for smacc2::client_behaviors::CbServiceCall< ServiceType >:
Inheritance graph
Collaboration diagram for smacc2::client_behaviors::CbServiceCall< ServiceType >:
Collaboration graph

Public Member Functions

 CbServiceCall (const char *serviceName)
 
 CbServiceCall (const char *serviceName, std::shared_ptr< typename ServiceType::Request > request, std::chrono::milliseconds pollRate=100ms)
 
void onEntry () override
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onExit ()
 

Public Attributes

std::shared_future< std::shared_ptr< typename ServiceType::Response > > resultFuture_
 

Protected Member Functions

virtual void onServiceResponse (std::shared_ptr< typename ServiceType::Response >)
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 

Protected Attributes

std::shared_ptr< rclcpp::Client< ServiceType > > client_
 
std::string serviceName_
 
std::shared_ptr< typename ServiceType::Request > request_
 
std::shared_ptr< typename ServiceType::Response > result_
 
std::chrono::milliseconds pollRate_
 

Detailed Description

template<typename ServiceType>
class smacc2::client_behaviors::CbServiceCall< ServiceType >

Definition at line 30 of file cb_call_service.hpp.

Constructor & Destructor Documentation

◆ CbServiceCall() [1/2]

template<typename ServiceType >
smacc2::client_behaviors::CbServiceCall< ServiceType >::CbServiceCall ( const char * serviceName)
inline

Definition at line 33 of file cb_call_service.hpp.

34 : serviceName_(serviceName),
35 request_(std::make_shared<typename ServiceType::Request>()),
36 pollRate_(100ms)
37 {
38 }
std::shared_ptr< typename ServiceType::Request > request_

◆ CbServiceCall() [2/2]

template<typename ServiceType >
smacc2::client_behaviors::CbServiceCall< ServiceType >::CbServiceCall ( const char * serviceName,
std::shared_ptr< typename ServiceType::Request > request,
std::chrono::milliseconds pollRate = 100ms )
inline

Definition at line 40 of file cb_call_service.hpp.

43 : serviceName_(serviceName), request_(request), result_(nullptr), pollRate_(pollRate)
44 {
45 }
std::shared_ptr< typename ServiceType::Response > result_

Member Function Documentation

◆ onEntry()

template<typename ServiceType >
void smacc2::client_behaviors::CbServiceCall< ServiceType >::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 47 of file cb_call_service.hpp.

48 {
49 RCLCPP_INFO_STREAM(
50 getLogger(), "[" << this->getName() << "] creating ros service client: " << serviceName_);
51
52 client_ = getNode()->template create_client<ServiceType>(serviceName_);
53
54 RCLCPP_INFO_STREAM(
55 getLogger(), "[" << this->getName() << "] making service request to " << serviceName_);
56
57 resultFuture_ = client_->async_send_request(request_).future.share();
58
59 std::future_status status = resultFuture_.wait_for(0s);
60
61 RCLCPP_INFO_STREAM(
62 getLogger(), "thread state: " << (int)status << " ok " << rclcpp::ok() << " shutdown "
63 << this->isShutdownRequested() << "");
64
65 while (status != std::future_status::ready && rclcpp::ok() && !this->isShutdownRequested())
66 {
67 RCLCPP_INFO_STREAM_THROTTLE(
68 getLogger(), *getNode()->get_clock(), 1000,
69 "[" << this->getName() << "] waiting response ");
70 rclcpp::sleep_for(pollRate_);
71 status = resultFuture_.wait_for(0s);
72 }
73
74 if (status == std::future_status::ready)
75 {
76 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] response received ");
77 result_ = resultFuture_.get();
79 this->postSuccessEvent();
80 }
81 else
82 {
83 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] response not received ");
84 this->postFailureEvent();
85 }
86 }
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...
std::shared_ptr< rclcpp::Client< ServiceType > > client_
virtual void onServiceResponse(std::shared_ptr< typename ServiceType::Response >)
std::shared_future< std::shared_ptr< typename ServiceType::Response > > resultFuture_

References smacc2::client_behaviors::CbServiceCall< ServiceType >::client_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), smacc2::SmaccAsyncClientBehavior::isShutdownRequested(), smacc2::client_behaviors::CbServiceCall< ServiceType >::onServiceResponse(), smacc2::client_behaviors::CbServiceCall< ServiceType >::pollRate_, smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), smacc2::client_behaviors::CbServiceCall< ServiceType >::request_, smacc2::client_behaviors::CbServiceCall< ServiceType >::result_, smacc2::client_behaviors::CbServiceCall< ServiceType >::resultFuture_, and smacc2::client_behaviors::CbServiceCall< ServiceType >::serviceName_.

Referenced by cl_nav2z::CbPauseSlam::onEntry(), and cl_nav2z::CbResumeSlam::onEntry().

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

◆ onServiceResponse()

template<typename ServiceType >
virtual void smacc2::client_behaviors::CbServiceCall< ServiceType >::onServiceResponse ( std::shared_ptr< typename ServiceType::Response > )
inlineprotectedvirtual

Definition at line 97 of file cb_call_service.hpp.

98 {
99 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] response received ");
100 }

References smacc2::ISmaccClientBehavior::getLogger(), and smacc2::ISmaccClientBehavior::getName().

Referenced by smacc2::client_behaviors::CbServiceCall< ServiceType >::onEntry().

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

Member Data Documentation

◆ client_

template<typename ServiceType >
std::shared_ptr<rclcpp::Client<ServiceType> > smacc2::client_behaviors::CbServiceCall< ServiceType >::client_
protected

◆ pollRate_

template<typename ServiceType >
std::chrono::milliseconds smacc2::client_behaviors::CbServiceCall< ServiceType >::pollRate_
protected

◆ request_

template<typename ServiceType >
std::shared_ptr<typename ServiceType::Request> smacc2::client_behaviors::CbServiceCall< ServiceType >::request_
protected

◆ result_

template<typename ServiceType >
std::shared_ptr<typename ServiceType::Response> smacc2::client_behaviors::CbServiceCall< ServiceType >::result_
protected

◆ resultFuture_

template<typename ServiceType >
std::shared_future<std::shared_ptr<typename ServiceType::Response> > smacc2::client_behaviors::CbServiceCall< ServiceType >::resultFuture_

◆ serviceName_

template<typename ServiceType >
std::string smacc2::client_behaviors::CbServiceCall< ServiceType >::serviceName_
protected

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