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