Skip to content

Commit 96b6cea

Browse files
committed
Make Reader simple struct
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 051ae3e commit 96b6cea

File tree

10 files changed

+25
-312
lines changed

10 files changed

+25
-312
lines changed

.github/workflows/cmake-linux-fedora.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ name: CMake (Fedora Linux)
22

33
on: [push, pull_request]
44

5-
env:
6-
BUILD_TYPE: RelWithDebInfo
7-
85
jobs:
96
build:
107
runs-on: ubuntu-latest
118
continue-on-error: ${{ matrix.experimental }}
129
strategy:
1310
matrix:
1411
container: ['fedora:latest']
12+
build_type: [Release, RelWithDebInfo]
1513
experimental: [false]
1614
include:
1715
- container: 'fedora:rawhide'
1816
experimental: true
17+
build_type: [Release]
1918

2019
container:
2120
image: ${{ matrix.container }}
@@ -27,10 +26,10 @@ jobs:
2726
- uses: actions/checkout@v4
2827

2928
- name: Configure CMake
30-
run: cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -S . -B build
29+
run: cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S . -B build
3130

3231
- name: Build
33-
run: cmake --build build --config $BUILD_TYPE -j $(nproc)
32+
run: cmake --build build --config ${{ matrix.build_type }} -j $(nproc)
3433

3534
- name: Test
36-
run: ctest -V -C $BUILD_TYPE --test-dir build
35+
run: ctest -V -C ${{ matrix.build_type }} --test-dir build

lib/libpcsc-cpp/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ add_library(${PROJECT_NAME}
99
include/${PROJECT_NAME}/${PROJECT_NAME}.hpp
1010
include/${PROJECT_NAME}/${PROJECT_NAME}-utils.hpp
1111
include/${PROJECT_NAME}/comp_winscard.hpp
12-
include/flag-set-cpp/flag_set.hpp
1312
include/magic_enum/magic_enum.hpp
1413
src/Context.hpp
15-
src/Reader.cpp
1614
src/SCardCall.hpp
1715
src/SmartCard.cpp
1816
src/listReaders.cpp

lib/libpcsc-cpp/include/flag-set-cpp/flag_set.hpp

Lines changed: 0 additions & 175 deletions
This file was deleted.

lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
#pragma once
2424

25-
#include "flag-set-cpp/flag_set.hpp"
26-
25+
#include <limits>
2726
#include <memory>
27+
#include <stdexcept>
28+
#include <string>
2829
#include <vector>
29-
#include <limits>
3030

3131
// The rule of five (C++ Core guidelines C.21).
3232
#define PCSC_CPP_DISABLE_COPY_MOVE(Class) \
@@ -253,39 +253,14 @@ class SmartCard
253253
};
254254

255255
/** Reader provides card reader information, status and gives access to the smart card in it. */
256-
class Reader
256+
struct Reader
257257
{
258-
public:
259-
enum class Status {
260-
UNAWARE,
261-
IGNORE,
262-
CHANGED,
263-
UNKNOWN,
264-
UNAVAILABLE,
265-
EMPTY,
266-
PRESENT,
267-
ATRMATCH,
268-
EXCLUSIVE,
269-
INUSE,
270-
MUTE,
271-
UNPOWERED,
272-
_
273-
};
274-
275-
Reader(ContextPtr context, string_t name, byte_vector cardAtr, flag_set<Status> status);
276-
277258
SmartCard::ptr connectToCard() const { return std::make_unique<SmartCard>(ctx, name, cardAtr); }
278259

279-
bool isCardInserted() const { return status[Status::PRESENT]; }
280-
281-
std::string statusString() const;
282-
260+
ContextPtr ctx;
283261
const string_t name;
284262
const byte_vector cardAtr;
285-
const flag_set<Status> status;
286-
287-
private:
288-
ContextPtr ctx;
263+
const bool isCardInserted;
289264
};
290265

291266
/**

lib/libpcsc-cpp/src/Reader.cpp

Lines changed: 0 additions & 54 deletions
This file was deleted.

lib/libpcsc-cpp/src/listReaders.cpp

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,6 @@ std::vector<SCARD_READERSTATE> getReaderStates(const SCARDCONTEXT ctx, const str
6565
return readerStates;
6666
}
6767

68-
inline flag_set<Reader::Status> flagSetFromReaderState(const DWORD readerState)
69-
{
70-
if (!readerState) {
71-
return flag_set<Reader::Status> {Reader::Status::UNAWARE};
72-
}
73-
74-
static const std::map<DWORD, Reader::Status> READER_STATUS_MAP = {
75-
// SCARD_STATE_UNAWARE is zero and covered with (!readerState) above.
76-
{SCARD_STATE_IGNORE, Reader::Status::IGNORE},
77-
{SCARD_STATE_CHANGED, Reader::Status::CHANGED},
78-
{SCARD_STATE_UNKNOWN, Reader::Status::UNKNOWN},
79-
{SCARD_STATE_UNAVAILABLE, Reader::Status::UNAVAILABLE},
80-
{SCARD_STATE_EMPTY, Reader::Status::EMPTY},
81-
{SCARD_STATE_PRESENT, Reader::Status::PRESENT},
82-
{SCARD_STATE_ATRMATCH, Reader::Status::ATRMATCH},
83-
{SCARD_STATE_EXCLUSIVE, Reader::Status::EXCLUSIVE},
84-
{SCARD_STATE_INUSE, Reader::Status::INUSE},
85-
{SCARD_STATE_MUTE, Reader::Status::MUTE},
86-
{SCARD_STATE_UNPOWERED, Reader::Status::UNPOWERED}};
87-
88-
auto result = flag_set<Reader::Status> {};
89-
90-
for (const auto& [key, value] : READER_STATUS_MAP) {
91-
if (readerState & key) {
92-
result.set(value);
93-
}
94-
}
95-
96-
return result;
97-
}
98-
9968
string_t populateReaderNames(const SCARDCONTEXT ctx)
10069
{
10170
// Buffer length is in characters, not bytes.
@@ -121,12 +90,14 @@ std::vector<Reader> listReaders()
12190

12291
try {
12392
auto readerNames = populateReaderNames(ctx->handle());
124-
125-
for (const auto& readerState : getReaderStates(ctx->handle(), readerNames)) {
126-
readers.emplace_back(
127-
ctx, readerState.szReader,
128-
byte_vector {readerState.rgbAtr, std::next(readerState.rgbAtr, readerState.cbAtr)},
129-
flagSetFromReaderState(readerState.dwEventState));
93+
auto readerStates = getReaderStates(ctx->handle(), readerNames);
94+
readers.reserve(readerStates.size());
95+
for (const auto& readerState : readerStates) {
96+
readers.push_back(
97+
{ctx, readerState.szReader,
98+
byte_vector {std::begin(readerState.rgbAtr),
99+
std::next(std::begin(readerState.rgbAtr), readerState.cbAtr)},
100+
bool(readerState.dwEventState & SCARD_STATE_PRESENT)});
130101
}
131102
} catch (const ScardNoReadersError& /* e */) {
132103
}

0 commit comments

Comments
 (0)