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