userver: /data/code/userver/libraries/grpc-reflection/src/grpc-reflection/reflection_service_component.cpp Source File
Loading...
Searching...
No Matches
reflection_service_component.cpp
1#include <userver/grpc-reflection/reflection_service_component.hpp>
2
3#include <userver/logging/log.hpp>
4#include <userver/ugrpc/server/server_component.hpp>
5#include <userver/ugrpc/server/service_component_base.hpp>
6
7#include <grpc-reflection/proto_server_reflection.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace grpc_reflection {
12
13ReflectionServiceComponent::ReflectionServiceComponent(
14 const components::ComponentConfig& config,
15 const components::ComponentContext& context
16)
17 : ugrpc::server::ServiceComponentBase(config, context),
18 service_(std::make_unique<grpc_reflection::ProtoServerReflection>()),
19 ugrpc_server_(context.FindComponent<ugrpc::server::ServerComponent>().GetServer()) {
20 LOG_INFO() << "Preparing to register service";
21 RegisterService(*service_);
22 LOG_INFO() << "Service registered";
23}
24
25ReflectionServiceComponent::~ReflectionServiceComponent() = default;
26
27void ReflectionServiceComponent::AddService(std::string_view service) { service_->AddService(service); }
28
29void ReflectionServiceComponent::OnAllComponentsLoaded() {
30 const auto& service_names = ugrpc_server_.GetServiceNames();
31 service_->AddServiceList(service_names);
32 ready_.store(true);
33}
34
35components::ComponentHealth ReflectionServiceComponent::GetComponentHealth() const {
36 return ready_.load() ? components::ComponentHealth::kOk : components::ComponentHealth::kFatal;
37}
38
39} // namespace grpc_reflection
40
41USERVER_NAMESPACE_END