diff --git a/include/cserver/engine/basic/task_processor.hpp b/include/cserver/engine/basic/task_processor.hpp index d41ca47..3e7042a 100644 --- a/include/cserver/engine/basic/task_processor.hpp +++ b/include/cserver/engine/basic/task_processor.hpp @@ -1,6 +1,5 @@ #pragma once -#include -#include +#include #include namespace cserver::engine::basic { @@ -15,14 +14,6 @@ struct TaskProcessor { pool{} { }; - template - static consteval auto Adder(const T& context) { - constexpr std::size_t Count = T::kConfig.template Get().template Get<"threadPoolSize">(); - return context.TransformComponents( - [&](const ComponentConfig, Options>&) -> ComponentConfig, Options> { - return {}; - }); - }; inline constexpr ~TaskProcessor() { for(auto& thread : this->pool) { thread.join(); diff --git a/include/cserver/engine/components.hpp b/include/cserver/engine/components.hpp index d37182f..4e7ac3b 100644 --- a/include/cserver/engine/components.hpp +++ b/include/cserver/engine/components.hpp @@ -1,8 +1,12 @@ #pragma once +#include #include #include namespace cserver { + +inline constexpr utempl::ConstexprString kBasicTaskProcessorName = "basicTaskProcessor"; + struct SeparatedComponent {}; template struct Options : utempl::TypeList {}; @@ -64,8 +68,10 @@ struct ServiceContext { static constexpr auto kConfig = config; static constexpr auto kList = utempl::TypeList{}; static constexpr auto kThreadsCount = config.template Get<"threads">(); + engine::basic::TaskProcessor taskProcessor; utempl::Tuple storage; inline constexpr ServiceContext() : + taskProcessor{utempl::Wrapper{}, *this}, storage{ [&](std::index_sequence) -> utempl::Tuple { return {[&](utempl::Wrapper) { @@ -89,6 +95,10 @@ struct ServiceContext { constexpr auto I = utempl::Find(names, name); return Get(this->storage); }; + template <> + inline constexpr auto FindComponent() -> auto& { + return this->taskProcessor; + }; template inline constexpr auto FindComponent() -> T& { constexpr auto I = utempl::Find>(utempl::kTypeList); @@ -159,8 +169,12 @@ struct DependencyInfoInjector { private: template static consteval auto FindComponentTypeImpl(ComponentConfig...) { - constexpr auto I = utempl::Find(utempl::Tuple{std::string_view{names}...}, std::string_view{name}); - return [] -> decltype(utempl::Get(utempl::TypeList{})) {}(); + if constexpr(name == kBasicTaskProcessorName) { + return [] -> engine::basic::TaskProcessor()> {}(); + } else { + constexpr auto I = utempl::Find(utempl::Tuple{std::string_view{names}...}, std::string_view{name}); + return [] -> decltype(utempl::Get(utempl::TypeList{})) {}(); + }; }; public: template @@ -187,6 +201,7 @@ public: > static constexpr auto FindComponent() -> FindComponentType&; + template < typename T, typename..., @@ -208,9 +223,19 @@ public: return utempl::Tuple{}; } else { if constexpr(requires{GetDependencies();}) { - return GetDependencies{}>{})>(); + constexpr auto name = Magic(loopholes::Getter{}>{}); + if constexpr(name == kBasicTaskProcessorName) { + return GetDependencies(); + } else { + return GetDependencies(); + }; } else { - return utempl::Tuple{names..., Magic(loopholes::Getter{}>{})}; + constexpr auto name = Magic(loopholes::Getter{}>{}); + if constexpr(name == kBasicTaskProcessorName) { + return utempl::Tuple{names...}; + } else { + return utempl::Tuple{names..., name}; + }; }; }; }; @@ -339,13 +364,16 @@ struct ServiceContextBuilder { }; template static consteval auto FindComponent() { - return [] - (const ServiceContextBuilder...>&) - -> decltype(utempl::Get(utempl::TypeList{})) { - std::unreachable(); - }(ServiceContextBuilder{}); + if constexpr(name == kBasicTaskProcessorName) { + return [] -> engine::basic::TaskProcessor()> {}(); + } else { + return [] + (const ServiceContextBuilder...>&) + -> decltype(utempl::Get(utempl::TypeList{})) { + std::unreachable(); + }(ServiceContextBuilder{}); + }; }; - static consteval auto Config() { return config; };