• Home
  • History
  • Annotate
  • 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 
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(
28       ::grpc::ServerContext* /* context */,
29       const ::google::protobuf::Empty* /* request */,
30       ::blueberry::facade::BluetoothAddress* response) override {
31     auto address = controller_->GetMacAddress().ToString();
32     response->set_address(address);
33     return ::grpc::Status::OK;
34   }
35 
36  private:
37   hci::Controller* controller_;
38 };
39 
ListDependencies(ModuleList * list) const40 void ReadOnlyPropertyServerModule::ListDependencies(ModuleList* list) const {
41   GrpcFacadeModule::ListDependencies(list);
42   list->add<hci::Controller>();
43 }
Start()44 void ReadOnlyPropertyServerModule::Start() {
45   GrpcFacadeModule::Start();
46   service_ = std::make_unique<ReadOnlyPropertyService>(GetDependency<hci::Controller>());
47 }
Stop()48 void ReadOnlyPropertyServerModule::Stop() {
49   service_.reset();
50   GrpcFacadeModule::Stop();
51 }
GetService() const52 ::grpc::Service* ReadOnlyPropertyServerModule::GetService() const {
53   return service_.get();
54 }
55 
56 const ModuleFactory ReadOnlyPropertyServerModule::Factory =
__anon422a40560102() 57     ::bluetooth::ModuleFactory([]() { return new ReadOnlyPropertyServerModule(); });
58 
59 }  // namespace facade
60 }  // namespace bluetooth
61