14#include "keyple/core/service/CardInsertionPassiveMonitoringJobAdapter.hpp"
19#include "keyple/core/plugin/ReaderIOException.hpp"
20#include "keyple/core/plugin/TaskCanceledException.hpp"
21#include "keyple/core/plugin/spi/reader/observable/state/insertion/CardInsertionWaiterBlockingSpi.hpp"
22#include "keyple/core/plugin/spi/reader/observable/state/insertion/WaitForCardInsertionBlockingSpi.hpp"
23#include "keyple/core/util/cpp/exception/RuntimeException.hpp"
29using keyple::core::plugin::ReaderIOException;
30using keyple::core::plugin::TaskCanceledException;
31using keyple::core::plugin::spi::reader::observable::state::insertion::
32 CardInsertionWaiterBlockingSpi;
33using keyple::core::plugin::spi::reader::observable::state::insertion::
34 WaitForCardInsertionBlockingSpi;
35using keyple::core::util::cpp::exception::RuntimeException;
39const std::string CardInsertionPassiveMonitoringJobAdapter::JOB_ID
40 =
"INSERTION_PASSIVE";
42CardInsertionPassiveMonitoringJobAdapter::CardInsertionPassiveMonitoringJob ::
43 CardInsertionPassiveMonitoringJob(
44 std::shared_ptr<AbstractObservableStateAdapter> monitoringState,
45 CardInsertionPassiveMonitoringJobAdapter* parent)
46: Job(
"CardInsertionPassiveMonitoringJob")
47, mMonitoringState(monitoringState)
53CardInsertionPassiveMonitoringJobAdapter::CardInsertionPassiveMonitoringJob::
57 mParent->mLogger->trace(
58 "[fsmJob=%, reader=%] Starting monitoring job process\n",
60 mParent->getReader()->getName());
62 const auto& cardInsertion
63 = std::dynamic_pointer_cast<CardInsertionWaiterBlockingSpi>(
65 const auto& waitForCard
66 = std::dynamic_pointer_cast<WaitForCardInsertionBlockingSpi>(
68 if (cardInsertion !=
nullptr) {
69 cardInsertion->waitForCardInsertion();
70 }
else if (waitForCard !=
nullptr) {
71 waitForCard->waitForCardInsertion();
73 mMonitoringState->onEvent(InternalEvent::CARD_INSERTED);
75 }
catch (
const ReaderIOException& e) {
77 mParent->mLogger->warn(
78 "[fsmJob=%, reader=%] Failed to process card insertion event "
81 mParent->getReader()->getName(),
84 }
catch (
const TaskCanceledException& e) {
85 mParent->mLogger->warn(
86 "[fsmJob=%, reader=%] Monitoring job process cancelled "
89 mParent->getReader()->getName(),
92 }
catch (
const RuntimeException& e) {
94 ->getObservationExceptionHandler()
95 ->onReaderObservationError(
96 mParent->getReader()->getPluginName(),
97 mParent->getReader()->getName(),
98 std::make_shared<RuntimeException>(e));
102CardInsertionPassiveMonitoringJobAdapter::
103 CardInsertionPassiveMonitoringJobAdapter(
104 ObservableLocalReaderAdapter* reader)
105: AbstractMonitoringJobAdapter(reader)
106, mReaderSpi(reader->getObservableReaderSpi())
111CardInsertionPassiveMonitoringJobAdapter::getMonitoringJob(
112 std::shared_ptr<AbstractObservableStateAdapter> monitoringState)
114 return std::make_shared<CardInsertionPassiveMonitoringJob>(
115 monitoringState,
this);
119CardInsertionPassiveMonitoringJobAdapter::stop()
122 "[fsmJob=%, reader=%] Stopping monitoring job process\n",
124 getReader()->getName());
126 const auto& cardInsertion
127 = std::dynamic_pointer_cast<CardInsertionWaiterBlockingSpi>(mReaderSpi);
128 const auto& waitForCard
129 = std::dynamic_pointer_cast<WaitForCardInsertionBlockingSpi>(
131 if (cardInsertion !=
nullptr) {
132 cardInsertion->stopWaitForCardInsertion();
133 }
else if (waitForCard !=
nullptr) {
134 waitForCard->stopWaitForCardInsertion();
138 "[fsmJob=%, reader=%] Monitoring job process stopped\n",
140 getReader()->getName());
ObservableLocalReaderAdapter::InternalEvent InternalEvent