From 7ae31a88980cba5e7e0173cad91e62dbfe1b0374 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Mon, 6 Jun 2016 14:21:11 -0700 Subject: Add more comments, fix format issues --- src/cpp/ext/proto_server_reflection.cc | 14 +++++++++----- src/cpp/ext/proto_server_reflection.h | 22 +++++++++++----------- src/cpp/ext/proto_server_reflection_plugin.cc | 6 ++++-- 3 files changed, 24 insertions(+), 18 deletions(-) (limited to 'src/cpp') diff --git a/src/cpp/ext/proto_server_reflection.cc b/src/cpp/ext/proto_server_reflection.cc index 6e54bc2720..348a035f0f 100644 --- a/src/cpp/ext/proto_server_reflection.cc +++ b/src/cpp/ext/proto_server_reflection.cc @@ -131,7 +131,8 @@ Status ProtoServerReflection::GetFileByName( return Status::CANCELLED; } - const protobuf::FileDescriptor* file_desc = descriptor_pool_->FindFileByName(filename); + const protobuf::FileDescriptor* file_desc = + descriptor_pool_->FindFileByName(filename); if (file_desc == nullptr) { return Status(StatusCode::NOT_FOUND, "File not found."); } @@ -170,8 +171,9 @@ Status ProtoServerReflection::GetFileContainingExtension( return Status(StatusCode::NOT_FOUND, "Type not found."); } - const protobuf::FieldDescriptor* field_desc = descriptor_pool_->FindExtensionByNumber( - desc, request->extension_number()); + const protobuf::FieldDescriptor* field_desc = + descriptor_pool_->FindExtensionByNumber(desc, + request->extension_number()); if (field_desc == nullptr) { return Status(StatusCode::NOT_FOUND, "Extension not found."); } @@ -187,7 +189,8 @@ Status ProtoServerReflection::GetAllExtensionNumbers( return Status::CANCELLED; } - const protobuf::Descriptor* desc = descriptor_pool_->FindMessageTypeByName(type); + const protobuf::Descriptor* desc = + descriptor_pool_->FindMessageTypeByName(type); if (desc == nullptr) { return Status(StatusCode::NOT_FOUND, "Type not found."); } @@ -202,7 +205,8 @@ Status ProtoServerReflection::GetAllExtensionNumbers( } void ProtoServerReflection::FillFileDescriptorResponse( - const protobuf::FileDescriptor* file_desc, ServerReflectionResponse* response, + const protobuf::FileDescriptor* file_desc, + ServerReflectionResponse* response, std::unordered_set* seen_files) { if (seen_files->find(file_desc->name()) != seen_files->end()) { return; diff --git a/src/cpp/ext/proto_server_reflection.h b/src/cpp/ext/proto_server_reflection.h index e7ab1fdf34..23c130513d 100644 --- a/src/cpp/ext/proto_server_reflection.h +++ b/src/cpp/ext/proto_server_reflection.h @@ -30,16 +30,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ - -#ifndef GRPC_EXTENSIONS_REFLECTION_PROTO_SERVER_REFLECTION_H -#define GRPC_EXTENSIONS_REFLECTION_PROTO_SERVER_REFLECTION_H +#ifndef GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H +#define GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H #include #include -#include - #include +#include namespace grpc { @@ -48,21 +46,23 @@ class ProtoServerReflection GRPC_FINAL public: ProtoServerReflection(); + // Add the full names of registered services void SetServiceList(const std::vector* services); + // implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc + // in ServerReflection service Status ServerReflectionInfo( ServerContext* context, ServerReaderWriter* - stream) GRPC_OVERRIDE; + reflection::v1alpha::ServerReflectionRequest>* stream) + GRPC_OVERRIDE; private: Status ListService(ServerContext* context, reflection::v1alpha::ListServiceResponse* response); - Status GetFileByName( - ServerContext* context, const grpc::string& file_name, - reflection::v1alpha::ServerReflectionResponse* response); + Status GetFileByName(ServerContext* context, const grpc::string& file_name, + reflection::v1alpha::ServerReflectionResponse* response); Status GetFileContainingSymbol( ServerContext* context, const grpc::string& symbol, @@ -91,4 +91,4 @@ class ProtoServerReflection GRPC_FINAL } // namespace grpc -#endif // GRPC_EXTENSIONS_REFLECTION_PROTO_SERVER_REFLECTION_H +#endif // GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H diff --git a/src/cpp/ext/proto_server_reflection_plugin.cc b/src/cpp/ext/proto_server_reflection_plugin.cc index becc949359..f31d102a9e 100644 --- a/src/cpp/ext/proto_server_reflection_plugin.cc +++ b/src/cpp/ext/proto_server_reflection_plugin.cc @@ -78,16 +78,18 @@ static std::unique_ptr<::grpc::ServerBuilderPlugin> CreateProtoReflection() { new ProtoServerReflectionPlugin()); } -static void AddProtoReflectionServerBuilderPlugin() { +void InitProtoReflectionServerBuilderPlugin() { static bool already_here = false; if (already_here) return; already_here = true; ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection); } +// Force InitProtoReflectionServerBuilderPlugin() to be called at static +// initialization time. struct StaticProtoReflectionPluginInitializer { StaticProtoReflectionPluginInitializer() { - AddProtoReflectionServerBuilderPlugin(); + InitProtoReflectionServerBuilderPlugin(); } } static_proto_reflection_plugin_initializer; -- cgit v1.2.3