Keyple Service C++ Library - 3.3.5
Component of the Keyple C++ middleware
WaitForCardInsertionStateAdapter.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/WaitForCardInsertionStateAdapter.hpp"
15
16#include <memory>
17
18namespace keyple {
19namespace core {
20namespace service {
21
22WaitForCardInsertionStateAdapter::WaitForCardInsertionStateAdapter(
23 ObservableLocalReaderAdapter* reader,
24 std::shared_ptr<AbstractMonitoringJobAdapter> monitoringJob,
25 std::shared_ptr<ExecutorService> executorService)
26: AbstractObservableStateAdapter(
27 MonitoringState::WAIT_FOR_CARD_INSERTION,
28 reader,
29 monitoringJob,
30 executorService)
31{
32}
33
34WaitForCardInsertionStateAdapter::WaitForCardInsertionStateAdapter(
35 ObservableLocalReaderAdapter* reader)
36: WaitForCardInsertionStateAdapter(reader, nullptr, nullptr)
37{
38}
39
40void
41WaitForCardInsertionStateAdapter::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_INSERTED: {
52 /* Process default selection if any, return an event, can be null */
53 const std::shared_ptr<CardReaderEvent> cardEvent
54 = getReader()->processCardInserted();
55 if (cardEvent != nullptr) {
56 /* Switch internal state */
57 switchState(MonitoringState::WAIT_FOR_CARD_PROCESSING);
58 /* Notify the external observer of the event */
59 getReader()->notifyObservers(cardEvent);
60 } else {
61 /*
62 * If none event was sent to the application, back to card detection
63 * stay in the same state, however switch to WAIT_FOR_CARD_INSERTION
64 * to relaunch the monitoring job
65 */
66 mLogger->trace("Inserted card hasn't matched\n");
67
68 switchState(MonitoringState::WAIT_FOR_CARD_REMOVAL);
69 }
70 break;
71 }
72 case InternalEvent::STOP_DETECT:
73 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
74 break;
75 default:
76 mLogger->trace("Event ignored\n");
77 break;
78 }
79}
80
81} /* namespace service */
82} /* namespace core */
83} /* namespace keyple */
ObservableLocalReaderAdapter::InternalEvent InternalEvent