Compare commits

...

41 Commits

Author SHA1 Message Date
ece9b7cf70 Обновление подмодулей 2021-10-07 09:19:51 +03:00
bb580c0938 Правка сигнатуры для компиляции в Smolensk 1.5 2021-09-20 11:41:14 +03:00
547a127956 Исправлен деструктор 2021-09-20 11:35:36 +03:00
554ab7efdf Ещё вариант 2021-09-20 11:34:33 +03:00
7319a202c3 Новый вариант 2021-09-20 11:32:28 +03:00
c1235edaa9 Правка для Smolensk 1.5 2021-09-20 11:24:37 +03:00
a4ea9864be Правка для Smolensk 1.5 2021-09-20 11:22:05 +03:00
347ef3d46d Классы и пример для журналирования (простой вывод и в syslog) 2021-09-17 14:35:10 +03:00
b21def5945 Обновление подмодулей 2021-08-02 18:00:55 +03:00
cfe4fe8a2e Обновление подмодулей 2021-08-02 14:34:42 +03:00
11c572a96c Merge branch 'master' of gitlab.2:f1x1t/myxlib 2021-07-27 13:30:27 +03:00
e3d5243f80 Обновление CMLib 2021-07-27 13:30:01 +03:00
3f633ee15c Обновление подмодулей 2021-07-06 05:35:28 +03:00
458dcd82c6 Обновление подмодулей 2021-07-06 05:00:46 +03:00
a4b181a838 Поддержка версии Elbrus-D 2021-07-05 13:43:04 +03:00
2261982479 Определение параметров текущей ОС во время выполнения 2021-07-05 13:11:00 +03:00
d159417bbb Обновление подмодулей 2021-07-05 10:58:56 +03:00
66ddb8a1fb Merge branch 'master' of gitlab.2:f1x1t/myxlib 2021-07-02 10:50:25 +03:00
dd1010a826 Обновление подмодулей 2021-07-02 10:50:18 +03:00
35ad2e1db8 Обновление подмодулей 2021-06-30 16:54:16 +03:00
7d0c2f68d6 Обновление подмодулей 2021-06-30 10:48:29 +03:00
7396f77054 Модули для поиска с помощью CMake 2021-06-24 11:38:58 +03:00
3d3690ca64 Цель для установки заголовочных файлов 2021-06-24 11:36:53 +03:00
105ed96f5f Обновление подмодулей 2021-06-24 10:39:43 +03:00
5645c5ea31 Примеры скриптов для поиска через find_package 2021-06-22 17:35:13 +03:00
e63e6a4c8a Обновление подмодулей 2021-06-21 13:02:54 +03:00
a017ca6814 Поддержка использования внешней CMLib 2021-06-18 01:16:37 +03:00
8114675c1c Удалён подмодуль cmake/doc 2021-06-18 00:59:05 +03:00
d839fa6ed4 Обновление CMLib 2021-06-17 15:51:28 +03:00
a368091252 Инициализация по умолчанию в конструкторе 2021-06-16 11:43:13 +03:00
9468f95dd3 Обновление CMLib 2021-06-15 10:46:37 +03:00
56a0b595d2 Merge branch 'master' of gitlab.2:f1x1t/myxlib 2021-06-12 14:52:34 +03:00
716545e49c Обновление подмодулей 2021-06-12 14:52:25 +03:00
b575634554 Обновление подмодулей 2021-06-11 09:52:58 +03:00
299dabf295 Путь к общему каталогу для темы (работы) 2021-06-11 08:52:57 +03:00
a29cea6f61 Упрощение и правка автоопределения в /opt 2021-06-11 08:21:00 +03:00
360b2b41d1 Переименования 2021-06-10 07:21:54 +03:00
297b04bd56 Обновление логики поиска и формирования стандартных каталогов 2021-06-09 17:34:52 +03:00
3b2332a82f Merge branch 'master' of git.246060.ru:f1x1t/myxlib into temp 2021-06-09 13:32:06 +03:00
2d1537a9b8 Обновление CMLib 2021-06-08 19:47:03 +03:00
77683831b9 Исправлена ошибка при установке myx/core 2021-06-08 19:43:11 +03:00
27 changed files with 1146 additions and 188 deletions

248
.cmake-format.py Normal file
View File

