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