Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactor of application, with new USB communication back-end. #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
25 changes: 0 additions & 25 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@ on:
release:

jobs:
qt5:
name: Build with Qt 5
runs-on: ubuntu-20.04
steps:

- uses: actions/checkout@v2

- name: Install dependencies
timeout-minutes: 10
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends cmake qt5-default libqt5serialport5-dev libusb-1.0-0-dev

- name: Configure
timeout-minutes: 5
run: cd Linux-Application && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_QT_VERSION=5 .

- name: Build
timeout-minutes: 15
run: make -C Linux-Application VERBOSE=1

- name: Install
timeout-minutes: 5
run: make -C Linux-Application DESTDIR=/tmp/staging install

qt6:
name: Build with Qt 6
runs-on: ubuntu-22.04
Expand Down
29 changes: 2 additions & 27 deletions Linux-Application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ project(DomesdayDuplicator)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Options that can be specified with -D

set(USE_QT_VERSION "" CACHE STRING
"Version of Qt to use (by default, try Qt 6 then Qt 5)"
)

# Check for dependencies

# Set up AUTOMOC and some sensible defaults for runtime execution
Expand All @@ -21,28 +15,9 @@ set(CMAKE_AUTOMOC ON)
include(GNUInstallDirs)
set(CMAKE_AUTOUIC ON)

set(QT_PACKAGE_NAMES Qt5 Qt6)
if(USE_QT_VERSION)
set(QT_PACKAGE_NAMES Qt${USE_QT_VERSION})
endif()
find_package(QT NAMES ${QT_PACKAGE_NAMES} REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widgets SerialPort)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets SerialPort)
find_package(LibUSB REQUIRED)

# For Qt < 5.15, emulate 5.15's Qt5CoreConfig.cmake, so we don't have to
# specify Qt5/Qt6 elsewhere.
if(QT_VERSION VERSION_LESS 5.15)
function(qt_add_resources outfiles)
qt5_add_resources("${outfiles}" ${ARGN})
set("${outfiles}" "${${outfiles}}" PARENT_SCOPE)
endfunction()
foreach(library Core Gui SerialPort Widgets)
add_library(Qt::${library} INTERFACE IMPORTED)
set_target_properties(Qt::${library} PROPERTIES
INTERFACE_LINK_LIBRARIES "Qt5::${library}")
endforeach()
endif()

add_subdirectory(DomesdayDuplicator)
add_subdirectory(dddconv)
add_subdirectory(dddutil)
9 changes: 6 additions & 3 deletions Linux-Application/DomesdayDuplicator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ set(DomesdayDuplicator_SOURCES
playercontrol.cpp
playerremotedialog.cpp playerremotedialog.ui
qcustomplot.cpp
usbcapture.cpp
usbdevice.cpp
QtLogger.cpp
UsbDeviceBase.cpp
UsbDeviceLibUsb.cpp
UsbDeviceWinUsb.cpp
)

qt_add_resources(DomesdayDuplicator_SOURCES resources.qrc)
Expand Down Expand Up @@ -44,8 +46,9 @@ if(WIN32)
)

target_link_libraries(DomesdayDuplicator PRIVATE
# TODO: Does this depend on compiler?
AdvAPI32
onecoreuap
winusb
)
endif()

Expand Down
197 changes: 197 additions & 0 deletions Linux-Application/DomesdayDuplicator/ILogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#pragma once
#include <string>
#include <type_traits>