@ -0,0 +1,248 @@
#!/usr/bin/env python3
# ----------------------------------
# Options affecting listfile parsing
# ----------------------------------
with section("parse"):
# Specify structure for custom cmake functions
additional_commands = {
'add_doxygen': { 'flags' : [],
'kwargs': { 'LATEX': 1,
'HTML': 1,
'COMMENT': 1}},
'add_breathe': { 'flags' : [],
'kwargs': { 'COMMENT': 1}},
'add_common_library': { 'flags' : [],
'kwargs': { 'OUTPUT_NAME': 1,
'SOURCES': '*',
'TARGET': 1}},
'qt5_translation': { 'flags' : [],
'kwargs': { 'OUTPUT_DIR': 1,
'LANGUAGES': '*',
'SOURCES': '*',
'BASE_NAME': 1}},
'pvs_studio_add_target': { 'flags' : [ 'COMPILE_COMMANDS',
'OUTPUT',
'HIDE_HELP'],
'kwargs': { 'ARGS': '*',
'CONFIG': '*',
'DEPENDS': '*',
'FORMAT': '*',
'MODE': '*',
'TARGET': 1}},
'write_compiler_detection_header': { 'flags' : [],
'kwargs': { 'COMPILERS': '*',
'FEATURES': '*',
'FILE': '*',
'PREFIX': '*'}}}
# Specify variable tags.
vartags = []
# Specify property tags.
proptags = []
# -----------------------------
# Options affecting formatting.
# -----------------------------
with section("format"):
# How wide to allow formatted cmake files
line_width = 110
# How many spaces to tab for indent
tab_size = 2
# If an argument group contains more than this many sub-groups (parg or kwarg
# groups) then force it to a vertical layout.
max_subgroups_hwrap = 3
# If a positional argument group contains more than this many arguments, then
# force it to a vertical layout.
max_pargs_hwrap = 5
# If a cmdline positional group consumes more than this many lines without
# nesting, then invalidate the layout (and nest)
max_rows_cmdline = 2
# If true, separate flow control names from their parentheses with a space
separate_ctrl_name_with_space = False
# If true, separate function names from parentheses with a space
separate_fn_name_with_space = False
# If a statement is wrapped to more than one line, than dangle the closing
# parenthesis on its own line.
dangle_parens = False
# If the trailing parenthesis must be 'dangled' on its on line, then align it
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
# the start of the statement, plus one indentation level, `child`: align to
# the column of the arguments
dangle_align = 'prefix'
# If the statement spelling length (including space and parenthesis) is
# smaller than this amount, then force reject nested layouts.
min_prefix_chars = 4
# If the statement spelling length (including space and parenthesis) is larger
# than the tab width by more than this amount, then force reject un-nested
# layouts.
max_prefix_chars = 2
# If a candidate layout is wrapped horizontally but it exceeds this many
# lines, then reject the layout.
max_lines_hwrap = 2
# What style line endings to use in the output.
line_ending = 'unix'
# Format command names consistently as 'lower' or 'upper' case
command_case = 'canonical'
# Format keywords consistently as 'lower' or 'upper' case
keyword_case = 'upper'
# A list of command names which should always be wrapped
always_wrap = []
# If true, the argument lists which are known to be sortable will be sorted
# lexicographicall
enable_sort = True
# If true, the parsers may infer whether or not an argument list is sortable
# (without annotation).
autosort = False
# By default, if cmake-format cannot successfully fit everything into the
# desired linewidth it will apply the last, most agressive attempt that it
# made. If this flag is True, however, cmake-format will print error, exit
# with non-zero status code, and write-out nothing
require_valid_layout = False
# A dictionary mapping layout nodes to a list of wrap decisions. See the
# documentation for more information.
layout_passes = {}
# ------------------------------------------------
# Options affecting comment reflow and formatting.
# ------------------------------------------------
with section("markup"):
# What character to use for bulleted lists
bullet_char = '*'
# What character to use as punctuation after numerals in an enumerated list
enum_char = '.'
# If comment markup is enabled, don't reflow the first comment block in each
# listfile. Use this to preserve formatting of your copyright/license
# statements.
first_comment_is_literal = False
# If comment markup is enabled, don't reflow any comment block which matches
# this (regex) pattern. Default is `None` (disabled).
literal_comment_pattern = None
# Regular expression to match preformat fences in comments default=
# ``r'^\s*([`~]{3}[`~]*)(.*)$'``
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
# Regular expression to match rulers in comments default=
# ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
# If a comment line matches starts with this pattern then it is explicitly a
# trailing comment for the preceeding argument. Default is '#<'
explicit_trailing_pattern = '#<'
# If a comment line starts with at least this many consecutive hash
# characters, then don't lstrip() them off. This allows for lazy hash rulers
# where the first hash char is not separated by space
hashruler_min_length = 10
# If true, then insert a space between the first hash char and remaining hash
# chars in a hash ruler, and normalize its length to fill the column
canonicalize_hashrulers = True
# enable comment markup parsing and reflow
enable_markup = False
# ----------------------------
# Options affecting the linter
# ----------------------------
with section("lint"):
# a list of lint codes to disable
disabled_codes = ['C0113']
# regular expression pattern describing valid function names
function_pattern = '[0-9a-z_]+'
# regular expression pattern describing valid macro names
macro_pattern = '[0-9A-Z_]+'
# regular expression pattern describing valid names for variables with global
# scope
global_var_pattern = '[0-9A-Z][0-9A-Z_]+'
# regular expression pattern describing valid names for variables with global
# scope (but internal semantic)
internal_var_pattern = '_[0-9A-Z][0-9A-Z_]+'
# regular expression pattern describing valid names for variables with local
# scope
local_var_pattern = '[0-9a-z_]+'
# regular expression pattern describing valid names for privatedirectory
# variables
private_var_pattern = '_[0-9a-z_]+'
# regular expression pattern describing valid names for publicdirectory
# variables
public_var_pattern = '[0-9A-Z][0-9A-Z_]+'
# regular expression pattern describing valid names for keywords used in
# functions or macros
keyword_pattern = '[0-9A-Z_]+'
# In the heuristic for C0201, how many conditionals to match within a loop in
# before considering the loop a parser.
max_conditionals_custom_parser = 2
# Require at least this many newlines between statements
min_statement_spacing = 1
# Require no more than this many newlines between statements
max_statement_spacing = 2
max_returns = 6
max_branches = 12
max_arguments = 5
max_localvars = 15
max_statements = 50
# -------------------------------
# Options affecting file encoding
# -------------------------------
with section("encode"):
# If true, emit the unicode byte-order mark (BOM) at the start of the file
emit_byteorder_mark = False
# Specify the encoding of the input file. Defaults to utf-8
input_encoding = 'utf-8'
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
# only claims to support utf-8 so be careful when using anything else
output_encoding = 'utf-8'
# -------------------------------------
# Miscellaneous configurations options.
# -------------------------------------
with section("misc"):
# A dictionary containing any per-command configuration overrides. Currently
# only `command_case` is supported.
per_command = {}

