1 /*
2  * Copyright 2020 HIMSA II K/S - www.himsa.com. Represented by EHIMA -
3  * www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "mock_eatt.h"
19 
20 #include "types/raw_address.h"
21 
22 namespace {
23 MockEattExtension* mock_pimpl_;
24 }
GetInstance()25 MockEattExtension* MockEattExtension::GetInstance() {
26   bluetooth::eatt::EattExtension::GetInstance();
27   return mock_pimpl_;
28 }
29 
30 namespace bluetooth {
31 namespace eatt {
32 
33 struct EattExtension::impl : public MockEattExtension {
34   impl() = default;
35   ~impl() = default;
IsRunningbluetooth::eatt::EattExtension::impl36   bool IsRunning() { return mock_pimpl_ ? true : false; }
37 };
38 
AddFromStorage(const RawAddress &)39 void EattExtension::AddFromStorage(const RawAddress& /* bd_addr */) {}
40 
EattExtension()41 EattExtension::EattExtension() : pimpl_(std::make_unique<impl>()) {}
42 
IsEattSupportedByPeer(const RawAddress & bd_addr)43 bool EattExtension::IsEattSupportedByPeer(const RawAddress& bd_addr) {
44   return pimpl_->IsEattSupportedByPeer(bd_addr);
45 }
46 
Connect(const RawAddress & bd_addr)47 void EattExtension::Connect(const RawAddress& bd_addr) {
48   pimpl_->Connect(bd_addr);
49 }
50 
Disconnect(const RawAddress & bd_addr,uint16_t cid)51 void EattExtension::Disconnect(const RawAddress& bd_addr, uint16_t cid) {
52   pimpl_->Disconnect(bd_addr, cid);
53 }
54 
Reconfigure(const RawAddress & bd_addr,uint16_t cid,uint16_t mtu)55 void EattExtension::Reconfigure(const RawAddress& bd_addr, uint16_t cid,
56                                 uint16_t mtu) {
57   pimpl_->Reconfigure(bd_addr, cid, mtu);
58 }
ReconfigureAll(const RawAddress & bd_addr,uint16_t mtu)59 void EattExtension::ReconfigureAll(const RawAddress& bd_addr, uint16_t mtu) {
60   pimpl_->ReconfigureAll(bd_addr, mtu);
61 }
62 
FindEattChannelByCid(const RawAddress & bd_addr,uint16_t cid)63 EattChannel* EattExtension::FindEattChannelByCid(const RawAddress& bd_addr,
64                                                  uint16_t cid) {
65   return pimpl_->FindEattChannelByCid(bd_addr, cid);
66 }
67 
FindEattChannelByTransId(const RawAddress & bd_addr,uint32_t trans_id)68 EattChannel* EattExtension::FindEattChannelByTransId(const RawAddress& bd_addr,
69                                                      uint32_t trans_id) {
70   return pimpl_->FindEattChannelByTransId(bd_addr, trans_id);
71 }
72 
IsIndicationPending(const RawAddress & bd_addr,uint16_t indication_handle)73 bool EattExtension::IsIndicationPending(const RawAddress& bd_addr,
74                                         uint16_t indication_handle) {
75   return pimpl_->IsIndicationPending(bd_addr, indication_handle);
76 }
77 
GetChannelAvailableForIndication(const RawAddress & bd_addr)78 EattChannel* EattExtension::GetChannelAvailableForIndication(
79     const RawAddress& bd_addr) {
80   return pimpl_->GetChannelAvailableForIndication(bd_addr);
81 }
82 
FreeGattResources(const RawAddress & bd_addr)83 void EattExtension::FreeGattResources(const RawAddress& bd_addr) {
84   pimpl_->FreeGattResources(bd_addr);
85 }
86 
IsOutstandingMsgInSendQueue(const RawAddress & bd_addr)87 bool EattExtension::IsOutstandingMsgInSendQueue(const RawAddress& bd_addr) {
88   return pimpl_->IsOutstandingMsgInSendQueue(bd_addr);
89 }
90 
GetChannelWithQueuedDataToSend(const RawAddress & bd_addr)91 EattChannel* EattExtension::GetChannelWithQueuedDataToSend(
92     const RawAddress& bd_addr) {
93   return pimpl_->GetChannelWithQueuedDataToSend(bd_addr);
94 }
95 
GetChannelAvailableForClientRequest(const RawAddress & bd_addr)96 EattChannel* EattExtension::GetChannelAvailableForClientRequest(
97     const RawAddress& bd_addr) {
98   return pimpl_->GetChannelAvailableForClientRequest(bd_addr);
99 }
100 
101 /* Start stop GATT indication timer per CID */
StartIndicationConfirmationTimer(const RawAddress & bd_addr,uint16_t cid)102 void EattExtension::StartIndicationConfirmationTimer(const RawAddress& bd_addr,
103                                                      uint16_t cid) {
104   pimpl_->StartIndicationConfirmationTimer(bd_addr, cid);
105 }
106 
StopIndicationConfirmationTimer(const RawAddress & bd_addr,uint16_t cid)107 void EattExtension::StopIndicationConfirmationTimer(const RawAddress& bd_addr,
108                                                     uint16_t cid) {
109   pimpl_->StopIndicationConfirmationTimer(bd_addr, cid);
110 }
111 
112 /* Start stop application indication timeout */
StartAppIndicationTimer(const RawAddress & bd_addr,uint16_t cid)113 void EattExtension::StartAppIndicationTimer(const RawAddress& bd_addr,
114                                             uint16_t cid) {
115   pimpl_->StartAppIndicationTimer(bd_addr, cid);
116 }
117 
StopAppIndicationTimer(const RawAddress & bd_addr,uint16_t cid)118 void EattExtension::StopAppIndicationTimer(const RawAddress& bd_addr,
119                                            uint16_t cid) {
120   pimpl_->StopAppIndicationTimer(bd_addr, cid);
121 }
122 
Start()123 void EattExtension::Start() {
124   // It is needed here as IsoManager which is a singleton creates it, but in
125   // this mock we want to destroy and recreate the mock on each test case.
126   if (!pimpl_) {
127     pimpl_ = std::make_unique<impl>();
128   }
129 
130   mock_pimpl_ = pimpl_.get();
131   pimpl_->Start();
132 }
133 
Stop()134 void EattExtension::Stop() {
135   // It is needed here as IsoManager which is a singleton creates it, but in
136   // this mock we want to destroy and recreate the mock on each test case.
137   if (pimpl_) {
138     pimpl_->Stop();
139     pimpl_.reset();
140   }
141 
142   mock_pimpl_ = nullptr;
143 }
144 
145 EattExtension::~EattExtension() = default;
146 }  // namespace eatt
147 }  // namespace bluetooth
148