class ILogger
{
public:
// Enumerations
enum class Severity : unsigned int
{
Critical = 0x01, // Fatal error or application crash
Error = 0x02, // Recoverable error
Warning = 0x04, // Noncritical problem
Info = 0x08, // Informational message
Debug = 0x10, // Debugging info. Not recorded by default.
Trace = 0x20, // Trace info. Logged to file but not displayed by default.
};
enum class SeverityFilter : unsigned int
{
None = 0,
Critical = int(Severity::Critical),
Error = int(Severity::Error),
Warning = int(Severity::Warning),
Info = int(Severity::Info),
Trace = int(Severity::Trace),
Debug = int(Severity::Debug),
CriticalOrHigher = Critical,
ErrorOrHigher = Critical | Error,
WarningOrHigher = Critical | Error | Warning,
InfoOrHigher = Critical | Error | Warning | Info,
DebugOrHigher = Critical | Error | Warning | Info | Debug,
TraceOrHigher = Critical | Error | Warning | Info | Debug | Trace,
All = TraceOrHigher,
};

public:
// Nested types
struct Deleter
{
inline void operator()(ILogger* target)
{
target->Delete();
}
};

public:
// Delete method
virtual void Delete() = 0;

// Severity methods
inline bool IsLogSeverityEnabled(Severity severity) const;

// Generic logging methods
inline void Log(Severity severity, const std::string& message) const;
inline void Log(Severity severity, const std::wstring& message) const;
template<class... Args>
void Log(Severity severity, const std::string& formatString, Args&&... args) const;
template<class... Args>
void Log(Severity severity, const std::wstring& formatString, Args&&... args) const;

// Severity logging methods
inline void Critical(const char* message) const;
inline void Critical(const wchar_t* message) const;
inline void Critical(const std::string& message) const;
inline void Critical(const std::wstring& message) const;
template<class... Args>
void Critical(const char* formatString, Args&&... args) const;
template<class... Args>
void Critical(const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void Critical(const std::string& formatString, Args&&... args) const;
template<class... Args>
void Critical(const std::wstring& formatString, Args&&... args) const;
inline void Error(const char* message) const;
inline void Error(const wchar_t* message) const;
inline void Error(const std::string& message) const;
inline void Error(const std::wstring& message) const;
template<class... Args>
void Error(const char* formatString, Args&&... args) const;
template<class... Args>
void Error(const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void Error(const std::string& formatString, Args&&... args) const;
template<class... Args>
void Error(const std::wstring& formatString, Args&&... args) const;
inline void Warning(const char* message) const;
inline void Warning(const wchar_t* message) const;
inline void Warning(const std::string& message) const;
inline void Warning(const std::wstring& message) const;
template<class... Args>
void Warning(const char* formatString, Args&&... args) const;
template<class... Args>
void Warning(const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void Warning(const std::string& formatString, Args&&... args) const;
template<class... Args>
void Warning(const std::wstring& formatString, Args&&... args) const;
inline void Info(const char* message) const;
inline void Info(const wchar_t* message) const;
inline void Info(const std::string& message) const;
inline void Info(const std::wstring& message) const;
template<class... Args>
void Info(const char* formatString, Args&&... args) const;
template<class... Args>
void Info(const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void Info(const std::string& formatString, Args&&... args) const;
template<class... Args>
void Info(const std::wstring& formatString, Args&&... args) const;
inline void Debug(const char* message) const;
inline void Debug(const wchar_t* message) const;
inline void Debug(const std::string& message) const;
inline void Debug(const std::wstring& message) const;
template<class... Args>
void Debug(const char* formatString, Args&&... args) const;
template<class... Args>
void Debug(const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void Debug(const std::string& formatString, Args&&... args) const;
template<class... Args>
void Debug(const std::wstring& formatString, Args&&... args) const;
inline void Trace(const char* message) const;
inline void Trace(const wchar_t* message) const;
inline void Trace(const std::string& message) const;
inline void Trace(const std::wstring& message) const;
template<class... Args>
void Trace(const char* formatString, Args&&... args) const;
template<class... Args>
void Trace(const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void Trace(const std::string& formatString, Args&&... args) const;
template<class... Args>
void Trace(const std::wstring& formatString, Args&&... args) const;

protected:
// Constructors
~ILogger() = default;
ILogger() = default;

// Severity methods
virtual bool IsLogSeverityEnabledInternal(Severity severity) const = 0;

// Logging methods
virtual void ProcessLogMessage(Severity severity, const wchar_t* message, size_t messageLength) const = 0;

// String conversion methods
inline static std::wstring Utf8StringToWString(const std::string& stringUtf8);
inline static std::string WStringToUtf8String(const std::wstring& wideString);

private:
// Argument resolver
template<class T, bool IsEnum = std::is_enum<T>::value, bool IsIntegral = std::is_integral<T>::value>
class ArgResolver
{};
template<class T>
class ArgResolver<T, false, false>
{
public:
inline static void ResolveArg(const T& arg, std::wstring& argResolved);
};
template<class T>
class ArgResolver<T, false, true>
{
public:
inline static void ResolveArg(T arg, std::wstring& argResolved);
};
template<class T>
class ArgResolver<T, true, false>
{
public:
inline static void ResolveArg(T arg, std::wstring& argResolved);
};

private:
// Logging methods
inline void LogInternal(Severity severity, const char* message) const;
inline void LogInternal(Severity severity, const wchar_t* message) const;
inline void LogInternal(Severity severity, const std::string& message) const;
inline void LogInternal(Severity severity, const std::wstring& message) const;
template<class... Args>
void LogInternal(Severity severity, const char* formatString, Args&&... args) const;
template<class... Args>
void LogInternal(Severity severity, const wchar_t* formatString, Args&&... args) const;
template<class... Args>
void LogInternal(Severity severity, const std::string& formatString, Args&&... args) const;
template<class... Args>
void LogInternal(Severity severity, const std::wstring& formatString, Args&&... args) const;

// Format string methods
inline std::wstring ResolveFormatString(const std::wstring& formatString, size_t argCount, const std::wstring* formatStringArgs) const;
template<class T>
void ResolveArgs(std::wstring* argAsString, T&& arg) const;
template<class T, class... Args>
void ResolveArgs(std::wstring* argAsString, T&& arg, Args&&... args) const;
};

#include "ILogger.inl"
Loading
Loading