60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#ifndef CLIENTCORE_H
|
|
#define CLIENTCORE_H
|
|
|
|
#include <InfoClient.hpp>
|
|
#include <InfoCommunicate.hpp>
|
|
#include <InfoDirFile.hpp>
|
|
#include <Communicate.h>
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <wx/socket.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)
|
|
{
|
|
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();
|
|
|
|
return Send(wxSock, 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
|