• 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 #include <grpcpp/ext/channelz_service_plugin.h>
21 #include <grpcpp/impl/server_builder_plugin.h>
22 #include <grpcpp/impl/server_initializer.h>
23 #include <grpcpp/server_builder.h>
24 
25 #include <memory>
26 #include <string>
27 
28 #include "src/cpp/server/channelz/channelz_service.h"
29 
30 namespace grpc {
31 namespace channelz {
32 namespace experimental {
33 
34 class ChannelzServicePlugin : public grpc::ServerBuilderPlugin {
35  public:
ChannelzServicePlugin()36   ChannelzServicePlugin() : channelz_service_(new grpc::ChannelzService()) {}
37 
name()38   std::string name() override { return "channelz_service"; }
39 
InitServer(grpc::ServerInitializer * si)40   void InitServer(grpc::ServerInitializer* si) override {
41     si->RegisterService(channelz_service_);
42   }
43 
Finish(grpc::ServerInitializer *)44   void Finish(grpc::ServerInitializer* /*si*/) override {}
45 
ChangeArguments(const std::string &,void *)46   void ChangeArguments(const std::string& /*name*/, void* /*value*/) override {}
47 
has_sync_methods() const48   bool has_sync_methods() const override {
49     if (channelz_service_) {
50       return channelz_service_->has_synchronous_methods();
51     }
52     return false;
53   }
54 
has_async_methods() const55   bool has_async_methods() const override {
56     if (channelz_service_) {
57       return channelz_service_->has_async_methods();
58     }
59     return false;
60   }
61 
62  private:
63   std::shared_ptr<grpc::ChannelzService> channelz_service_;
64 };
65 
66 static std::unique_ptr<grpc::ServerBuilderPlugin>
CreateChannelzServicePlugin()67 CreateChannelzServicePlugin() {
68   return std::unique_ptr<grpc::ServerBuilderPlugin>(
69       new ChannelzServicePlugin());
70 }
71 
InitChannelzService()72 void InitChannelzService() {
73   static struct Initializer {
74     Initializer() {
75       grpc::ServerBuilder::InternalAddPluginFactory(
76           &grpc::channelz::experimental::CreateChannelzServicePlugin);
77     }
78   } initialize;
79 }
80 
81 }  // namespace experimental
82 }  // namespace channelz
83 }  // namespace grpc
84