• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
ReadOnlyPropertyService(hci::Controller * controller)25   ReadOnlyPropertyService(hci::Controller* controller) : controller_(controller) {}
ReadLocalAddress(::grpc::ServerContext * context,const::google::protobuf::Empty * request,::bluetooth::facade::BluetoothAddress * response)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 
ListDependencies(ModuleList * list)37 void ReadOnlyPropertyServerModule::ListDependencies(ModuleList* list) {
38   GrpcFacadeModule::ListDependencies(list);
39   list->add<hci::Controller>();
40 }
Start()41 void ReadOnlyPropertyServerModule::Start() {
42   GrpcFacadeModule::Start();
43   service_ = std::make_unique<ReadOnlyPropertyService>(GetDependency<hci::Controller>());
44 }
Stop()45 void ReadOnlyPropertyServerModule::Stop() {
46   service_.reset();
47   GrpcFacadeModule::Stop();
48 }
GetService() const49 ::grpc::Service* ReadOnlyPropertyServerModule::GetService() const {
50   return service_.get();
51 }
52 
53 const ModuleFactory ReadOnlyPropertyServerModule::Factory =
__anona94ac8cb0102() 54     ::bluetooth::ModuleFactory([]() { return new ReadOnlyPropertyServerModule(); });
55 
56 }  // namespace facade
57 }  // namespace bluetooth
58