FPDErrorWarningProcess.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "stdafx.h"
  2. #include "FPDErrorWarningProcess.h"
  3. extern Log4CPP::Logger* mLog::gLogger;
  4. FPDErrorWarning::FPDErrorWarning(std::shared_ptr <DIOS::Dev::IOEventCenter> EventCenter, std::string DevInstance, std::string strInfoPath)
  5. {
  6. m_MSGUnit.reset(new nDetail::MSGUnit(EventCenter, DevInstance));
  7. m_EventCenter = EventCenter;
  8. mLog::FINFO("strInfoPath:{$}", strInfoPath);
  9. m_ErrRes.setFileName(strInfoPath + "\\PNLErrorInfor.xml");
  10. m_WarnRes.setFileName(strInfoPath + "\\PNLWarnInfor.xml");
  11. m_WarnList.clear();
  12. m_ErrList.clear();
  13. }
  14. FPDErrorWarning::~FPDErrorWarning()
  15. {
  16. m_WarnList.clear();
  17. m_ErrList.clear();
  18. }
  19. void FPDErrorWarning::SendError(std::string strErrCode, std::string strErr)
  20. {
  21. if (m_ErrList.isExist(strErrCode)) //错误已经存在错误列表中,无需重复发送
  22. {
  23. mLog::Info("Same Error({$}), Omit", strErrCode.c_str());
  24. return;
  25. }
  26. DeviceError tErr;
  27. if (!m_ErrRes.getDeviceError(strErrCode, tErr))
  28. {
  29. mLog::Warn("Get Error Resouse Fault! ErrorCode:{$}", strErrCode);
  30. tErr.setCode(strErrCode);
  31. tErr.setName(strErrCode);
  32. }
  33. if (strErr != "")
  34. {
  35. std::string strDesc = strErr + tErr.getDescription();
  36. tErr.setDescription(strDesc);
  37. }
  38. m_ErrList.add(tErr);
  39. mLog::Info("AddErrorMsg {$}: {$}", tErr.getCode().c_str(), tErr.getDescription().c_str());
  40. int level = std::stoi(tErr.getNotifyType());
  41. m_MSGUnit->AddErrorMessage(tErr.getCode().c_str(), level, tErr.getDescription().c_str());
  42. }
  43. void FPDErrorWarning::ClearError(std::string strErrCode)
  44. {
  45. if (m_ErrList.isExist(strErrCode)) //错误列表中存在才清除
  46. {
  47. DeviceError tErr;
  48. if (!m_ErrRes.getDeviceError(strErrCode, tErr))
  49. {
  50. mLog::Warn("Get Error Resouse Fault! ErrorCode:{$}", strErrCode);
  51. tErr.setCode(strErrCode);
  52. tErr.setName(strErrCode);
  53. }
  54. m_ErrList.remove(strErrCode);
  55. mLog::Info("DelErrMsg {$}", strErrCode.c_str());
  56. int level = std::stoi(tErr.getNotifyType());
  57. m_MSGUnit->DelErrorMessage(strErrCode.c_str(), level, "");
  58. }
  59. }
  60. void FPDErrorWarning::SendWarn(std::string strWarnCode, std::string strWarn)
  61. {
  62. if (m_WarnList.isExist(strWarnCode))
  63. {
  64. mLog::Info("Same Warn({$}), Omit", strWarnCode.c_str());
  65. return;
  66. }
  67. DeviceError tWarn;
  68. if (!m_WarnRes.getDeviceWarn(strWarnCode, tWarn))
  69. {
  70. mLog::Warn(("Get Warn Resouse Fault! WarnCode:{$}"), strWarnCode);
  71. tWarn.setCode(strWarnCode);
  72. tWarn.setName(strWarnCode);
  73. }
  74. if (strWarn != "")
  75. {
  76. std::string strDesc = strWarn + tWarn.getDescription();
  77. tWarn.setDescription(strDesc);
  78. }
  79. m_WarnList.add(tWarn);
  80. mLog::Info("AddWarnMsg {$}: {$}", tWarn.getCode().c_str(), tWarn.getDescription().c_str());
  81. int level = std::stoi(tWarn.getNotifyType());
  82. m_MSGUnit->AddWarnMessage(tWarn.getCode().c_str(), level, tWarn.getDescription().c_str());
  83. }
  84. void FPDErrorWarning::ClearWarn(std::string strWarnCode)
  85. {
  86. if (m_WarnList.isExist(strWarnCode))
  87. {
  88. DeviceError tWarn;
  89. if (!m_WarnRes.getDeviceWarn(strWarnCode, tWarn))
  90. {
  91. mLog::Warn(("Get Warn Resouse Fault! WarnCode:{$}"), strWarnCode);
  92. tWarn.setCode(strWarnCode);
  93. tWarn.setName(strWarnCode);
  94. }
  95. m_WarnList.remove(strWarnCode);
  96. mLog::Info("DelWarnMsg {$}", strWarnCode.c_str());
  97. int level = std::stoi(tWarn.getNotifyType());
  98. m_MSGUnit->DelWarnMessage(strWarnCode.c_str(), level, "");
  99. }
  100. }
  101. void FPDErrorWarning::SendAllError()
  102. {
  103. mLog::Info("Send All Error");
  104. for (int i = 0; i < m_ErrList.size(); i++)
  105. {
  106. DeviceError tError = m_ErrList.item(i);
  107. SendError(tError.getCode(), tError.getDescription());
  108. }
  109. }
  110. void FPDErrorWarning::SendAllWarn()
  111. {
  112. mLog::Info("Send All Warn");
  113. for (int i = 0; i < m_WarnList.size(); i++)
  114. {
  115. DeviceError tWarn = m_WarnList.item(i);
  116. SendWarn(tWarn.getCode(), tWarn.getDescription());
  117. }
  118. }
  119. void FPDErrorWarning::ClearAllError()
  120. {
  121. mLog::Info("Clear All Error");
  122. for (int i = 0; i < m_ErrList.size(); i++)
  123. {
  124. DeviceError tError = m_ErrList.item(i);
  125. ClearError(tError.getCode());
  126. }
  127. }
  128. void FPDErrorWarning::ClearAllWarn()
  129. {
  130. mLog::Info("Clear All Warn");
  131. for (int i = 0; i < m_WarnList.size(); i++)
  132. {
  133. DeviceError tWarn = m_WarnList.item(i);
  134. ClearWarn(tWarn.getCode());
  135. }
  136. }
  137. RET_STATUS FPDErrorWarning::JSGetErrorList(std::string& out)
  138. {
  139. out = m_MSGUnit->JSGet();
  140. return RET_STATUS::RET_SUCCEED;
  141. }
  142. bool FPDErrorWarning::IsErrorExist()
  143. {
  144. if (m_ErrList.size() > 0)
  145. {
  146. return true;
  147. }
  148. return false;
  149. }