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