Keyple Plugin Stub C++ Library - 2.2.2
Component of the Keyple C++ middleware
StubPluginAdapter.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * This program and the accompanying materials are made available under the *
5 * terms of the MIT License which is available at *
6 * https://opensource.org/licenses/MIT. *
7 * *
8 * SPDX-License-Identifier: MIT *
9 ******************************************************************************/
10
11#include "keyple/plugin/stub/StubPluginAdapter.hpp"
12
13namespace keyple {
14namespace plugin {
15namespace stub {
16
17StubPluginAdapter::StubPluginAdapter(
18 const std::string& name,
19 const std::vector<std::shared_ptr<StubReaderConfiguration>>&
20 readerConfigurations,
21 const int monitoringCycleDuration)
22: mName(name)
23, mMonitoringCycleDuration(monitoringCycleDuration)
24{
25 for (const auto& configuration : readerConfigurations) {
26 plugReader(
27 configuration->getName(),
28 configuration->getContactless(),
29 configuration->getCard());
30 }
31}
32
33int
34StubPluginAdapter::getMonitoringCycleDuration() const
35{
36 return mMonitoringCycleDuration;
37}
38
39const std::vector<std::string>
40StubPluginAdapter::searchAvailableReaderNames()
41{
42 std::vector<std::string> readers;
43 for (const auto& reader : mStubReaders) {
44 readers.push_back(reader.first);
45 }
46
47 return readers;
48}
49
50std::shared_ptr<ReaderSpi>
51StubPluginAdapter::searchReader(const std::string& readerName)
52{
53 const auto it = mStubReaders.find(readerName);
54 if (it != mStubReaders.end()) {
55 return it->second;
56 }
57
58 return nullptr;
59}
60
61const std::string&
62StubPluginAdapter::getName() const
63{
64 return mName;
65}
66
67const std::vector<std::shared_ptr<ReaderSpi>>
68StubPluginAdapter::searchAvailableReaders()
69{
70 std::vector<std::shared_ptr<ReaderSpi>> readers;
71 for (const auto& reader : mStubReaders) {
72 readers.push_back(reader.second);
73 }
74
75 return readers;
76}
77
78void
79StubPluginAdapter::onUnregister()
80{
81 /* NO-OP */
82}
83
84void
85StubPluginAdapter::plugReader(
86 const std::string& name,
87 const bool isContactless,
88 std::shared_ptr<StubSmartCard> card)
89{
90 mStubReaders.insert(
91 {name, std::make_shared<StubReaderAdapter>(name, isContactless, card)});
92}
93
94void
95StubPluginAdapter::unplugReader(const std::string& name)
96{
97 mStubReaders.erase(name);
98}
99
100} /* namespace stub */
101} /* namespace plugin */
102} /* namespace keyple */