RelayFile/ClientCore/ClientCore.h

60 lines
1.3 KiB
C
Raw Normal View History

2025-05-05 23:22:43 +08:00
#ifndef CLIENTCORE_H
#define CLIENTCORE_H
2025-05-08 21:13:36 +08:00
#include <InfoClient.hpp>
2025-05-10 21:43:25 +08:00
#include <InfoCommunicate.hpp>
2025-05-08 21:13:36 +08:00
#include <InfoDirFile.hpp>
2025-05-10 21:43:25 +08:00
#include <Communicate.h>
#include <array>
2025-05-06 23:21:10 +08:00
#include <cstdint>
#include <memory>
#include <vector>
#include <wx/socket.h>
2025-05-10 21:43:25 +08:00
#include <Util.h>
2025-05-06 23:21:10 +08:00
class ClientCore : public wxEvtHandler
2025-05-05 23:22:43 +08:00
{
public:
ClientCore();
2025-05-06 23:21:10 +08:00
public:
bool Connect(const wxString& host, uint16_t port);
void Disconnect();
public:
2025-05-08 21:13:36 +08:00
bool GetOnlineList(InfoClientVec& infoClientVec);
bool AskDirectory(const wxString& id, const wxString& path, DirFileInfoVec& dirInfoVec);
2025-05-06 23:21:10 +08:00
2025-05-10 21:43:25 +08:00
private:
void UseFrame(FrameBuffer* buf);
2025-05-06 23:21:10 +08:00
private:
void OnSocketEvent(wxSocketEvent& event);
private:
void HeartBeat();
2025-05-10 21:43:25 +08:00
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);
2025-05-06 23:21:10 +08:00
private:
wxString id_;
2025-05-10 21:43:25 +08:00
bool thRun_;
MutBuffer buffer_;
std::array<char, GBUFFER_SIZE> buf_;
2025-05-06 23:21:10 +08:00
std::shared_ptr<wxSocketClient> socket_;
std::shared_ptr<wxThread> heartsThread_;
2025-05-05 23:22:43 +08:00
};
#endif // CLIENTCORE_H