2#include <rosgraph_msgs/Log.h>
3#include <smacc_msgs/SmaccTransitionLogEntry.h>
4#include <boost/signals2.hpp>
18 virtual void init(XmlRpc::XmlRpcValue& initXmlRpcValue)
37 boost::signals2::signal<void(
const rosgraph_msgs::Log&)>
onRosOutMsg;
38 boost::signals2::signal<void(
const smacc_msgs::SmaccTransitionLogEntry&)>
onSmaccTransition;
41 std::shared_ptr<TestPolicy>
tryTestPolicyFactory(std::string matchname, XmlRpc::XmlRpcValue& initXmlRpcValue)
43 std::shared_ptr<TestPolicy> policy =
nullptr;
44 ROS_INFO_STREAM(initXmlRpcValue);
46 auto type = (std::string)initXmlRpcValue[
"type"];
48 if (type == matchname)
50 auto specificPolicy = std::make_shared<T>();
51 policy = std::dynamic_pointer_cast<TestPolicy>(specificPolicy);
54 policy->owner_ =
this;
55 policy->init(initXmlRpcValue);
63 ROS_INFO(
"[SmaccTestruntimeNode] subscribing rosout");
65 ros::NodeHandle private_nh(
"~");
66 std::string stateMachineROSParamWs;
67 if (private_nh.getParam(
"state_machine_rosparam_ws", stateMachineROSParamWs))
69 ROS_INFO_STREAM(
"state machine param ws: " << stateMachineROSParamWs);
75 XmlRpc::XmlRpcValue successSwitchParam;
76 private_nh.getParam(
"success_switch", successSwitchParam);
77 ROS_INFO_STREAM(
"[SmaccTestruntimeNode] success switch" << successSwitchParam);
78 ROS_ASSERT(successSwitchParam.getType() == XmlRpc::XmlRpcValue::TypeArray);
80 for (int32_t i = 0; i < successSwitchParam.size(); ++i)
82 auto initXmlRpcValue = successSwitchParam[i];
83 if (tryTestPolicyFactory<ReachedStateSuccessTestPolicy>(
"state_reached", initXmlRpcValue) !=
nullptr)
87 XmlRpc::XmlRpcValue failureSwitchParam;
88 private_nh.getParam(
"failure_switch", failureSwitchParam);
89 ROS_INFO_STREAM(
"[SmaccTestruntimeNode] failure switch" << failureSwitchParam);
90 ROS_ASSERT(failureSwitchParam.getType() == XmlRpc::XmlRpcValue::TypeArray);
92 for (int32_t i = 0; i < failureSwitchParam.size(); ++i)
94 auto initXmlRpcValue = failureSwitchParam[i];
95 if (tryTestPolicyFactory<TimeoutFailureTestPolicy>(
"timeout", initXmlRpcValue) !=
nullptr)
101 ROS_INFO_STREAM(
"SmaccRuntimeTestNode policy thrown success exit: " << msg);
107 ROS_FATAL_STREAM(
"SmaccRuntimeTestNode policy thrown failure exit: " << msg);
136 virtual void init(XmlRpc::XmlRpcValue& initXmlRpcValue)
override
138 ROS_INFO(
"[TimeoutFailureTestPolicy] initializating");
140 timeout_ = ros::Duration((
double)initXmlRpcValue[
"duration"]);
142 ROS_INFO_STREAM(
"[TimeoutFailureTestPolicy] duration: " <<
timeout_);
147 auto now = ros::Time::now();
161 virtual void init(XmlRpc::XmlRpcValue& initXmlRpcValue)
override
163 ROS_INFO(
"[ReachedStateSuccessTestPolicy] initializating");
165 ROS_INFO_STREAM(
"[ReachedStateSuccessTestPolicy] success state: " <<
targetStateName_);
169 ROS_INFO_STREAM(
"[ReachedStateSuccessTestPolicy] received state: " << msg.transition.destiny_state_name);
187 ros::init(argc, argv,
"smacc_runtime_test_node");
virtual void init(XmlRpc::XmlRpcValue &initXmlRpcValue) override
std::string targetStateName_
std::vector< std::shared_ptr< TestPolicy > > testPolicies
void onSmaccTransitionCallback(const smacc_msgs::SmaccTransitionLogEntry &msg)
void success(std::string msg)
void failure(std::string msg)
std::shared_ptr< TestPolicy > tryTestPolicyFactory(std::string matchname, XmlRpc::XmlRpcValue &initXmlRpcValue)
ros::Subscriber rosoutSub_
ros::Subscriber smaccTransitionSub_
boost::signals2::signal< void(const rosgraph_msgs::Log &)> onRosOutMsg
void onRosOutCallback(const rosgraph_msgs::Log &msg)
boost::signals2::signal< void(const smacc_msgs::SmaccTransitionLogEntry &)> onSmaccTransition
virtual void init(XmlRpc::XmlRpcValue &initXmlRpcValue)
SmaccTestRuntimeNode * owner_
virtual void init(XmlRpc::XmlRpcValue &initXmlRpcValue) override
int main(int argc, char **argv)