Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake-linux-fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Deps
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

- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
submodules: recursive
persist-credentials: false
Expand Down
1 change: 0 additions & 1 deletion src/controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ add_library(controller STATIC
logging.cpp
logging.hpp
qeid.hpp
retriableerror.cpp
retriableerror.hpp
threads/cardeventmonitorthread.hpp
threads/commandhandlerconfirmthread.hpp
Expand Down
3 changes: 1 addition & 2 deletions src/controller/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ CommandWithArgumentsPtr Application::parseArgs()
if (command == CMDLINE_GET_SIGNING_CERTIFICATE || command == CMDLINE_AUTHENTICATE
|| command == CMDLINE_SIGN) {
// TODO: add command-specific argument validation
return std::make_unique<CommandWithArguments>(commandNameToCommandType(command),
return std::make_unique<CommandWithArguments>(CommandType(command),
parseArgumentJson(arguments));
}
throw ArgumentError("The command has to be one of " + COMMANDS.toStdString());
Expand All @@ -193,7 +193,6 @@ CommandWithArgumentsPtr Application::parseArgs()

void Application::registerMetatypes()
{
qRegisterMetaType<electronic_id::AutoSelectFailed::Reason>();
qRegisterMetaType<electronic_id::ElectronicID::ptr>();
qRegisterMetaType<std::vector<electronic_id::ElectronicID::ptr>>();
qRegisterMetaType<electronic_id::VerifyPinFailed::Status>();
Expand Down
8 changes: 4 additions & 4 deletions src/controller/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "commands.hpp"

#include "magic_enum/magic_enum.hpp"
#include <QMetaEnum>

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

CommandType commandNameToCommandType(const QString& cmdName)
CommandType::CommandType(const QString& cmdName)
{
static const std::map<QString, CommandType> SUPPORTED_COMMANDS {
{CMDLINE_GET_SIGNING_CERTIFICATE, CommandType::GET_SIGNING_CERTIFICATE},
Expand All @@ -43,13 +43,13 @@ CommandType commandNameToCommandType(const QString& cmdName)
};

try {
return SUPPORTED_COMMANDS.at(cmdName);
value = SUPPORTED_COMMANDS.at(cmdName);
} catch (const std::out_of_range&) {
throw std::invalid_argument("Command '" + cmdName.toStdString() + "' is not supported");
}
}

CommandType::operator std::string() const
{
return std::string(magic_enum::enum_name(value));
return QMetaEnum::fromType<CommandType::CommandTypeEnum>().valueToKey(value);
}
19 changes: 9 additions & 10 deletions src/controller/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,34 @@

class CommandType
{
Q_GADGET
public:
enum CommandTypeEnum {
enum CommandTypeEnum : quint8 {
NONE,
INSERT_CARD,
GET_SIGNING_CERTIFICATE,
AUTHENTICATE,
SIGN,
QUIT,
ABOUT,
NONE = -1
};
Q_ENUM(CommandTypeEnum)

CommandType() = default;
constexpr CommandType(const CommandTypeEnum _value) : value(_value) {}
constexpr CommandType(CommandTypeEnum _value = NONE) noexcept : value(_value) { }
explicit CommandType(const QString& cmdName);

constexpr bool operator==(CommandTypeEnum other) const { return value == other; }
constexpr bool operator!=(CommandTypeEnum other) const { return value != other; }
constexpr operator CommandTypeEnum() const { return value; }
constexpr bool operator==(CommandTypeEnum other) const noexcept { return value == other; }
constexpr operator CommandTypeEnum() const noexcept { return value; }

operator std::string() const;

private:
CommandTypeEnum value = NONE;
CommandTypeEnum value;
};

extern const QString CMDLINE_GET_SIGNING_CERTIFICATE;
extern const QString CMDLINE_AUTHENTICATE;
extern const QString CMDLINE_SIGN;

CommandType commandNameToCommandType(const QString& cmdName);

using CommandWithArguments = std::pair<CommandType, QVariantMap>;
using CommandWithArgumentsPtr = std::unique_ptr<CommandWithArguments>;
5 changes: 2 additions & 3 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void Controller::onCommandHandlerConfirmCompleted(const QVariantMap& res)
_result = res;
writeResponseToStdOut(isInStdinMode, res, commandHandler->commandType());
} catch (const std::exception& error) {
qCritical() << "Command" << std::string(commandType())
qCritical() << "Command" << commandType()
<< "fatal error while writing response to stdout:" << error;
}

Expand Down Expand Up @@ -283,8 +283,7 @@ void Controller::onDialogCancel()
void Controller::onCriticalFailure(const QString& error)
{
emit stopCardEventMonitorThread();
qCritical() << "Exiting due to command" << std::string(commandType())
<< "fatal error:" << error;
qCritical() << "Exiting due to command" << commandType() << "fatal error:" << error;
_result =
makeErrorObject(RESP_TECH_ERROR, QStringLiteral("Technical error, see application logs"));
disposeUI();
Expand Down
2 changes: 1 addition & 1 deletion src/controller/inputoutputmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ CommandWithArgumentsPtr readCommandFromStdin()
"contain a 'command' string and 'arguments' object");
}

return std::make_unique<CommandWithArguments>(commandNameToCommandType(command.toString()),
return std::make_unique<CommandWithArguments>(CommandType(command.toString()),
arguments.toObject().toVariantMap());
}
14 changes: 5 additions & 9 deletions src/controller/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@

void setupLogging();

inline QDebug operator<<(QDebug out, const std::string& s)
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
template <typename... Args>
inline QDebug operator<<(QDebug out, const std::basic_string<char, Args...>& s)
{
out << QString::fromStdString(s);
return out;
}

inline QDebug operator<<(QDebug out, const std::wstring& s)
{
out << QString::fromStdWString(s);
return out;
return out << QUtf8StringView(s);
}
#endif

inline QDebug operator<<(QDebug out, const std::exception& e)
{
Expand Down
1 change: 0 additions & 1 deletion src/controller/qeid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <QMetaType>

Q_DECLARE_METATYPE(electronic_id::AutoSelectFailed::Reason)
Q_DECLARE_METATYPE(electronic_id::ElectronicID::ptr)
Q_DECLARE_METATYPE(std::vector<electronic_id::ElectronicID::ptr>)
Q_DECLARE_METATYPE(electronic_id::VerifyPinFailed::Status)
50 changes: 0 additions & 50 deletions src/controller/retriableerror.cpp

This file was deleted.

Loading