Home | History | Annotate | Download | only in ext
      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 
     19 #ifndef GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
     20 #define GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
     21 
     22 #include <unordered_set>
     23 #include <vector>
     24 
     25 #include <grpcpp/grpcpp.h>
     26 #include "src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h"
     27 
     28 namespace grpc {
     29 
     30 class ProtoServerReflection final
     31     : public reflection::v1alpha::ServerReflection::Service {
     32  public:
     33   ProtoServerReflection();
     34 
     35   // Add the full names of registered services
     36   void SetServiceList(const std::vector<grpc::string>* services);
     37 
     38   // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
     39   // in ServerReflection service
     40   Status ServerReflectionInfo(
     41       ServerContext* context,
     42       ServerReaderWriter<reflection::v1alpha::ServerReflectionResponse,
     43                          reflection::v1alpha::ServerReflectionRequest>* stream)
     44       override;
     45 
     46  private:
     47   Status ListService(ServerContext* context,
     48                      reflection::v1alpha::ListServiceResponse* response);
     49 
     50   Status GetFileByName(ServerContext* context, const grpc::string& file_name,
     51                        reflection::v1alpha::ServerReflectionResponse* response);
     52 
     53   Status GetFileContainingSymbol(
     54       ServerContext* context, const grpc::string& symbol,
     55       reflection::v1alpha::ServerReflectionResponse* response);
     56 
     57   Status GetFileContainingExtension(
     58       ServerContext* context,
     59       const reflection::v1alpha::ExtensionRequest* request,
     60       reflection::v1alpha::ServerReflectionResponse* response);
     61 
     62   Status GetAllExtensionNumbers(
     63       ServerContext* context, const grpc::string& type,
     64       reflection::v1alpha::ExtensionNumberResponse* response);
     65 
     66   void FillFileDescriptorResponse(
     67       const protobuf::FileDescriptor* file_desc,
     68       reflection::v1alpha::ServerReflectionResponse* response,
     69       std::unordered_set<grpc::string>* seen_files);
     70 
     71   void FillErrorResponse(const Status& status,
     72                          reflection::v1alpha::ErrorResponse* error_response);
     73 
     74   const protobuf::DescriptorPool* descriptor_pool_;
     75   const std::vector<string>* services_;
     76 };
     77 
     78 }  // namespace grpc
     79 
     80 #endif  // GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
     81