diff options
Diffstat (limited to 'src/cpp/ext/proto_server_reflection.h')
-rw-r--r-- | src/cpp/ext/proto_server_reflection.h | 104 |
1 files changed, 29 insertions, 75 deletions
diff --git a/src/cpp/ext/proto_server_reflection.h b/src/cpp/ext/proto_server_reflection.h index 5482c9bc25..60a6f5614a 100644 --- a/src/cpp/ext/proto_server_reflection.h +++ b/src/cpp/ext/proto_server_reflection.h @@ -19,10 +19,8 @@ #ifndef GRPC_SRC_CPP_EXT_PROTO_SERVER_REFLECTION_H #define GRPC_SRC_CPP_EXT_PROTO_SERVER_REFLECTION_H -#include <memory> #include <string> #include <unordered_set> -#include <utility> #include <vector> #include <grpcpp/grpcpp.h> @@ -31,72 +29,18 @@ #include <grpcpp/support/status.h> #include <grpcpp/support/sync_stream.h> -#include "src/proto/grpc/reflection/v1/reflection.grpc.pb.h" -#include "src/proto/grpc/reflection/v1/reflection.pb.h" #include "src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h" #include "src/proto/grpc/reflection/v1alpha/reflection.pb.h" namespace grpc { -class ProtoServerReflectionBackend { - public: - ProtoServerReflectionBackend() - : descriptor_pool_(protobuf::DescriptorPool::generated_pool()) {} - - void SetServiceList(const std::vector<std::string>* services) { - services_ = services; - } - - template <typename Request, typename Response> - Status ServerReflectionInfo( - ServerReaderWriter<Response, Request>* stream) const; - - private: - template <typename Response> - Status ListService(Response* response) const; - - template <typename Response> - Status GetFileByName(const std::string& file_name, Response* response) const; - - template <typename Response> - Status GetFileContainingSymbol(const std::string& symbol, - Response* response) const; - - template <typename Request, typename Response> - Status GetFileContainingExtension(const Request* request, - Response* response) const; - - template <typename Response> - Status GetAllExtensionNumbers(const std::string& type, - Response* response) const; - - template <typename Response> - void FillFileDescriptorResponse( - const protobuf::FileDescriptor* file_desc, Response* response, - std::unordered_set<std::string>* seen_files) const; - - template <typename Response> - void FillErrorResponse(const Status& status, Response* error_response) const; - - const protobuf::DescriptorPool* descriptor_pool_; - const std::vector<string>* services_; -}; - class ProtoServerReflection final : public reflection::v1alpha::ServerReflection::Service { public: - ProtoServerReflection() - : grpc::ProtoServerReflection( - std::make_shared<ProtoServerReflectionBackend>()) {} - - explicit ProtoServerReflection( - std::shared_ptr<ProtoServerReflectionBackend> backend) - : backend_(std::move(backend)) {} + ProtoServerReflection(); // Add the full names of registered services - void SetServiceList(const std::vector<std::string>* services) { - backend_->SetServiceList(services); - } + void SetServiceList(const std::vector<std::string>* services); // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc // in ServerReflection service @@ -106,26 +50,36 @@ class ProtoServerReflection final reflection::v1alpha::ServerReflectionRequest>* stream) override; - std::shared_ptr<ProtoServerReflectionBackend> backend_; -}; + private: + Status ListService(ServerContext* context, + reflection::v1alpha::ListServiceResponse* response); -class ProtoServerReflectionV1 final - : public reflection::v1::ServerReflection::Service { - public: - explicit ProtoServerReflectionV1( - std::shared_ptr<ProtoServerReflectionBackend> backend) - : backend_(std::move(backend)) {} + Status GetFileByName(ServerContext* context, const std::string& file_name, + reflection::v1alpha::ServerReflectionResponse* response); - // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc - // in ServerReflection service - Status ServerReflectionInfo( - ServerContext* /* context */, - ServerReaderWriter<reflection::v1::ServerReflectionResponse, - reflection::v1::ServerReflectionRequest>* stream) - override; + Status GetFileContainingSymbol( + ServerContext* context, const std::string& symbol, + reflection::v1alpha::ServerReflectionResponse* response); - private: - std::shared_ptr<ProtoServerReflectionBackend> backend_; + Status GetFileContainingExtension( + ServerContext* context, + const reflection::v1alpha::ExtensionRequest* request, + reflection::v1alpha::ServerReflectionResponse* response); + + Status GetAllExtensionNumbers( + ServerContext* context, const std::string& type, + reflection::v1alpha::ExtensionNumberResponse* response); + + void FillFileDescriptorResponse( + const protobuf::FileDescriptor* file_desc, + reflection::v1alpha::ServerReflectionResponse* response, + std::unordered_set<std::string>* seen_files); + + void FillErrorResponse(const Status& status, + reflection::v1alpha::ErrorResponse* error_response); + + const protobuf::DescriptorPool* descriptor_pool_; + const std::vector<string>* services_; }; } // namespace grpc |