#ifndef CLIENTCORE_H #define CLIENTCORE_H #include <InfoClient.hpp> #include <InfoCommunicate.hpp> #include <InfoDirFile.hpp> #include <array> #include <cstdint> #include <memory> #include <vector> #include <wx/socket.h> #include <Communicate.h> #include <Util.h> class ClientCore : public wxEvtHandler { public: ClientCore(); public: bool Connect(const wxString& host, uint16_t port); void Disconnect(); public: bool GetOnlineList(InfoClientVec& infoClientVec); bool AskDirectory(const wxString& id, const wxString& path, DirFileInfoVec& dirInfoVec); private: void UseFrame(FrameBuffer* buf); private: void OnSocketEvent(wxSocketEvent& event); private: void HeartBeat(); template <typename T> bool Send(const T& info, FrameBufferType type) { std::stringstream ss; cereal::BinaryOutputArchive archive(ss); archive(info); auto buf = std::make_shared<FrameBuffer>(); buf->dataConst = ss.view().data(); buf->len = ss.str().size(); buf->dataType = type; return Send(buf.get()); } bool Send(FrameBuffer* buf); private: wxString id_; bool thRun_; MutBuffer buffer_; std::array<char, GBUFFER_SIZE> buf_; std::shared_ptr<wxSocketClient> socket_; std::shared_ptr<wxThread> heartsThread_; }; #endif // CLIENTCORE_H