26#include <lttng/tracepoint.h>
37using namespace std::chrono_literals;
61 lastState_ = std::numeric_limits<unsigned long>::quiet_NaN();
78 auto & orthogonal = pair.second;
79 auto & clients = orthogonal->getClients();
81 for (
auto & client : clients)
86 if (updatableClient !=
nullptr)
94 std::vector<std::shared_ptr<ISmaccComponent>> components;
95 client->getComponents(components);
96 for (
auto & componententry : components)
98 auto updatableComponent =
dynamic_cast<ISmaccUpdatable *
>(componententry.get());
99 if (updatableComponent !=
nullptr)
103 "Adding updatable component: " <<
demangleType(
typeid(*updatableComponent)));
121 auto & orthogonal = pair.second;
122 auto & behaviors = orthogonal->getClientBehaviors();
124 for (
auto & currentBehavior : behaviors)
129 if (updatableClientBehavior !=
nullptr)
133 "Adding updatable behavior: " <<
demangleType(
typeid(updatableClientBehavior)));
140 if (updatableState !=
nullptr)
146 for (
auto & sr : statereactors)
149 if (updatableStateReactor !=
nullptr)
153 "Adding updatable stateReactorr: " <<
demangleType(
typeid(updatableStateReactor)));
159 for (
auto & eg : eventgenerators)
162 if (updatableEventGenerator !=
nullptr)
166 "Adding updatable eventGenerator: " <<
demangleType(
typeid(updatableEventGenerator)));
226 if (currentState !=
nullptr)
228 RCLCPP_INFO_THROTTLE(
230 "[SignalDetector] heartbeat. Current State: %s",
242 auto updatableElementName =
demangleType(
typeid(*updatableClient)).c_str();
247 "[PollOnce] update client call: " <<
demangleType(
typeid(*updatableClient)));
253 catch (
const std::exception & e)
257 "Error in updatable elemnent " << updatableElementName <<
": " << e.what() <<
'\n');
266 this->smaccStateMachine_->stateMachineCurrentAction !=
268 this->smaccStateMachine_->stateMachineCurrentAction !=
272 RCLCPP_DEBUG_STREAM(
getLogger(),
"[SignalDetector] update behaviors. checking current state");
274 if (currentState !=
nullptr)
276 RCLCPP_DEBUG_STREAM(
getLogger(),
"[SignalDetector] current state: " << currentStateIndex);
280 if (currentStateIndex != 0)
282 if (currentStateIndex != (
long)this->
lastState_.load())
286 "[PollOnce] detected new state, refreshing updatable client "
299 auto updatableElementName =
demangleType(
typeid(*udpatableStateElement)).c_str();
304 "[SignalDetector] update client behavior call: " << updatableElementName);
310 catch (
const std::exception & e)
314 "Error in updatable elemnent " << updatableElementName <<
": " << e.what() <<
'\n');
321 catch (std::exception & ex)
323 RCLCPP_ERROR(
getLogger(),
"Exception during Signal Detector update loop. %s", ex.what());
327 rclcpp::spin_some(nh);
339 rclcpp::Node::SharedPtr _;
349 if (!nh->get_parameter(
"signal_detector_loop_freq", this->loop_rate_hz))
353 "Signal detector frequency (ros param signal_detector_loop_freq) was not set, using default "
361 getLogger(),
"Signal detector frequency (ros param signal_detector_loop_freq): %lf",
365 nh->set_parameter(rclcpp::Parameter(
"signal_detector_loop_freq", this->
loop_rate_hz));
371 while (rclcpp::ok() && !
end_)
374 rclcpp::spin_some(nh);
StateMachineInternalAction stateMachineCurrentAction
rclcpp::Node::SharedPtr getNode()
const std::map< std::string, std::shared_ptr< smacc2::ISmaccOrthogonal > > & getOrthogonals() const
std::recursive_mutex m_mutex_
unsigned long getCurrentStateCounter() const
ISmaccState * getCurrentState() const
std::vector< std::shared_ptr< StateReactor > > & getStateReactors()
std::vector< std::shared_ptr< SmaccEventGenerator > > & getEventGenerators()
SmaccFifoScheduler * scheduler_
boost::thread signalDetectorThread_
void initialize(ISmaccStateMachine *stateMachine)
SignalDetector(SmaccFifoScheduler *scheduler)
std::atomic< unsigned long > lastState_
std::vector< ISmaccUpdatable * > updatableStateElements_
rclcpp::Logger getLogger()
rclcpp::Node::SharedPtr getNode()
SmaccFifoScheduler::processor_handle processorHandle_
std::vector< ISmaccUpdatable * > updatableClients_
void setProcessorHandle(SmaccFifoScheduler::processor_handle processorHandle)
void findUpdatableStateElements(ISmaccState *currentState)
void findUpdatableClientsAndComponents()
ISmaccStateMachine * smaccStateMachine_
std::atomic< bool > initialized_
std::string demangleType(const std::type_info *tinfo)
boost::statechart::fifo_scheduler< SmaccFifoWorker, SmaccAllocator > SmaccFifoScheduler
void TRACEPOINT(spinOnce)
smacc2_state_update_start