Keyple Service C++ Library - 3.3.5
Component of the Keyple C++ middleware
WaitForCardRemovalStateAdapter.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/WaitForCardRemovalStateAdapter.hpp"
15
16#include <memory>
17
18namespace keyple {
19namespace core {
20namespace service {
21
22WaitForCardRemovalStateAdapter::WaitForCardRemovalStateAdapter(
23 ObservableLocalReaderAdapter* reader,
24 std::shared_ptr<AbstractMonitoringJobAdapter> monitoringJob,
25 std::shared_ptr<ExecutorService> executorService)
26: AbstractObservableStateAdapter(
27 MonitoringState::WAIT_FOR_CARD_REMOVAL,
28 reader,
29 monitoringJob,
30 executorService)
31{
32}
33
34WaitForCardRemovalStateAdapter::WaitForCardRemovalStateAdapter(
35 ObservableLocalReaderAdapter* reader)
36: WaitForCardRemovalStateAdapter(reader, nullptr, nullptr)
37{
38}
39
40void
41WaitForCardRemovalStateAdapter::onEvent(const InternalEvent event)
42{
43 mLogger->trace(
44 "Internal event [%] received for reader [%] in current state [%]\n",
45 event,
46 getReader()->getName(),
47 getMonitoringState());
48
49 /* Process InternalEvent */
50 switch (event) {
51 case InternalEvent::CARD_REMOVED:
52 /*
53 * The card has been removed, we close all channels and return to the
54 * currentState of waiting for insertion We notify the application of
55 * the CARD_REMOVED event.
56 */
57 getReader()->processCardRemoved();
58 if (getReader()->getDetectionMode() == DetectionMode::REPEATING) {
59 switchState(MonitoringState::WAIT_FOR_CARD_INSERTION);
60 } else {
61 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
62 }
63 break;
64
65 case InternalEvent::STOP_DETECT:
66 getReader()->processCardRemoved();
67 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
68 break;
69
70 default:
71 mLogger->trace("Event ignored\n");
72 break;
73 }
74}
75
76} /* namespace service */
77} /* namespace core */
78} /* namespace keyple */
ObservableLocalReaderAdapter::InternalEvent InternalEvent