1 /*
2 * Copyright 2020 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 "hci/facade/controller_facade.h"
18
19 #include <condition_variable>
20 #include <memory>
21 #include <mutex>
22
23 #include "common/bind.h"
24 #include "common/blocking_queue.h"
25 #include "grpc/grpc_event_queue.h"
26 #include "hci/address.h"
27 #include "hci/controller.h"
28 #include "hci/facade/controller_facade.grpc.pb.h"
29 #include "hci/facade/controller_facade.pb.h"
30
31 using ::grpc::ServerAsyncResponseWriter;
32 using ::grpc::ServerAsyncWriter;
33 using ::grpc::ServerContext;
34
35 namespace bluetooth {
36 namespace hci {
37 namespace facade {
38
39 class ControllerFacadeService : public ControllerFacade::Service {
40 public:
ControllerFacadeService(Controller * controller,::bluetooth::os::Handler *)41 ControllerFacadeService(Controller* controller, ::bluetooth::os::Handler*) : controller_(controller) {}
42
GetMacAddress(::grpc::ServerContext * context,const::google::protobuf::Empty * request,AddressMsg * response)43 ::grpc::Status GetMacAddress(::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
44 AddressMsg* response) override {
45 Address local_address = controller_->GetMacAddress();
46 response->set_address(local_address.ToString());
47 return ::grpc::Status::OK;
48 }
49
GetLocalName(::grpc::ServerContext * context,const::google::protobuf::Empty * request,NameMsg * response)50 ::grpc::Status GetLocalName(::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
51 NameMsg* response) override {
52 std::string local_name = controller_->GetLocalName();
53 response->set_name(local_name);
54 return ::grpc::Status::OK;
55 }
56
WriteLocalName(::grpc::ServerContext * context,const NameMsg * request,::google::protobuf::Empty * response)57 ::grpc::Status WriteLocalName(::grpc::ServerContext* context, const NameMsg* request,
58 ::google::protobuf::Empty* response) override {
59 controller_->WriteLocalName(request->name());
60 return ::grpc::Status::OK;
61 }
62
63 private:
64 Controller* controller_;
65 };
66
ListDependencies(ModuleList * list)67 void ControllerFacadeModule::ListDependencies(ModuleList* list) {
68 ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
69 list->add<Controller>();
70 }
71
Start()72 void ControllerFacadeModule::Start() {
73 ::bluetooth::grpc::GrpcFacadeModule::Start();
74 service_ = new ControllerFacadeService(GetDependency<Controller>(), GetHandler());
75 }
76
Stop()77 void ControllerFacadeModule::Stop() {
78 delete service_;
79 ::bluetooth::grpc::GrpcFacadeModule::Stop();
80 }
81
GetService() const82 ::grpc::Service* ControllerFacadeModule::GetService() const {
83 return service_;
84 }
85
86 const ModuleFactory ControllerFacadeModule::Factory =
__anon9aee7bcf0102() 87 ::bluetooth::ModuleFactory([]() { return new ControllerFacadeModule(); });
88
89 } // namespace facade
90 } // namespace hci
91 } // namespace bluetooth
92