diff --git a/source/RobotAPI/libraries/skills/provider/CMakeLists.txt b/source/RobotAPI/libraries/skills/provider/CMakeLists.txt index 9cb59c319fdf937ee9eb341610071f44114de3c1..83d51089a1298c56819a820b02e4db8eb3b0ff5a 100644 --- a/source/RobotAPI/libraries/skills/provider/CMakeLists.txt +++ b/source/RobotAPI/libraries/skills/provider/CMakeLists.txt @@ -46,6 +46,8 @@ armarx_add_library( detail/SkillImplementationWrapper.h SkillContext.h + blueprints/SkillWithContextBlueprint.h + mixins/All.h mixins/ArvizSkillMixin.h diff --git a/source/RobotAPI/libraries/skills/provider/SkillProviderComponentPlugin.h b/source/RobotAPI/libraries/skills/provider/SkillProviderComponentPlugin.h index 20ffe1fbdb75ee9f4b5831dbd406180f7acf22fc..858ee511de6fa042e257b202b6cee3bf94a446a1 100644 --- a/source/RobotAPI/libraries/skills/provider/SkillProviderComponentPlugin.h +++ b/source/RobotAPI/libraries/skills/provider/SkillProviderComponentPlugin.h @@ -72,7 +72,7 @@ namespace armarx::plugins { auto fac = std::make_unique<FactoryT>(std::forward<Args>(args)...); auto* facPtr = fac.get(); - addCustomSkillFactory(std::move(fac)); + addSkillFactory(std::move(fac)); return static_cast<FactoryT*>(facPtr); } @@ -189,7 +189,7 @@ namespace armarx requires skills::isSkillBlueprint<FacT> FacT* addCustomSkillFactory(Args&&... args) { - return plugin->addSkillFactory<FacT>(std::forward<Args>(args)...); + return plugin->addCustomSkillFactory<FacT>(std::forward<Args>(args)...); } private: diff --git a/source/RobotAPI/libraries/skills/provider/blueprints/SkillWithContextBlueprint.h b/source/RobotAPI/libraries/skills/provider/blueprints/SkillWithContextBlueprint.h new file mode 100644 index 0000000000000000000000000000000000000000..0efc94c812001203a30f24b8b4d7ce4fa55280aa --- /dev/null +++ b/source/RobotAPI/libraries/skills/provider/blueprints/SkillWithContextBlueprint.h @@ -0,0 +1,68 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI + * @author Christoph Pohl ( christoph dot pohl at kit dot edu ) + * @date 05.12.23 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/skills/provider/SkillFactory.h> + +namespace armarx +{ + namespace skills + { +// template <typename T> +// concept takesContext = requires(typename T::Context cntxt) { +// { T::connectTo(cntxt) } -> void; +// }; + + + template <typename SkillT> + class SkillWithContextBlueprint : public SkillBlueprint + { + public: + using ContextT = typename SkillT::Context; + + template <typename... Args> + SkillWithContextBlueprint(Args&&... args) : + SkillBlueprint(*SkillBlueprint::ForSkill<SkillT>(std::forward<Args>(args)...)) + { + } + + virtual std::unique_ptr<Skill> + createSkill(const ProviderID& pid) const override + { + auto s = _createSkill(); + s->setProviderId(pid); + static_cast<SkillT*>(s.get())->connectTo(context_); + return s; + } + + void + connectTo(const ContextT& services) + { + context_ = services; + } + + private: + ContextT context_; + }; + } // namespace skills +} // namespace armarx \ No newline at end of file