keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
CommonTransactionManagerAdapter.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2023 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/CommonTransactionManagerAdapter.hpp"
15
16#include <memory>
17#include <string>
18#include <vector>
19
20#include "keyple/card/calypso/crypto/legacysam/CommandExecutor.hpp"
21
22namespace keyple {
23namespace card {
24namespace calypso {
25namespace crypto {
26namespace legacysam {
27
28const std::string CommonTransactionManagerAdapter::SAM_COMMANDS_TYPES
29 = "samCommandsTypes";
30const std::string CommonTransactionManagerAdapter::SAM_COMMANDS = "samCommands";
31
32CommonTransactionManagerAdapter::CommonTransactionManagerAdapter(
33 std::shared_ptr<ProxyReaderApi> targetSamReader,
34 std::shared_ptr<LegacySamAdapter> targetSam,
35 std::shared_ptr<ProxyReaderApi> controlSamReader,
36 std::shared_ptr<LegacySamAdapter> controlSam)
37: mTargetSamReader(targetSamReader)
38, mTargetSam(targetSam)
39, mControlSamReader(controlSamReader)
40, mControlSam(controlSam)
41, mTargetSamCommands(std::vector<std::shared_ptr<Command>>())
42{
43}
44
45std::shared_ptr<CommandContextDto>
46CommonTransactionManagerAdapter::getContext() const
47{
48 return std::make_shared<CommandContextDto>(
49 mTargetSam, mControlSamReader, mControlSam);
50}
51
52void
53CommonTransactionManagerAdapter::addTargetSamCommand(
54 std::shared_ptr<Command> samCommand)
55{
56 mTargetSamCommands.push_back(samCommand);
57}
58
59const std::vector<std::shared_ptr<Command>>&
60CommonTransactionManagerAdapter::getTargetSamCommands() const
61{
62 return mTargetSamCommands;
63}
64
65void
66CommonTransactionManagerAdapter::processTargetSamCommands(
67 ChannelControl channelControl)
68{
69 try {
70 CommandExecutor::processCommands(
71 mTargetSamCommands, mTargetSamReader, channelControl);
72 } catch (...) {
73 mTargetSamCommands.clear();
74 throw;
75 }
76
77 mTargetSamCommands.clear();
78}
79
80void
81CommonTransactionManagerAdapter::processTargetSamCommands(
82 std::vector<std::shared_ptr<Command>> commands)
83{
84 CommandExecutor::processCommands(
85 commands, mTargetSamReader, ChannelControl::KEEP_OPEN);
86}
87
88void
89CommonTransactionManagerAdapter::processTargetSamCommandsAlreadyFinalized(
90 ChannelControl channelControl)
91{
92 try {
93 CommandExecutor::processCommandsAlreadyFinalized(
94 mTargetSamCommands, mTargetSamReader, channelControl);
95 } catch (...) {
96 mTargetSamCommands.clear();
97 throw;
98 }
99
100 mTargetSamCommands.clear();
101}
102
103} /* namespace legacysam */
104} /* namespace crypto */
105} /* namespace calypso */
106} /* namespace card */
107} /* namespace keyple */