Keyple Service C++ Library - 3.3.5
Component of the Keyple C++ middleware
LocalPluginAdapter.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/LocalPluginAdapter.hpp"
15
16#include <memory>
17#include <vector>
18
19#include "keyple/core/service/LocalReaderAdapter.hpp"
20#include "keyple/core/service/ObservableLocalReaderAdapter.hpp"
21#include "keyple/core/util/cpp/exception/Exception.hpp"
22#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
23
24namespace keyple {
25namespace core {
26namespace service {
27
28using keyple::core::util::cpp::exception::Exception;
29using keyple::core::util::cpp::exception::IllegalArgumentException;
30
31LocalPluginAdapter::LocalPluginAdapter(std::shared_ptr<PluginSpi> pluginSpi)
32: AbstractPluginAdapter(
33 pluginSpi ? pluginSpi->getName() : "",
34 std::dynamic_pointer_cast<KeyplePluginExtension>(pluginSpi))
35, mPluginSpi(pluginSpi)
36{
37 if (pluginSpi == nullptr) {
38 throw IllegalArgumentException("Invalid pluginSpi");
39 }
40}
41
42void
43LocalPluginAdapter::doRegister()
44{
45 AbstractPluginAdapter::doRegister();
46
47 const std::vector<std::shared_ptr<ReaderSpi>> readerSpiList
48 = mPluginSpi->searchAvailableReaders();
49
50 for (const auto& readerSpi : readerSpiList) {
51 std::shared_ptr<LocalReaderAdapter> localReaderAdapter
52 = buildLocalReaderAdapter(readerSpi);
53 getReadersMap().insert({readerSpi->getName(), localReaderAdapter});
54 localReaderAdapter->doRegister();
55 }
56}
57
58void
59LocalPluginAdapter::doUnregister()
60{
61 try {
62 mPluginSpi->onUnregister();
63 } catch (const Exception& e) {
64 mLogger->error(
65 "Error unregistering plugin extension [%]: %\n",
66 getName(),
67 e.getMessage());
68 }
69
70 AbstractPluginAdapter::doUnregister();
71}
72
73} /* namespace service */
74} /* namespace core */
75} /* namespace keyple */