blob: 3c57b879e419e09639c8385a7f15776e8a556d39 [file] [log] [blame]
Hansong Zhange0a997f2019-08-29 14:27:11 -07001/*
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
20namespace bluetooth {
21namespace facade {
22
23class 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
37void ReadOnlyPropertyServerModule::ListDependencies(ModuleList* list) {
38 GrpcFacadeModule::ListDependencies(list);
39 list->add<hci::Controller>();
40}
41void ReadOnlyPropertyServerModule::Start() {
42 GrpcFacadeModule::Start();
43 service_ = std::make_unique<ReadOnlyPropertyService>(GetDependency<hci::Controller>());
44}
45void ReadOnlyPropertyServerModule::Stop() {
46 service_.reset();
47 GrpcFacadeModule::Stop();
48}
49::grpc::Service* ReadOnlyPropertyServerModule::GetService() const {
50 return service_.get();
51}
52
53const ModuleFactory ReadOnlyPropertyServerModule::Factory =
54 ::bluetooth::ModuleFactory([]() { return new ReadOnlyPropertyServerModule(); });
55
56} // namespace facade
57} // namespace bluetooth