// DIOS.Dev.FPDDeviceMould.cpp : 定义 DLL 应用程序的导出函数。 // #include "stdafx.h" #include "DIOS.Dev.MSGMould.hpp" #include "MessageInfo.tlh" #include "MessageInfo.tli" namespace DIOS::Dev::Detail { MSGUnit::MSGUnit(std::shared_ptr center, std::string DevInstance) { m_DevInstance = DevInstance; m_Eventcenter = center; } MSGUnit:: ~MSGUnit() { } std::string MSGUnit::JSGet() { return m_ErrorList; } std::string MSGUnit::GetKey() { return Key; } int MSGUnit::AddMessage(const char* Code, int &Level, const char* ResInfo, int nMessageType) { if (Code == 0 || (string)ResInfo == "") { return 1; } ResDataObject tempErrorList; if (m_ErrorList != "") { tempErrorList.decode(m_ErrorList.c_str()); } MessageInfo info; info.CodeID = Code; info.Type = nMessageType; info.Level = Level; info.Resouceinfo = ResInfo; info.Description = ""; int ret = 1; for (size_t i = 0; i < tempErrorList.size(); i++) { string strCodekey = tempErrorList.GetKey(i); string strtype = tempErrorList[strCodekey.c_str()]["Type"]; if (strCodekey == (string)Code && atoi(strtype.c_str()) == nMessageType) {//Same Code:%s with MessageType:%d already Exist ret = 0; break; } } if (ret == 1) { ResDataObject ResNotify, ErrorInfo, tempInfo; info.GetResDataObject(tempInfo); if (nMessageType == ERRORTYPE)//只有错误会增加到错误列表中,警告通知上层即可 { tempErrorList.add(Code, tempInfo); m_ErrorList = tempErrorList.encode(); } ErrorInfo.add(Code, tempInfo); ResNotify.add(m_DevInstance.c_str(), ErrorInfo); m_Eventcenter->OnNotify(2, "ErrorList", ResNotify.encode()); } //put log here return 2; } int MSGUnit::DelMessage(const char* Code, int &Level, const char* ResInfo, int nMessageType) { ResDataObject tempErrorList; if (m_ErrorList != "") { tempErrorList.decode(m_ErrorList.c_str()); } else { return 0; } ResDataObject ResNotify, ErrorInfo, tempInfo; MessageInfo info; info.CodeID = Code; info.Type = nMessageType; info.Level = Level; info.Resouceinfo = ResInfo; info.Description = ""; info.GetResDataObject(tempInfo); ErrorInfo.add(Code, tempInfo); ResNotify.add(m_DevInstance.c_str(), ErrorInfo); bool m_bClearAll = false; if ((string)Code == "0" || (string)Code == "") { m_bClearAll = true; } if (m_bClearAll) { m_ErrorList =""; m_Eventcenter->OnNotify(3, "ErrorList", ResNotify.encode()); } else { int ret = 1; for (size_t i = 0; i < tempErrorList.size(); i++) { string strCodekey = tempErrorList.GetKey(i); string strtype = tempErrorList[strCodekey.c_str()]["Type"]; if (strCodekey == (string)Code && atoi(strtype.c_str()) == nMessageType) { ret = 0; break; } } if (ret == 0) { tempErrorList.eraseAllOf(Code); m_ErrorList = tempErrorList.encode(); m_Eventcenter->OnNotify(3, "ErrorList", ResNotify.encode()); } } return 2; } int MSGUnit::AddWarnMessage(const char* Code, int& Level, const char* ResInfo) { return AddMessage(Code, Level, ResInfo, WARNTYPE); } int MSGUnit::DelWarnMessage(const char* Code, int& Level, const char* ResInfo) { return DelMessage(Code, Level, ResInfo, WARNTYPE); } int MSGUnit::AddErrorMessage(const char* Code, int& Level, const char* ResInfo) { return AddMessage(Code, Level, ResInfo, ERRORTYPE); } int MSGUnit::DelErrorMessage(const char* Code, int& Level, const char* ResInfo) { return DelMessage(Code, Level, ResInfo, ERRORTYPE); } }