Keyple Service C++ Library - 3.3.5
Component of the Keyple C++ middleware
WaitForCardProcessingStateAdapter.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/core/service/WaitForCardProcessingStateAdapter.hpp"
15
16#include <memory>
17
18namespace keyple {
19namespace core {
20namespace service {
21
23
24WaitForCardProcessingStateAdapter::WaitForCardProcessingStateAdapter(
25 ObservableLocalReaderAdapter* reader,
26 std::shared_ptr<AbstractMonitoringJobAdapter> monitoringJob,
27 std::shared_ptr<ExecutorService> executorService)
28: AbstractObservableStateAdapter(
29 MonitoringState::WAIT_FOR_CARD_PROCESSING,
30 reader,
31 monitoringJob,
32 executorService)
33{
34}
35
36WaitForCardProcessingStateAdapter::WaitForCardProcessingStateAdapter(
37 ObservableLocalReaderAdapter* reader)
38: WaitForCardProcessingStateAdapter(reader, nullptr, nullptr)
39{
40}
41
42void
43WaitForCardProcessingStateAdapter::onEvent(const InternalEvent event)
44{
45 mLogger->trace(
46 "Internal event [%] received for reader [%] in current state [%]\n",
47 event,
48 getReader()->getName(),
49 getMonitoringState());
50
51 /* Process InternalEvent */
52 switch (event) {
53 case InternalEvent::CARD_PROCESSED:
54 if (getReader()->getDetectionMode() == DetectionMode::REPEATING) {
55 switchState(MonitoringState::WAIT_FOR_CARD_REMOVAL);
56 } else {
57 /* We close the channels now and notify the application of the
58 * CARD_REMOVED event */
59 getReader()->processCardRemoved();
60 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
61 }
62 break;
63
64 case InternalEvent::CARD_REMOVED:
65 /*
66 * The card has been removed, we close all channels and return to the
67 * currentState of waiting for insertion We notify the application of
68 * the CARD_REMOVED event.
69 */
70 getReader()->processCardRemoved();
71 if (getReader()->getDetectionMode() == DetectionMode::REPEATING) {
72 switchState(MonitoringState::WAIT_FOR_CARD_INSERTION);
73 } else {
74 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
75 }
76 break;
77
78 case InternalEvent::STOP_DETECT:
79 getReader()->processCardRemoved();
80 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
81 break;
82
83 default:
84 mLogger->trace("Event ignored\n");
85 break;
86 }
87}
88
89} /* namespace service */
90} /* namespace core */
91} /* namespace keyple */
ObservableCardReader::DetectionMode DetectionMode
ObservableLocalReaderAdapter::InternalEvent InternalEvent