2025-06-14 23:25:16 +08:00
|
|
|
#ifndef CLIENTCORE_H
|
|
|
|
|
#define CLIENTCORE_H
|
|
|
|
|
|
2025-06-15 14:31:54 +08:00
|
|
|
#include <InfoClient.h>
|
|
|
|
|
#include <InfoDirFile.h>
|
2025-06-14 23:25:16 +08:00
|
|
|
#include <Protocol.h>
|
|
|
|
|
#include <QDataStream>
|
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
#include <QMutex>
|
|
|
|
|
#include <QMutexLocker>
|
|
|
|
|
#include <QTcpSocket>
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
|
|
class ClientCore : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ClientCore(QObject* parent = nullptr);
|
|
|
|
|
~ClientCore();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool Connect(const QString& ip, quint16 port);
|
|
|
|
|
void Disconnect();
|
2025-06-15 14:31:54 +08:00
|
|
|
bool Send(QSharedPointer<FrameBuffer> frame);
|
|
|
|
|
bool Send(const char* data, qint64 len);
|
2025-06-14 23:25:16 +08:00
|
|
|
|
2025-06-14 23:44:13 +08:00
|
|
|
private:
|
|
|
|
|
void onReadyRead();
|
|
|
|
|
void onDisconnected();
|
2025-06-14 23:25:16 +08:00
|
|
|
|
2025-06-14 23:44:13 +08:00
|
|
|
private:
|
|
|
|
|
void UseFrame(QSharedPointer<FrameBuffer> frame);
|
2025-06-15 14:31:54 +08:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void SetClientsCall(const std::function<void(const InfoClientVec& clients)>& call);
|
|
|
|
|
void SetPathCall(const std::function<void(const QString& path)>& call);
|
|
|
|
|
void SetFileCall(const std::function<void(const DirFileInfoVec& files)>& call);
|
|
|
|
|
void SetRemoteID(const QString& id);
|
|
|
|
|
QString GetRemoteID();
|
2025-06-14 23:25:16 +08:00
|
|
|
|
2025-06-14 23:44:13 +08:00
|
|
|
public:
|
|
|
|
|
QMutex conMutex_;
|
2025-06-15 20:37:25 +08:00
|
|
|
QString ownID_;
|
2025-06-14 23:25:16 +08:00
|
|
|
QString remoteID_;
|
2025-06-14 23:44:13 +08:00
|
|
|
QTcpSocket* socket_;
|
2025-06-14 23:25:16 +08:00
|
|
|
QByteArray recvBuffer_;
|
2025-06-14 23:44:13 +08:00
|
|
|
|
|
|
|
|
std::function<void(const QString& path)> pathCall_;
|
2025-06-15 20:37:25 +08:00
|
|
|
std::function<void(const InfoClientVec& clients)> clientsCall_;
|
|
|
|
|
std::function<void(const DirFileInfoVec& files)> fileCall_;
|
2025-06-14 23:25:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // CLIENTCORE_H
|