SMACC2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
smacc2::client_bases::ClRosLaunch Class Reference

#include <smacc_ros_launch_client.hpp>

Inheritance diagram for smacc2::client_bases::ClRosLaunch:
Inheritance graph
Collaboration diagram for smacc2::client_bases::ClRosLaunch:
Collaboration graph

Public Member Functions

 ClRosLaunch (std::string packageName, std::string launchFilename)
 
virtual ~ClRosLaunch ()
 
void launch ()
 
void stop ()
 
- 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 ()
 

Static Public Member Functions

static std::future< std::string > executeRosLaunch (std::string packageName, std::string launchFilename, std::function< bool()> cancelCondition)
 

Public Attributes

std::string packageName_
 
std::string launchFileName_
 

Protected Attributes

std::future< std::string > result_
 
std::atomic< boolcancellationToken_ = ATOMIC_VAR_INIT(false)
 
- Protected Attributes inherited from smacc2::ISmaccClient
std::map< ComponentKey, std::shared_ptr< smacc2::ISmaccComponent > > components_
 

Additional Inherited Members

- 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 ()
 

Detailed Description

Definition at line 33 of file smacc_ros_launch_client.hpp.

Constructor & Destructor Documentation

◆ ClRosLaunch()

smacc2::client_bases::ClRosLaunch::ClRosLaunch ( std::string  packageName,
std::string  launchFilename 
)

Definition at line 27 of file smacc_ros_launch_client.cpp.

◆ ~ClRosLaunch()

smacc2::client_bases::ClRosLaunch::~ClRosLaunch ( )
virtual

Definition at line 32 of file smacc_ros_launch_client.cpp.

32{}

Member Function Documentation

◆ executeRosLaunch()

std::future< std::string > smacc2::client_bases::ClRosLaunch::executeRosLaunch ( std::string  packageName,
std::string  launchFilename,
std::function< bool()>  cancelCondition 
)
static

Definition at line 42 of file smacc_ros_launch_client.cpp.

44{
45 return std::async(
46 std::launch::async,
47 [=]()
48 {
49 RCLCPP_WARN_STREAM(
50 rclcpp::get_logger("smacc2"), "[ClRosLaunch static] starting ros launch thread ");
51
52 std::stringstream cmd;
53 cmd << "ros2 launch " << packageName << " " << launchFileName;
54
55 std::array<char, 128> buffer;
56 std::string result;
57 std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.str().c_str(), "r"), pclose);
58 if (!pipe)
59 {
60 throw std::runtime_error("popen() failed!");
61 }
62
63 std::stringstream ss;
64 bool cancelled = false;
65 while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr &&
66 !(cancelled = cancelCondition()))
67 {
68 ss << buffer.data();
69 }
70
71 result = ss.str();
72 RCLCPP_WARN_STREAM(
73 rclcpp::get_logger("smacc2"), "[ClRosLaunch static]] RESULT = \n " << ss.str());
74 return result;
75 });
76}

Referenced by launch(), and smacc2::client_behaviors::CbRosLaunch::onEntry().

Here is the caller graph for this function:

◆ launch()

void smacc2::client_bases::ClRosLaunch::launch ( )

Definition at line 34 of file smacc_ros_launch_client.cpp.

35{
37 packageName_, launchFileName_, [this]() { return this->cancellationToken_.load(); });
38}
static std::future< std::string > executeRosLaunch(std::string packageName, std::string launchFilename, std::function< bool()> cancelCondition)

References cancellationToken_, executeRosLaunch(), launchFileName_, packageName_, and result_.

Referenced by smacc2::client_behaviors::CbRosLaunch::onEntry().

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

◆ stop()

void smacc2::client_bases::ClRosLaunch::stop ( )

Definition at line 40 of file smacc_ros_launch_client.cpp.

40{ cancellationToken_.store(true); }

References cancellationToken_.

Member Data Documentation

◆ cancellationToken_

std::atomic<bool> smacc2::client_bases::ClRosLaunch::cancellationToken_ = ATOMIC_VAR_INIT(false)
protected

Definition at line 54 of file smacc_ros_launch_client.hpp.

Referenced by launch(), and stop().

◆ launchFileName_

std::string smacc2::client_bases::ClRosLaunch::launchFileName_

◆ packageName_

std::string smacc2::client_bases::ClRosLaunch::packageName_

◆ result_

std::future<std::string> smacc2::client_bases::ClRosLaunch::result_
protected

Definition at line 52 of file smacc_ros_launch_client.hpp.

Referenced by launch().


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