This commit is contained in:
flowerstonezl
2026-03-10 17:56:36 +08:00
commit 993581b2a4
22 changed files with 378 additions and 0 deletions

82
.gitignore vendored Normal file
View File

@@ -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*/

70
CMakeLists.txt Normal file
View File

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

View File

@@ -0,0 +1,5 @@
{
"plugin_dir": "bin/plugins",
"device_tree": [],
"routes": []
}

View File

@@ -0,0 +1,5 @@
{
"modbus_rtu": {
"register_map": []
}
}

35
main.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include <QCoreApplication>
#include <QCommandLineParser>
#include <signal.h>
#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;
}

6
plugins/CMakeLists.txt Normal file
View File

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

View File

@@ -0,0 +1 @@
# Placeholder for filter plugins

View File

@@ -0,0 +1,3 @@
# Placeholder for can_raw plugin
add_library(can_raw SHARED)
set_target_properties(can_raw PROPERTIES OUTPUT_NAME "can_raw")

View File

@@ -0,0 +1,3 @@
# Placeholder for custom_proto plugin
add_library(custom_proto SHARED)
set_target_properties(custom_proto PROPERTIES OUTPUT_NAME "custom_proto")

View File

@@ -0,0 +1,3 @@
# Placeholder for modbus_rtu plugin
add_library(modbus_rtu SHARED)
set_target_properties(modbus_rtu PROPERTIES OUTPUT_NAME "modbus_rtu")

47
src/core/CoreService.cpp Normal file
View File

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

23
src/core/CoreService.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include <QObject>
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;
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Placeholder for a lock-free ring queue.
class LockFreeQueue {
public:
LockFreeQueue() = default;
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Placeholder for a preallocated memory pool.
class MemoryPool {
public:
MemoryPool() = default;
};

View File

@@ -0,0 +1,5 @@
#pragma once
// Placeholder for data trace model.
struct DataTrace {
};

View File

@@ -0,0 +1,5 @@
#pragma once
// Placeholder for metadata model.
struct Metadata {
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Placeholder protocol plugin interface.
class IProtocolPlugin {
public:
virtual ~IProtocolPlugin() = default;
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Placeholder for plugin manager.
class PluginManager {
public:
PluginManager() = default;
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Placeholder for pipeline context.
class PipelineContext {
public:
PipelineContext() = default;
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Placeholder for pipeline engine.
class PipelineEngine {
public:
PipelineEngine() = default;
};

View File

@@ -0,0 +1,7 @@
#pragma once
// Log stream buffer placeholder.
class LogStream {
public:
LogStream() = default;
};

36
src/utils/logs/logging.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef LOGGING_H
#define LOGGING_H
#include <QDebug>
#include <QLoggingCategory>
#include <QString>
#include <cstring>
/**
* @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