VTrain/interface/ToWeb.h

57 lines
1.5 KiB
C++

#ifndef ToWeb_H_
#define ToWeb_H_
#include "json/json.h"
#include "httplib.h"
#include "AppCommon.h"
namespace ai_matrix
{
class ToWeb final
{
public:
static ToWeb *getins();
std::string webToken; //授权信息
HttpServerConfig httpConfig_;
void setConfig(const HttpServerConfig &httpConfig);
bool getToken();
// 列车信息提交http接口
bool upWeb(const Json::Value &jvRequest, int retransmission = 0);
// 上传车号识别状态
bool upDeviceStatus(const Json::Value &jvRequest, int retransmission = 0);
// 获取火车状态(仅程序运行时运行一次)
bool getTrainStatus(const std::string &strPoundNo, Json::Value &jvResponse, int retransmission = 0);
private:
ToWeb() = default;
ToWeb(const ToWeb &) = delete;
ToWeb(ToWeb &&) = delete;
ToWeb &operator=(const ToWeb &) = delete;
ToWeb &operator=(ToWeb &&) = delete;
~ToWeb() = default;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (ToWeb::ins)
{
delete ToWeb::ins;
ToWeb::ins = nullptr;
}
}
};
static GarbageCollector gc;
static ToWeb *ins;
static std::mutex mx; //锁,保证线程安全
};
}
#endif