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 "shim/facade/facade.h"
18
19 #include <memory>
20
21 #include "common/bind.h"
22 #include "flatbuffers/idl.h"
23 #include "flatbuffers/reflection_generated.h"
24 #include "grpc/grpc_event_queue.h"
25 #include "os/log.h"
26 #include "shim/dumpsys.h"
27 #include "shim/facade/facade.grpc.pb.h"
28 #include "shim/facade/facade.pb.h"
29
30 using ::grpc::ServerAsyncResponseWriter;
31 using ::grpc::ServerAsyncWriter;
32 using ::grpc::ServerContext;
33
34 namespace bluetooth {
35 namespace shim {
36 namespace facade {
37
38 class ShimFacadeService : public ShimFacade::Service {
39 public:
ShimFacadeService(shim::Dumpsys * dumpsys_layer,::bluetooth::os::Handler * facade_handler)40 ShimFacadeService(shim::Dumpsys* dumpsys_layer, ::bluetooth::os::Handler* facade_handler)
41 : dumpsys_layer_(dumpsys_layer), facade_handler_(facade_handler) {}
42
~ShimFacadeService()43 virtual ~ShimFacadeService() {}
44
Dump(::grpc::ServerContext * context,const::google::protobuf::Empty * request,::grpc::ServerWriter<DumpsysMsg> * writer)45 ::grpc::Status Dump(
46 ::grpc::ServerContext* context,
47 const ::google::protobuf::Empty* request,
48 ::grpc::ServerWriter<DumpsysMsg>* writer) override {
49 dumpsys_layer_->Dump(0, nullptr);
50 return ::grpc::Status::OK;
51 }
52
53 private:
54 shim::Dumpsys* dumpsys_layer_{nullptr};
55 [[maybe_unused]] ::bluetooth::os::Handler* facade_handler_{nullptr};
56 };
57
ListDependencies(ModuleList * list)58 void ShimFacadeModule::ListDependencies(ModuleList* list) {
59 ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
60 list->add<Dumpsys>();
61 }
62
Start()63 void ShimFacadeModule::Start() {
64 ::bluetooth::grpc::GrpcFacadeModule::Start();
65 service_ = new ShimFacadeService(GetDependency<Dumpsys>(), GetHandler());
66 }
67
Stop()68 void ShimFacadeModule::Stop() {
69 delete service_;
70 ::bluetooth::grpc::GrpcFacadeModule::Stop();
71 }
72
GetService() const73 ::grpc::Service* ShimFacadeModule::GetService() const {
74 return service_;
75 }
76
__anon463b7e1d0102() 77 const ModuleFactory ShimFacadeModule::Factory = ::bluetooth::ModuleFactory([]() { return new ShimFacadeModule(); });
78
79 } // namespace facade
80 } // namespace shim
81 } // namespace bluetooth
82