#ifndef TCPCONTROLLER_H #define TCPCONTROLLER_H #include #include #include #include #include using Routes = QMap>; class TcpController : public QObject { Q_OBJECT public: TcpController(QObject* parent = nullptr); Routes getRoutes(); private: Routes routes; void setIpaddr(QTcpSocket* socket); void setName(QTcpSocket* socket); void getName(QTcpSocket* socket); void setVideoEnc(QTcpSocket* socket); void getVideoEnc(QTcpSocket* socket); void getFileList(QTcpSocket* socket); void deleteFile(QTcpSocket* socket); static QString writeCom(const QString& com); inline QVariantMap parseParams(QTcpSocket* socket); inline QList listFile(QString path); }; /** * @brief parse tcp request params * @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; } /** * @brief list all .mp4 file in the folder * @param path * @return */ inline QList TcpController::listFile(QString path) { QStringList fileList; QDir dir(path); if (!dir.exists()) { qDebug() << "folder " << path << " dont exists"; return fileList; } dir.setFilter(QDir::Files); dir.setSorting(QDir::Name); QStringList nameFilters; nameFilters << "*.mp4" << "*.jpg"; dir.setNameFilters(nameFilters); fileList = dir.entryList(); return fileList; } #endif // TCPCONTROLLER_H