11#include "keyple/plugin/stub/StubReaderAdapter.hpp"
13#include "keyple/core/plugin/CardIOException.hpp"
14#include "keyple/core/plugin/TaskCanceledException.hpp"
15#include "keyple/core/util/HexUtil.hpp"
16#include "keyple/core/util/KeypleAssert.hpp"
17#include "keyple/core/util/cpp/Any.hpp"
18#include "keyple/core/util/cpp/Arrays.hpp"
19#include "keyple/core/util/cpp/Thread.hpp"
20#include "keyple/core/util/cpp/exception/InterruptedException.hpp"
26using keyple::core::plugin::CardIOException;
27using keyple::core::plugin::TaskCanceledException;
28using keyple::core::util::Assert;
29using keyple::core::util::HexUtil;
30using keyple::core::util::cpp::any;
31using keyple::core::util::cpp::Arrays;
32using keyple::core::util::cpp::Thread;
33using keyple::core::util::cpp::exception::InterruptedException;
35StubReaderAdapter::StubReaderAdapter(
36 const std::string& name,
37 const bool isContactLess,
38 std::shared_ptr<StubSmartCard> card)
40, mIsContactLess(isContactLess)
42, mContinueWaitForCardRemovalTask(false)
47StubReaderAdapter::onStartDetection()
53StubReaderAdapter::onStopDetection()
59StubReaderAdapter::getName()
const
65StubReaderAdapter::isProtocolSupported(
const std::string& readerProtocol)
const
74StubReaderAdapter::activateProtocol(
const std::string& readerProtocol)
76 mActivatedProtocols.push_back(readerProtocol);
80StubReaderAdapter::deactivateProtocol(
const std::string& readerProtocol)
82 const auto it = std::find(
83 mActivatedProtocols.begin(), mActivatedProtocols.end(), readerProtocol);
84 if (it != mActivatedProtocols.end()) {
85 mActivatedProtocols.erase(it);
90StubReaderAdapter::isCurrentProtocol(
const std::string& readerProtocol)
const
92 if (mSmartCard !=
nullptr && mSmartCard->getCardProtocol() !=
"") {
93 return mSmartCard->getCardProtocol() == readerProtocol;
100StubReaderAdapter::openPhysicalChannel()
102 if (mSmartCard !=
nullptr) {
103 mSmartCard->openPhysicalChannel();
108StubReaderAdapter::closePhysicalChannel()
110 if (mSmartCard !=
nullptr) {
111 mSmartCard->closePhysicalChannel();
116StubReaderAdapter::isPhysicalChannelOpen()
const
118 return mSmartCard !=
nullptr && mSmartCard->isPhysicalChannelOpen();
122StubReaderAdapter::checkCardPresence()
124 return mSmartCard !=
nullptr;
128StubReaderAdapter::getPowerOnData()
const
130 return HexUtil::toHex(mSmartCard->getPowerOnData());
133const std::vector<uint8_t>
134StubReaderAdapter::transmitApdu(
const std::vector<uint8_t>& apduIn)
136 if (mSmartCard ==
nullptr) {
137 throw CardIOException(
"No card is available");
140 return mSmartCard->processApdu(apduIn);
144StubReaderAdapter::isContactless()
146 return mIsContactLess;
150StubReaderAdapter::onUnregister()
156StubReaderAdapter::insertCard(std::shared_ptr<StubSmartCard> smartCard)
158 Assert::getInstance().notNull(smartCard,
"smart card");
160 if (checkCardPresence()) {
162 "[readerExt=%] A card is already inserted. First remove the " \
163 "inserted card before inserting a new one\n",
168 const std::string protocol = smartCard->getCardProtocol();
169 if (!Arrays::contains(mActivatedProtocols, protocol)) {
171 "[readerExt=%] Inserted card protocol does not match any " \
172 "activated protocol. Please use 'activateProtocol()' method first" \
173 "[cardProtocol=%]\n",
181 "[readerExt=%] Card inserted [smartCard=%]\n", getName(), smartCard);
183 mSmartCard = smartCard;
187StubReaderAdapter::removeCard()
189 if (mSmartCard !=
nullptr) {
191 "[readerExt=%] Card removed [smartCard=%]\n",
194 closePhysicalChannel();
195 mSmartCard =
nullptr;
199std::shared_ptr<StubSmartCard>
200StubReaderAdapter::getSmartcard()
206StubReaderAdapter::getSelectedSmartCard()
const
212StubReaderAdapter::getCardInsertionMonitoringSleepDuration()
const
218StubReaderAdapter::getCardRemovalMonitoringSleepDuration()
const