diff --git a/include/keyple/core/service/ObservableLocalReaderAdapter.hpp b/include/keyple/core/service/ObservableLocalReaderAdapter.hpp index 883e6dd..defbe6b 100644 --- a/include/keyple/core/service/ObservableLocalReaderAdapter.hpp +++ b/include/keyple/core/service/ObservableLocalReaderAdapter.hpp @@ -469,6 +469,43 @@ class KEYPLESERVICE_API ObservableLocalReaderAdapter cardSelectionResponses); }; +/** + * Operator << for InternalEvent enum to enable readable logging. + * + * @param os The output stream. + * @param event The internal event. + * @return The output stream. + */ +inline std::ostream& +operator<<(std::ostream& os, + const ObservableLocalReaderAdapter::InternalEvent event) +{ + switch (event) { + case ObservableLocalReaderAdapter::InternalEvent::CARD_INSERTED: + os << "CARD_INSERTED"; + break; + case ObservableLocalReaderAdapter::InternalEvent::CARD_REMOVED: + os << "CARD_REMOVED"; + break; + case ObservableLocalReaderAdapter::InternalEvent::CARD_PROCESSED: + os << "CARD_PROCESSED"; + break; + case ObservableLocalReaderAdapter::InternalEvent::START_DETECT: + os << "START_DETECT"; + break; + case ObservableLocalReaderAdapter::InternalEvent::STOP_DETECT: + os << "STOP_DETECT"; + break; + case ObservableLocalReaderAdapter::InternalEvent::TIME_OUT: + os << "TIME_OUT"; + break; + default: + os << "UNKNOWN_EVENT(" << static_cast(event) << ")"; + break; + } + return os; +} + } /* namespace service */ } /* namespace core */ } /* namespace keyple */ diff --git a/include/keyple/core/service/PluginEvent.hpp b/include/keyple/core/service/PluginEvent.hpp index 6a2bcee..ae09794 100644 --- a/include/keyple/core/service/PluginEvent.hpp +++ b/include/keyple/core/service/PluginEvent.hpp @@ -93,20 +93,27 @@ class KEYPLESERVICE_API PluginEvent { virtual Type getType() const = 0; /** + * Operator << for PluginEvent::Type enum to enable readable logging. * + * @param os The output stream. + * @param t The event type. + * @return The output stream. */ friend std::ostream& operator<<(std::ostream& os, const Type t) { switch (t) { case Type::READER_CONNECTED: - os << "TYPE = READER_CONNECTED"; + os << "READER_CONNECTED"; break; case Type::READER_DISCONNECTED: - os << "TYPE = READER_DISCONNECTED"; + os << "READER_DISCONNECTED"; break; case Type::UNAVAILABLE: - os << "TYPE = UNAVAILABLE"; + os << "UNAVAILABLE"; + break; + default: + os << "UNKNOWN_TYPE(" << static_cast(t) << ")"; break; } diff --git a/src/main/MonitoringState.cpp b/src/main/MonitoringState.cpp index 3d9cf70..c5f0659 100644 --- a/src/main/MonitoringState.cpp +++ b/src/main/MonitoringState.cpp @@ -22,16 +22,16 @@ operator<<(std::ostream& os, const MonitoringState ms) { switch (ms) { case MonitoringState::WAIT_FOR_START_DETECTION: - os << "MONITORING_STATE = WAIT_FOR_START_DETECTION"; + os << "WAIT_FOR_START_DETECTION"; break; case MonitoringState::WAIT_FOR_CARD_PROCESSING: - os << "MONITORING_STATE = WAIT_FOR_CARD_PROCESSING"; + os << "WAIT_FOR_CARD_PROCESSING"; break; case MonitoringState::WAIT_FOR_CARD_REMOVAL: - os << "MONITORING_STATE = WAIT_FOR_CARD_REMOVAL"; + os << "WAIT_FOR_CARD_REMOVAL"; break; case MonitoringState::WAIT_FOR_CARD_INSERTION: - os << "MONITORING_STATE = WAIT_FOR_CARD_INSERTION"; + os << "WAIT_FOR_CARD_INSERTION"; break; } diff --git a/src/main/WaitForCardInsertionStateAdapter.cpp b/src/main/WaitForCardInsertionStateAdapter.cpp index bd8dd05..bfd57fb 100644 --- a/src/main/WaitForCardInsertionStateAdapter.cpp +++ b/src/main/WaitForCardInsertionStateAdapter.cpp @@ -42,8 +42,8 @@ WaitForCardInsertionStateAdapter::onEvent(const InternalEvent event) { mLogger->trace( "Internal event [%] received for reader [%] in current state [%]\n", - getReader()->getName(), event, + getReader()->getName(), getMonitoringState()); /* Process InternalEvent */ diff --git a/src/main/WaitForCardProcessingStateAdapter.cpp b/src/main/WaitForCardProcessingStateAdapter.cpp index 3f25677..2c697e3 100644 --- a/src/main/WaitForCardProcessingStateAdapter.cpp +++ b/src/main/WaitForCardProcessingStateAdapter.cpp @@ -44,8 +44,8 @@ WaitForCardProcessingStateAdapter::onEvent(const InternalEvent event) { mLogger->trace( "Internal event [%] received for reader [%] in current state [%]\n", - getReader()->getName(), event, + getReader()->getName(), getMonitoringState()); /* Process InternalEvent */ diff --git a/src/main/WaitForCardRemovalStateAdapter.cpp b/src/main/WaitForCardRemovalStateAdapter.cpp index d326108..8cbf5ad 100644 --- a/src/main/WaitForCardRemovalStateAdapter.cpp +++ b/src/main/WaitForCardRemovalStateAdapter.cpp @@ -42,8 +42,8 @@ WaitForCardRemovalStateAdapter::onEvent(const InternalEvent event) { mLogger->trace( "Internal event [%] received for reader [%] in current state [%]\n", - getReader()->getName(), event, + getReader()->getName(), getMonitoringState()); /* Process InternalEvent */ diff --git a/src/main/WaitForStartDetectStateAdapter.cpp b/src/main/WaitForStartDetectStateAdapter.cpp index 2f7826c..41b268a 100644 --- a/src/main/WaitForStartDetectStateAdapter.cpp +++ b/src/main/WaitForStartDetectStateAdapter.cpp @@ -42,8 +42,8 @@ WaitForStartDetectStateAdapter::onEvent(const InternalEvent event) { mLogger->trace( "Internal event [%] received for reader [%] in current state [%]\n", - getReader()->getName(), event, + getReader()->getName(), getMonitoringState()); /* Process InternalEvent */ diff --git a/src/main/cpp/ExecutorService.cpp b/src/main/cpp/ExecutorService.cpp index 721ab80..d611fc7 100644 --- a/src/main/cpp/ExecutorService.cpp +++ b/src/main/cpp/ExecutorService.cpp @@ -51,7 +51,10 @@ ExecutorService::run() if (mPool.size()) { /* Start first service and wait until completion */ std::shared_ptr job = mPool[0]; - job->run(); + + if(!job->isCancelled()) { + job->run(); + } /* Remove from vector */ mPool.erase(mPool.begin()); diff --git a/src/main/cpp/Job.cpp b/src/main/cpp/Job.cpp index da2349a..de2958f 100644 --- a/src/main/cpp/Job.cpp +++ b/src/main/cpp/Job.cpp @@ -39,12 +39,12 @@ Job::cancel(const bool mayInterruptIfRunning) "Unsupported value for mayInterruptIfRunning (true)"); } + mCancelled = true; + if (!isAlive()) { return false; } - mCancelled = true; - return true; }