Keyple Plugin PC/SC C++ Library - 2.5.2
Component of the Keyple C++ middleware
PcscPluginFactoryBuilder.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/plugin/pcsc/PcscPluginFactoryBuilder.hpp"
15
16#include "keyple/core/util/KeypleAssert.hpp"
17#include "keyple/core/util/cpp/Pattern.hpp"
18#include "keyple/core/util/cpp/exception/Exception.hpp"
19#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
20#include "keyple/plugin/pcsc/PcscPluginFactoryAdapter.hpp"
21
22namespace keyple {
23namespace plugin {
24namespace pcsc {
25
26using keyple::core::util::Assert;
27using keyple::core::util::cpp::Pattern;
28using keyple::core::util::cpp::exception::Exception;
29using keyple::core::util::cpp::exception::IllegalArgumentException;
30
32
33const std::string Builder::DEFAULT_CONTACTLESS_READER_FILTER
34 = ".*(contactless|ask logo|acs acr122).*";
35
36/* BUILDER ------------------------------------------------------------------ */
37
39: mContactlessReaderIdentificationFilterPattern(
40 Pattern::compile(Builder::DEFAULT_CONTACTLESS_READER_FILTER))
41, mCardMonitoringCycleDuration(500)
42{
43}
44
46Builder::useContactReaderIdentificationFilter(
47 const std::string& /*contactReaderIdentificationFilter*/)
48{
49 return *this;
50}
51
53Builder::useContactlessReaderIdentificationFilter(
54 const std::string& contactlessReaderIdentificationFilter)
55{
56 Assert::getInstance().notEmpty(
57 contactlessReaderIdentificationFilter,
58 "contactlessReaderIdentificationFilter");
59
60 try {
61 mContactlessReaderIdentificationFilterPattern
62 = Pattern::compile(contactlessReaderIdentificationFilter);
63
64 } catch (const Exception& e) {
65 throw IllegalArgumentException(
66 "Bad regular expression.", e);
67 }
68
69 return *this;
70}
71
73Builder::updateProtocolIdentificationRule(
74 const std::string& readerProtocolName, const std::string& protocolRule)
75{
76 Assert::getInstance().notEmpty(readerProtocolName, "readerProtocolName");
77
78 if (protocolRule == "") {
79 /* Disable the protocol by defining a regex that always fails */
80 mProtocolRulesMap.insert({readerProtocolName, "X"});
81
82 } else {
83 mProtocolRulesMap.insert({readerProtocolName, protocolRule});
84 }
85
86 return *this;
87}
88
90Builder::setCardMonitoringCycleDuration(const int cycleDuration)
91{
92 Assert::getInstance().greaterOrEqual(cycleDuration, 1, "cycleDuration");
93
94 mCardMonitoringCycleDuration = cycleDuration;
95
96 return *this;
97}
98
99std::shared_ptr<PcscPluginFactory>
100PcscPluginFactoryBuilder::Builder::build()
101{
102 return std::make_shared<PcscPluginFactoryAdapter>(
103 mContactlessReaderIdentificationFilterPattern,
104 mProtocolRulesMap,
105 mCardMonitoringCycleDuration);
106}
107
108/* PCSC PLUGIN FACTORY BUILDER
109 * ------------------------------------------------------------------ */
110
111std::unique_ptr<Builder>
112PcscPluginFactoryBuilder::builder()
113{
114 return std::unique_ptr<Builder>(new Builder());
115}
116
117} /* namespace pcsc */
118} /* namespace plugin */
119} /* namespace keyple */
PcscPluginFactoryBuilder::Builder Builder
Definition: Card.cpp:20