userver: /data/code/userver/libraries/grpc-reflection/src/grpc-reflection/proto_server_reflection.hpp Source File
Loading...
Searching...
No Matches
proto_server_reflection.hpp
1/*
2 *
3 * Copyright 2015 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18/* Code was modified by Yandex developers
19 * based on
20 * https://github.com/grpc/grpc/blob/0f9d024fec6a96cfa07ebae633e3ee96c933d3c4/src/cpp/ext/proto_server_reflection.cc
21 */
22
23#pragma once
24
25#include <string>
26#include <unordered_set>
27#include <vector>
28
29#include <grpcpp/grpcpp.h>
30#include <grpcpp/impl/codegen/config_protobuf.h>
31#include <grpcpp/support/config.h>
32#include <grpcpp/support/status.h>
33#include <grpcpp/support/sync_stream.h>
34
35#include <reflection.grpc.pb.h>
36#include <reflection.pb.h>
37#include <reflection_service.usrv.pb.hpp>
38
39#include <userver/concurrent/variable.hpp>
40
41USERVER_NAMESPACE_BEGIN
42
43namespace grpc_reflection {
44
45class ProtoServerReflection final : public grpc::reflection::v1alpha::ServerReflectionBase {
46public:
47 ProtoServerReflection();
48
49 // Add the full names of registered services
50 void AddService(std::string_view service);
51
52 // Add the full names of registered services
53 void AddServiceList(const std::vector<std::string_view>& services);
54
55 // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
56 // in ServerReflection service
57 ServerReflectionInfoResult ServerReflectionInfo(CallContext& context, ServerReflectionInfoReaderWriter& stream)
58 override;
59
60private:
61 grpc::Status ListService(grpc::reflection::v1alpha::ListServiceResponse& response);
62
63 grpc::Status
64 GetFileByName(std::string_view file_name, grpc::reflection::v1alpha::ServerReflectionResponse& response);
65
66 grpc::Status
67 GetFileContainingSymbol(std::string_view symbol, grpc::reflection::v1alpha::ServerReflectionResponse& response);
68
69 grpc::Status GetFileContainingExtension(
70 const grpc::reflection::v1alpha::ExtensionRequest& request,
71 grpc::reflection::v1alpha::ServerReflectionResponse& response
72 );
73
74 grpc::Status
75 GetAllExtensionNumbers(std::string_view type, grpc::reflection::v1alpha::ExtensionNumberResponse& response);
76
77 void FillFileDescriptorResponse(
78 const grpc::protobuf::FileDescriptor& file_desc,
79 grpc::reflection::v1alpha::ServerReflectionResponse& response,
80 std::unordered_set<std::string_view>& seen_files
81 );
82
83 void FillErrorResponse(const grpc::Status& status, grpc::reflection::v1alpha::ErrorResponse& error_response);
84
85 const grpc::protobuf::DescriptorPool* descriptor_pool_;
86 concurrent::Variable<std::unordered_set<std::string_view>> services_;
87};
88
89} // namespace grpc_reflection
90
91USERVER_NAMESPACE_END