Update 更新文档
This commit is contained in:
226
Sqbase/Sqbase.cpp
Normal file
226
Sqbase/Sqbase.cpp
Normal file
@@ -0,0 +1,226 @@
|
||||
#include "Sqbase.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Sqbase {
|
||||
|
||||
// Static variables for singleton management
|
||||
static QTradeCore* s_core = nullptr;
|
||||
static SystemStatus s_systemStatus = SystemStatus::Uninitialized;
|
||||
static SystemConfig s_systemConfig;
|
||||
|
||||
// Core system access
|
||||
QTradeCore* System::core() {
|
||||
return s_core;
|
||||
}
|
||||
|
||||
// Data layer access
|
||||
QDataBuffer* System::dataBuffer() {
|
||||
return s_core ? s_core->dataBuffer() : nullptr;
|
||||
}
|
||||
|
||||
QDataQuality* System::dataQuality() {
|
||||
return s_core ? s_core->dataQuality() : nullptr;
|
||||
}
|
||||
|
||||
QOrderProcessor* System::orderProcessor() {
|
||||
return s_core ? s_core->orderProcessor() : nullptr;
|
||||
}
|
||||
|
||||
QBigOrderManager* System::bigOrderManager() {
|
||||
return s_core ? s_core->bigOrderManager() : nullptr;
|
||||
}
|
||||
|
||||
// Network layer access
|
||||
QFaultTolerance* System::faultTolerance() {
|
||||
return s_core ? s_core->faultTolerance() : nullptr;
|
||||
}
|
||||
|
||||
QSubscriptionManager* System::subscriptionManager() {
|
||||
return s_core ? s_core->subscriptionManager() : nullptr;
|
||||
}
|
||||
|
||||
// Configuration layer access
|
||||
QConfigManager* System::configManager() {
|
||||
return s_core ? s_core->configManager() : nullptr;
|
||||
}
|
||||
|
||||
QLogManager* System::logManager() {
|
||||
return s_core ? s_core->logManager() : nullptr;
|
||||
}
|
||||
|
||||
// Utility layer access
|
||||
QEventBus* System::eventBus() {
|
||||
return s_core ? s_core->eventBus() : nullptr;
|
||||
}
|
||||
|
||||
// System control
|
||||
bool System::initialize(const SystemConfig& config, int flags) {
|
||||
if (s_systemStatus != SystemStatus::Uninitialized &&
|
||||
s_systemStatus != SystemStatus::Stopped) {
|
||||
qWarning() << "System is already initialized or in process";
|
||||
return false;
|
||||
}
|
||||
|
||||
s_systemStatus = SystemStatus::Initializing;
|
||||
s_systemConfig = config;
|
||||
|
||||
try {
|
||||
// Initialize core system
|
||||
s_core = QTradeCore::instance();
|
||||
if (!s_core) {
|
||||
throw std::runtime_error("Failed to create core system instance");
|
||||
}
|
||||
|
||||
// Apply configuration
|
||||
if (configManager()) {
|
||||
configManager()->setBufferSize(config.bufferSize);
|
||||
configManager()->setMaxPacketsPerSecond(config.maxPacketsPerSecond);
|
||||
configManager()->setMonitorInterval(config.heartbeatInterval);
|
||||
}
|
||||
|
||||
// Initialize components based on flags
|
||||
if (flags & InitDataBuffer && dataBuffer()) {
|
||||
dataBuffer()->setBufferSize(config.bufferSize);
|
||||
dataBuffer()->setMaxPacketsPerSecond(config.maxPacketsPerSecond);
|
||||
dataBuffer()->setFlowControlEnabled(true);
|
||||
}
|
||||
|
||||
if (flags & InitDataQuality && dataQuality()) {
|
||||
dataQuality()->enableAlerts(config.enableDataValidation);
|
||||
}
|
||||
|
||||
if (flags & InitFaultTolerance && faultTolerance()) {
|
||||
faultTolerance()->enableFaultTolerance(config.enableFaultTolerance);
|
||||
|
||||
HeartbeatConfig hbConfig;
|
||||
hbConfig.intervalMs = config.heartbeatInterval;
|
||||
faultTolerance()->setHeartbeatConfig(hbConfig);
|
||||
|
||||
ReconnectConfig rcConfig;
|
||||
rcConfig.maxAttempts = config.reconnectAttempts;
|
||||
faultTolerance()->setReconnectConfig(rcConfig);
|
||||
}
|
||||
|
||||
if (flags & InitConfigManager && configManager()) {
|
||||
configManager()->loadDefaults();
|
||||
}
|
||||
|
||||
s_systemStatus = SystemStatus::Running;
|
||||
qInfo() << "Sqbase system initialized successfully";
|
||||
return true;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
s_systemStatus = SystemStatus::Error;
|
||||
qCritical() << "Failed to initialize Sqbase system:" << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void System::shutdown() {
|
||||
if (s_systemStatus == SystemStatus::Stopped ||
|
||||
s_systemStatus == SystemStatus::Uninitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_systemStatus = SystemStatus::Stopping;
|
||||
|
||||
try {
|
||||
// Shutdown core system
|
||||
if (s_core) {
|
||||
s_core->shutdown();
|
||||
}
|
||||
|
||||
s_systemStatus = SystemStatus::Stopped;
|
||||
qInfo() << "Sqbase system shutdown completed";
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
s_systemStatus = SystemStatus::Error;
|
||||
qCritical() << "Error during system shutdown:" << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
SystemStatus System::status() {
|
||||
return s_systemStatus;
|
||||
}
|
||||
|
||||
QString System::statusString() {
|
||||
switch (s_systemStatus) {
|
||||
case SystemStatus::Uninitialized: return "Uninitialized";
|
||||
case SystemStatus::Initializing: return "Initializing";
|
||||
case SystemStatus::Running: return "Running";
|
||||
case SystemStatus::Degraded: return "Degraded";
|
||||
case SystemStatus::Stopping: return "Stopping";
|
||||
case SystemStatus::Stopped: return "Stopped";
|
||||
case SystemStatus::Error: return "Error";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// System information
|
||||
QString System::version() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
QDateTime System::buildTime() {
|
||||
return QDateTime::fromString(__DATE__ " " __TIME__, "MMM d yyyy hh:mm:ss");
|
||||
}
|
||||
|
||||
QString System::systemInfo() {
|
||||
QString info;
|
||||
info += "Sqbase Trading System\n";
|
||||
info += "Version: " + version() + "\n";
|
||||
info += "Build Time: " + buildTime().toString("yyyy-MM-dd hh:mm:ss") + "\n";
|
||||
info += "Status: " + statusString() + "\n";
|
||||
|
||||
if (s_core && s_core->isInitialized()) {
|
||||
info += "Core System: Initialized\n";
|
||||
|
||||
if (dataBuffer()) {
|
||||
auto stats = dataBuffer()->getStatistics();
|
||||
info += QString("Data Buffer: %1 packets, %2 p/s\n")
|
||||
.arg(stats.totalPackets)
|
||||
.arg(stats.packetsPerSecond, 0, 'f', 2);
|
||||
}
|
||||
|
||||
if (dataQuality()) {
|
||||
auto metrics = dataQuality()->getOverallMetrics();
|
||||
info += QString("Data Quality: %.1f%% complete, %.1f%% accurate\n")
|
||||
.arg(metrics.completeness)
|
||||
.arg(metrics.accuracy);
|
||||
}
|
||||
|
||||
if (faultTolerance()) {
|
||||
info += QString("Fault Tolerance: %1\n")
|
||||
.arg(faultTolerance()->isSystemHealthy() ? "Healthy" : "Degraded");
|
||||
}
|
||||
} else {
|
||||
info += "Core System: Not Initialized\n";
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
} // namespace Sqbase
|
||||
|
||||
// Convenience global functions for quick access
|
||||
Sqbase::QTradeCore* SqCore() {
|
||||
return Sqbase::System::core();
|
||||
}
|
||||
|
||||
Sqbase::QDataBuffer* SqDataBuffer() {
|
||||
return Sqbase::System::dataBuffer();
|
||||
}
|
||||
|
||||
Sqbase::QDataQuality* SqDataQuality() {
|
||||
return Sqbase::System::dataQuality();
|
||||
}
|
||||
|
||||
Sqbase::QFaultTolerance* SqFaultTolerance() {
|
||||
return Sqbase::System::faultTolerance();
|
||||
}
|
||||
|
||||
Sqbase::QConfigManager* SqConfigManager() {
|
||||
return Sqbase::System::configManager();
|
||||
}
|
||||
Reference in New Issue
Block a user