transm/client/client.h

72 lines
1.7 KiB
C
Raw Normal View History

2024-12-11 23:23:48 +08:00
#pragma once
#include "file_oper.h"
#include <memory>
#include <mutex>
2024-12-11 23:23:48 +08:00
#include <net_base.h>
#include <of_util.h>
#include <string>
2024-12-11 23:23:48 +08:00
#include <util.h>
#include <vector>
using namespace ofen;
struct DownClientInfo {
std::vector<std::string> files;
std::string id;
};
enum TransState {
TRANS_FAILED,
TRANS_ING,
TRANS_REDAY,
TRANS_DONE
};
struct TransInfomation {
std::string cur_remote_id_;
std::string cur_remote_file_;
std::string cur_file_;
FILE* file_{};
TransState trans_state_{TRANS_FAILED};
};
2024-12-11 23:23:48 +08:00
class CClient
{
public:
CClient(const std::shared_ptr<spdlog::logger>& logger);
~CClient();
public:
void run(const std::string& ip, const std::string& port);
2024-12-11 23:23:48 +08:00
public:
bool get_task_list();
bool down_task(const std::string& param);
bool up_task(const std::string& cmd);
bool cancel_task();
bool down_one_file(const std::string& id, const std::string& file);
void report_trans_ret(TransState state, const std::string& key = "");
private:
bool send_frame(CFrameBuffer* buf);
private:
void handle_frame(CFrameBuffer* buf);
void send_file_data_th(const char* keys);
void hearts();
2024-12-11 23:23:48 +08:00
private:
std::mutex mutex_;
std::mutex send_mut_;
std::string work_key_;
std::thread hearts_;
CThreadSleep sleep_;
bool th_run_{false};
2024-12-11 23:23:48 +08:00
std::shared_ptr<spdlog::logger> logger_;
asio::io_context io_context_;
std::shared_ptr<CTcpClient> client_;
std::vector<std::string> supported_;
std::map<int, std::shared_ptr<DownClientInfo>> task_list_;
std::shared_ptr<TransInfomation> down_;
std::vector<std::thread> ths_;
std::map<std::string, std::shared_ptr<TransInfomation>> up_;
2024-12-11 23:23:48 +08:00
};