AntiClipSettings/DeviceConnection.h

40 lines
1000 B
C
Raw Normal View History

2024-08-13 20:06:10 +08:00
#ifndef DEVICECONNECTION_H
#define DEVICECONNECTION_H
#include <QObject>
#include <string_view>
class QTcpSocket;
class DeviceConnection : public QObject {
Q_OBJECT
public:
using H264FrameCallback = std::function<void(const char *data, uint32_t size)>;
explicit DeviceConnection(QObject *parent = nullptr);
void setH264FrameCallback(H264FrameCallback &&callback);
void connect();
void start();
void requestOpenDoorArea();
signals:
void currentOpenDoorAreaPointsChanged(const QList<QPointF> &points);
protected:
void onConnected();
void onH264ReadyRead();
void onCommandReadyRead();
void handleCommand(const std::string_view &replyText);
private:
QTcpSocket *m_commandSocket = nullptr;
QTcpSocket *m_h264Socket = nullptr;
bool m_receivedFirstJsonReply = false;
QByteArray m_commandBuffer;
QByteArray m_h264Buffer;
H264FrameCallback m_frameCallback;
};
#endif // DEVICECONNECTION_H