3 * Copyright 2018 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 <grpc/support/port_platform.h>
21 #include <grpcpp/ext/channelz_service_plugin.h>
22 #include <grpcpp/impl/server_builder_plugin.h>
23 #include <grpcpp/impl/server_initializer.h>
24 #include <grpcpp/server.h>
26 #include "src/cpp/server/channelz/channelz_service.h"
30 namespace experimental {
32 class ChannelzServicePlugin : public ::grpc::ServerBuilderPlugin {
34 ChannelzServicePlugin() : channelz_service_(new grpc::ChannelzService()) {}
36 std::string name() override { return "channelz_service"; }
38 void InitServer(grpc::ServerInitializer* si) override {
39 si->RegisterService(channelz_service_);
42 void Finish(grpc::ServerInitializer* /*si*/) override {}
44 void ChangeArguments(const std::string& /*name*/, void* /*value*/) override {}
46 bool has_sync_methods() const override {
47 if (channelz_service_) {
48 return channelz_service_->has_synchronous_methods();
53 bool has_async_methods() const override {
54 if (channelz_service_) {
55 return channelz_service_->has_async_methods();
61 std::shared_ptr<grpc::ChannelzService> channelz_service_;
64 static std::unique_ptr< ::grpc::ServerBuilderPlugin>
65 CreateChannelzServicePlugin() {
66 return std::unique_ptr< ::grpc::ServerBuilderPlugin>(
67 new ChannelzServicePlugin());
70 } // namespace experimental
71 } // namespace channelz
75 namespace experimental {
77 void InitChannelzService() {
78 static struct Initializer {
80 ::grpc::ServerBuilder::InternalAddPluginFactory(
81 &grpc::channelz::experimental::CreateChannelzServicePlugin);
86 } // namespace experimental
87 } // namespace channelz
88 } // namespace grpc_impl