74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
|
|
// CommunicationManager.h
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "channelConfig.h"
|
||
|
|
#include "httpChannel.h"
|
||
|
|
#include "webSocketChannel.h"
|
||
|
|
#include <QObject>
|
||
|
|
#include <QSharedPointer>
|
||
|
|
#include "export.hpp"
|
||
|
|
|
||
|
|
class DIAGRAM_DESIGNER_PUBLIC CommunicationManager : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
|
||
|
|
public:
|
||
|
|
static CommunicationManager* instance();
|
||
|
|
|
||
|
|
// 初始化
|
||
|
|
bool initialize();
|
||
|
|
|
||
|
|
// HTTP通道操作
|
||
|
|
bool connectHttp();
|
||
|
|
bool disconnectHttp();
|
||
|
|
bool sendHttpRequest(const QString& path,
|
||
|
|
const QByteArray& data = QByteArray(),
|
||
|
|
const QString& method = "GET");
|
||
|
|
|
||
|
|
// WebSocket通道操作
|
||
|
|
bool connectWebSocket();
|
||
|
|
bool disconnectWebSocket();
|
||
|
|
bool sendWebSocketMessage(const QByteArray& data);
|
||
|
|
bool sendWebSocketText(const QString& text);
|
||
|
|
|
||
|
|
// 状态查询
|
||
|
|
bool isHttpConnected() const;
|
||
|
|
bool isWebSocketConnected() const;
|
||
|
|
ChannelConfig getHttpConfig() const;
|
||
|
|
ChannelConfig getWebSocketConfig() const;
|
||
|
|
|
||
|
|
// 配置更新
|
||
|
|
void updateHttpConfig(const ChannelConfig& config);
|
||
|
|
void updateWebSocketConfig(const ChannelConfig& config);
|
||
|
|
|
||
|
|
signals:
|
||
|
|
// HTTP通道信号
|
||
|
|
void httpConnected();
|
||
|
|
void httpDisconnected();
|
||
|
|
void httpDataReceived(const QByteArray& data);
|
||
|
|
void httpError(const QString& error);
|
||
|
|
|
||
|
|
// WebSocket通道信号
|
||
|
|
void websocketConnected();
|
||
|
|
void websocketDisconnected();
|
||
|
|
void websocketDataReceived(const QByteArray& data);
|
||
|
|
void websocketTextReceived(const QString& text);
|
||
|
|
void websocketError(const QString& error);
|
||
|
|
|
||
|
|
private:
|
||
|
|
CommunicationManager(QObject* parent = nullptr);
|
||
|
|
~CommunicationManager();
|
||
|
|
|
||
|
|
// 内部初始化
|
||
|
|
void initHttpChannel();
|
||
|
|
void initWebSocketChannel();
|
||
|
|
|
||
|
|
// 配置
|
||
|
|
ChannelConfig m_httpConfig;
|
||
|
|
ChannelConfig m_websocketConfig;
|
||
|
|
|
||
|
|
// 通道实例
|
||
|
|
QSharedPointer<HttpChannel> m_httpChannel;
|
||
|
|
QSharedPointer<WebSocketChannel> m_websocketChannel;
|
||
|
|
};
|