Compare commits
19 Commits
35ad2e1db8
...
master
Author | SHA1 | Date | |
---|---|---|---|
ece9b7cf70 | |||
bb580c0938 | |||
547a127956 | |||
554ab7efdf | |||
7319a202c3 | |||
c1235edaa9 | |||
a4ea9864be | |||
347ef3d46d | |||
b21def5945 | |||
cfe4fe8a2e | |||
11c572a96c | |||
e3d5243f80 | |||
3f633ee15c | |||
458dcd82c6 | |||
a4b181a838 | |||
2261982479 | |||
d159417bbb | |||
66ddb8a1fb | |||
dd1010a826 |
@ -1,26 +1,67 @@
|
||||
if(NOT MYXLIB_PREFIX STREQUAL CMAKE_BINARY_DIR)
|
||||
set(MYXLIB_PREFIX
|
||||
""
|
||||
CACHE PATH "The path to the previx of an myxlib installation")
|
||||
#[=======================================================================[.rst:
|
||||
FindMyxlib
|
||||
--------
|
||||
|
||||
Поиск библиотеки Myxlib
|
||||
|
||||
Входные переменные
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``MYXLIB_PREFIX``
|
||||
корневой каталог установленной библиотеки.
|
||||
``MYXLIB_INCLUDE_DIR``
|
||||
каталог, в котором производится поиск заголовочных файлов.
|
||||
``MYXLIB_LIBRARY_DIR``
|
||||
каталог, в котором производится поиск библиотек.
|
||||
|
||||
Выходные переменные
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``MYXLIB_FOUND``
|
||||
true, если MYXLIB найдена
|
||||
``MYXLIB_INCLUDE_DIRS``
|
||||
каталог с найденными заголовочными файлами
|
||||
``MYXLIB_LIBRARIES``
|
||||
каталог с найденными библиотеками
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
if(NOT MYXLIB_IS_EXTERNAL_PROJECT)
|
||||
set(MYXLIB_PREFIX "" CACHE PATH "The path to the prefix of an myxlib installation")
|
||||
set(MYXLIB_INCLUDE_DIR "" CACHE PATH "The path to the headers of an myxlib installation")
|
||||
set(MYXLIB_LIBRARY_DIR "" CACHE PATH "The path to the library of an myxlib installation")
|
||||
|
||||
set(_search_paths "")
|
||||
if(MYXLIB_INCLUDE_DIR AND EXISTS ${MYXLIB_INCLUDE_DIR})
|
||||
list(APPEND _search_paths ${MYXLIB_INCLUDE_DIR})
|
||||
endif()
|
||||
if(MYXLIB_PREFIX AND EXISTS ${MYXLIB_PREFIX})
|
||||
list(APPEND _search_paths "${MYXLIB_PREFIX}/include")
|
||||
endif()
|
||||
find_path(
|
||||
MYXLIB_INCLUDE_DIRS
|
||||
NAMES myx/core/config.hpp
|
||||
PATHS ${MYXLIB_PREFIX}/include)
|
||||
find_library(
|
||||
MYXLIB_QT_LIBRARY
|
||||
NAMES myx-qt
|
||||
PATHS ${MYXLIB_PREFIX}/lib)
|
||||
find_library(
|
||||
MYXLIB_FILESYSTEM_LIBRARY
|
||||
NAMES myx-filesystem
|
||||
PATHS ${MYXLIB_PREFIX}/lib)
|
||||
PATHS ${_search_paths})
|
||||
|
||||
if(MYXLIB_INCLUDE_DIRS
|
||||
AND MYXLIB_QT_LIBRARY
|
||||
AND MYXLIB_FILESYSTEM_LIBRARY)
|
||||
get_filename_component(MYXLIB_LIBRARY_DIR ${MYXLIB_QT_LIBRARY} DIRECTORY
|
||||
CACHE)
|
||||
set(_search_paths "")
|
||||
if(MYXLIB_LIBRARY_DIR AND EXISTS ${MYXLIB_LIBRARY_DIR})
|
||||
list(APPEND _search_paths ${MYXLIB_LIBRARY_DIR})
|
||||
endif()
|
||||
if(MYXLIB_PREFIX AND EXISTS ${MYXLIB_PREFIX})
|
||||
list(APPEND _search_paths "${MYXLIB_PREFIX}/lib")
|
||||
endif()
|
||||
find_library(
|
||||
MYXLIB_QT_LIBRARIES
|
||||
NAMES myx-qt
|
||||
PATHS ${_search_paths})
|
||||
find_library(
|
||||
MYXLIB_FILESYSTEM_LIBRARIES
|
||||
NAMES myx-filesystem
|
||||
PATHS ${_search_paths})
|
||||
unset(_search_paths)
|
||||
set(MYXLIB_LIBRARIES ${MYXLIB_QT_LIBRARIES} ${MYXLIB_FILESYSTEM_LIBRARIES})
|
||||
|
||||
if(MYXLIB_INCLUDE_DIRS AND MYXLIB_LIBRARIES)
|
||||
set(MYXLIB_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
|
@ -4,18 +4,18 @@ include(ExternalProject)
|
||||
# cmake-format: off
|
||||
list(APPEND _ext_project_args
|
||||
myxlib
|
||||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/myxlib
|
||||
INSTALL_DIR ${CMAKE_BINARY_DIR}
|
||||
DOWNLOAD_COMMAND ""
|
||||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
|
||||
-DCMLIB_MAIN_DIR=${CMLIB_MAIN_DIR}
|
||||
${CMLIB_EXT_PROJ_DEFAULT_ARGS}
|
||||
<SOURCE_DIR>)
|
||||
|
||||
SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/myxlib
|
||||
INSTALL_DIR ${CMAKE_BINARY_DIR}
|
||||
CMAKE_ARGS ${CMLIB_EXT_PROJ_DEFAULT_ARGS}
|
||||
<SOURCE_DIR>)
|
||||
if(MyxlibThirdparty_FIND_COMPONENTS STREQUAL "headers")
|
||||
list(APPEND _ext_project_args
|
||||
BUILD_COMMAND true
|
||||
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} myxlib-install-headers)
|
||||
else()
|
||||
list(APPEND _ext_project_args
|
||||
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-qt.a
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-filesystem.a)
|
||||
endif()
|
||||
ExternalProject_Add(${_ext_project_args})
|
||||
unset(_ext_project_args)
|
||||
@ -26,15 +26,22 @@ set(MYXLIB_IS_EXTERNAL_PROJECT ON CACHE BOOL "" FORCE)
|
||||
set(MYXLIB_PREFIX
|
||||
${CMAKE_BINARY_DIR}
|
||||
CACHE FILEPATH "" FORCE)
|
||||
set(MYXLIB_INCLUDE_DIR
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}
|
||||
CACHE PATH "" FORCE)
|
||||
set(MYXLIB_INCLUDE_DIRS
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}
|
||||
CACHE PATH "" FORCE)
|
||||
set(MYXLIB_LIBRARY_DIR
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
|
||||
CACHE PATH "" FORCE)
|
||||
set(MYXLIB_QT_LIBRARY
|
||||
set(MYXLIB_QT_LIBRARIES
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-qt.a
|
||||
CACHE FILEPATH "" FORCE)
|
||||
set(MYXLIB_FILESYSTEM_LIBRARY
|
||||
set(MYXLIB_FILESYSTEM_LIBRARIES
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-filesystem.a
|
||||
CACHE FILEPATH "" FORCE)
|
||||
set(MYXLIB_LIBRARIES
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-qt.a
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-filesystem.a
|
||||
CACHE FILEPATH "" FORCE)
|
||||
|
Submodule cmake/cmlib updated: ffa6262670...5708fcd5e4
Submodule cmake/find updated: 022a282637...c2b09e5cb2
51
examples/core/02_current-system/CMakeLists.txt
Normal file
51
examples/core/02_current-system/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
||||
# Название основной цели в текущем каталоге
|
||||
set(TRGT example-core-current-system)
|
||||
|
||||
# Список файлов исходных текстов
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/current_system.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
add_dependencies(${TRGT} core)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME current-system-minimal)
|
||||
|
||||
add_sanitizers(${TRGT})
|
||||
|
||||
cotire(${TRGT})
|
||||
|
||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
# install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
23
examples/core/02_current-system/current_system.cpp
Normal file
23
examples/core/02_current-system/current_system.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/core/current_system.hpp>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
#define CMLIB_PROJECT_NAME "myxlib"
|
||||
|
||||
namespace MC = myx::core;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
MC::CurrentSystem& currentSystem = MC::CurrentSystem::instance();
|
||||
qDebug() << "Current OS: " << QString::fromStdString( currentSystem.os() );
|
||||
qDebug() << "OS distrib: " << QString::fromStdString( currentSystem.distribution() );
|
||||
qDebug() << "OS variant: " << QString::fromStdString( currentSystem.variant() );
|
||||
qDebug() << "OS version: " << QString::fromStdString( currentSystem.version() );
|
||||
|
||||
return( 0 );
|
||||
} // main
|
@ -1 +1,2 @@
|
||||
add_subdirectory(01_endian)
|
||||
add_subdirectory(02_current-system)
|
||||
|
53
examples/qt/03_message-logger/CMakeLists.txt
Normal file
53
examples/qt/03_message-logger/CMakeLists.txt
Normal file
@ -0,0 +1,53 @@
|
||||
# Название основной цели в текущем каталоге
|
||||
set(TRGT example-qt-message-logger)
|
||||
|
||||
# Список файлов исходных текстов
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/message_logger.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
add_dependencies(${TRGT} core qt)
|
||||
|
||||
target_link_libraries(${TRGT} qt_static)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-message-logger)
|
||||
|
||||
add_sanitizers(${TRGT})
|
||||
|
||||
cotire(${TRGT})
|
||||
|
||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
# install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
29
examples/qt/03_message-logger/message_logger.cpp
Normal file
29
examples/qt/03_message-logger/message_logger.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <myx/qt/message_logger_default.hpp>
|
||||
#include <myx/qt/message_logger_handler.hpp>
|
||||
#include <myx/qt/message_logger_syslog.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
namespace MQ = myx::qt;
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QCoreApplication app( argc, argv );
|
||||
|
||||
auto mld = QSharedPointer< MQ::MessageLoggerDefault >( new MQ::MessageLoggerDefault );
|
||||
MQ::messageLoggersList.append( mld );
|
||||
MQ::messageLoggersList.append( mld );
|
||||
auto mls = QSharedPointer< MQ::MessageLoggerSyslog >( new MQ::MessageLoggerSyslog );
|
||||
MQ::messageLoggersList.append( mls );
|
||||
qInstallMessageHandler( MQ::message_logger_handler );
|
||||
|
||||
qDebug() << "Hello from process:" << QCoreApplication::applicationPid();
|
||||
qWarning() << "Warning";
|
||||
|
||||
qInstallMessageHandler( 0 );
|
||||
|
||||
qDebug() << "Reset user handlers";
|
||||
qWarning() << "Goodbye";
|
||||
|
||||
return( 0 );
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
add_subdirectory(01_translators)
|
||||
add_subdirectory(02_posix-signal-watcher)
|
||||
add_subdirectory(03_message-logger)
|
||||
|
@ -9,6 +9,7 @@ set(TRGT_cpp)
|
||||
set(TRGT_hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/config.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/current_system.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/endian_types.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/enum_bitmask_operations.hpp)
|
||||
|
||||
|
109
src/myx/core/current_system.hpp
Normal file
109
src/myx/core/current_system.hpp
Normal file
@ -0,0 +1,109 @@
|
||||
#ifndef MYX_CORE_CURRENT_SYSTEM_HPP_
|
||||
#define MYX_CORE_CURRENT_SYSTEM_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace core {
|
||||
|
||||
class CurrentSystem
|
||||
{
|
||||
public:
|
||||
CurrentSystem( const CurrentSystem& ) = delete;
|
||||
CurrentSystem& operator=( const CurrentSystem& ) = delete;
|
||||
CurrentSystem( CurrentSystem&& ) = delete;
|
||||
CurrentSystem& operator=( CurrentSystem&& ) = delete;
|
||||
|
||||
/**
|
||||
* @brief instance
|
||||
* @return Уникальный экземпляр класса CurrentSystem
|
||||
*/
|
||||
static CurrentSystem& instance()
|
||||
{
|
||||
static CurrentSystem sCurrentSystem;
|
||||
return( sCurrentSystem );
|
||||
}
|
||||
|
||||
std::string os() const { return( m_os ); }
|
||||
std::string distribution() const { return( m_distribution ); }
|
||||
std::string variant() const { return( m_variant ); }
|
||||
std::string version() const { return( m_version ); }
|
||||
|
||||
protected:
|
||||
CurrentSystem() :
|
||||
m_os
|
||||
(
|
||||
#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __NT__ )
|
||||
"windows"
|
||||
#elif __linux__
|
||||
"linux"
|
||||
#else
|
||||
#error "Unknown OS"
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if defined( __e2k__ )
|
||||
m_distribution = "debian";
|
||||
m_variant = "elbrus";
|
||||
std::ifstream file( "/etc/mcst_version" );
|
||||
if ( file.is_open() )
|
||||
{
|
||||
std::getline( file, m_version );
|
||||
file.close();
|
||||
}
|
||||
#else
|
||||
std::ifstream file( "/etc/os-release" );
|
||||
if ( file.is_open() )
|
||||
{
|
||||
std::string line;
|
||||
while ( std::getline( file, line ) )
|
||||
{
|
||||
std::size_t pos = line.find( "ID=" );
|
||||
if ( pos == 0 )
|
||||
{
|
||||
m_distribution = line.replace( pos, sizeof( "ID=" ) - 1, "" );
|
||||
}
|
||||
|
||||
pos = line.find( "VARIANT_ID=" );
|
||||
if ( pos != std::string::npos )
|
||||
{
|
||||
m_variant = line.replace( pos, sizeof( "VARIANT_ID=" ) - 1, "" );
|
||||
}
|
||||
|
||||
pos = line.find( "VERSION_ID=" );
|
||||
if ( pos != std::string::npos )
|
||||
{
|
||||
m_version = line.replace( pos, sizeof( "VERSION_ID=" ) - 1, "" );
|
||||
while ( ( pos = m_version.find( '"' ) ) != std::string::npos )
|
||||
{
|
||||
m_version.erase( pos, sizeof( '"' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
#endif // if defined( __e2k__ )
|
||||
}
|
||||
|
||||
~CurrentSystem() = default;
|
||||
|
||||
private:
|
||||
std::string m_os;
|
||||
std::string m_distribution;
|
||||
std::string m_variant;
|
||||
std::string m_version;
|
||||
}; // class CurrentSystem
|
||||
|
||||
// class CurrentSystem
|
||||
|
||||
} // namespace core
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_CORE_CURRENT_SYSTEM_HPP_
|
@ -6,6 +6,9 @@ set(TRGT qt)
|
||||
set(TRGT_cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_default.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_handler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_syslog.cpp
|
||||
)
|
||||
|
||||
set(TRGT_moc_hpp
|
||||
@ -18,6 +21,10 @@ set(TRGT_moc_private_hpp
|
||||
|
||||
set(TRGT_hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_default.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_handler.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_syslog.hpp
|
||||
)
|
||||
|
||||
set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp})
|
||||
|
44
src/myx/qt/message_logger.hpp
Normal file
44
src/myx/qt/message_logger.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <QList>
|
||||
#include <QMessageLogContext>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
class MessageLogger
|
||||
{
|
||||
public:
|
||||
virtual ~MessageLogger() noexcept ( true ) = default;
|
||||
|
||||
virtual void debug( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void info( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void warning( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void critical( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void fatal( const QMessageLogContext& context, const QString& ) = 0;
|
||||
|
||||
void setEnabled( bool v = true ) { m_enabled = v; }
|
||||
bool isEnabled() { return( m_enabled ); }
|
||||
|
||||
protected:
|
||||
bool m_enabled { true };
|
||||
};
|
||||
|
||||
using MessageLoggersList = QList< QSharedPointer< MessageLogger > >;
|
||||
extern MessageLoggersList messageLoggersList;
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_HPP_
|
46
src/myx/qt/message_logger_default.cpp
Normal file
46
src/myx/qt/message_logger_default.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <myx/qt/message_logger_default.hpp>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
void MessageLoggerDefault::debug( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
fprintf( stderr, "D: %s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::info( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
fprintf( stderr, "I: %s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::warning( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
fprintf( stderr, "W: %s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::critical( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::fatal( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
}
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
31
src/myx/qt/message_logger_default.hpp
Normal file
31
src/myx/qt/message_logger_default.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
class MessageLoggerDefault : public MessageLogger
|
||||
{
|
||||
public:
|
||||
virtual ~MessageLoggerDefault() noexcept ( true ) = default;
|
||||
|
||||
void debug( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void info( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void warning( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void critical( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void fatal( const QMessageLogContext& context, const QString& msg ) override;
|
||||
};
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
81
src/myx/qt/message_logger_handler.cpp
Normal file
81
src/myx/qt/message_logger_handler.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
MessageLoggersList messageLoggersList;
|
||||
|
||||
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
if ( messageLoggersList.isEmpty() )
|
||||
{
|
||||
QByteArray localMsg = msg.toLocal8Bit();
|
||||
const char* file = context.file ? context.file : "";
|
||||
const char* function = context.function ? context.function : "";
|
||||
switch ( type )
|
||||
{
|
||||
case QtDebugMsg:
|
||||
#ifndef QT_NO_DEBUG_OUTPUT
|
||||
// fprintf( stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
#endif
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
#ifndef QT_NO_INFO_OUTPUT
|
||||
// fprintf( stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
#endif
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
#ifndef QT_NO_WARNING_OUTPUT
|
||||
// fprintf( stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
#endif
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
// fprintf( stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
// fprintf( stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case QtDebugMsg:
|
||||
for ( auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->debug( context, msg ); } }
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
for ( auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->info( context, msg ); } }
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
for ( auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->warning( context, msg ); } }
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
for ( auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->critical( context, msg ); } }
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
for ( auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->fatal( context, msg ); } }
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
} // message_logger_handler
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
20
src/myx/qt/message_logger_handler.hpp
Normal file
20
src/myx/qt/message_logger_handler.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg );
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
61
src/myx/qt/message_logger_syslog.cpp
Normal file
61
src/myx/qt/message_logger_syslog.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <myx/qt/message_logger_syslog.hpp>
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
MessageLoggerSyslog::MessageLoggerSyslog() :
|
||||
MessageLogger()
|
||||
{
|
||||
// openlog( nullptr, LOG_ODELAY, LOG_USER );
|
||||
}
|
||||
|
||||
|
||||
MessageLoggerSyslog::~MessageLoggerSyslog() noexcept ( true )
|
||||
{
|
||||
closelog();
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::debug( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_DEBUG, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::info( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_INFO, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::warning( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_WARNING, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::critical( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_CRIT, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::fatal( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_EMERG, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
32
src/myx/qt/message_logger_syslog.hpp
Normal file
32
src/myx/qt/message_logger_syslog.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
class MessageLoggerSyslog : public MessageLogger
|
||||
{
|
||||
public:
|
||||
MessageLoggerSyslog();
|
||||
virtual ~MessageLoggerSyslog() noexcept ( true );
|
||||
|
||||
void debug( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void info( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void warning( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void critical( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void fatal( const QMessageLogContext& context, const QString& msg ) override;
|
||||
};
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
Reference in New Issue
Block a user