2024-12-11 22:51:43 +08:00
|
|
|
#pragma once
|
2025-03-01 03:49:40 +08:00
|
|
|
#include <ColorConsole.hpp>
|
2025-01-21 14:39:38 +08:00
|
|
|
#include <chrono>
|
2024-12-12 22:43:24 +08:00
|
|
|
#include <cstdint>
|
2025-02-10 23:16:45 +08:00
|
|
|
#include <filecomplete.h>
|
2025-03-01 03:49:40 +08:00
|
|
|
#include <fmt/format.h>
|
2024-12-12 23:11:55 +08:00
|
|
|
#include <functional>
|
2025-01-21 14:39:38 +08:00
|
|
|
#include <iomanip>
|
2025-01-21 14:47:42 +08:00
|
|
|
#include <sstream>
|
2024-12-12 22:43:24 +08:00
|
|
|
|
2025-03-01 03:49:40 +08:00
|
|
|
#include "of_util.h"
|
|
|
|
|
2024-12-20 13:22:28 +08:00
|
|
|
constexpr size_t g_BuffSize = 102400;
|
|
|
|
const size_t MAX_FRAME_SIZE = 10 * g_BuffSize;
|
2024-12-14 11:57:33 +08:00
|
|
|
enum FrameType : int16_t {
|
|
|
|
TYPE_DEFAULT = 0,
|
|
|
|
TYPE_GET_LIST,
|
|
|
|
TYPE_DOWN_LIST,
|
|
|
|
TYPE_UP_LIST,
|
|
|
|
TYPE_CANCEL_LIST,
|
|
|
|
TYPE_OPEN_FILE,
|
2025-01-21 22:10:15 +08:00
|
|
|
TYPE_OPEN_FAILED,
|
2024-12-14 11:57:33 +08:00
|
|
|
TYPE_TRANS_FILE,
|
2024-12-14 16:20:25 +08:00
|
|
|
TYPE_TRANS_DONE,
|
2024-12-14 11:57:33 +08:00
|
|
|
TYPE_INTERRUPT,
|
|
|
|
TYPE_NO_HIT_TASK,
|
2024-12-18 13:55:56 +08:00
|
|
|
TYPE_WAITTING,
|
2024-12-18 16:55:32 +08:00
|
|
|
TYPE_HEARTS,
|
2024-12-18 22:04:54 +08:00
|
|
|
TYPE_OFFLINE,
|
2024-12-20 16:57:44 +08:00
|
|
|
TYPE_JUDGE_ACTIVE,
|
|
|
|
TYPE_REQUEST_UPDATE_LIST,
|
|
|
|
TYPE_CONFIRM_UPDATE_LIST,
|
|
|
|
TYPE_UNCONFIRM_UPDATE_LIST,
|
|
|
|
TYPE_DONE_UPDATE_LIST,
|
2025-01-21 22:10:15 +08:00
|
|
|
TYPE_BUSY_UPDATE_LIST,
|
2024-12-21 23:24:18 +08:00
|
|
|
TYPE_FAILED_UPDATE_LIST,
|
2025-01-07 12:07:43 +08:00
|
|
|
TYPE_GET_ID,
|
2025-04-07 16:41:28 +08:00
|
|
|
TYPE_FILE_INFO,
|
|
|
|
TYPE_GET_DIRFILES,
|
|
|
|
TYPE_GET_DIRFILES_DONE,
|
|
|
|
TYPE_GET_DIRFILES_FAILED,
|
2024-12-14 11:57:33 +08:00
|
|
|
};
|
2024-12-11 10:22:14 +08:00
|
|
|
|
2024-12-11 17:00:59 +08:00
|
|
|
using namespace ofen;
|
|
|
|
class CFrameBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CFrameBuffer();
|
|
|
|
~CFrameBuffer();
|
2024-12-13 12:35:08 +08:00
|
|
|
|
2024-12-12 23:11:55 +08:00
|
|
|
public:
|
2024-12-14 11:57:33 +08:00
|
|
|
std::string fid_{};
|
|
|
|
std::string tid_{};
|
2024-12-12 22:43:24 +08:00
|
|
|
|
2024-12-11 22:51:43 +08:00
|
|
|
public:
|
2024-12-14 11:57:33 +08:00
|
|
|
FrameType type_{};
|
2024-12-11 22:51:43 +08:00
|
|
|
char* data_{};
|
|
|
|
int len_{};
|
2024-12-12 22:43:24 +08:00
|
|
|
char mark_{};
|
2024-12-11 17:00:59 +08:00
|
|
|
};
|
2025-03-01 03:49:40 +08:00
|
|
|
|
2024-12-12 23:11:55 +08:00
|
|
|
using ExFun_t = std::function<void(CFrameBuffer* buf)>;
|
2024-12-11 17:00:59 +08:00
|
|
|
/*
|
|
|
|
【 transm TCP 数据协议 】
|
|
|
|
header 2 char: 0xFF 0xFE
|
2024-12-12 22:43:24 +08:00
|
|
|
type 2 char:
|
|
|
|
mark 1 char:
|
2024-12-14 16:20:25 +08:00
|
|
|
from 32 char:
|
|
|
|
to 32 char:
|
2024-12-11 17:00:59 +08:00
|
|
|
len 4 char:
|
|
|
|
data xxxxx:
|
|
|
|
tail 2 char: 0xFF 0xFF
|
|
|
|
*/
|
|
|
|
class CTransProtocal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTransProtocal();
|
|
|
|
~CTransProtocal();
|
2024-12-12 22:43:24 +08:00
|
|
|
|
2024-12-11 17:00:59 +08:00
|
|
|
public:
|
2024-12-11 22:51:43 +08:00
|
|
|
static CFrameBuffer* parse(CMutBuffer& buffer);
|
|
|
|
static bool pack(CFrameBuffer* buf, char** out_buf, int& len);
|
2025-01-07 12:07:43 +08:00
|
|
|
static void display_progress(float percent);
|
2024-12-13 16:59:31 +08:00
|
|
|
};
|
2025-01-21 14:39:38 +08:00
|
|
|
|
|
|
|
inline std::string now_str()
|
|
|
|
{
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
|
auto time_t_now = std::chrono::system_clock::to_time_t(now);
|
|
|
|
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
|
|
|
|
|
|
|
|
std::ostringstream timestamp;
|
|
|
|
timestamp << std::put_time(std::localtime(&time_t_now), "[%Y-%m-%d %H:%M:%S") << "." << std::setfill('0')
|
|
|
|
<< std::setw(3) << milliseconds.count() << "] ";
|
|
|
|
|
|
|
|
return timestamp.str();
|
2025-02-24 17:43:58 +08:00
|
|
|
}
|
|
|
|
|
2025-03-01 03:49:40 +08:00
|
|
|
template <typename... Args> void TLOGI(const std::string& format, Args&&... args)
|
2025-02-24 17:43:58 +08:00
|
|
|
{
|
|
|
|
fc_lock_print();
|
2025-03-01 03:49:40 +08:00
|
|
|
std::cout << ConsoleColor::Green << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
2025-02-24 17:43:58 +08:00
|
|
|
fc_unlock_print();
|
|
|
|
}
|
|
|
|
|
2025-03-01 03:49:40 +08:00
|
|
|
template <typename... Args> void TLOGW(const std::string& format, Args&&... args)
|
2025-02-24 17:43:58 +08:00
|
|
|
{
|
|
|
|
fc_lock_print();
|
2025-03-01 03:49:40 +08:00
|
|
|
std::cout << ConsoleColor::Yellow << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
2025-02-24 17:43:58 +08:00
|
|
|
fc_unlock_print();
|
|
|
|
}
|
|
|
|
|
2025-03-01 03:49:40 +08:00
|
|
|
template <typename... Args> void TLOGE(const std::string& format, Args&&... args)
|
2025-02-24 17:43:58 +08:00
|
|
|
{
|
|
|
|
fc_lock_print();
|
2025-03-01 03:49:40 +08:00
|
|
|
std::cout << ConsoleColor::Red << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
2025-02-24 17:43:58 +08:00
|
|
|
fc_unlock_print();
|
|
|
|
}
|
|
|
|
|
2025-03-01 03:49:40 +08:00
|
|
|
template <typename... Args> void TLOGD(const std::string& format, Args&&... args)
|
2025-02-24 17:43:58 +08:00
|
|
|
{
|
|
|
|
fc_lock_print();
|
2025-03-01 03:49:40 +08:00
|
|
|
std::cout << ConsoleColor::Cyan << fmt::format(now_str() + format, std::forward<Args>(args)...) << std::endl;
|
2025-02-24 17:43:58 +08:00
|
|
|
fc_unlock_print();
|
2025-01-21 14:39:38 +08:00
|
|
|
}
|