Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
AbstractSamCommand.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 "AbstractSamCommand.h"
14
15/* Keyple Card calypso */
16#include "CalypsoCardCommand.h"
25
26namespace keyple {
27namespace card {
28namespace calypso {
29
30const std::map<const int, const std::shared_ptr<StatusProperties>>
31 AbstractSamCommand::STATUS_TABLE = initStatusTable();
32
34: AbstractApduCommand(commandRef) {}
35
37{
38 return dynamic_cast<const CalypsoSamCommand&>(AbstractApduCommand::getCommandRef());
39}
40
42 const std::type_info& exceptionClass,
43 const std::string& message,
44 const CardCommand& commandRef,
45 const int statusWord) const
46{
47
48 const auto& command = dynamic_cast<const CalypsoSamCommand&>(commandRef);
49 const auto sw = std::make_shared<int>(statusWord);
50
51 if (exceptionClass == typeid(CalypsoSamAccessForbiddenException)) {
52 return CalypsoSamAccessForbiddenException(message, command, sw);
53 } else if (exceptionClass == typeid(CalypsoSamCounterOverflowException)) {
54 return CalypsoSamCounterOverflowException(message, command, sw);
55 } else if (exceptionClass == typeid(CalypsoSamDataAccessException)) {
56 return CalypsoSamDataAccessException(message, command, sw);
57 } else if (exceptionClass == typeid(CalypsoSamIllegalArgumentException)) {
58 return CalypsoSamIllegalArgumentException(message, command);
59 } else if (exceptionClass == typeid(CalypsoSamIllegalParameterException)) {
60 return CalypsoSamIllegalParameterException(message, command, sw);
61 } else if (exceptionClass == typeid(CalypsoSamIncorrectInputDataException)) {
62 return CalypsoSamIncorrectInputDataException(message, command, sw);
63 } else if (exceptionClass == typeid(CalypsoSamSecurityDataException)) {
64 return CalypsoSamSecurityDataException(message, command, sw);
65 } else {
66 return CalypsoSamUnknownStatusException(message, command, sw);
67 }
68}
69
71 const std::shared_ptr<ApduResponseApi> apduResponse)
72{
73 return dynamic_cast<AbstractSamCommand&>(AbstractApduCommand::setApduResponse(apduResponse));
74}
75
77{
78 try {
80 } catch (const CalypsoApduCommandException& e) {
81 throw static_cast<const CalypsoSamCommandException&>(e);
82 }
83}
84
85const std::map<const int, const std::shared_ptr<StatusProperties>>
86 AbstractSamCommand::initStatusTable()
87{
88 std::map<const int, const std::shared_ptr<StatusProperties>> m =
90
91 m.insert({0x6D00,
92 std::make_shared<StatusProperties>("Instruction unknown.",
94 m.insert({0x6E00,
95 std::make_shared<StatusProperties>("Class not supported.",
96 typeid(CalypsoSamIllegalParameterException))});
97
98 return m;
99}
100
101const std::map<const int, const std::shared_ptr<StatusProperties>>&
103{
104 return STATUS_TABLE;
105}
106
107}
108}
109}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual AbstractApduCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse)
virtual const CardCommand & getCommandRef() const
AbstractSamCommand & setApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
AbstractSamCommand(const CalypsoSamCommand &commandRef)
const CalypsoApduCommandException buildCommandException(const std::type_info &exceptionClass, const std::string &message, const CardCommand &commandRef, const int statusWord) const final
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
const CalypsoSamCommand & getCommandRef() const override