#ifndef CLIENTCORE_H #define CLIENTCORE_H #include #include #include #include #include #include #include #include #include #include #include #include #include class ClientCore : public QObject { Q_OBJECT public: ClientCore(QObject* parent = nullptr); ~ClientCore(); public: bool Connect(const QString& ip, quint16 port); void Disconnect(); bool Send(QSharedPointer frame); bool Send(const char* data, qint64 len); template bool Send(const T& info, FrameBufferType type, const QString& tid) { auto f = QSharedPointer::create(); f->tid = tid; f->data = infoPack(info); f->type = type; return Send(f); } private: void onReadyRead(); void onDisconnected(); private: void UseFrame(QSharedPointer frame); public: void SetClientsCall(const std::function& call); void SetPathCall(const std::function& call); void SetFileCall(const std::function& call); void SetFrameCall(FrameBufferType type, const std::function& call); void SetRemoteID(const QString& id); QString GetRemoteID(); public: QMutex conMutex_; QString ownID_; QString remoteID_; QTcpSocket* socket_; QByteArray recvBuffer_; LocalFile localFile_; std::function pathCall_; std::function clientsCall_; std::function fileCall_; std::array, 256> frameCall_; }; #endif // CLIENTCORE_H