Update 更新文档
This commit is contained in:
155
TradingCore/core/TradingCore.cpp
Normal file
155
TradingCore/core/TradingCore.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#include "qtradecore.h"
|
||||
#include <QDebug>
|
||||
#include <QCoreApplication>
|
||||
|
||||
QTradeCore* QTradeCore::instance()
|
||||
{
|
||||
static QTradeCore* instance = nullptr;
|
||||
static QMutex mutex;
|
||||
|
||||
if (!instance) {
|
||||
QMutexLocker locker(&mutex);
|
||||
if (!instance) {
|
||||
instance = new QTradeCore();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
QTradeCore::QTradeCore(QObject *parent) : QObject(parent)
|
||||
{
|
||||
// 延迟初始化,在initialize()方法中创建实例
|
||||
}
|
||||
|
||||
QTradeCore::~QTradeCore()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
void QTradeCore::initialize()
|
||||
{
|
||||
if (m_initialized) {
|
||||
qWarning() << "QTradeCore: Already initialized";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "QTradeCore: Initializing...";
|
||||
|
||||
try {
|
||||
// 初始化事件总线
|
||||
m_eventBus = QEventBus::instance();
|
||||
|
||||
// 初始化订阅管理器
|
||||
m_subscriptionManager = QSubscriptionManager::instance();
|
||||
|
||||
// 初始化大单管理器
|
||||
m_bigOrderManager = QBigOrderManager::instance();
|
||||
|
||||
// 初始化日志管理器
|
||||
m_logManager = QLogManager::Instance();
|
||||
|
||||
// 初始化订单处理器
|
||||
m_orderProcessor = new QOrderProcessor(this);
|
||||
|
||||
// 设置初始状态
|
||||
m_initialized = true;
|
||||
|
||||
qDebug() << "QTradeCore: Initialization completed successfully";
|
||||
emit systemInitialized();
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
qCritical() << "QTradeCore: Initialization failed:" << e.what();
|
||||
emit errorOccurred(QString("Initialization failed: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void QTradeCore::shutdown()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "QTradeCore: Shutting down...";
|
||||
|
||||
// 清理资源
|
||||
if (m_orderProcessor) {
|
||||
delete m_orderProcessor;
|
||||
m_orderProcessor = nullptr;
|
||||
}
|
||||
|
||||
// 注意:单例对象由它们自己管理生命周期
|
||||
// 我们只清理我们直接创建的对象
|
||||
|
||||
m_initialized = false;
|
||||
|
||||
qDebug() << "QTradeCore: Shutdown completed";
|
||||
emit systemShutdown();
|
||||
}
|
||||
|
||||
QSubscriptionManager* QTradeCore::subscriptionManager()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
qWarning() << "QTradeCore: Not initialized, cannot access subscription manager";
|
||||
return nullptr;
|
||||
}
|
||||
return m_subscriptionManager;
|
||||
}
|
||||
|
||||
QOrderProcessor* QTradeCore::orderProcessor()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
qWarning() << "QTradeCore: Not initialized, cannot access order processor";
|
||||
return nullptr;
|
||||
}
|
||||
return m_orderProcessor;
|
||||
}
|
||||
|
||||
QBigOrderManager* QTradeCore::bigOrderManager()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
qWarning() << "QTradeCore: Not initialized, cannot access big order manager";
|
||||
return nullptr;
|
||||
}
|
||||
return m_bigOrderManager;
|
||||
}
|
||||
|
||||
QLogManager* QTradeCore::logManager()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
qWarning() << "QTradeCore: Not initialized, cannot access log manager";
|
||||
return nullptr;
|
||||
}
|
||||
return m_logManager;
|
||||
}
|
||||
|
||||
QEventBus* QTradeCore::eventBus()
|
||||
{
|
||||
if (!m_initialized) {
|
||||
qWarning() << "QTradeCore: Not initialized, cannot access event bus";
|
||||
return nullptr;
|
||||
}
|
||||
return m_eventBus;
|
||||
}
|
||||
|
||||
QString QTradeCore::getSystemStatus() const
|
||||
{
|
||||
QString status;
|
||||
|
||||
if (m_initialized) {
|
||||
status = "System is running\n";
|
||||
|
||||
// Build component list manually to avoid lambda issues
|
||||
QStringList components;
|
||||
if (m_subscriptionManager) components << "SubscriptionManager";
|
||||
if (m_orderProcessor) components << "OrderProcessor";
|
||||
if (m_bigOrderManager) components << "BigOrderManager";
|
||||
if (m_logManager) components << "LogManager";
|
||||
if (m_eventBus) components << "EventBus";
|
||||
|
||||
status += QString("Components: %1\n").arg(components.join(", "));
|
||||
} else {
|
||||
status = "System is not initialized";
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
66
TradingCore/core/TradingCore.h
Normal file
66
TradingCore/core/TradingCore.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef TRADING_CORE_H
|
||||
#define TRADING_CORE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "../data_processing/DataBuffer.h"
|
||||
#include "../data_processing/DataQualityValidator.h"
|
||||
#include "../data_processing/OrderProcessor.h"
|
||||
#include "../data_processing/BigOrderManager.h"
|
||||
#include "../network_communication/FaultToleranceManager.h"
|
||||
#include "../network_communication/SubscriptionManager.h"
|
||||
#include "../configuration/ConfigurationManager.h"
|
||||
#include "../configuration/LogManager.h"
|
||||
#include "../utilities/EventBus.h"
|
||||
|
||||
class TradingCore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TradingCore* instance();
|
||||
|
||||
// Core service access
|
||||
SubscriptionManager* subscriptionManager();
|
||||
OrderProcessor* orderProcessor();
|
||||
BigOrderManager* bigOrderManager();
|
||||
LogManager* logManager();
|
||||
EventBus* eventBus();
|
||||
|
||||
// New system component access
|
||||
DataBuffer* dataBuffer();
|
||||
DataQualityValidator* dataQuality();
|
||||
FaultToleranceManager* faultTolerance();
|
||||
ConfigurationManager* configManager();
|
||||
|
||||
// System control
|
||||
void initialize();
|
||||
void shutdown();
|
||||
|
||||
// System status
|
||||
bool isInitialized() const { return m_initialized; }
|
||||
QString getSystemStatus() const;
|
||||
|
||||
signals:
|
||||
void systemInitialized();
|
||||
void systemShutdown();
|
||||
void errorOccurred(const QString& error);
|
||||
|
||||
private:
|
||||
explicit TradingCore(QObject *parent = nullptr);
|
||||
~TradingCore();
|
||||
|
||||
bool m_initialized = false;
|
||||
|
||||
SubscriptionManager* m_subscriptionManager = nullptr;
|
||||
OrderProcessor* m_orderProcessor = nullptr;
|
||||
BigOrderManager* m_bigOrderManager = nullptr;
|
||||
LogManager* m_logManager = nullptr;
|
||||
EventBus* m_eventBus = nullptr;
|
||||
|
||||
// New system components
|
||||
DataBuffer* m_dataBuffer = nullptr;
|
||||
DataQualityValidator* m_dataQuality = nullptr;
|
||||
FaultToleranceManager* m_faultTolerance = nullptr;
|
||||
ConfigurationManager* m_configManager = nullptr;
|
||||
};
|
||||
|
||||
#endif // TRADING_CORE_H
|
||||
Reference in New Issue
Block a user