• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <grpcpp/ext/proto_server_reflection_plugin.h>
20 #include <grpcpp/impl/server_builder_plugin.h>
21 #include <grpcpp/impl/server_initializer.h>
22 #include <grpcpp/server.h>
23 
24 #include "src/cpp/ext/proto_server_reflection.h"
25 
26 namespace grpc {
27 namespace reflection {
28 
ProtoServerReflectionPlugin()29 ProtoServerReflectionPlugin::ProtoServerReflectionPlugin()
30     : reflection_service_(new grpc::ProtoServerReflection()) {}
31 
name()32 grpc::string ProtoServerReflectionPlugin::name() {
33   return "proto_server_reflection";
34 }
35 
InitServer(grpc::ServerInitializer * si)36 void ProtoServerReflectionPlugin::InitServer(grpc::ServerInitializer* si) {
37   si->RegisterService(reflection_service_);
38 }
39 
Finish(grpc::ServerInitializer * si)40 void ProtoServerReflectionPlugin::Finish(grpc::ServerInitializer* si) {
41   reflection_service_->SetServiceList(si->GetServiceList());
42 }
43 
ChangeArguments(const grpc::string & name,void * value)44 void ProtoServerReflectionPlugin::ChangeArguments(const grpc::string& name,
45                                                   void* value) {}
46 
has_sync_methods() const47 bool ProtoServerReflectionPlugin::has_sync_methods() const {
48   if (reflection_service_) {
49     return reflection_service_->has_synchronous_methods();
50   }
51   return false;
52 }
53 
has_async_methods() const54 bool ProtoServerReflectionPlugin::has_async_methods() const {
55   if (reflection_service_) {
56     return reflection_service_->has_async_methods();
57   }
58   return false;
59 }
60 
CreateProtoReflection()61 static std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateProtoReflection() {
62   return std::unique_ptr< ::grpc::ServerBuilderPlugin>(
63       new ProtoServerReflectionPlugin());
64 }
65 
InitProtoReflectionServerBuilderPlugin()66 void InitProtoReflectionServerBuilderPlugin() {
67   static bool already_here = false;
68   if (already_here) return;
69   already_here = true;
70   ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection);
71 }
72 
73 // Force InitProtoReflectionServerBuilderPlugin() to be called at static
74 // initialization time.
75 struct StaticProtoReflectionPluginInitializer {
StaticProtoReflectionPluginInitializergrpc::reflection::StaticProtoReflectionPluginInitializer76   StaticProtoReflectionPluginInitializer() {
77     InitProtoReflectionServerBuilderPlugin();
78   }
79 } static_proto_reflection_plugin_initializer;
80 
81 }  // namespace reflection
82 }  // namespace grpc
83