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 #define LOG_TAG "neighbor2"
17 
18 #include "neighbor/connectability.h"
19 
20 #include <memory>
21 
22 #include "hci/hci_layer.h"
23 #include "hci/hci_packets.h"
24 #include "module.h"
25 #include "neighbor/scan.h"
26 #include "os/handler.h"
27 #include "os/log.h"
28 
29 namespace bluetooth {
30 namespace neighbor {
31 
32 struct ConnectabilityModule::impl {
33   void StartConnectability();
34   void StopConnectability();
35   bool IsConnectable() const;
36 
37   void Start();
38   void Stop();
39 
40   impl(ConnectabilityModule& connectability_module);
41 
42  private:
43   ConnectabilityModule& module_;
44 
45   neighbor::ScanModule* scan_module_;
46 };
47 
48 const ModuleFactory neighbor::ConnectabilityModule::Factory =
__anon083f0f470102() 49     ModuleFactory([]() { return new ConnectabilityModule(); });
50 
impl(neighbor::ConnectabilityModule & module)51 neighbor::ConnectabilityModule::impl::impl(neighbor::ConnectabilityModule& module) : module_(module) {}
52 
StartConnectability()53 void neighbor::ConnectabilityModule::impl::StartConnectability() {
54   scan_module_->SetPageScan();
55 }
56 
StopConnectability()57 void neighbor::ConnectabilityModule::impl::StopConnectability() {
58   scan_module_->ClearPageScan();
59 }
60 
IsConnectable() const61 bool neighbor::ConnectabilityModule::impl::IsConnectable() const {
62   return scan_module_->IsPageEnabled();
63 }
64 
Start()65 void neighbor::ConnectabilityModule::impl::Start() {
66   scan_module_ = module_.GetDependency<neighbor::ScanModule>();
67 }
68 
Stop()69 void neighbor::ConnectabilityModule::impl::Stop() {}
70 
ConnectabilityModule()71 neighbor::ConnectabilityModule::ConnectabilityModule() : pimpl_(std::make_unique<impl>(*this)) {}
72 
~ConnectabilityModule()73 neighbor::ConnectabilityModule::~ConnectabilityModule() {
74   pimpl_.reset();
75 }
76 
StartConnectability()77 void neighbor::ConnectabilityModule::StartConnectability() {
78   pimpl_->StartConnectability();
79 }
80 
StopConnectability()81 void neighbor::ConnectabilityModule::StopConnectability() {
82   pimpl_->StopConnectability();
83 }
84 
IsConnectable() const85 bool neighbor::ConnectabilityModule::IsConnectable() const {
86   return pimpl_->IsConnectable();
87 }
88 
89 /**
90  * Module stuff
91  */
ListDependencies(ModuleList * list)92 void neighbor::ConnectabilityModule::ListDependencies(ModuleList* list) {
93   list->add<neighbor::ScanModule>();
94 }
95 
Start()96 void neighbor::ConnectabilityModule::Start() {
97   pimpl_->Start();
98 }
99 
Stop()100 void neighbor::ConnectabilityModule::Stop() {
101   pimpl_->Stop();
102 }
103 
104 }  // namespace neighbor
105 }  // namespace bluetooth
106