3
.gitmodules vendored
View File

@ -10,6 +10,3 @@
[submodule "cmake/generators"]
path = cmake/generators
url = ../../f1x1t/cmake-generators
[submodule "cmake/doc"]
path = cmake/doc
url = ../../f1x1t/cmake-doc

View File

@ -5,13 +5,21 @@ cmake_policy(VERSION 3.0.2..3.7)
# Название проекта
project(myx VERSION 0.4.0 LANGUAGES C CXX)
# В каталоге cmake/lib находятся файлы с библиотечными функциями
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/cmlib)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/cmlib)
else()
message(FATAL_ERROR "CMake library directory not exists")
# Обязательные переменные
set(CMLIB_ORGANIZATION_NAME "ECS5" CACHE STRING "")
set(CMLIB_AUTHOR_NAME "Андрей Астафьев" CACHE STRING "")
set(CMLIB_AUTHOR_EMAIL "dev@246060.ru" CACHE STRING "")
set(CMLIB_DESCRIPTION "Разные функции" CACHE STRING "")
# В каталоге cmake/cmlib находятся файлы с библиотечными функциями
if(NOT DEFINED CMLIB_MAIN_DIR)
set(CMLIB_MAIN_DIR "${CMAKE_SOURCE_DIR}/cmake/cmlib")
endif()
if(IS_DIRECTORY "${CMLIB_MAIN_DIR}" AND EXISTS "${CMLIB_MAIN_DIR}/CMLibCommon.cmake")
list(INSERT CMAKE_MODULE_PATH 0 "${CMLIB_MAIN_DIR}")
else()
message(FATAL_ERROR "CMLib main directory ${CMLIB_MAIN_DIR} does not exists")
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/find)
if(NOT DEFINED MYXLIB_MASTER_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
@ -46,6 +54,9 @@ add_subdirectory(src/myx/core)
add_subdirectory(src/myx/filesystem)
add_subdirectory(src/myx/qt)
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
add_custom_target(myxlib-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
# Примеры
if(MYXLIB_BUILD_EXAMPLES)
add_subdirectory(examples/core)
@ -56,4 +67,5 @@ if(MYXLIB_BUILD_EXAMPLES)
endif()
# Документация
add_subdirectory(cmake/doc)
add_breathe_target(doc-breathe)
add_doxygen_target(doc-doxygen LATEX YES HTML YES)

78
cmake/FindMyxlib.cmake Normal file
View File

@ -0,0 +1,78 @@
#[=======================================================================[.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 ${_search_paths})
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()
if(MYXLIB_FOUND)
if(NOT MYXLIB_FIND_QUIETLY)
message(STATUS "Found myxlib")
endif()
set(HAVE_MYXLIB 1)
elseif(MYXLIB_FOUND)
if(MYXLIB_FIND_REQUIRED)
message(FATAL_ERROR "Could not find myxlib")
endif()
endif()
endif()

View File

@ -0,0 +1,47 @@
# Подключение внешних проектов
include(ExternalProject)
# cmake-format: off
list(APPEND _ext_project_args
myxlib
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)
set(MYXLIB_IS_EXTERNAL_PROJECT ON CACHE BOOL "" FORCE)
# cmake-format: on
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_LIBRARIES
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/libmyx-qt.a
CACHE FILEPATH "" FORCE)
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/doc deleted from dc9622f57e

View 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()

View 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

View File

@ -1 +1,2 @@
add_subdirectory(01_endian)
add_subdirectory(02_current-system)

View File

@ -18,22 +18,19 @@ int main( int argc, char** argv )
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
MF::Paths& paths = MF::Paths::instance();
paths.init();
qDebug() << "prefixDirectory : " << paths.projectDirectory();
qDebug() << "executableName : " << paths.executableName();
qDebug() << "executableFilePath : " << paths.executableFilePath();
qDebug() << "executableDirectory : " << paths.executableDirectory();
qDebug() << "configFileName : " << paths.configFileName();
qDebug() << "configFilePath : " << paths.configFilePath();
qDebug() << "executableDirectory : " << paths.executableDirectory() << endl;
qDebug() << "systemThemeDirectory : " << paths.systemThemeDirectory();
qDebug() << "systemConfigDirectory : " << paths.systemConfigDirectory();
qDebug() << "systemConstDataDirectory : " << paths.systemConstDataDirectory();
qDebug() << "systemVarDataDirectory : " << paths.systemVarDataDirectory();
qDebug() << "systemLogDirectory : " << paths.systemLogDirectory();
qDebug() << "systemLogDirectory : " << paths.systemLogDirectory() << endl;
qDebug() << "userThemeDirectory : " << paths.userThemeDirectory();
qDebug() << "userConfigDirectory : " << paths.userConfigDirectory();
qDebug() << "userConstDataDirectory : " << paths.userConstDataDirectory();
qDebug() << "userVarDataDirectory : " << paths.userVarDataDirectory();

View 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()

View 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 );
}

