Change API Component(Wrapper<name> name, auto& context) -> Component(T& context) T::kName
This commit is contained in:
parent
3e1c4cfb84
commit
4d917d6375
8 changed files with 23 additions and 24 deletions
|
@ -6,8 +6,8 @@ struct SomeComponent : public cserver::server::handlers::HttpHandlerBaseWithAdde
|
|||
static constexpr utempl::ConstexprString kPath = "/v1/some/";
|
||||
static constexpr utempl::ConstexprString kName = "name";
|
||||
static constexpr utempl::ConstexprString kHandlerManagerName = "server";
|
||||
inline constexpr SomeComponent(auto name, auto& context) :
|
||||
HttpHandlerBaseWithAdder(name, context) {};
|
||||
inline constexpr SomeComponent(auto& context) :
|
||||
HttpHandlerBaseWithAdder(context) {};
|
||||
|
||||
inline auto HandleRequestThrow(const cserver::server::http::HttpRequest& request) -> cserver::Task<cserver::server::http::HttpResponse> {
|
||||
co_return cserver::server::http::HttpResponse{.body = request.url.data()};
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace cserver {
|
|||
|
||||
struct StopBlocker {
|
||||
boost::asio::io_context::work guard;
|
||||
inline constexpr StopBlocker(auto, auto& context) :
|
||||
inline constexpr StopBlocker(auto& context) :
|
||||
guard(context.template FindComponent<kBasicTaskProcessorName>().ioContext) {};
|
||||
};
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@ struct ServiceContextForComponent {
|
|||
T& context;
|
||||
static constexpr auto kConfig = T::kConfig;
|
||||
static constexpr auto kUtils = T::kUtils;
|
||||
static constexpr auto kName = Component::kName;
|
||||
|
||||
template <std::size_t I>
|
||||
constexpr auto FindComponent() -> decltype(this->context.template FindComponent<Component, I>()) {
|
||||
|
@ -174,8 +175,7 @@ inline constexpr auto InitComponents(T& ccontext) -> void {
|
|||
co_await flag->AsyncWait();
|
||||
};
|
||||
ServiceContextForComponent<decltype(Get<Is>(decltype(T::kUtils)::kComponentConfigs)), T> currentContext{context};
|
||||
Get<Is>(context.storage).emplace(utempl::Wrapper<Get<Is>(T::kUtils.kNames)>{},
|
||||
currentContext);
|
||||
Get<Is>(context.storage).emplace(currentContext);
|
||||
auto& componentInitFlag = GetInitFlagFor<AsyncConditionVariable, Is>(ioContext);
|
||||
componentInitFlag.NotifyAll();
|
||||
if constexpr(requires{Get<Is>(context.storage)->Run();}) {
|
||||
|
@ -311,7 +311,7 @@ template <typename Current, ConstexprConfig Config, typename... Ts>
|
|||
struct DependencyInfoInjector {
|
||||
static constexpr ConstexprConfig kConfig = Config;
|
||||
static constexpr DependenciesUtils<Ts...> kUtils;
|
||||
|
||||
static constexpr utempl::ConstexprString kName = Current::kName;
|
||||
template <utempl::ConstexprString name>
|
||||
static consteval auto FindComponentType() {
|
||||
if constexpr(name == kBasicTaskProcessorName) {
|
||||
|
@ -392,7 +392,7 @@ public:
|
|||
};
|
||||
template <utempl::ConstexprString name>
|
||||
static inline consteval auto Inject() {
|
||||
Ignore<decltype(Use<Current, utempl::Wrapper<name>{}, DependencyInfoInjector<Current, Config, Ts...>{}>())>();
|
||||
Ignore<decltype(Use<Current, DependencyInfoInjector<Current, Config, Ts...>{}>())>();
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ struct HttpHandlerBase {
|
|||
};
|
||||
co_await stream.Close();
|
||||
};
|
||||
inline constexpr HttpHandlerBase(auto, auto&) {};
|
||||
inline constexpr HttpHandlerBase(auto&) {};
|
||||
};
|
||||
template <typename T>
|
||||
struct HttpHandlerAdderType {
|
||||
|
@ -51,8 +51,8 @@ struct HttpHandlerAdderType {
|
|||
};
|
||||
template <typename T>
|
||||
struct HttpHandlerBaseWithAdder : HttpHandlerBase, HttpHandlerAdderType<T> {
|
||||
inline constexpr HttpHandlerBaseWithAdder(auto name, auto& context) :
|
||||
HttpHandlerBase(name, context),
|
||||
inline constexpr HttpHandlerBaseWithAdder(auto& context) :
|
||||
HttpHandlerBase(context),
|
||||
HttpHandlerAdderType<T>{} {};
|
||||
};
|
||||
|
||||
|
|
|
@ -35,18 +35,17 @@ struct Server : StopBlocker {
|
|||
});
|
||||
};
|
||||
template <
|
||||
utempl::ConstexprString Name,
|
||||
typename T,
|
||||
std::size_t... Is>
|
||||
inline constexpr Server(std::index_sequence<Is...>, utempl::Wrapper<Name> name, T& context) :
|
||||
StopBlocker(name, context),
|
||||
inline constexpr Server(std::index_sequence<Is...>, T& context) :
|
||||
StopBlocker(context),
|
||||
taskProcessor(context.template FindComponent<TPName>()),
|
||||
handlers{context.template FindComponent<Get<Is>(kNames)>()...},
|
||||
port(T::kConfig.template Get<Name>().template Get<"port">()) {
|
||||
port(T::kConfig.template Get<T::kName>().template Get<"port">()) {
|
||||
|
||||
};
|
||||
inline constexpr Server(auto name, auto& context) :
|
||||
Server(std::index_sequence_for<Ts...>{}, name, context) {
|
||||
inline constexpr Server(auto& context) :
|
||||
Server(std::index_sequence_for<Ts...>{}, context) {
|
||||
};
|
||||
template<auto I, typename Socket>
|
||||
auto ProcessHandler(Socket&& socket, http::HttpRequest request) -> Task<void> {
|
||||
|
|
|
@ -6,7 +6,7 @@ COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as<void>;});
|
|||
|
||||
struct SomeComponent {
|
||||
static constexpr utempl::ConstexprString kName = "some";
|
||||
constexpr SomeComponent(auto, auto& context) {
|
||||
constexpr SomeComponent(auto& context) {
|
||||
context.template FindAllComponents<SomeM>();
|
||||
};
|
||||
};
|
||||
|
@ -14,13 +14,13 @@ struct SomeComponent {
|
|||
struct OtherComponent {
|
||||
static constexpr utempl::ConstexprString kName = "other";
|
||||
auto f() -> void {};
|
||||
constexpr OtherComponent(auto, auto& context) {};
|
||||
constexpr OtherComponent(auto& context) {};
|
||||
};
|
||||
|
||||
struct OtherComponent2 {
|
||||
static constexpr utempl::ConstexprString kName = "other2";
|
||||
auto f() -> void {};
|
||||
constexpr OtherComponent2(auto, auto& context) {};
|
||||
constexpr OtherComponent2(auto& context) {};
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
struct SomeComponent {
|
||||
static constexpr utempl::ConstexprString kName = "some";
|
||||
constexpr SomeComponent(auto, auto&) {};
|
||||
constexpr SomeComponent(auto&) {};
|
||||
};
|
||||
|
||||
|
||||
struct SomeOtherComponent {
|
||||
SomeComponent& component;
|
||||
static constexpr utempl::ConstexprString kName = "other";
|
||||
constexpr SomeOtherComponent(auto, auto& context) : component(context.template FindComponent<"some">()) {
|
||||
constexpr SomeOtherComponent(auto& context) : component(context.template FindComponent<"some">()) {
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ COMPONENT_REQUIRES(Some, requires(T t){{t.f()} -> std::same_as<void>;});
|
|||
|
||||
struct SomeComponent {
|
||||
static constexpr utempl::ConstexprString kName = "some";
|
||||
constexpr SomeComponent(auto, auto& context) {
|
||||
constexpr SomeComponent(auto& context) {
|
||||
context.template FindComponent<SomeM>();
|
||||
};
|
||||
};
|
||||
|
@ -14,13 +14,13 @@ struct SomeComponent {
|
|||
struct OtherComponent {
|
||||
static constexpr utempl::ConstexprString kName = "other";
|
||||
auto f() -> void {};
|
||||
constexpr OtherComponent(auto, auto& context) {};
|
||||
constexpr OtherComponent(auto& context) {};
|
||||
};
|
||||
|
||||
struct OtherComponent2 {
|
||||
static constexpr utempl::ConstexprString kName = "other2";
|
||||
auto f() -> void {};
|
||||
constexpr OtherComponent2(auto, auto& context) {};
|
||||
constexpr OtherComponent2(auto& context) {};
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue