commit 993581b2a4be494c1b1029db805e5d18684c902a Author: flowerstonezl <125468358+flowerstonezl@users.noreply.github.com> Date: Tue Mar 10 17:56:36 2026 +0800 log diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa3808c --- /dev/null +++ b/.gitignore @@ -0,0 +1,82 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* +*.qbs.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + +# Directories with generated files +.moc/ +.obj/ +.pch/ +.rcc/ +.uic/ +/build*/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5acb568 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 3.19) +project(soft_bus_daemon + LANGUAGES CXX + VERSION 1.0.0 +) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") + +# Output layout +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/plugins) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/plugins) + +# 启用AddressSanitizer(仅在非Windows平台上) +if(NOT WIN32) + set(SANITIZE_FLAGS "-fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZE_FLAGS}") +else() + message(STATUS "AddressSanitizer disabled on Windows because the runtime is unavailable in the MinGW kit.") +endif() + +# 设置C++标准 +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOMOC ON) +# 查找Qt6(守护进程只需要 Core/DBus/Network/SerialPort/Sql) +find_package(Qt6 6.5 REQUIRED COMPONENTS Core SerialPort Network Sql DBus) + +# 检测编译平台 +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") + set(PlatformDir "x86") +else() + set(PlatformDir "x64") +endif() + +qt_standard_project_setup() + +# 添加软总线模板库 +# 1. 日志库 +qt_add_library(softbus_template + src/utils/logs/logging.h + src/utils/logs/LogStream.h +) + +qt_add_executable(softbus_daemon + main.cpp + src/core/CoreService.cpp +) + + + +target_link_libraries(softbus_daemon + PRIVATE + Qt::Core +) + +add_subdirectory(plugins) + + +install(TARGETS softbus_daemon + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/config/daemon_config.json b/config/daemon_config.json new file mode 100644 index 0000000..8b02b04 --- /dev/null +++ b/config/daemon_config.json @@ -0,0 +1,5 @@ +{ + "plugin_dir": "bin/plugins", + "device_tree": [], + "routes": [] +} diff --git a/config/plugins_config.json b/config/plugins_config.json new file mode 100644 index 0000000..9581b98 --- /dev/null +++ b/config/plugins_config.json @@ -0,0 +1,5 @@ +{ + "modbus_rtu": { + "register_map": [] + } +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..fc0ac96 --- /dev/null +++ b/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include "src/utils/logs/logging.h" +#include "src/core/CoreService.h" + +void signalHandler(int signal) +{ + LOG_INFO() << "Received signal:" << signal; + QCoreApplication::quit(); +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + app.setApplicationName("soft_bus_daemon"); + app.setApplicationVersion("1.0.0"); + app.setOrganizationName("soft_bus"); + + QCommandLineParser parser; + parser.setApplicationDescription(QStringLiteral("Soft Bus Daemon")); + parser.addHelpOption(); + parser.addVersionOption(); + parser.process(app); + + LOG_INFO() << "Starting Soft Bus Daemon"; + + signal(SIGINT, signalHandler); + signal(SIGTERM, signalHandler); + + CoreService::instance()->initialize(); + int ret = app.exec(); + CoreService::instance()->shutdown(); + return ret; +} diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 0000000..3e0ff6a --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.19) + +add_subdirectory(protocols/modbus_rtu) +add_subdirectory(protocols/can_raw) +add_subdirectory(protocols/custom_proto) +add_subdirectory(filters) diff --git a/plugins/filters/CMakeLists.txt b/plugins/filters/CMakeLists.txt new file mode 100644 index 0000000..7e81cdd --- /dev/null +++ b/plugins/filters/CMakeLists.txt @@ -0,0 +1 @@ +# Placeholder for filter plugins diff --git a/plugins/protocols/can_raw/CMakeLists.txt b/plugins/protocols/can_raw/CMakeLists.txt new file mode 100644 index 0000000..9ee7371 --- /dev/null +++ b/plugins/protocols/can_raw/CMakeLists.txt @@ -0,0 +1,3 @@ +# Placeholder for can_raw plugin +add_library(can_raw SHARED) +set_target_properties(can_raw PROPERTIES OUTPUT_NAME "can_raw") diff --git a/plugins/protocols/custom_proto/CMakeLists.txt b/plugins/protocols/custom_proto/CMakeLists.txt new file mode 100644 index 0000000..6bf80de --- /dev/null +++ b/plugins/protocols/custom_proto/CMakeLists.txt @@ -0,0 +1,3 @@ +# Placeholder for custom_proto plugin +add_library(custom_proto SHARED) +set_target_properties(custom_proto PROPERTIES OUTPUT_NAME "custom_proto") diff --git a/plugins/protocols/modbus_rtu/CMakeLists.txt b/plugins/protocols/modbus_rtu/CMakeLists.txt new file mode 100644 index 0000000..9c8d48f --- /dev/null +++ b/plugins/protocols/modbus_rtu/CMakeLists.txt @@ -0,0 +1,3 @@ +# Placeholder for modbus_rtu plugin +add_library(modbus_rtu SHARED) +set_target_properties(modbus_rtu PROPERTIES OUTPUT_NAME "modbus_rtu") diff --git a/src/core/CoreService.cpp b/src/core/CoreService.cpp new file mode 100644 index 0000000..eb5aff0 --- /dev/null +++ b/src/core/CoreService.cpp @@ -0,0 +1,47 @@ +#include "CoreService.h" +#include "../utils/logs/logging.h" + +CoreService* CoreService::instance() +{ + static CoreService inst; + return &inst; +} + +CoreService::CoreService(QObject* parent) + : QObject(parent) + , m_initialized(false) +{ +} + +CoreService::~CoreService() +{ + shutdown(); +} + +bool CoreService::initialize() +{ + if (m_initialized) { + LOG_WARNING() << "CoreService already initialized"; + return true; + } + + LOG_INFO() << "CoreService initializing"; + m_initialized = true; + return true; +} + +void CoreService::shutdown() +{ + if (!m_initialized) { + LOG_DEBUG() << "CoreService shutdown called while not initialized"; + return; + } + + LOG_INFO() << "CoreService shutting down"; + m_initialized = false; +} + +bool CoreService::isInitialized() const +{ + return m_initialized; +} diff --git a/src/core/CoreService.h b/src/core/CoreService.h new file mode 100644 index 0000000..188edd6 --- /dev/null +++ b/src/core/CoreService.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +class CoreService : public QObject { + Q_OBJECT + +public: + static CoreService* instance(); + + bool initialize(); + void shutdown(); + bool isInitialized() const; + +private: + explicit CoreService(QObject* parent = nullptr); + ~CoreService(); + + CoreService(const CoreService&) = delete; + CoreService& operator=(const CoreService&) = delete; + + bool m_initialized = false; +}; diff --git a/src/core/memory/LockFreeQueue.h b/src/core/memory/LockFreeQueue.h new file mode 100644 index 0000000..077122c --- /dev/null +++ b/src/core/memory/LockFreeQueue.h @@ -0,0 +1,7 @@ +#pragma once + +// Placeholder for a lock-free ring queue. +class LockFreeQueue { +public: + LockFreeQueue() = default; +}; diff --git a/src/core/memory/MemoryPool.h b/src/core/memory/MemoryPool.h new file mode 100644 index 0000000..2c1ef88 --- /dev/null +++ b/src/core/memory/MemoryPool.h @@ -0,0 +1,7 @@ +#pragma once + +// Placeholder for a preallocated memory pool. +class MemoryPool { +public: + MemoryPool() = default; +}; diff --git a/src/core/metadata/DataTrace.h b/src/core/metadata/DataTrace.h new file mode 100644 index 0000000..9ecbce0 --- /dev/null +++ b/src/core/metadata/DataTrace.h @@ -0,0 +1,5 @@ +#pragma once + +// Placeholder for data trace model. +struct DataTrace { +}; diff --git a/src/core/metadata/Metadata.h b/src/core/metadata/Metadata.h new file mode 100644 index 0000000..8a06787 --- /dev/null +++ b/src/core/metadata/Metadata.h @@ -0,0 +1,5 @@ +#pragma once + +// Placeholder for metadata model. +struct Metadata { +}; diff --git a/src/core/plugin_system/IProtocolPlugin.h b/src/core/plugin_system/IProtocolPlugin.h new file mode 100644 index 0000000..6404102 --- /dev/null +++ b/src/core/plugin_system/IProtocolPlugin.h @@ -0,0 +1,7 @@ +#pragma once + +// Placeholder protocol plugin interface. +class IProtocolPlugin { +public: + virtual ~IProtocolPlugin() = default; +}; diff --git a/src/core/plugin_system/PluginManager.h b/src/core/plugin_system/PluginManager.h new file mode 100644 index 0000000..64946c1 --- /dev/null +++ b/src/core/plugin_system/PluginManager.h @@ -0,0 +1,7 @@ +#pragma once + +// Placeholder for plugin manager. +class PluginManager { +public: + PluginManager() = default; +}; diff --git a/src/message_bus/pipeline/PipelineContext.h b/src/message_bus/pipeline/PipelineContext.h new file mode 100644 index 0000000..0a2db3e --- /dev/null +++ b/src/message_bus/pipeline/PipelineContext.h @@ -0,0 +1,7 @@ +#pragma once + +// Placeholder for pipeline context. +class PipelineContext { +public: + PipelineContext() = default; +}; diff --git a/src/message_bus/pipeline/PipelineEngine.h b/src/message_bus/pipeline/PipelineEngine.h new file mode 100644 index 0000000..83d21c4 --- /dev/null +++ b/src/message_bus/pipeline/PipelineEngine.h @@ -0,0 +1,7 @@ +#pragma once + +// Placeholder for pipeline engine. +class PipelineEngine { +public: + PipelineEngine() = default; +}; diff --git a/src/utils/logs/LogStream.h b/src/utils/logs/LogStream.h new file mode 100644 index 0000000..1dd8767 --- /dev/null +++ b/src/utils/logs/LogStream.h @@ -0,0 +1,7 @@ +#pragma once + +// Log stream buffer placeholder. +class LogStream { +public: + LogStream() = default; +}; diff --git a/src/utils/logs/logging.h b/src/utils/logs/logging.h new file mode 100644 index 0000000..a30742c --- /dev/null +++ b/src/utils/logs/logging.h @@ -0,0 +1,36 @@ +#ifndef LOGGING_H +#define LOGGING_H + +#include +#include +#include +#include + + +/** + * @file logging.h + * @brief 日志宏定义,提供带文件名和函数名的日志输出,并异步存储到数据库 + */ + +// 获取文件名(不含路径) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) + +// 构建来源字符串的辅助宏 +#define __LOG_SOURCE__ (QString(__FILENAME__) + "." + QString(__FUNCTION__)) + +// 日志宏,格式:[文件名.函数名] 消息 + +#define LOG_DEBUG() \ + qDebug() << "[" << "SYSTEM" << "DEBUG" << __LOG_SOURCE__ << "[" << __FILENAME__ << "." << __FUNCTION__ << "]" + +#define LOG_ERROR() \ + qCritical() << "[" << "SYSTEM" << "ERROR" << __LOG_SOURCE__ << "[" << __FILENAME__ << "." << __FUNCTION__ << "]" + +#define LOG_INFO() \ + qInfo() << "[" << "SYSTEM" << "INFO" << __LOG_SOURCE__ << "[" << __FILENAME__ << "." << __FUNCTION__ << "]" + +#define LOG_WARNING() \ + qWarning() << "[" << "SYSTEM" << "WARNING" << __LOG_SOURCE__ << "[" << __FILENAME__ << "." << __FUNCTION__ << "]" + +#endif // LOGGING_H +