View File

@ -1,2 +1,3 @@
add_subdirectory(01_translators)
add_subdirectory(02_posix-signal-watcher)
add_subdirectory(03_message-logger)

View File

@ -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)
@ -36,6 +37,8 @@ add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers})
target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src)
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
install(FILES ${TRGT_headers} COMPONENT base-dev
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P

View 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_

View File

@ -9,54 +9,28 @@
#include <QCoreApplication>
#include <QString>
#ifndef QT_NO_DEBUG
#include <QDebug>
#endif
namespace myx {
namespace filesystem {
MYXLIB_INLINE Paths::Paths() :
m_configFileExtension( ".conf" ),
m_binDirRegex ( "/s*bin$" ),
m_unityBinDirRegex ( "/bin/unity$" )
m_binDirRegex ( QStringLiteral( "/s*bin$" ) ),
m_unityBinDirRegex( QStringLiteral( "/bin/unity$" ) )
{
QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) );
QFileInfo currentExecutable = procSelfExe.canonicalFilePath();
m_executableName = currentExecutable.fileName();
m_executableFilePath = currentExecutable.absoluteFilePath();
m_executableDirectory = currentExecutable.absolutePath();
// Инициализация значениями по умолчанию
init();
}
MYXLIB_INLINE bool Paths::init()
{
m_configFileName = m_executableName + m_configFileExtension;
return( initCommon() );
}
//MYXLIB_INLINE bool Paths::init( const QString& configFileName )
//{
// m_configFileName = configFileName;
// return( initCommon() );
//}
//MYXLIB_INLINE bool Paths::init( const QString& projectName, const QString& configFileExtension )
//{
// m_projectName = projectName.isEmpty() ? m_executableName
// : projectName;
// auto ext = configFileExtension.isEmpty() ? QStringLiteral( "conf" )
// : configFileExtension;
// m_configFileName = m_projectName + "." + ext;
// return( initCommon() );
//}
MYXLIB_INLINE bool Paths::initCommon()
MYXLIB_INLINE bool Paths::init( bool autodetect )
{
m_autodetect = autodetect;
m_homeDirectory = QDir::homePath();
m_tempDirectory = QDir::tempPath();
@ -72,79 +46,97 @@ MYXLIB_INLINE bool Paths::initCommon()
m_dataDirectory = m_homeDirectory + "/.local/share";
}
if ( m_projectName.isEmpty() )
{
m_projectName = m_executableName;
}
m_hierarchyType = getHierarchyType();
calculatePaths( m_hierarchyType );
m_configFilePath = m_systemConfigDirectory + "/" + m_configFileName;
return( true );
} // Paths::initCommon
} // Paths::init
MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultProjectDirectory,
const QString& defaultEtcDirectory,
const QString& defaultConstDataDirectory,
const QString& defaultVarDataDirectory,
const QString& defaultLogDirectory )
MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& projectDir,
const QString& etcDir,
const QString& constDataDir,
const QString& varDataDir,
const QString& logDir )
{
QFileInfo prefixDirInfo { defaultProjectDirectory };
QFileInfo prefixDirInfo { projectDir };
if ( prefixDirInfo.isDir() && prefixDirInfo.isReadable() )
{
m_projectDirectory = defaultProjectDirectory;
m_projectDirectory = projectDir;
}
else
{
m_projectDirectory = QStringLiteral( "." );
}
QFileInfo etcDirInfo { defaultEtcDirectory };
QFileInfo etcDirInfo { etcDir };
if ( etcDirInfo.isDir() && etcDirInfo.isReadable() )
{
m_systemConfigDirectory = defaultEtcDirectory;
m_systemConfigDirectory = etcDir;
}
else
{
m_systemConfigDirectory = m_userConfigDirectory;
}
QFileInfo constDataDirInfo { defaultConstDataDirectory };
QFileInfo constDataDirInfo { constDataDir };
if ( constDataDirInfo.isDir() && constDataDirInfo.isReadable() )
{
m_systemConstDataDirectory = defaultConstDataDirectory;
m_systemConstDataDirectory = constDataDir;
}
else
{
m_systemConstDataDirectory = m_userConstDataDirectory;
}
QFileInfo varDataDirInfo { defaultVarDataDirectory };
QFileInfo varDataDirInfo { varDataDir };
if ( varDataDirInfo.isDir() && varDataDirInfo.isWritable() )
{
m_systemVarDataDirectory = defaultVarDataDirectory;
m_systemVarDataDirectory = varDataDir;
}
else
{
m_systemVarDataDirectory = m_userVarDataDirectory;
}
QFileInfo logDirInfo { defaultLogDirectory };
QFileInfo logDirInfo { logDir };
if ( logDirInfo.isDir() && logDirInfo.isWritable() )
{
m_systemLogDirectory = defaultLogDirectory;
m_systemLogDirectory = logDir;
}
else
{
m_systemLogDirectory = m_userLogDirectory;
}
if ( !m_organizationName.isEmpty() && !m_themeName.isEmpty() )
{
m_systemThemeDirectory = "/opt/" + m_organizationName + "-" + m_themeName;
}
} // Paths::setupSystemDirectories
MYXLIB_INLINE void Paths::setupUserDirectories( const QString& prefix )
MYXLIB_INLINE void Paths::setupUserDirectories()
{
m_userConfigDirectory = m_configDirectory + "/" + prefix;
m_userConstDataDirectory = m_dataDirectory + "/" + prefix + "/share";
m_userVarDataDirectory = m_dataDirectory + "/" + prefix + "/var";
m_userLogDirectory = m_dataDirectory + "/" + prefix + "/log";
QString prefix;
if ( !m_organizationName.isEmpty() )
{
prefix = "/" + m_organizationName;
if ( !m_themeName.isEmpty() )
{
prefix.append( "-" + m_themeName );
m_userThemeDirectory = m_dataDirectory + prefix;
}
}
prefix.append( "/" + m_projectName );
m_userConfigDirectory = m_configDirectory + prefix;
m_userConstDataDirectory = m_dataDirectory + prefix + "/share";
m_userVarDataDirectory = m_dataDirectory + prefix + "/var";
m_userLogDirectory = m_dataDirectory + prefix + "/log";
}
@ -193,51 +185,17 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType()
MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
{
auto directory = m_executableDirectory;
setupUserDirectories();
switch ( hType )
{
case HierarchyType::kFlat:
setupSystemDirectories( directory, directory, directory, directory, directory );
return;
break;
case HierarchyType::kOpt:
if ( m_organizationName.isEmpty() || m_themeName.isEmpty() )
{
QRegularExpression regex( "^/opt/(.+?)-(.+?)/" );
QRegularExpressionMatch match = regex.match( m_executableDirectory );
if ( match.hasMatch() )
{
m_organizationName = match.captured( 1 );
m_themeName = match.captured( 2 );
QRegularExpression vr( "(.+?)\\.(.+)" );
QRegularExpressionMatch vm = vr.match( m_themeName );
if ( vm.hasMatch() )
{
m_themeName = vm.captured( 1 );
m_version = vm.captured( 2 );
}
}
}
if ( m_projectName.isEmpty() )
{
QRegularExpression regex( "^/opt/.+/(.+?)/" );
QRegularExpressionMatch match = regex.match( m_executableDirectory );
if ( match.hasMatch() )
{
m_projectName = match.captured( 1 );
}
}
directory.remove( m_binDirRegex );
setupSystemDirectories( directory,
directory + "/etc",
directory + "/share",
directory + "/var",
directory + "/log" );
setupUserDirectories( m_organizationName + "-" + m_themeName + "/" + m_projectName );
return;
processOptHierarhy();
break;
case HierarchyType::kUsr:
setupSystemDirectories( QStringLiteral( "/usr" ),
@ -245,7 +203,7 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
"/usr/share/" + m_projectName,
"/var/lib/" + m_projectName,
"/var/log/" + m_projectName );
return;
break;
case HierarchyType::kUsrLocal:
setupSystemDirectories( QStringLiteral( "/usr/local" ),
@ -253,7 +211,7 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
"/usr/local/share/" + m_projectName,
"/var/lib/" + m_projectName,
"/var/log/" + m_projectName );
return;
break;
case HierarchyType::kUsrLocalOrg:
directory.remove( m_binDirRegex );
@ -262,15 +220,15 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
directory + "/share",
directory + "/var",
directory + "/log" );
return;
break;
case HierarchyType::kHome:
m_projectDirectory = m_homeDirectory;
m_systemConfigDirectory = m_userConfigDirectory;
m_systemConstDataDirectory = m_userConstDataDirectory;
m_systemVarDataDirectory = m_userVarDataDirectory;
m_systemLogDirectory = m_userLogDirectory;
return;
setupSystemDirectories( m_homeDirectory,
m_userConfigDirectory,
m_userConstDataDirectory,
m_userVarDataDirectory,
m_userLogDirectory );
break;
case HierarchyType::kDevelopment:
directory.remove( m_unityBinDirRegex );
@ -280,23 +238,66 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
directory + "/share",
directory + "/var",
directory + "/log" );
return;
break;
case HierarchyType::kUndefined:
;
} // switch
setupUserDirectories();
} // Paths::calculatePaths
MYXLIB_INLINE void Paths::processOptHierarhy()
{
auto directory = m_executableDirectory;
if ( m_autodetect )
{
QRegularExpression regex( QStringLiteral( "^/opt/(.+?)/(.+?)/" ) );
QRegularExpressionMatch match = regex.match( m_executableDirectory );
if ( match.hasMatch() )
{
m_organizationName = match.captured( 1 );
m_projectName = match.captured( 2 );
QRegularExpression themeRegex( QStringLiteral( "(.+?)-(.+)" ) );
QRegularExpressionMatch themeMatch = themeRegex.match( m_organizationName );
if ( themeMatch.hasMatch() )
{
m_themeName = themeMatch.captured( 2 );
m_organizationName = themeMatch.captured( 1 );
}
QRegularExpression versionRegex( QStringLiteral( "(.+?)\\.(.+)" ) );
QRegularExpressionMatch versionMatch = versionRegex.match( m_projectName );
if ( versionMatch.hasMatch() )
{
m_projectName = versionMatch.captured( 1 );
m_version = versionMatch.captured( 2 );
}
}
}
directory.remove( m_binDirRegex );
setupSystemDirectories( directory,
directory + "/etc",
directory + "/share",
directory + "/var",
directory + "/log" );
setupUserDirectories();
} // Paths::processOptHierarhy
MYXLIB_INLINE bool Paths::makeDefaultSystemDirectories()
{
bool status = true;
QDir dir;
if ( !dir.mkpath( m_systemConfigDirectory ) ) { status = false; }
if ( !dir.mkpath( m_systemVarDataDirectory ) ) { status = false; }
if ( !dir.mkpath( m_systemConstDataDirectory ) ) { status = false; }
if ( !dir.mkpath( m_systemLogDirectory ) ) { status = false; }
if ( !dir.mkpath( m_systemConfigDirectory ) ) { status = false; }
if ( !dir.mkpath( m_systemVarDataDirectory ) ) { status = false; }
return( status );
}
@ -307,10 +308,10 @@ MYXLIB_INLINE bool Paths::makeDefaultUserDirectories()
bool status = true;
QDir dir;
if ( !dir.mkpath( m_userConfigDirectory ) ) { status = false; }
if ( !dir.mkpath( m_userVarDataDirectory ) ) { status = false; }
if ( !dir.mkpath( m_userConstDataDirectory ) ) { status = false; }
if ( !dir.mkpath( m_userLogDirectory ) ) { status = false; }
if ( !dir.mkpath( m_userConfigDirectory ) ) { status = false; }
if ( !dir.mkpath( m_userVarDataDirectory ) ) { status = false; }
return( status );
}
@ -322,25 +323,24 @@ MYXLIB_INLINE bool Paths::makeDefaultDirectories()
}
MYXLIB_INLINE QString Paths::findConfigFile( const QString& defaultConfigFile )
MYXLIB_INLINE QString Paths::findConfigFile( const QString& configFileName )
{
if ( !defaultConfigFile.isEmpty() && QFileInfo( defaultConfigFile ).isReadable() )
if ( !configFileName.isEmpty() && QFileInfo( configFileName ).isReadable() )
{
m_configFilePath = defaultConfigFile;
return( defaultConfigFile );
return( configFileName );
}
auto fileName = QString::fromLocal8Bit( qgetenv( QCoreApplication::applicationName()
.toUpper().toUtf8() + "_CONFIG" ) );
if ( QFileInfo( fileName ).isReadable() )
{
m_configFilePath = fileName;
return( fileName );
}
if ( QFileInfo( m_configFilePath ).isReadable() )
QString autoConfigFile = m_systemConfigDirectory + "/" + m_executableName;
if ( QFileInfo( autoConfigFile ).isReadable() )
{
return( m_configFilePath );
return( configFileName );
}
return( QString() );
@ -359,27 +359,15 @@ MYXLIB_INLINE const QString& Paths::systemConfigDirectory() const
}
MYXLIB_INLINE const QString& Paths::configFilePath() const
MYXLIB_INLINE const QString& Paths::userThemeDirectory() const
{
return( m_configFilePath );
return( m_userThemeDirectory );
}
MYXLIB_INLINE const QString& Paths::configFileName() const
MYXLIB_INLINE const QString& Paths::systemThemeDirectory() const
{
return( m_configFileName );
}
const QString& Paths::configFileExtension() const
{
return( m_configFileExtension );
}
void Paths::setConfigFileExtension( const QString& name )
{
m_configFileExtension = name;
return( m_systemThemeDirectory );
}
@ -437,6 +425,12 @@ MYXLIB_INLINE const QString& Paths::projectName() const
}
MYXLIB_INLINE void Paths::setProjectName( const QString& name )
{
m_projectName = name;
}
MYXLIB_INLINE const QString& Paths::organizationName() const
{
return( m_organizationName );

View File

@ -62,7 +62,7 @@ public:
}
/** @brief Обновление путей с учётом расположения исполняемого файла */
bool init();
bool init( bool autodetect = true );
/** @brief Создание стандартных системных каталогов */
bool makeDefaultSystemDirectories();
@ -76,14 +76,11 @@ public:
/** @brief Поиск существующего файла настойки.
* Поиск выполняется до тех пор пока не будет найден файл в следующем порядке:
* 1. Имя файла, указанное в качестве параметра функции
* 2. Имя файла, заданное переменной окружения вида PROJECT_NAME_CONFIG
* 3. Имя файла, полученное из внутренней переменной класса
* 2. Имя файла, заданное переменной окружения вида EXECUTABLE_NAME_CONFIG
* 3. Имя файла, полученное из имени каталога системных настроек и имени исполняемого файла
* Если файл настройки не будет найден, то будет возвращена пустая строка
*/
QString findConfigFile( const QString& defaultConfigFile = QLatin1String( "" ) );
/** @brief Полный путь к базовому каталогу */
const QString& projectName() const;
QString findConfigFile( const QString& configFileName = QLatin1String( "" ) );
/** @brief Имя исполняемого файла */
const QString& executableName() const;
@ -94,17 +91,11 @@ public:
/** @brief Полный путь к каталогу с исполняемым файлом */
const QString& executableDirectory() const;
/** @brief Имя файла настройки */
const QString& configFileName() const;
/** @brief Путь к общему пользовательскому каталогу для файлов работы (темы) */
const QString& userThemeDirectory() const;
/** @brief Расширение файла настройки */
const QString& configFileExtension() const;
/** @brief Установка расширения файла настройки */
void setConfigFileExtension( const QString& name );
/** @brief Полный путь к файлу настройки */
const QString& configFilePath() const;
/** @brief Путь к общему системному каталогу для файлов работы (темы) */
const QString& systemThemeDirectory() const;
/** @brief Полный путь к пользовательскому каталогу с файлами настройки */
const QString& userConfigDirectory() const;
@ -136,9 +127,6 @@ public:
/** @brief Полный путь к домашнему каталогу текущего пользователя */
const QString& homeDirectory() const;
/** @brief Имя каталога для работы (темы) */
const QString& themeDirectory() const;
/** @brief Имя каталога для проекта */
const QString& projectDirectory() const;
@ -150,6 +138,10 @@ public:
const QString& themeName() const;
void setThemeName( const QString& name );
/** @brief Название программного проекта */
const QString& projectName() const;
void setProjectName( const QString& name );
protected:
Paths();
~Paths() = default;
@ -158,6 +150,13 @@ private:
/** @brief Тип расположения файлов по каталогам */
HierarchyType m_hierarchyType { HierarchyType::kFlat };
/** @brief Автоматически определять значения organizationName, themeName и projectName
* @detail Если true, то пытаться автоматически определять значения переменных
* на основании полного пути к исполняемому файлу.
* Иначе использовать значения переменных, указанные пользователем.
*/
bool m_autodetect { true };
/** @brief Название организации */
QString m_organizationName;
@ -174,9 +173,6 @@ private:
QString m_executableFilePath;
QString m_executableDirectory;
/** @brief Общий каталог для файлов работы (темы) */
QString m_themeDirectory;
/** @brief Общий каталог для файлов проекта */
QString m_projectDirectory;
@ -189,6 +185,11 @@ private:
/** @brief Путь к общему пользовательскому каталогу данных */
QString m_dataDirectory;
/** @brief Путь к общему пользовательскому каталогу для файлов работы (темы) */
QString m_userThemeDirectory;
/** @brief Путь к общему системному каталогу для файлов работы (темы) */
QString m_systemThemeDirectory;
/** @brief Путь к пользовательскому каталогу с изменяемыми файлами */
QString m_userVarDataDirectory;
/** @brief Путь к системному каталогу с изменяемыми файлами */
@ -209,26 +210,19 @@ private:
/** @brief Путь к системному каталогу с файлами настройки */
QString m_systemConfigDirectory;
/** @brief Полный путь к файлу настройки */
QString m_configFilePath;
/** @brief Имя файла настройки */
QString m_configFileName;
/** @brief Расширение файла настройки */
QString m_configFileExtension;
QRegularExpression m_binDirRegex;
QRegularExpression m_unityBinDirRegex;
void setupSystemDirectories( const QString& defaultProjectDirectory,
const QString& defaultEtcDirectory,
const QString& defaultConstDataDirectory,
const QString& defaultVarDataDirectory,
const QString& defaultLogDirectory );
void setupUserDirectories( const QString& prefix );
void setupSystemDirectories( const QString& projectDir,
const QString& etcDir,
const QString& constDataDir,
const QString& varDataDir,
const QString& logDir );
void setupUserDirectories();
bool initCommon();
HierarchyType getHierarchyType();
void calculatePaths( HierarchyType hType );
void processOptHierarhy();
}; // class Paths
} // namespace filesystem

View File

@ -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})

View 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_

View 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

View 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_

View 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

View 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_

View 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

View 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_