Keyple Service Resource C++ Library - 3.1.1
Component of the Keyple C++ middleware
PoolPluginsConfigurator.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/PoolPluginsConfigurator.hpp"
15
16#include "keyple/core/util/KeypleAssert.hpp"
17#include "keyple/core/util/cpp/Arrays.hpp"
18#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
19
20namespace keyple {
21namespace core {
22namespace service {
23namespace resource {
24
25using keyple::core::util::Assert;
26using keyple::core::util::cpp::Arrays;
27using keyple::core::util::cpp::exception::IllegalStateException;
28
30
31/* BUILDER ------------------------------------------------------------------ */
32
34PoolPluginsConfigurator::Builder::usePoolFirst()
35{
36 if (mUsePoolFirstConfigured == true) {
37 throw IllegalStateException("Pool plugins priority already configured");
38 }
39
40 mUsePoolFirst = true;
41 mUsePoolFirstConfigured = true;
42
43 return *this;
44}
45
47PoolPluginsConfigurator::Builder::addPoolPlugin(
48 std::shared_ptr<PoolPlugin> poolPlugin)
49{
50 Assert::getInstance().notNull(poolPlugin, "poolPlugin");
51
52 if (Arrays::contains(mPoolPlugins, poolPlugin)) {
53 throw IllegalStateException("Pool plugin already configured");
54 }
55
56 mPoolPlugins.push_back(poolPlugin);
57
58 return *this;
59}
60
61std::shared_ptr<PoolPluginsConfigurator>
62PoolPluginsConfigurator::Builder::build()
63{
64 if (mPoolPlugins.empty()) {
65 throw IllegalStateException("No pool plugin was configured");
66 }
67
68 if (mUsePoolFirstConfigured == false) {
69 mUsePoolFirst = false;
70 }
71
72 return std::make_shared<PoolPluginsConfigurator>(this);
73}
74
76: mUsePoolFirstConfigured(false)
77{
78}
79
80/* POOL PLUGINS CONFIGURATOR ------------------------------------------------ */
81
82bool
83PoolPluginsConfigurator::isUsePoolFirst() const
84{
85 return mUsePoolFirst;
86}
87
88const std::vector<std::shared_ptr<PoolPlugin>>&
89PoolPluginsConfigurator::getPoolPlugins() const
90{
91 return mPoolPlugins;
92}
93
95PoolPluginsConfigurator::builder()
96{
97 return new Builder();
98}
99
100PoolPluginsConfigurator::PoolPluginsConfigurator(const Builder* builder)
101: mUsePoolFirst(builder->mUsePoolFirst)
102, mPoolPlugins(builder->mPoolPlugins)
103{
104 /* Deleted builder here. It's been allocated with new */
105 delete builder;
106}
107
108} /* namespace resource */
109} /* namespace service */
110} /* namespace core */
111} /* namespace keyple */
CardResourceProfileConfigurator::Builder Builder