88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
#ifndef ALARMEVENTDATASERVICE_H
|
||
#define ALARMEVENTDATASERVICE_H
|
||
|
||
#include "alarmEventGlobal.h"
|
||
#include "alarmEventUtils.h"
|
||
#include "qamqpclient.h"
|
||
#include "qamqpexchange.h"
|
||
#include "qamqpqueue.h"
|
||
//#include <QNetworkRequest>
|
||
|
||
class QAmqpClient;
|
||
class QAmqpQueue;
|
||
class QAmqpExchange;
|
||
class QNetworkAccessManager;
|
||
class QNetworkReply;
|
||
class QTimer;
|
||
class QSettings;
|
||
|
||
class AlarmEventDataService : public QObject
|
||
{
|
||
Q_OBJECT
|
||
Q_DISABLE_COPY(AlarmEventDataService) //禁止拷贝,等价于:AlarmEventDataService(const AlarmEventDataService&) = delete; AlarmEventDataService& operator=(const AlarmEventDataService&) = delete;
|
||
|
||
public:
|
||
static AlarmEventDataService* instance();
|
||
void start();
|
||
void stop();
|
||
void queryHistoricalEvents(const QDateTime& startTime, const QDateTime& endTime);
|
||
|
||
signals:
|
||
void realTimeEventReceived(const EventData& event);
|
||
void historicalQueryError(const QString& msg);
|
||
void historicalQueryData(const QList<EventData>& events);
|
||
|
||
private slots:
|
||
void onRabbitMQConnected();
|
||
void onRabbitMQDisconnected();
|
||
void onRabbitMQError(QAMQP::Error error);
|
||
void onMessageReceived();
|
||
void onReconnectTimeout();
|
||
void onHistoricalRequestFinished(QNetworkReply* reply);
|
||
|
||
private:
|
||
explicit AlarmEventDataService();
|
||
~AlarmEventDataService();
|
||
|
||
void initialize();
|
||
|
||
//连接管理
|
||
void startRealTimeDataService();
|
||
void cleanupRabbitMQConnection();
|
||
void scheduleReconnect();
|
||
void cancelReconnect();
|
||
//实时信息处理
|
||
MessageHandleResult processMessage(const QAmqpMessage& message);
|
||
EventData parseEventFromMessage(const QByteArray& data, QString& errorString);
|
||
bool validateEvent(const EventData& event);
|
||
//历史数据处理
|
||
QUrl bulidHistoricalQueryUrl(const QDateTime& startTime, const QDateTime& endTime);
|
||
void processHistoricalResponse(const QByteArray& data);
|
||
//QNetworkRequest createHistoricalRequest(const QUrl& url);
|
||
|
||
ServiceConfig m_config;
|
||
ServiceStatus m_serviceStatus;
|
||
//ConnectionStatus m_realTimeConnectionStatus;
|
||
//ConnectionStatus m_historicalConnectionStatus;
|
||
|
||
//RabbitMQ通信相关组件
|
||
QAmqpClient* m_amqpClient;
|
||
QAmqpQueue* m_amqpQueue;
|
||
QAmqpExchange* m_amqpExchange;
|
||
|
||
//重连相关
|
||
QTimer* m_reconnectTimer;
|
||
int m_reconnectAttempts;
|
||
int m_maxReconnectAttempts;
|
||
|
||
//历史数据相关
|
||
QNetworkAccessManager* m_networkManager;
|
||
|
||
//配置相关
|
||
QSettings* m_settings;
|
||
QString m_settingsFile;
|
||
bool m_isVaildSettingsFile;
|
||
};
|
||
|
||
#endif
|