Imported Upstream version 1.36.0
[platform/upstream/grpc.git] / src / cpp / server / load_reporter / load_reporting_service_server_builder_plugin.cc
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 "src/cpp/server/load_reporter/load_reporting_service_server_builder_plugin.h"
22
23 #include <grpcpp/impl/server_initializer.h>
24
25 namespace grpc {
26 namespace load_reporter {
27
28 bool LoadReportingServiceServerBuilderPlugin::has_sync_methods() const {
29   if (service_ != nullptr) {
30     return service_->has_synchronous_methods();
31   }
32   return false;
33 }
34
35 bool LoadReportingServiceServerBuilderPlugin::has_async_methods() const {
36   if (service_ != nullptr) {
37     return service_->has_async_methods();
38   }
39   return false;
40 }
41
42 void LoadReportingServiceServerBuilderPlugin::UpdateServerBuilder(
43     grpc::ServerBuilder* builder) {
44   auto cq = builder->AddCompletionQueue();
45   service_ = std::make_shared<LoadReporterAsyncServiceImpl>(std::move(cq));
46 }
47
48 void LoadReportingServiceServerBuilderPlugin::InitServer(
49     grpc::ServerInitializer* si) {
50   si->RegisterService(service_);
51 }
52
53 void LoadReportingServiceServerBuilderPlugin::Finish(
54     grpc::ServerInitializer* /*si*/) {
55   service_->StartThread();
56   service_.reset();
57 }
58
59 }  // namespace load_reporter
60 }  // namespace grpc