• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2018 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 <grpc/support/port_platform.h>
20 
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>
25 
26 #include "src/cpp/server/channelz/channelz_service.h"
27 
28 namespace grpc {
29 namespace channelz {
30 namespace experimental {
31 
32 class ChannelzServicePlugin : public ::grpc::ServerBuilderPlugin {
33  public:
ChannelzServicePlugin()34   ChannelzServicePlugin() : channelz_service_(new grpc::ChannelzService()) {}
35 
name()36   grpc::string name() override { return "channelz_service"; }
37 
InitServer(grpc::ServerInitializer * si)38   void InitServer(grpc::ServerInitializer* si) override {
39     si->RegisterService(channelz_service_);
40   }
41 
Finish(grpc::ServerInitializer * si)42   void Finish(grpc::ServerInitializer* si) override {}
43 
ChangeArguments(const grpc::string & name,void * value)44   void ChangeArguments(const grpc::string& name, void* value) override {}
45 
has_sync_methods() const46   bool has_sync_methods() const override {
47     if (channelz_service_) {
48       return channelz_service_->has_synchronous_methods();
49     }
50     return false;
51   }
52 
has_async_methods() const53   bool has_async_methods() const override {
54     if (channelz_service_) {
55       return channelz_service_->has_async_methods();
56     }
57     return false;
58   }
59 
60  private:
61   std::shared_ptr<grpc::ChannelzService> channelz_service_;
62 };
63 
64 static std::unique_ptr< ::grpc::ServerBuilderPlugin>
CreateChannelzServicePlugin()65 CreateChannelzServicePlugin() {
66   return std::unique_ptr< ::grpc::ServerBuilderPlugin>(
67       new ChannelzServicePlugin());
68 }
69 
InitChannelzService()70 void InitChannelzService() {
71   static bool already_here = false;
72   if (already_here) return;
73   already_here = true;
74   ::grpc::ServerBuilder::InternalAddPluginFactory(&CreateChannelzServicePlugin);
75 }
76 
77 }  // namespace experimental
78 }  // namespace channelz
79 }  // namespace grpc
80