Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CardCommandManager.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#include "CardCommandManager.h"
14
15/* Keyple Card Calypso */
16#include "CalypsoCardCommand.h"
17
18/* Keyple Core Util */
19#include "IllegalStateException.h"
20
21namespace keyple {
22namespace card {
23namespace calypso {
24
25using namespace keyple::core::util::cpp::exception;
26
28: mSvLastCommand(CalypsoCardCommand::NONE), mSvOperationComplete(false) {}
29
30void CardCommandManager::addRegularCommand(const std::shared_ptr<AbstractCardCommand> command)
31{
32 mCardCommands.push_back(command);
33}
34
35void CardCommandManager::addStoredValueCommand(const std::shared_ptr<AbstractCardCommand> command,
36 const SvOperation svOperation)
37{
38 /* Check the logic of the SV command sequencing */
39 const CalypsoCardCommand& cmd = command->getCommandRef();
40 if (cmd == CalypsoCardCommand::SV_GET) {
41 mSvOperation = svOperation;
42 } else if (cmd == CalypsoCardCommand::SV_RELOAD ||
45 /*
46 * CL-SV-GETDEBIT.1
47 * CL-SV-GETRLOAD.1
48 */
49 if (!mCardCommands.empty()) {
50 throw IllegalStateException("This SV command can only be placed in the first position" \
51 " in the list of prepared commands");
52 }
53
54 if (mSvLastCommand != CalypsoCardCommand::SV_GET) {
55 throw IllegalStateException("This SV command must follow an SV Get command");
56 }
57
58 /* Here, we expect the command and the SV operation to be consistent */
59 if (svOperation != mSvOperation) {
60 mLogger->error("Sv operation = %, current command = %\n", mSvOperation, svOperation);
61 throw IllegalStateException("Inconsistent SV operation.");
62 }
63
64 mSvOperationComplete = true;
65 } else {
66 throw IllegalStateException("An SV command is expected.");
67 }
68
69 mSvLastCommand = command->getCommandRef();
70
71 mCardCommands.push_back(command);
72}
73
75{
76 mCardCommands.clear();
77}
78
79const std::vector<std::shared_ptr<AbstractCardCommand>>& CardCommandManager::getCardCommands() const
80{
81 return mCardCommands;
82}
83
85{
86 return !mCardCommands.empty();
87}
88
90{
91 const bool flag = mSvOperationComplete;
92 mSvOperationComplete = false;
93
94 return flag;
95}
96
97}
98}
99}
static const CalypsoCardCommand SV_RELOAD
static const CalypsoCardCommand SV_DEBIT
static const CalypsoCardCommand SV_GET
static const CalypsoCardCommand SV_UNDEBIT
void addStoredValueCommand(const std::shared_ptr< AbstractCardCommand > command, const SvOperation svOperation)
const std::vector< std::shared_ptr< AbstractCardCommand > > & getCardCommands() const
void addRegularCommand(const std::shared_ptr< AbstractCardCommand > command)