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(ScanModule* scan_module) : scan_module_(scan_module) {} 38 EnablePageScan(::grpc::ServerContext *,const EnableMsg * request,::google::protobuf::Empty *)39 ::grpc::Status EnablePageScan(::grpc::ServerContext* /* context */, const EnableMsg* request, 40 ::google::protobuf::Empty* /* response */) override { 41 if (request->enabled()) { 42 scan_module_->SetPageScan(); 43 } else { 44 scan_module_->ClearPageScan(); 45 } 46 return ::grpc::Status::OK; 47 } 48 49 private: 50 ScanModule* scan_module_; 51 }; 52 ListDependencies(ModuleList * list) const53void NeighborFacadeModule::ListDependencies(ModuleList* list) const { 54 ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list); 55 list->add<ScanModule>(); 56 } 57 Start()58void NeighborFacadeModule::Start() { 59 ::bluetooth::grpc::GrpcFacadeModule::Start(); 60 service_ = new NeighborFacadeService(GetDependency<ScanModule>()); 61 } 62 Stop()63void NeighborFacadeModule::Stop() { 64 delete service_; 65 ::bluetooth::grpc::GrpcFacadeModule::Stop(); 66 } 67 GetService() const68::grpc::Service* NeighborFacadeModule::GetService() const { return service_; } 69 70 const ModuleFactory NeighborFacadeModule::Factory = __anonbf7436e60102() 71 ::bluetooth::ModuleFactory([]() { return new NeighborFacadeModule(); }); 72 73 } // namespace facade 74 } // namespace neighbor 75 } // namespace bluetooth 76