DIOS.Dev.MSG_V3.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // DIOS.Dev.FPDDeviceMould.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "DIOS.Dev.MSG_V3.hpp"
  4. #include "MessageInfo.tlh"
  5. #include "MessageInfo.tli"
  6. //#include "Base64.h"
  7. #include "PlatformInteraction.h"
  8. namespace DIOS::Dev::Detail
  9. {
  10. MSGUnit::MSGUnit(std::string strPath)
  11. {
  12. m_pDevicePath = strPath;
  13. }
  14. MSGUnit:: ~MSGUnit()
  15. {}
  16. std::string MSGUnit::JSGet()
  17. {
  18. return m_ErrorList;
  19. }
  20. std::string MSGUnit::GetKey()
  21. {
  22. return Key;
  23. }
  24. std::wstring mb2wc(const char* mbstr)
  25. {
  26. std::wstring strVal;
  27. int size = MultiByteToWideChar(CP_UTF8, 0, mbstr, -1, NULL, 0);
  28. wchar_t* wcstr = new wchar_t[size + 1];
  29. if (wcstr)
  30. {
  31. memset(wcstr, 0, size * sizeof(wchar_t));
  32. int ret = MultiByteToWideChar(CP_UTF8, 0, mbstr, -1, wcstr, size);
  33. if (ret != 0) // MultiByteToWideChar returns 0 if it does not succeed.
  34. {
  35. strVal = wcstr;
  36. }
  37. delete[] wcstr;
  38. wcstr = NULL;
  39. }
  40. return strVal;
  41. }
  42. int MSGUnit::AddMessage(const char* Code, int& Level, const char* ResInfo, int nMessageType, int nSenderID)
  43. {
  44. if (Code == 0 || (string)ResInfo == "")
  45. {
  46. return 1;
  47. }
  48. ResDataObject tempErrorList;
  49. if (m_ErrorList != "")
  50. {
  51. tempErrorList.decode(m_ErrorList.c_str());
  52. }
  53. MessageInfo info;
  54. info.CodeID = Code;
  55. info.Type = nMessageType;
  56. info.Level = Level;
  57. info.Resouceinfo = ResInfo;
  58. info.Description = "";
  59. int ret = 1;
  60. for (size_t i = 0; i < tempErrorList.size(); i++)
  61. {
  62. string strCodekey = tempErrorList.GetKey(i);
  63. string strtype = tempErrorList[strCodekey.c_str()]["Type"];
  64. if (strCodekey == (string)Code && atoi(strtype.c_str()) == nMessageType)
  65. {//Same Code:%s with MessageType:%d already Exist
  66. ret = 0;
  67. break;
  68. }
  69. }
  70. if (ret == 1)
  71. {
  72. ResDataObject ErrorInfo, tempInfo;
  73. info.GetResDataObject(tempInfo);
  74. if (0 != nSenderID)
  75. {
  76. string strSenderID = std::to_string(nSenderID);
  77. tempInfo.add("SenderId", strSenderID.c_str());
  78. }
  79. if (nMessageType == ERRORTYPE)//只有错误会增加到错误列表中,警告通知上层即可
  80. {
  81. tempErrorList.add(Code, tempInfo);
  82. m_ErrorList = tempErrorList.encode();
  83. }
  84. ErrorInfo.add(Code, tempInfo);
  85. PlatformInterface::DIOSNotifyCallBackEntry(PACKET_CMD::PACKET_CMD_UPDATE, "ErrorList", ErrorInfo.encode(), m_pDevicePath);
  86. }
  87. return 2;
  88. }
  89. int MSGUnit::DelMessage(const char* Code, int &Level, const char* ResInfo, int nMessageType)
  90. {
  91. ResDataObject tempErrorList;
  92. if (m_ErrorList != "")
  93. {
  94. tempErrorList.decode(m_ErrorList.c_str());
  95. }
  96. else
  97. {
  98. return 0;
  99. }
  100. ResDataObject ErrorInfo, tempInfo;
  101. MessageInfo info;
  102. info.CodeID = Code;
  103. info.Type = nMessageType;
  104. info.Level = Level;
  105. info.Resouceinfo = ResInfo;
  106. info.Description = "";
  107. info.GetResDataObject(tempInfo);
  108. ErrorInfo.add(Code, tempInfo);
  109. bool m_bClearAll = false;
  110. if ((string)Code == "0" || (string)Code == "")
  111. {
  112. m_bClearAll = true;
  113. }
  114. if (m_bClearAll)
  115. {
  116. m_ErrorList ="";
  117. PlatformInterface::DIOSNotifyCallBackEntry(PACKET_CMD::PACKET_CMD_UPDATE, "ErrorList", ErrorInfo.encode(), m_pDevicePath);
  118. }
  119. else
  120. {
  121. int ret = 1;
  122. for (size_t i = 0; i < tempErrorList.size(); i++)
  123. {
  124. string strCodekey = tempErrorList.GetKey(i);
  125. string strtype = tempErrorList[strCodekey.c_str()]["Type"];
  126. if (strCodekey == (string)Code && atoi(strtype.c_str()) == nMessageType)
  127. {
  128. ret = 0;
  129. break;
  130. }
  131. }
  132. if (ret == 0)
  133. {
  134. tempErrorList.eraseAllOf(Code);
  135. m_ErrorList = tempErrorList.encode();
  136. PlatformInterface::DIOSNotifyCallBackEntry(PACKET_CMD::PACKET_CMD_UPDATE, "ErrorList", ErrorInfo.encode(), m_pDevicePath);
  137. }
  138. }
  139. return 2;
  140. }
  141. int MSGUnit::AddWarnMessage(const char* Code, int& Level, const char* ResInfo, int nSenderID)
  142. {
  143. return AddMessage(Code, Level, ResInfo, WARNTYPE, nSenderID);
  144. }
  145. int MSGUnit::DelWarnMessage(const char* Code, int& Level, const char* ResInfo)
  146. {
  147. ResDataObject /*ResNotify,*/ ErrorInfo, tempInfo;
  148. MessageInfo info;
  149. info.CodeID = Code;
  150. info.Type = WARNTYPE;
  151. info.Level = Level;
  152. info.Resouceinfo = ResInfo;
  153. info.Description = "";
  154. info.GetResDataObject(tempInfo);
  155. ErrorInfo.add(Code, tempInfo);
  156. PlatformInterface::DIOSNotifyCallBackEntry(PACKET_CMD::PACKET_CMD_UPDATE, "ErrorList", ErrorInfo.encode(), m_pDevicePath);
  157. return 2;
  158. }
  159. int MSGUnit::AddErrorMessage(const char* Code, int& Level, const char* ResInfo, int nSenderID)
  160. {
  161. return AddMessage(Code, Level, ResInfo, ERRORTYPE, nSenderID);
  162. }
  163. int MSGUnit::DelErrorMessage(const char* Code, int& Level, const char* ResInfo)
  164. {
  165. return DelMessage(Code, Level, ResInfo, ERRORTYPE);
  166. }
  167. }