You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef TPAS_APPPROTOCOL_H__
#define TPAS_APPPROTOCOL_H__
#include <QMap>
#include <QString>
enum emTPAS_TOKS{
TOK_UNKNOWN = 0,
TOK_HEARTBEAT,
TOK_CK_DISK_SPACE,
TOK_COPY_FOLDER,
TOK_CLOSE_CLIENT_APP,
TOK_COMPRESS,
TOK_UNCOMPRESS,
};
class CIPCHeartBeat{
private:
emTPAS_TOKS m_cmd;
public:
QString m_appName;
qint64 m_time;
CIPCHeartBeat()
: m_cmd(TOK_HEARTBEAT)
{}
CIPCHeartBeat(const QJsonObject& jsobj)
: m_cmd(TOK_HEARTBEAT)
{
m_appName = jsobj["app_name"].toString("");
m_time = jsobj["time"].toInt(QDateTime::currentMSecsSinceEpoch());
}
void toJsonObj(QJsonObject& jsobj) const {
jsobj = QJsonObject();
jsobj["cmd"] = m_cmd;
jsobj["app_name"] = m_appName;
jsobj["time"] = m_time;
}
};
class CIPCCheckDiskSpace{
private:
emTPAS_TOKS m_cmd;
public:
QString m_diskTarget; // like"D:","D:/","D:\\Program Files", "\\\\server\\share"
double m_total; // resp in GB
double m_free; // resp in GB
double m_avail; // resp in GB
double m_used; // resp in GB
CIPCCheckDiskSpace()
: m_cmd(TOK_CK_DISK_SPACE)
{}
CIPCCheckDiskSpace(const QJsonObject& jsobj)
: m_cmd(TOK_CK_DISK_SPACE)
{
m_diskTarget = jsobj["disk_target"].toString("D");
m_total = jsobj["total_space"].toDouble(0.0f);
m_free = jsobj["free_space"].toDouble(0.0f);
m_avail = jsobj["avalible_space"].toDouble(0.0f);
m_used = jsobj["used_space"].toDouble(0.0f);
}
void toJsonObj(QJsonObject& jsobj) const {
jsobj = QJsonObject();
jsobj["cmd"] = m_cmd;
jsobj["disk_target"] = m_diskTarget;
jsobj["total_space"] = m_total;
jsobj["free_space"] = m_free;
jsobj["avalible_space"] = m_avail;
jsobj["used_space"] = m_used;
}
};
class CIPCCopyFolder{
private:
emTPAS_TOKS m_cmd;
public:
QString m_srcFolder;
QString m_dstFolder;
bool m_needReply;
bool m_result; // resp true:copy complete false:error occur
QString m_error; // resp error detail
CIPCCopyFolder()
: m_cmd(TOK_COPY_FOLDER)
{}
CIPCCopyFolder(const QJsonObject& jsobj)
: m_cmd(TOK_COPY_FOLDER)
{
m_srcFolder = jsobj["src_folder"].toString("");
m_dstFolder = jsobj["dst_folder"].toString("");
m_needReply = jsobj["need_reply"].toBool(false);
m_result = jsobj["result"].toBool(false);
m_error = jsobj["error"].toString("");
}
void toJsonObj(QJsonObject& jsobj) const {
jsobj = QJsonObject();
jsobj["cmd"] = m_cmd;
jsobj["src_folder"] = m_srcFolder;
jsobj["dst_folder"] = m_dstFolder;
jsobj["need_reply"] = m_needReply;
jsobj["result"] = m_result;
jsobj["error"] = m_error;
}
};
class CIPCClientClose{
private:
emTPAS_TOKS m_cmd;
public:
CIPCClientClose()
: m_cmd(TOK_CLOSE_CLIENT_APP)
{}
CIPCClientClose(const QJsonObject& jsobj)
: m_cmd(TOK_CLOSE_CLIENT_APP)
{
}
void toJsonObj(QJsonObject& jsobj) const {
jsobj = QJsonObject();
jsobj["cmd"] = m_cmd;
}
};
/*
* @brief 压缩文件或文件夹src和dst都是完整路径
* 源和目标的路径可以是本地路径,也可以是网络路径。但必须可到达,并且有权限。
* 比如D:\\LeaperWork\\git\\tadpole, \\\\server\\share\\bbb\\quatest.zip
* 如果目标文件的目录不存在则试着创建创建失败则返回error
*/
class CIPCCompress{
private:
emTPAS_TOKS m_cmd;
public:
QString m_src; // 要压缩的文件或者文件夹。
QString m_dst; // 生成的压缩文件一般以zip为后缀
int m_result; // 0:ok 1:src error 2:dst error 3:zip err
CIPCCompress()
: m_cmd(TOK_COMPRESS)
{}
CIPCCompress(const QJsonObject& jsobj)
: m_cmd(TOK_COMPRESS)
{
m_src = jsobj["src"].toString("");
m_dst = jsobj["dst"].toString("");
m_result = jsobj["result"].toInt(-1);
}
void toJsonObj(QJsonObject& jsobj) const {
jsobj = QJsonObject();
jsobj["cmd"] = m_cmd;
jsobj["src"] = m_src;
jsobj["dst"] = m_dst;
jsobj["result"] = m_result;
}
};
class CIPCUnCompress : public CIPCCompress
{
private:
emTPAS_TOKS m_cmd;
public:
CIPCUnCompress()
: m_cmd(TOK_UNCOMPRESS)
{}
CIPCUnCompress(const QJsonObject& jsobj)
: CIPCCompress(jsobj)
, m_cmd(TOK_UNCOMPRESS)
{
}
void toJsonObj(QJsonObject& jsobj) const {
jsobj = QJsonObject();
CIPCCompress::toJsonObj(jsobj);
jsobj["cmd"] = m_cmd;
}
};
#endif //TPAS_APPPROTOCOL_H__