14#include "keyple/plugin/pcsc/cpp/TerminalFactory.hpp"
22#include "keyple/plugin/pcsc/cpp/exception/CardTerminalException.hpp"
29using keyple::plugin::pcsc::cpp::exception::CardTerminalException;
31std::shared_ptr<TerminalFactory> TerminalFactory::mInstance;
33std::shared_ptr<TerminalFactory>
34TerminalFactory::getDefault()
36 if (mInstance ==
nullptr) {
37 mInstance = std::shared_ptr<TerminalFactory>(
new TerminalFactory());
44const std::vector<std::string>
45TerminalFactory::listTerminals()
51 static std::vector<std::string> list;
56 ret = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &mContext);
57 if (ret != SCARD_S_SUCCESS) {
58 throw CardTerminalException(pcsc_stringify_error(ret));
61 ret = SCardListReaders(mContext, NULL, NULL, &len);
62 if (ret != SCARD_S_SUCCESS) {
63 throw CardTerminalException(pcsc_stringify_error(ret));
66 readers =
static_cast<char*
>(calloc(len,
sizeof(
char)));
68 if (readers == NULL) {
73 ret = SCardListReaders(mContext, NULL, readers, &len);
74 if (ret != SCARD_S_SUCCESS) {
75 throw CardTerminalException(pcsc_stringify_error(ret));
87 ptr += strlen(ptr) + 1;
90 SCardReleaseContext(mContext);
96std::shared_ptr<CardTerminals>
97TerminalFactory::terminals()
99 LONG ret = SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &mContext);
100 if (ret != SCARD_S_SUCCESS) {
101 throw CardTerminalException(pcsc_stringify_error(ret));
104 return std::make_shared<CardTerminals>(mContext);