.. _program_listing_file__tmp_ws_src_SMACC2_smacc2_include_smacc2_impl_smacc_state_reactor_impl.hpp: Program Listing for File smacc_state_reactor_impl.hpp ===================================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/SMACC2/smacc2/include/smacc2/impl/smacc_state_reactor_impl.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2021 RobosoftAI Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /***************************************************************************************************************** * * Authors: Pablo Inigo Blasco, Brett Aldrich * ******************************************************************************************************************/ #pragma once #include #include namespace smacc2 { template void StateReactor::postEvent(const EventType & ev) { ownerState->postEvent(ev); } template void StateReactor::postEvent() { ownerState->postEvent(); } template void StateReactor::setOutputEvent() { this->postEventFn = [this]() { RCLCPP_INFO_STREAM( this->getLogger(), "[State Reactor Base] postingfn posting event: " << demangleSymbol()); auto * ev = new TEv(); this->ownerState->getStateMachine().postEvent(ev); }; } template void StateReactor::addInputEvent() { this->eventTypes.push_back(&typeid(TEv)); } template void StateReactor::createEventCallback(void (TClass::*callback)(T *), TClass * object) { const auto * eventtype = &typeid(T); this->eventCallbacks_[eventtype] = [=](void * msg) { T * evptr = (T *)msg; (object->*callback)(evptr); }; } template void StateReactor::createEventCallback(std::function callback) { const auto * eventtype = &typeid(T); this->eventCallbacks_[eventtype] = [=](void * msg) { T * evptr = (T *)msg; callback(evptr); }; } namespace introspection { template void StateReactorHandler::addInputEvent() { StateReactorCallbackFunctor functor; functor.fn = [this](std::shared_ptr sr) { RCLCPP_INFO( nh_->get_logger(), "[%s] State Reactor adding input event: %s", srInfo_->stateReactorType->getFullName().c_str(), demangledTypeName().c_str()); sr->addInputEvent(); }; this->callbacks_.push_back(functor); auto evtype = TypeInfo::getFromStdTypeInfo(typeid(TEv)); auto evinfo = std::make_shared(evtype); EventLabel(evinfo->label); srInfo_->sourceEventTypes.push_back(evinfo); } template void StateReactorHandler::setOutputEvent() { StateReactorCallbackFunctor functor; functor.fn = [this](std::shared_ptr sr) { RCLCPP_INFO( nh_->get_logger(), "[%s] State Reactor setting output event: %s", srInfo_->stateReactorType->getFullName().c_str(), demangledTypeName().c_str()); sr->setOutputEvent(); }; this->callbacks_.push_back(functor); } } // namespace introspection } // namespace smacc2