3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
24 #include "src/cpp/ext/proto_server_reflection.h"
27 namespace reflection {
29 ProtoServerReflectionPlugin::ProtoServerReflectionPlugin()
30 : reflection_service_(new grpc::ProtoServerReflection()) {}
32 grpc::string ProtoServerReflectionPlugin::name() {
33 return "proto_server_reflection";
36 void ProtoServerReflectionPlugin::InitServer(grpc::ServerInitializer* si) {
37 si->RegisterService(reflection_service_);
40 void ProtoServerReflectionPlugin::Finish(grpc::ServerInitializer* si) {
41 reflection_service_->SetServiceList(si->GetServiceList());
44 void ProtoServerReflectionPlugin::ChangeArguments(const grpc::string& name,
47 bool ProtoServerReflectionPlugin::has_sync_methods() const {
48 if (reflection_service_) {
49 return reflection_service_->has_synchronous_methods();
54 bool ProtoServerReflectionPlugin::has_async_methods() const {
55 if (reflection_service_) {
56 return reflection_service_->has_async_methods();
61 static std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateProtoReflection() {
62 return std::unique_ptr< ::grpc::ServerBuilderPlugin>(
63 new ProtoServerReflectionPlugin());
66 void InitProtoReflectionServerBuilderPlugin() {
67 static bool already_here = false;
68 if (already_here) return;
70 ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection);
73 // Force InitProtoReflectionServerBuilderPlugin() to be called at static
74 // initialization time.
75 struct StaticProtoReflectionPluginInitializer {
76 StaticProtoReflectionPluginInitializer() {
77 InitProtoReflectionServerBuilderPlugin();
79 } static_proto_reflection_plugin_initializer;
81 } // namespace reflection
82 } // namespace grpc_impl