Keyple Service Resource C++ Library - 3.1.1
Component of the Keyple C++ middleware
CardResourceProfileConfigurator.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/core/service/resource/CardResourceProfileConfigurator.hpp"
15
16#include "keyple/core/util/KeypleAssert.hpp"
17#include "keyple/core/util/cpp/Pattern.hpp"
18#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
19#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
20#include "keyple/core/util/cpp/exception/PatternSyntaxException.hpp"
21
22namespace keyple {
23namespace core {
24namespace service {
25namespace resource {
26
27using keyple::core::util::Assert;
28using keyple::core::util::cpp::Pattern;
29using keyple::core::util::cpp::exception::IllegalArgumentException;
30using keyple::core::util::cpp::exception::IllegalStateException;
31using keyple::core::util::cpp::exception::PatternSyntaxException;
32
34
35/* CARD RESOURCE PROFILE CONFIGURATOR --------------------------------------- */
36
37CardResourceProfileConfigurator::CardResourceProfileConfigurator(
38 Builder* builder)
39: mProfileName(builder->mProfileName)
40, mCardResourceProfileExtension(builder->mCardResourceProfileExtension)
41, mPlugins(builder->mPlugins)
42, mReaderNameRegex(builder->mReaderNameRegex)
43, mReaderGroupReference(builder->mReaderGroupReference)
44{
45 /* Deleted builder here. It's been allocated with new */
46 delete builder;
47}
48
49const std::string&
50CardResourceProfileConfigurator::getProfileName() const
51{
52 return mProfileName;
53}
54
55std::shared_ptr<CardResourceProfileExtension>
56CardResourceProfileConfigurator::getCardResourceProfileExtension() const
57{
58 return mCardResourceProfileExtension;
59}
60
61const std::vector<std::shared_ptr<Plugin>>&
62CardResourceProfileConfigurator::getPlugins() const
63{
64 return mPlugins;
65}
66
67const std::string&
68CardResourceProfileConfigurator::getReaderNameRegex() const
69{
70 return mReaderNameRegex;
71}
72
73const std::string&
74CardResourceProfileConfigurator::getReaderGroupReference() const
75{
76 return mReaderGroupReference;
77}
78
80CardResourceProfileConfigurator::builder(
81 const std::string& profileName,
82 std::shared_ptr<CardResourceProfileExtension> cardResourceProfileExtension)
83{
84 return new Builder(profileName, cardResourceProfileExtension);
85}
86
87/* BUILDER ------------------------------------------------------------------ */
88
90 const std::string& profileName,
91 std::shared_ptr<CardResourceProfileExtension> cardResourceProfileExtension)
92: mProfileName(profileName)
93, mCardResourceProfileExtension(cardResourceProfileExtension)
94, mReaderNameRegex("")
95, mReaderGroupReference("")
96{
97 Assert::getInstance().notNull(
98 cardResourceProfileExtension, "cardResourceProfileExtension");
99}
100
101Builder&
102Builder::withPlugins(const std::vector<std::shared_ptr<Plugin>>& plugins)
103{
104 for (const auto& plugin : plugins) {
105 Assert::getInstance().notNull(plugin, "plugin");
106 mPlugins.push_back(plugin);
107 }
108
109 return *this;
110}
111
112Builder&
113Builder::withReaderNameRegex(const std::string& readerNameRegex)
114{
115 Assert::getInstance().notEmpty(readerNameRegex, "readerNameRegex");
116
117 if (mReaderNameRegex != "") {
118 throw IllegalStateException("Reader name regex has already been set");
119 }
120
121 try {
122 Pattern::compile(readerNameRegex);
123 } catch (const PatternSyntaxException&) {
124 throw IllegalArgumentException(
125 "Invalid regular expression [regex=" + readerNameRegex + "]");
126 }
127
128 mReaderNameRegex = readerNameRegex;
129
130 return *this;
131}
132
133Builder&
134Builder::withReaderGroupReference(const std::string& readerGroupReference)
135{
136 Assert::getInstance().notEmpty(
137 readerGroupReference, "readerGroupReference");
138
139 if (mReaderGroupReference != "") {
140 throw IllegalStateException(
141 "Reader group reference has already been set");
142 }
143
144 mReaderGroupReference = readerGroupReference;
145
146 return *this;
147}
148
149std::shared_ptr<CardResourceProfileConfigurator>
150Builder::build()
151{
152 return std::make_shared<CardResourceProfileConfigurator>(this);
153}
154
155} /* namespace resource */
156} /* namespace service */
157} /* namespace core */
158} /* namespace keyple */
CardResourceProfileConfigurator::Builder Builder