DIOS.Dev.MSGMould.cpp 4.5 KB

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