// 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; } std::wstring mb2wc(const char* mbstr) { std::wstring strVal; int size = MultiByteToWideChar(CP_UTF8, 0, mbstr, -1, NULL, 0); wchar_t* wcstr = new wchar_t[size + 1]; if (wcstr) { memset(wcstr, 0, size * sizeof(wchar_t)); int ret = MultiByteToWideChar(CP_UTF8, 0, mbstr, -1, wcstr, size); if (ret != 0) // MultiByteToWideChar returns 0 if it does not succeed. { strVal = wcstr; } delete[] wcstr; wcstr = NULL; } return strVal; } int MSGUnit::AddMessage(const char* Code, int& Level, const char* ResInfo, int nMessageType, int nSenderID) { 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 ErrorInfo, tempInfo; info.GetResDataObject(tempInfo); if (0 != nSenderID) { string strSenderID = std::to_string(nSenderID); tempInfo.add("SenderId", strSenderID.c_str()); } if (nMessageType == ERRORTYPE)//只有错误会增加到错误列表中,警告通知上层即可 { tempErrorList.add(Code, tempInfo); m_ErrorList = tempErrorList.encode(); } ErrorInfo.add(Code, tempInfo); m_Eventcenter->OnNotify(2, "ErrorList", ErrorInfo.encode()); } 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; } bool m_bClearAll = false; ResDataObject ErrorInfo, tempInfo; MessageInfo info; if (strcmp(Code, "0") == 0 || strlen(Code) == 0) { info.CodeID = ""; m_bClearAll = true; } else { info.CodeID = Code; } info.Type = nMessageType; info.Level = Level; info.Resouceinfo = ResInfo; info.Description = ""; info.GetResDataObject(tempInfo); ErrorInfo.add(Code, tempInfo); if (m_bClearAll) { m_ErrorList = ""; m_Eventcenter->OnNotify(3, "ErrorList", ErrorInfo.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", ErrorInfo.encode()); } } return 2; } int MSGUnit::AddWarnMessage(const char* Code, int& Level, const char* ResInfo, int nSenderID) { return AddMessage(Code, Level, ResInfo, WARNTYPE, nSenderID); } int MSGUnit::DelWarnMessage(const char* Code, int& Level, const char* ResInfo) { ResDataObject ErrorInfo, tempInfo; MessageInfo info; info.CodeID = Code; info.Type = WARNTYPE; info.Level = Level; info.Resouceinfo = ResInfo; info.Description = ""; info.GetResDataObject(tempInfo); ErrorInfo.add(Code, tempInfo); m_Eventcenter->OnNotify(3, "ErrorList", ErrorInfo.encode()); return 2; } int MSGUnit::AddErrorMessage(const char* Code, int& Level, const char* ResInfo, int nSenderID) { return AddMessage(Code, Level, ResInfo, ERRORTYPE, nSenderID); } int MSGUnit::DelErrorMessage(const char* Code, int& Level, const char* ResInfo) { return DelMessage(Code, Level, ResInfo, ERRORTYPE); } }