Skip to content

Commit 7ba4a06

Browse files
committed
Make RetriableError separate class and avoid macros
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent ed1a78c commit 7ba4a06

15 files changed

+140
-201
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install Deps
2121
run: dnf install -y --setopt=install_weak_deps=False git gcc-c++ cmake rpm-build openssl-devel pcsc-lite-devel qt6-qtsvg-devel qt6-qttools-devel gtest-devel
2222

23-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v5
2424
with:
2525
submodules: recursive
2626
persist-credentials: false

src/controller/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ add_library(controller STATIC
2222
logging.cpp
2323
logging.hpp
2424
qeid.hpp
25-
retriableerror.cpp
2625
retriableerror.hpp
2726
threads/cardeventmonitorthread.hpp
2827
threads/commandhandlerconfirmthread.hpp

src/controller/application.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ CommandWithArgumentsPtr Application::parseArgs()
167167
if (command == CMDLINE_GET_SIGNING_CERTIFICATE || command == CMDLINE_AUTHENTICATE
168168
|| command == CMDLINE_SIGN) {
169169
// TODO: add command-specific argument validation
170-
return std::make_unique<CommandWithArguments>(commandNameToCommandType(command),
170+
return std::make_unique<CommandWithArguments>(CommandType(command),
171171
parseArgumentJson(arguments));
172172
}
173173
throw ArgumentError("The command has to be one of " + COMMANDS.toStdString());
@@ -193,7 +193,6 @@ CommandWithArgumentsPtr Application::parseArgs()
193193

194194
void Application::registerMetatypes()
195195
{
196-
qRegisterMetaType<electronic_id::AutoSelectFailed::Reason>();
197196
qRegisterMetaType<electronic_id::ElectronicID::ptr>();
198197
qRegisterMetaType<std::vector<electronic_id::ElectronicID::ptr>>();
199198
qRegisterMetaType<electronic_id::VerifyPinFailed::Status>();

src/controller/commands.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "commands.hpp"
2424

25-
#include "magic_enum/magic_enum.hpp"
25+
#include <QMetaEnum>
2626

2727
#include <stdexcept>
2828
#include <map>
@@ -33,7 +33,7 @@ const QString CMDLINE_SIGN = QStringLiteral("sign");
3333
// A special command for stdin mode for quitting the application after sending the version.
3434
const QString STDINMODE_QUIT = QStringLiteral("quit");
3535

36-
CommandType commandNameToCommandType(const QString& cmdName)
36+
CommandType::CommandType(const QString& cmdName)
3737
{
3838
static const std::map<QString, CommandType> SUPPORTED_COMMANDS {
3939
{CMDLINE_GET_SIGNING_CERTIFICATE, CommandType::GET_SIGNING_CERTIFICATE},
@@ -43,13 +43,13 @@ CommandType commandNameToCommandType(const QString& cmdName)
4343
};
4444

4545
try {
46-
return SUPPORTED_COMMANDS.at(cmdName);
46+
value = SUPPORTED_COMMANDS.at(cmdName);
4747
} catch (const std::out_of_range&) {
4848
throw std::invalid_argument("Command '" + cmdName.toStdString() + "' is not supported");
4949
}
5050
}
5151

5252
CommandType::operator std::string() const
5353
{
54-
return std::string(magic_enum::enum_name(value));
54+
return QMetaEnum::fromType<CommandType::CommandTypeEnum>().valueToKey(value);
5555
}

src/controller/commands.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,34 @@
2929

3030
class CommandType
3131
{
32+
Q_GADGET
3233
public:
33-
enum CommandTypeEnum {
34+
enum CommandTypeEnum : quint8 {
35+
NONE,
3436
INSERT_CARD,
3537
GET_SIGNING_CERTIFICATE,
3638
AUTHENTICATE,
3739
SIGN,
3840
QUIT,
3941
ABOUT,
40-
NONE = -1
4142
};
43+
Q_ENUM(CommandTypeEnum)
4244

43-
CommandType() = default;
44-
constexpr CommandType(const CommandTypeEnum _value) : value(_value) {}
45+
constexpr CommandType(CommandTypeEnum _value = NONE) noexcept : value(_value) { }
46+
explicit CommandType(const QString& cmdName);
4547

46-
constexpr bool operator==(CommandTypeEnum other) const { return value == other; }
47-
constexpr bool operator!=(CommandTypeEnum other) const { return value != other; }
48-
constexpr operator CommandTypeEnum() const { return value; }
48+
constexpr bool operator==(CommandTypeEnum other) const noexcept { return value == other; }
49+
constexpr operator CommandTypeEnum() const noexcept { return value; }
4950

5051
operator std::string() const;
5152

5253
private:
53-
CommandTypeEnum value = NONE;
54+
CommandTypeEnum value;
5455
};
5556

5657
extern const QString CMDLINE_GET_SIGNING_CERTIFICATE;
5758
extern const QString CMDLINE_AUTHENTICATE;
5859
extern const QString CMDLINE_SIGN;
5960

60-
CommandType commandNameToCommandType(const QString& cmdName);
61-
6261
using CommandWithArguments = std::pair<CommandType, QVariantMap>;
6362
using CommandWithArgumentsPtr = std::unique_ptr<CommandWithArguments>;

src/controller/controller.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void Controller::onCommandHandlerConfirmCompleted(const QVariantMap& res)
228228
_result = res;
229229
writeResponseToStdOut(isInStdinMode, res, commandHandler->commandType());
230230
} catch (const std::exception& error) {
231-
qCritical() << "Command" << std::string(commandType())
231+
qCritical() << "Command" << commandType()
232232
<< "fatal error while writing response to stdout:" << error;
233233
}
234234

@@ -283,8 +283,7 @@ void Controller::onDialogCancel()
283283
void Controller::onCriticalFailure(const QString& error)
284284
{
285285
emit stopCardEventMonitorThread();
286-
qCritical() << "Exiting due to command" << std::string(commandType())
287-
<< "fatal error:" << error;
286+
qCritical() << "Exiting due to command" << commandType() << "fatal error:" << error;
288287
_result =
289288
makeErrorObject(RESP_TECH_ERROR, QStringLiteral("Technical error, see application logs"));
290289
disposeUI();

src/controller/inputoutputmode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ CommandWithArgumentsPtr readCommandFromStdin()
101101
"contain a 'command' string and 'arguments' object");
102102
}
103103

104-
return std::make_unique<CommandWithArguments>(commandNameToCommandType(command.toString()),
104+
return std::make_unique<CommandWithArguments>(CommandType(command.toString()),
105105
arguments.toObject().toVariantMap());
106106
}

src/controller/logging.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@
2626

2727
void setupLogging();
2828

29-
inline QDebug operator<<(QDebug out, const std::string& s)
29+
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
30+
template <typename... Args>
31+
inline QDebug operator<<(QDebug out, const std::basic_string<char, Args...>& s)
3032
{
31-
out << QString::fromStdString(s);
32-
return out;
33-
}
34-
35-
inline QDebug operator<<(QDebug out, const std::wstring& s)
36-
{
37-
out << QString::fromStdWString(s);
38-
return out;
33+
return out << QUtf8StringView(s);
3934
}
35+
#endif
4036

4137
inline QDebug operator<<(QDebug out, const std::exception& e)
4238
{

src/controller/qeid.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <QMetaType>
2828

29-
Q_DECLARE_METATYPE(electronic_id::AutoSelectFailed::Reason)
3029
Q_DECLARE_METATYPE(electronic_id::ElectronicID::ptr)
3130
Q_DECLARE_METATYPE(std::vector<electronic_id::ElectronicID::ptr>)
3231
Q_DECLARE_METATYPE(electronic_id::VerifyPinFailed::Status)

src/controller/retriableerror.cpp

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

0 commit comments

Comments
 (0)