COMPASSi/trunk/code/projects/Application/MessageHandle.cpp

66 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma execution_character_set("utf-8")
#include "MessageHandle.h"
#include <QString>
#include <QDebug>
#include <nlohmann/json.hpp>
#include "IniFileManager.h"
#include "Chinese_English_bullet_box.h"
ccsMessageHandle::ccsMessageHandle()
{
}
ccsMessageHandle::~ccsMessageHandle()
{
}
void ccsMessageHandle::web2qt(const int &cmd, const QString &data)
{
if (m_cmd2func.contains(cmd))
{
// qDebug() << data;
m_cmd2func[cmd](data);
// 执行完毕获取返回结果通过map映射根据该函数的处理代码返回查询对应的错误信息然后将信息返回到网页端。
}
}
void ccsMessageHandle::register_callback(const std::function<void(QString)> &func, const int &functionID)
{
m_cmd2func[functionID] = func;
}
void ccsMessageHandle::unregister_callback(const int &functionID)
{
m_cmd2func.remove(functionID);
}
void ccsMessageHandle::qt2web(int cmd, int errorCode, QString msg, QString data)
{
QString jsonMsg = ccsMessageHandle::instance()->createMsg(cmd, errorCode,msg,data);
ccsMessageHandle::instance()->qt2web(cmd, jsonMsg);
}
QString ccsMessageHandle::createMsg(int cmd, int errorCode, const QString &msg, QString data)
{
QString code = QString("%1_%2").arg(errorCode).arg(cmd);
nlohmann::json json, jsonData;
string strRet = msg.toStdString();
if(!strRet.empty())
{
//路径在这里部支持
//int iLange = IniFileManager::getInstance().getLanguage();
//strRet = Chinese_English_bullet_box::getInstance().get_Bullet_box_array(strRet,iLange);
}
json["msg"] = strRet;
json["code"] = code.toStdString();
if (!data.isEmpty())
json["data"]=jsonData.parse(data.toStdString());
else
json["data"]=jsonData;
return QString::fromStdString(json.dump());
}