// CCOS.Dev.FPDDeviceMould.cpp : 定义 DLL 应用程序的导出函数。 // #include "stdafx.h" #include "CCOS.Dev.MSGMould.hpp" #include "MessageInfo.tlh" #include "MessageInfo.tli" //#include "Base64.h" namespace CCOS::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; } //string strBase64; //wstring wResUTF = mb2wc(ResInfo); //CBase64::Encode((const unsigned char*)wResUTF.c_str(), (unsigned long)wResUTF.size() * sizeof(wchar_t), strBase64); 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 (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); //ResNotify.add(m_DevInstance.c_str(), ErrorInfo); //ResNotify.add(Code, ErrorInfo);//for json format unique key when multi-error in list //ResNotify.add(m_DevInstance.c_str(), ErrorInfo); //m_Eventcenter->OnNotify(2, "ErrorList", ResNotify.encode()); m_Eventcenter->OnNotify(2, "ErrorList", ErrorInfo.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); //ResNotify.add(Code, ErrorInfo);//for json format unique key when multi-error in list // 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()); 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", ResNotify.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 /*ResNotify,*/ 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); //ResNotify.add(m_DevInstance.c_str(), ErrorInfo); 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); } }