14#include "keyple/core/service/CardInsertionPassiveMonitoringJobAdapter.hpp"
18#include "keyple/core/plugin/ReaderIOException.hpp"
19#include "keyple/core/plugin/TaskCanceledException.hpp"
20#include "keyple/core/plugin/spi/reader/observable/state/insertion/CardInsertionWaiterBlockingSpi.hpp"
21#include "keyple/core/plugin/spi/reader/observable/state/insertion/WaitForCardInsertionBlockingSpi.hpp"
22#include "keyple/core/util/cpp/exception/RuntimeException.hpp"
28using keyple::core::plugin::ReaderIOException;
29using keyple::core::plugin::TaskCanceledException;
30using keyple::core::plugin::spi::reader::observable::state::insertion::
31 CardInsertionWaiterBlockingSpi;
32using keyple::core::plugin::spi::reader::observable::state::insertion::
33 WaitForCardInsertionBlockingSpi;
34using keyple::core::util::cpp::exception::RuntimeException;
41CardInsertionPassiveMonitoringJobAdapter::CardInsertionPassiveMonitoringJob ::
42 CardInsertionPassiveMonitoringJob(
43 std::shared_ptr<AbstractObservableStateAdapter> monitoringState,
44 CardInsertionPassiveMonitoringJobAdapter* parent)
45: Job(
"CardInsertionPassiveMonitoringJob")
46, mMonitoringState(monitoringState)
52CardInsertionPassiveMonitoringJobAdapter::CardInsertionPassiveMonitoringJob::
56 mParent->mLogger->trace(
57 "Start monitoring job process on reader [%]\n",
58 mParent->getReader()->getName());
60 const auto& cardInsertion
61 = std::dynamic_pointer_cast<CardInsertionWaiterBlockingSpi>(
63 const auto& waitForCard
64 = std::dynamic_pointer_cast<WaitForCardInsertionBlockingSpi>(
66 if (cardInsertion !=
nullptr) {
67 cardInsertion->waitForCardInsertion();
68 }
else if (waitForCard !=
nullptr) {
69 waitForCard->waitForCardInsertion();
71 mMonitoringState->onEvent(InternalEvent::CARD_INSERTED);
73 }
catch (
const ReaderIOException& e) {
75 mParent->mLogger->warn(
76 "Monitoring job error while processing card insertion event on "
78 mParent->getReader()->getName(),
81 }
catch (
const TaskCanceledException& e) {
82 mParent->mLogger->warn(
83 "Monitoring job process cancelled: %\n", e.getMessage());
85 }
catch (
const RuntimeException& e) {
87 ->getObservationExceptionHandler()
88 ->onReaderObservationError(
89 mParent->getReader()->getPluginName(),
90 mParent->getReader()->getName(),
91 std::make_shared<RuntimeException>(e));
98CardInsertionPassiveMonitoringJobAdapter::
99 CardInsertionPassiveMonitoringJobAdapter(
100 ObservableLocalReaderAdapter* reader)
101: AbstractMonitoringJobAdapter(reader)
102, mReaderSpi(reader->getObservableReaderSpi())
107CardInsertionPassiveMonitoringJobAdapter::getMonitoringJob(
108 std::shared_ptr<AbstractObservableStateAdapter> monitoringState)
110 return std::make_shared<CardInsertionPassiveMonitoringJob>(
111 monitoringState,
this);
115CardInsertionPassiveMonitoringJobAdapter::stop()
117 mLogger->trace(
"Stop monitoring job process\n");
119 const auto& cardInsertion
120 = std::dynamic_pointer_cast<CardInsertionWaiterBlockingSpi>(mReaderSpi);
121 const auto& waitForCard
122 = std::dynamic_pointer_cast<WaitForCardInsertionBlockingSpi>(
124 if (cardInsertion !=
nullptr) {
125 cardInsertion->stopWaitForCardInsertion();
126 }
else if (waitForCard !=
nullptr) {
127 waitForCard->stopWaitForCardInsertion();
130 mLogger->trace(
"Monitoring job process stopped\n");
ObservableLocalReaderAdapter::InternalEvent InternalEvent