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 #ifndef GRPC_SRC_CPP_SERVER_LOAD_REPORTER_LOAD_REPORTING_SERVICE_SERVER_BUILDER_PLUGIN_H
20 #define GRPC_SRC_CPP_SERVER_LOAD_REPORTER_LOAD_REPORTING_SERVICE_SERVER_BUILDER_PLUGIN_H
21 
22 #include <grpc/support/port_platform.h>
23 
24 #include <memory>
25 #include <string>
26 
27 #include <grpcpp/grpcpp.h>
28 #include <grpcpp/impl/server_builder_plugin.h>
29 #include <grpcpp/server_builder.h>
30 #include <grpcpp/support/channel_arguments.h>
31 
32 #include "src/cpp/server/load_reporter/load_reporter_async_service_impl.h"
33 
34 namespace grpc {
35 namespace load_reporter {
36 
37 // The plugin that registers and starts load reporting service when starting a
38 // server.
39 class LoadReportingServiceServerBuilderPlugin : public ServerBuilderPlugin {
40  public:
41   ~LoadReportingServiceServerBuilderPlugin() override = default;
name()42   std::string name() override { return "load_reporting_service"; }
43 
44   // Creates a load reporting service.
45   void UpdateServerBuilder(ServerBuilder* builder) override;
46 
47   // Registers the load reporter service.
48   void InitServer(ServerInitializer* si) override;
49 
50   // Starts the load reporter service.
51   void Finish(ServerInitializer* si) override;
52 
ChangeArguments(const std::string &,void *)53   void ChangeArguments(const std::string& /*name*/, void* /*value*/) override {}
UpdateChannelArguments(grpc::ChannelArguments *)54   void UpdateChannelArguments(grpc::ChannelArguments* /*args*/) override {}
55   bool has_sync_methods() const override;
56   bool has_async_methods() const override;
57 
58  private:
59   std::shared_ptr<LoadReporterAsyncServiceImpl> service_;
60 };
61 
62 std::unique_ptr<grpc::ServerBuilderPlugin>
63 CreateLoadReportingServiceServerBuilderPlugin();
64 
65 }  // namespace load_reporter
66 }  // namespace grpc
67 
68 #endif  // GRPC_SRC_CPP_SERVER_LOAD_REPORTER_LOAD_REPORTING_SERVICE_SERVER_BUILDER_PLUGIN_H
69