.. _program_listing_file__tmp_ws_src_SMACC2_smacc2_include_smacc2_impl_smacc_client_impl.hpp: Program Listing for File smacc_client_impl.hpp ============================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/SMACC2/smacc2/include/smacc2/impl/smacc_client_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 ISmaccClient::postEvent(const EventType & ev) { stateMachine_->postEvent(ev); } template void ISmaccClient::postEvent() { stateMachine_->postEvent(); } template TComponent * ISmaccClient::getComponent() { return this->getComponent(std::string()); } template TComponent * ISmaccClient::getComponent(int index) { int count = 0; for (auto & component : components_) { auto * tcomponent = dynamic_cast(component.second.get()); if (tcomponent != nullptr) { if (count == index) { return tcomponent; } else { count++; continue; } } } return nullptr; } template TComponent * ISmaccClient::getComponent(std::string name) { for (auto & component : components_) { if (!name.empty() && component.first.name != name) continue; auto * tcomponent = dynamic_cast(component.second.get()); if (tcomponent != nullptr) { return tcomponent; } } return nullptr; } //inline ISmaccStateMachine * ISmaccClient::getStateMachine() { return this->stateMachine_; } template SmaccComponentType * ISmaccClient::createNamedComponent(std::string name, TArgs... targs) { ComponentKey componentkey(&typeid(SmaccComponentType), name); std::shared_ptr ret; auto it = this->components_.find(componentkey); if (it == this->components_.end()) { auto tname = demangledTypeName(); RCLCPP_INFO( getLogger(), "Creating a new component of type %s smacc component is required by client '%s'. Creating a " "new instance %s", this->getName().c_str(), demangledTypeName().c_str(), tname.c_str()); ret = std::shared_ptr(new SmaccComponentType(targs...)); ret->setStateMachine(this->getStateMachine()); ret->owner_ = this; ret->initialize(this); this->components_[componentkey] = ret; //std::dynamic_pointer_cast(ret); RCLCPP_DEBUG(getLogger(), "%s resource is required. Done.", tname.c_str()); } else { RCLCPP_INFO( getLogger(), "%s resource is required. Found resource in cache.", demangledTypeName().c_str()); ret = dynamic_pointer_cast(it->second); } ret->template onOrthogonalAllocation(); return ret.get(); } template SmaccComponentType * ISmaccClient::createComponent(TArgs... targs) { return this->createNamedComponent( std::string(), targs...); } template void ISmaccClient::connectSignal(TSmaccSignal & signal, void (T::*callback)(), T * object) { return this->getStateMachine()->createSignalConnection(signal, callback, object); } template void ISmaccClient::requiresClient(SmaccClientType *& storage) { this->orthogonal_->requiresClient(storage); } } // namespace smacc2