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 "facade/read_only_property_server.h" 18 19 #include "hci/controller.h" 20 21 namespace bluetooth { 22 namespace facade { 23 24 class ReadOnlyPropertyService : public blueberry::facade::ReadOnlyProperty::Service { 25 public: ReadOnlyPropertyService(hci::Controller * controller)26 ReadOnlyPropertyService(hci::Controller* controller) : controller_(controller) {} ReadLocalAddress(::grpc::ServerContext *,const::google::protobuf::Empty *,::blueberry::facade::BluetoothAddress * response)27 ::grpc::Status ReadLocalAddress(::grpc::ServerContext* /* context */, 28 const ::google::protobuf::Empty* /* request */, 29 ::blueberry::facade::BluetoothAddress* response) override { 30 auto address = controller_->GetMacAddress().ToString(); 31 response->set_address(address); 32 return ::grpc::Status::OK; 33 } 34 35 private: 36 hci::Controller* controller_; 37 }; 38 ListDependencies(ModuleList * list) const39void ReadOnlyPropertyServerModule::ListDependencies(ModuleList* list) const { 40 GrpcFacadeModule::ListDependencies(list); 41 list->add<hci::Controller>(); 42 } Start()43void ReadOnlyPropertyServerModule::Start() { 44 GrpcFacadeModule::Start(); 45 service_ = std::make_unique<ReadOnlyPropertyService>(GetDependency<hci::Controller>()); 46 } Stop()47void ReadOnlyPropertyServerModule::Stop() { 48 service_.reset(); 49 GrpcFacadeModule::Stop(); 50 } GetService() const51::grpc::Service* ReadOnlyPropertyServerModule::GetService() const { return service_.get(); } 52 53 const ModuleFactory ReadOnlyPropertyServerModule::Factory = __anon5b18a18c0102() 54 ::bluetooth::ModuleFactory([]() { return new ReadOnlyPropertyServerModule(); }); 55 56 } // namespace facade 57 } // namespace bluetooth 58