66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
#pragma once
|
|
#include <net_base.h>
|
|
#include <util.h>
|
|
#include <vector>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include "file_oper.h"
|
|
#include <of_util.h>
|
|
|
|
using namespace ofen;
|
|
struct DownClientInfo {
|
|
std::vector<std::string> files;
|
|
std::string id;
|
|
};
|
|
|
|
enum TransState {
|
|
TRANS_FAILE,
|
|
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_FAILE};
|
|
};
|
|
|
|
class CClient
|
|
{
|
|
public:
|
|
CClient(const std::shared_ptr<spdlog::logger>& logger);
|
|
~CClient();
|
|
|
|
public:
|
|
void run(const std::string& ip, const std::string& port);
|
|
|
|
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 cancel_trans_file(const std::string& key = "");
|
|
|
|
private:
|
|
bool send_frame(CFrameBuffer* buf);
|
|
|
|
private:
|
|
void handle_frame(CFrameBuffer* buf);
|
|
void send_file_data_th();
|
|
|
|
private:
|
|
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::map<std::string, std::shared_ptr<TransInfomation>> up_;
|
|
std::mutex mutex_;
|
|
std::shared_ptr<CThreadPool> send_pool_;
|
|
std::string work_key_;
|
|
}; |