• 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 #pragma once
18 
19 #include <mutex>
20 
21 #include "main/shim/acl.h"
22 #include "main/shim/btm.h"
23 #include "main/shim/link_policy_interface.h"
24 
25 #include "gd/module.h"
26 #include "gd/os/handler.h"
27 #include "gd/os/thread.h"
28 #include "gd/os/utils.h"
29 #include "gd/stack_manager.h"
30 #include "src/bridge.rs.h"
31 
32 // The shim layer implementation on the Gd stack side.
33 namespace bluetooth {
34 namespace shim {
35 
36 // GD shim stack, having modes corresponding to legacy stack
37 class Stack {
38  public:
39   static Stack* GetInstance();
40 
41   Stack() = default;
42   Stack(const Stack&) = delete;
43   Stack& operator=(const Stack&) = delete;
44 
45   ~Stack() = default;
46 
47   // Idle mode, config is loaded, but controller is not enabled
48   void StartIdleMode();
49   // Running mode, everything is up
50   void StartEverything();
51 
52   void Stop();
53   bool IsRunning();
54   bool IsDumpsysModuleStarted() const;
55 
56   StackManager* GetStackManager();
57   const StackManager* GetStackManager() const;
58 
59   legacy::Acl* GetAcl();
60   LinkPolicyInterface* LinkPolicy();
61 
62   Btm* GetBtm();
63   os::Handler* GetHandler();
64 
GetRustHci()65   ::rust::Box<rust::Hci>* GetRustHci() { return rust_hci_; }
GetRustController()66   ::rust::Box<rust::Controller>* GetRustController() {
67     return rust_controller_;
68   }
69 
70  private:
71   mutable std::recursive_mutex mutex_;
72   StackManager stack_manager_;
73   bool is_running_ = false;
74   os::Thread* stack_thread_ = nullptr;
75   os::Handler* stack_handler_ = nullptr;
76   legacy::Acl* acl_ = nullptr;
77   Btm* btm_ = nullptr;
78   ::rust::Box<rust::Stack>* rust_stack_ = nullptr;
79   ::rust::Box<rust::Hci>* rust_hci_ = nullptr;
80   ::rust::Box<rust::Controller>* rust_controller_ = nullptr;
81 
82   void Start(ModuleList* modules);
83 };
84 
85 }  // namespace shim
86 }  // namespace bluetooth
87