RecordControlApplication/TcpController.h

58 lines
1.3 KiB
C
Raw Normal View History

2024-01-18 15:41:43 +08:00
#ifndef TCPCONTROLLER_H
#define TCPCONTROLLER_H
#include <QDir>
2024-01-18 15:41:43 +08:00
#include <QMap>
#include <QObject>
#include <QTcpSocket>
#include <functional>
using Routes = QMap<QString, std::function<void(QTcpSocket*)>>;
class TcpController : public QObject {
Q_OBJECT
public:
TcpController(QObject* parent = nullptr);
Routes getRoutes();
private:
Routes routes;
void setIpaddr(QTcpSocket* socket);
2024-03-04 16:22:40 +08:00
void setName(QTcpSocket* socket);
void getName(QTcpSocket* socket);
2024-03-04 16:22:40 +08:00
2024-01-18 15:41:43 +08:00
void setVideoEnc(QTcpSocket* socket);
void getVideoEnc(QTcpSocket* socket);
2024-03-04 16:22:40 +08:00
2024-01-18 15:41:43 +08:00
void getFileList(QTcpSocket* socket);
void deleteFile(QTcpSocket* socket);
2024-03-04 16:22:40 +08:00
void setRecordMode(QTcpSocket* socket);
void setPlaybackMode(QTcpSocket* socket);
inline QVariantMap parseParams(QTcpSocket* socket);
2024-01-18 15:41:43 +08:00
};
/**
2024-03-04 16:22:40 +08:00
* @brief tcp请求参数
* @param socket
* @return
*/
inline QVariantMap TcpController::parseParams(QTcpSocket* socket)
{
QVariantMap params;
// exmaple:data1=xxx\r\ndata2=xxx\r\n...
QStringList data = QString(socket->readAll()).split("\r\n");
for (int i = 0; i < data.length(); i++) {
if (data.at(i).contains("=")) {
QStringList pair = data.at(i).split("=");
params.insert(pair[0], pair[1]);
}
}
return params;
}
2024-01-18 15:41:43 +08:00
#endif // TCPCONTROLLER_H