14#include "keyple/core/service/AbstractObservableStateAdapter.hpp"
19#include "keyple/core/service/AbstractMonitoringJobAdapter.hpp"
25AbstractObservableStateAdapter::AbstractObservableStateAdapter(
26 const MonitoringState monitoringState,
27 ObservableLocalReaderAdapter* reader,
28 std::shared_ptr<AbstractMonitoringJobAdapter> monitoringJob,
29 std::shared_ptr<ExecutorService> executorService)
30: mMonitoringState(monitoringState)
32, mMonitoringJob(monitoringJob)
33, mExecutorService(executorService)
38AbstractObservableStateAdapter::getMonitoringState()
const
40 return mMonitoringState;
43ObservableLocalReaderAdapter*
44AbstractObservableStateAdapter::getReader()
const
50AbstractObservableStateAdapter::switchState(
const MonitoringState stateId)
52 mReader->switchState(stateId);
56AbstractObservableStateAdapter::onActivate()
59 if (mMonitoringJob !=
nullptr) {
60 if (mExecutorService ==
nullptr) {
61 throw IllegalStateException(
62 "ExecutorService is not set. Cannot launch monitoring job");
65 mMonitoringEvent = mExecutorService->submit(
66 mMonitoringJob->getMonitoringJob(shared_from_this()));
71AbstractObservableStateAdapter::onDeactivate()
74 if (mMonitoringEvent !=
nullptr && !mMonitoringEvent->isDone()) {
75 mMonitoringJob->stop();
76 mMonitoringEvent->cancel(
false);
81 mMonitoringEvent =
nullptr;