14#include "keyple/core/service/CardRemovalActiveMonitoringJobAdapter.hpp"
18#include "keyple/core/plugin/ReaderIOException.hpp"
19#include "keyple/core/plugin/TaskCanceledException.hpp"
20#include "keyple/core/service/ObservableLocalReaderAdapter.hpp"
21#include "keyple/core/util/cpp/Thread.hpp"
22#include "keyple/core/util/cpp/exception/InterruptedException.hpp"
23#include "keyple/core/util/cpp/exception/RuntimeException.hpp"
30using keyple::core::util::cpp::exception::InterruptedException;
31using keyple::core::util::cpp::exception::RuntimeException;
36CardRemovalActiveMonitoringJobAdapter::CardRemovalActiveMonitoringJob ::
37 CardRemovalActiveMonitoringJob(
38 std::shared_ptr<AbstractObservableStateAdapter> monitoringState,
39 CardRemovalActiveMonitoringJobAdapter* parent)
40: Job(
"CardRemovalActiveMonitoringJobAdapter")
41, mMonitoringState(monitoringState)
47CardRemovalActiveMonitoringJobAdapter::CardRemovalActiveMonitoringJob::execute()
50 mParent->mLogger->trace(
51 "Start monitoring job polling process using 'isCardPresentPing()'"
52 "method on reader [%]\n",
53 mParent->getReader()->getName());
56 mParent->mLoop =
true;
58 while (mParent->mLoop) {
59 if (!mParent->getReader()->isCardPresentPing()) {
60 mParent->mLogger->trace(
"Card stop responding\n");
66 Thread::sleep(mParent->mSleepDurationMillis);
67 }
catch (
const InterruptedException& ignored) {
71 mParent->mLoop =
false;
75 mParent->mLogger->trace(
"Monitoring job polling process stopped\n");
76 }
catch (
const RuntimeException& e) {
78 ->getObservationExceptionHandler()
79 ->onReaderObservationError(
80 mParent->getReader()->getPluginName(),
81 mParent->getReader()->getName(),
82 std::make_shared<RuntimeException>(e));
86 mMonitoringState->onEvent(InternalEvent::CARD_REMOVED);
92CardRemovalActiveMonitoringJobAdapter::CardRemovalActiveMonitoringJobAdapter(
93 ObservableLocalReaderAdapter* reader,
const int64_t sleepDurationMillis)
94: AbstractMonitoringJobAdapter(reader)
95, mReaderSpi(std::dynamic_pointer_cast<WaitForCardRemovalBlockingSpi>(
96 reader->getObservableReaderSpi()))
97, mSleepDurationMillis(sleepDurationMillis)
102CardRemovalActiveMonitoringJobAdapter::getMonitoringJob(
103 std::shared_ptr<AbstractObservableStateAdapter> monitoringState)
105 return std::make_shared<CardRemovalActiveMonitoringJob>(
106 monitoringState,
this);
110CardRemovalActiveMonitoringJobAdapter::stop()
ObservableLocalReaderAdapter::InternalEvent InternalEvent