keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
AsyncTransactionExecutorManagerAdapter.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/card/calypso/crypto/legacysam/AsyncTransactionExecutorManagerAdapter.hpp"
15
16#include <memory>
17#include <string>
18#include <vector>
19
20#include "keypop/calypso/crypto/legacysam/transaction/ReaderIOException.hpp"
21#include "keypop/calypso/crypto/legacysam/transaction/SamIOException.hpp"
22#include "keypop/calypso/crypto/legacysam/transaction/UnexpectedCommandStatusException.hpp"
23#include "keypop/reader/CardCommunicationException.hpp"
24#include "keypop/reader/InvalidCardResponseException.hpp"
25#include "keypop/reader/ReaderCommunicationException.hpp"
26
27namespace keyple {
28namespace card {
29namespace calypso {
30namespace crypto {
31namespace legacysam {
32
33using keypop::calypso::crypto::legacysam::transaction::ReaderIOException;
34using keypop::calypso::crypto::legacysam::transaction::SamIOException;
35using keypop::calypso::crypto::legacysam::transaction::
36 UnexpectedCommandStatusException;
37using keypop::reader::CardCommunicationException;
38using keypop::reader::InvalidCardResponseException;
39using keypop::reader::ReaderCommunicationException;
40
41AsyncTransactionExecutorManagerAdapter::AsyncTransactionExecutorManagerAdapter(
42 std::shared_ptr<ProxyReaderApi> targetSamReader,
43 std::shared_ptr<LegacySamAdapter> targetSam,
44 const std::string& /*samCommandsJson**/)
45: CommonTransactionManagerAdapter(targetSamReader, targetSam, nullptr, nullptr)
46{
47 // JsonObject jsonObject = JsonUtil.getParser().fromJson(samCommandsJson,
48 // JsonObject.class);
49
50 /* Extract the type and command lists. */
51 // std::vector<std::string> commandsTypes;
52 // JsonUtil.getParser()
53 // .fromJson(
54 // jsonObject.get(SAM_COMMANDS_TYPES).getAsJsonArray(),
55 // new TypeToken<ArrayList<String>>() {}.getType());
56 // JsonArray commands = jsonObject.get(SAM_COMMANDS).getAsJsonArray();
57
58 // for (int i = 0; i < commandsTypes.size(); i++) {
59 // check the resulting command class
60 // try {
61 // Class<?> classOfCommand = Class.forName(commandsTypes.get(i));
62 // addTargetSamCommand(
63 // (Command) JsonUtil.getParser().fromJson(commands.get(i),
64 // classOfCommand));
65
66 // } catch (const ClassNotFoundException& e) {
67 // throw IllegalStateException(
68 // "Class '" + commandsTypes[i] + "' not found. Unable to "
69 // "parse JSON object: " + samCommandsJson,
70 // std::make_shared<ClassNotFoundException>(e));
71 // }
72 // }
73}
74
75AsyncTransactionExecutorManager&
76AsyncTransactionExecutorManagerAdapter::processCommands()
77{
78 try {
79 return processCommands(ChannelControl::KEEP_OPEN);
80 } catch (const ReaderCommunicationException& e) {
81 throw ReaderIOException(e.what(), e);
82 } catch (const CardCommunicationException& e) {
83 throw SamIOException(e.what(), e);
84 } catch (const InvalidCardResponseException& e) {
85 throw UnexpectedCommandStatusException(e.what(), e);
86 }
87}
88
89AsyncTransactionExecutorManager&
90AsyncTransactionExecutorManagerAdapter::processCommands(
91 ChannelControl channelControl)
92{
93 processTargetSamCommandsAlreadyFinalized(channelControl);
94
95 return *this;
96}
97
98} /* namespace legacysam */
99} /* namespace crypto */
100} /* namespace calypso */
101} /* namespace card */
102} /* namespace keyple */