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