1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "neighbor/facade/facade.h" 18 19 #include <bluetooth/log.h> 20 21 #include <memory> 22 23 #include "blueberry/facade/neighbor/facade.grpc.pb.h" 24 25 using ::grpc::ServerAsyncResponseWriter; 26 using ::grpc::ServerAsyncWriter; 27 using ::grpc::ServerContext; 28 29 namespace bluetooth { 30 namespace neighbor { 31 namespace facade { 32 33 using namespace blueberry::facade::neighbor; 34 35 class NeighborFacadeService : public NeighborFacade::Service { 36 public: NeighborFacadeService(ScanModule * scan_module)37 NeighborFacadeService( 38 ScanModule* scan_module) 39 : scan_module_(scan_module) {} 40 EnablePageScan(::grpc::ServerContext *,const EnableMsg * request,::google::protobuf::Empty *)41 ::grpc::Status EnablePageScan( 42 ::grpc::ServerContext* /* context */, 43 const EnableMsg* request, 44 ::google::protobuf::Empty* /* response */) override { 45 if (request->enabled()) { 46 scan_module_->SetPageScan(); 47 } else { 48 scan_module_->ClearPageScan(); 49 } 50 return ::grpc::Status::OK; 51 } 52 53 private: 54 ScanModule* scan_module_; 55 }; 56 ListDependencies(ModuleList * list) const57void NeighborFacadeModule::ListDependencies(ModuleList* list) const { 58 ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list); 59 list->add<ScanModule>(); 60 } 61 Start()62void NeighborFacadeModule::Start() { 63 ::bluetooth::grpc::GrpcFacadeModule::Start(); 64 service_ = new NeighborFacadeService(GetDependency<ScanModule>()); 65 } 66 Stop()67void NeighborFacadeModule::Stop() { 68 delete service_; 69 ::bluetooth::grpc::GrpcFacadeModule::Stop(); 70 } 71 GetService() const72::grpc::Service* NeighborFacadeModule::GetService() const { 73 return service_; 74 } 75 76 const ModuleFactory NeighborFacadeModule::Factory = __anonb508f1300102() 77 ::bluetooth::ModuleFactory([]() { return new NeighborFacadeModule(); }); 78 79 } // namespace facade 80 } // namespace neighbor 81 } // namespace bluetooth 82