DIOS.Dev.MSGMould.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. int MSGUnit::AddMessage(const char* Code, int &Level, const char* ResInfo, int nMessageType)
  26. {
  27. if (Code == 0 || (string)ResInfo == "")
  28. {
  29. return 1;
  30. }
  31. ResDataObject tempErrorList;
  32. if (m_ErrorList != "")
  33. {
  34. tempErrorList.decode(m_ErrorList.c_str());
  35. }
  36. MessageInfo info;
  37. info.CodeID = Code;
  38. info.Type = nMessageType;
  39. info.Level = Level;
  40. info.Resouceinfo = ResInfo;
  41. info.Description = "";
  42. int ret = 1;
  43. for (size_t i = 0; i < tempErrorList.size(); i++)
  44. {
  45. string strCodekey = tempErrorList.GetKey(i);
  46. string strtype = tempErrorList[strCodekey.c_str()]["Type"];
  47. if (strCodekey == (string)Code && atoi(strtype.c_str()) == nMessageType)
  48. {//Same Code:%s with MessageType:%d already Exist
  49. ret = 0;
  50. break;
  51. }
  52. }
  53. if (ret == 1)
  54. {
  55. ResDataObject ResNotify, ErrorInfo, tempInfo;
  56. info.GetResDataObject(tempInfo);
  57. if (nMessageType == ERRORTYPE)//只有错误会增加到错误列表中,警告通知上层即可
  58. {
  59. tempErrorList.add(Code, tempInfo);
  60. m_ErrorList = tempErrorList.encode();
  61. }
  62. ErrorInfo.add(Code, tempInfo);
  63. ResNotify.add(m_DevInstance.c_str(), ErrorInfo);
  64. m_Eventcenter->OnNotify(2, "ErrorList", ResNotify.encode());
  65. }
  66. //put log here
  67. return 2;
  68. }
  69. int MSGUnit::DelMessage(const char* Code, int &Level, const char* ResInfo, int nMessageType)
  70. {
  71. ResDataObject tempErrorList;
  72. if (m_ErrorList != "")
  73. {
  74. tempErrorList.decode(m_ErrorList.c_str());
  75. }
  76. else
  77. {
  78. return 0;
  79. }
  80. ResDataObject ResNotify, ErrorInfo, tempInfo;
  81. MessageInfo info;
  82. info.CodeID = Code;
  83. info.Type = nMessageType;
  84. info.Level = Level;
  85. info.Resouceinfo = ResInfo;
  86. info.Description = "";
  87. info.GetResDataObject(tempInfo);
  88. ErrorInfo.add(Code, tempInfo);
  89. ResNotify.add(m_DevInstance.c_str(), ErrorInfo);
  90. bool m_bClearAll = false;
  91. if ((string)Code == "0" || (string)Code == "")
  92. {
  93. m_bClearAll = true;
  94. }
  95. if (m_bClearAll)
  96. {
  97. m_ErrorList ="";
  98. m_Eventcenter->OnNotify(3, "ErrorList", ResNotify.encode());
  99. }
  100. else
  101. {
  102. int ret = 1;
  103. for (size_t i = 0; i < tempErrorList.size(); i++)
  104. {
  105. string strCodekey = tempErrorList.GetKey(i);
  106. string strtype = tempErrorList[strCodekey.c_str()]["Type"];
  107. if (strCodekey == (string)Code && atoi(strtype.c_str()) == nMessageType)
  108. {
  109. ret = 0;
  110. break;
  111. }
  112. }
  113. if (ret == 0)
  114. {
  115. tempErrorList.eraseAllOf(Code);
  116. m_ErrorList = tempErrorList.encode();
  117. m_Eventcenter->OnNotify(3, "ErrorList", ResNotify.encode());
  118. }
  119. }
  120. return 2;
  121. }
  122. int MSGUnit::AddWarnMessage(const char* Code, int& Level, const char* ResInfo)
  123. {
  124. return AddMessage(Code, Level, ResInfo, WARNTYPE);
  125. }
  126. int MSGUnit::DelWarnMessage(const char* Code, int& Level, const char* ResInfo)
  127. {
  128. return DelMessage(Code, Level, ResInfo, WARNTYPE);
  129. }
  130. int MSGUnit::AddErrorMessage(const char* Code, int& Level, const char* ResInfo)
  131. {
  132. return AddMessage(Code, Level, ResInfo, ERRORTYPE);
  133. }
  134. int MSGUnit::DelErrorMessage(const char* Code, int& Level, const char* ResInfo)
  135. {
  136. return DelMessage(Code, Level, ResInfo, ERRORTYPE);
  137. }
  138. }