Keyple Service C++ Library - 3.4.1
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 "[fsmState=%, reader=%] Processing internal event [type=%]\n",
45 getMonitoringState(),
46 getReader()->getName(),
47 event);
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(
67 "[fsmState=%, reader=%] Inserted card hasn't matched",
68 getMonitoringState(),
69 getReader()->getName());
70
71 switchState(MonitoringState::WAIT_FOR_CARD_REMOVAL);
72 }
73 break;
74 }
75 case InternalEvent::STOP_DETECT:
76 switchState(MonitoringState::WAIT_FOR_START_DETECTION);
77 break;
78 default:
79 mLogger->trace(
80 "[fsmState=%, reader=%] Internal event ignored\n",
81 getMonitoringState(),
82 getReader()->getName());
83 break;
84 }
85
86 mLogger->trace(
87 "[fsmState=%, reader=%] Internal event processed [type=%]\n",
88 getMonitoringState(),
89 getReader()->getName(),
90 event);
91}
92
93} /* namespace service */
94} /* namespace core */
95} /* namespace keyple */
ObservableLocalReaderAdapter::InternalEvent InternalEvent