.. _program_listing_file_include_smacc2_smacc_client.hpp: Program Listing for File smacc_client.hpp ========================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/smacc2/smacc_client.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 #include namespace smacc2 { struct ComponentKey { ComponentKey(const std::type_info * typeinfo, std::string name) { this->name = name; this->typeinfo = typeinfo; encodedKey = std::to_string((long)(void *)typeinfo) + "_" + name; } std::string encodedKey; const std::type_info * typeinfo; std::string name; bool operator<(const ComponentKey & other) const { return this->encodedKey < other.encodedKey; } bool operator==(const ComponentKey & other) const { return this->encodedKey == other.encodedKey; } }; class ISmaccClient { public: ISmaccClient(); virtual ~ISmaccClient(); virtual void onInitialize(); // Returns a custom identifier defined by the specific plugin implementation virtual std::string getName() const; template TComponent * getComponent(); template TComponent * getComponent(std::string name); // Gets the i-th component of type TComponent template TComponent * getComponent(int index); virtual smacc2::introspection::TypeInfo::Ptr getType(); inline ISmaccStateMachine * getStateMachine(); template void connectSignal(TSmaccSignal & signal, void (T::*callback)(), T * object); template void requiresClient(SmaccClientType *& storage); void getComponents(std::vector> & components); const std::vector> & iterateComponents() const; // now this needs to be public because sub-components needs to use. This is something to improve. template void postEvent(const EventType & ev); // now this needs to be public because sub-components needs to use. This is something to improve. template void postEvent(); protected: // it is called after the client initialization, provides information about the orthogonal it is located in template void onOrthogonalAllocation() { } // components std::map> components_; template SmaccComponentType * createComponent(TArgs... targs); template SmaccComponentType * createNamedComponent(std::string name, TArgs... targs); rclcpp::Node::SharedPtr getNode(); inline rclcpp::Logger getLogger() { return getNode()->get_logger(); } private: // A reference to the state machine object that owns this resource ISmaccStateMachine * stateMachine_; ISmaccOrthogonal * orthogonal_; // friend method called by orthogonal void initialize(); // friend method called by orthogonal // Assigns the owner of this resource to the given state machine parameter object void setStateMachine(ISmaccStateMachine * stateMachine); // friend method called by orthogonal void setOrthogonal(ISmaccOrthogonal * orthogonal); friend class ISmaccOrthogonal; friend class ISmaccComponent; }; } // namespace smacc2