#include "stdafx.h" #include "FPDErrorWarningProcess.h" extern Log4CPP::Logger* mLog::gLogger; FPDErrorWarning::FPDErrorWarning(std::shared_ptr EventCenter, std::string DevInstance, std::string strInfoPath) { m_MSGUnit.reset(new nDetail::MSGUnit(EventCenter, DevInstance)); m_EventCenter = EventCenter; mLog::FINFO("strInfoPath:{$}", strInfoPath); m_ErrRes.setFileName(strInfoPath + "\\PNLErrorInfor.xml"); m_WarnRes.setFileName(strInfoPath + "\\PNLWarnInfor.xml"); m_WarnList.clear(); m_ErrList.clear(); } FPDErrorWarning::~FPDErrorWarning() { m_WarnList.clear(); m_ErrList.clear(); } void FPDErrorWarning::SendError(std::string strErrCode, std::string strErr) { if (m_ErrList.isExist(strErrCode)) //错误已经存在错误列表中,无需重复发送 { mLog::Info("Same Error({$}), Omit", strErrCode.c_str()); return; } DeviceError tErr; if (!m_ErrRes.getDeviceError(strErrCode, tErr)) { mLog::Warn("Get Error Resouse Fault! ErrorCode:{$}", strErrCode); tErr.setCode(strErrCode); tErr.setName(strErrCode); } if (strErr != "") { std::string strDesc = strErr + tErr.getDescription(); tErr.setDescription(strDesc); } m_ErrList.add(tErr); mLog::Info("AddErrorMsg {$}: {$}", tErr.getCode().c_str(), tErr.getDescription().c_str()); int level = std::stoi(tErr.getNotifyType()); m_MSGUnit->AddErrorMessage(tErr.getCode().c_str(), level, tErr.getDescription().c_str()); } void FPDErrorWarning::ClearError(std::string strErrCode) { if (m_ErrList.isExist(strErrCode)) //错误列表中存在才清除 { DeviceError tErr; if (!m_ErrRes.getDeviceError(strErrCode, tErr)) { mLog::Warn("Get Error Resouse Fault! ErrorCode:{$}", strErrCode); tErr.setCode(strErrCode); tErr.setName(strErrCode); } m_ErrList.remove(strErrCode); mLog::Info("DelErrMsg {$}", strErrCode.c_str()); int level = std::stoi(tErr.getNotifyType()); m_MSGUnit->DelErrorMessage(strErrCode.c_str(), level, ""); } } void FPDErrorWarning::SendWarn(std::string strWarnCode, std::string strWarn) { if (m_WarnList.isExist(strWarnCode)) { mLog::Info("Same Warn({$}), Omit", strWarnCode.c_str()); return; } DeviceError tWarn; if (!m_WarnRes.getDeviceWarn(strWarnCode, tWarn)) { mLog::Warn(("Get Warn Resouse Fault! WarnCode:{$}"), strWarnCode); tWarn.setCode(strWarnCode); tWarn.setName(strWarnCode); } if (strWarn != "") { std::string strDesc = strWarn + tWarn.getDescription(); tWarn.setDescription(strDesc); } m_WarnList.add(tWarn); mLog::Info("AddWarnMsg {$}: {$}", tWarn.getCode().c_str(), tWarn.getDescription().c_str()); int level = std::stoi(tWarn.getNotifyType()); m_MSGUnit->AddWarnMessage(tWarn.getCode().c_str(), level, tWarn.getDescription().c_str()); } void FPDErrorWarning::ClearWarn(std::string strWarnCode) { if (m_WarnList.isExist(strWarnCode)) { DeviceError tWarn; if (!m_WarnRes.getDeviceWarn(strWarnCode, tWarn)) { mLog::Warn(("Get Warn Resouse Fault! WarnCode:{$}"), strWarnCode); tWarn.setCode(strWarnCode); tWarn.setName(strWarnCode); } m_WarnList.remove(strWarnCode); mLog::Info("DelWarnMsg {$}", strWarnCode.c_str()); int level = std::stoi(tWarn.getNotifyType()); m_MSGUnit->DelWarnMessage(strWarnCode.c_str(), level, ""); } } void FPDErrorWarning::SendAllError() { mLog::Info("Send All Error"); for (int i = 0; i < m_ErrList.size(); i++) { DeviceError tError = m_ErrList.item(i); SendError(tError.getCode(), tError.getDescription()); } } void FPDErrorWarning::SendAllWarn() { mLog::Info("Send All Warn"); for (int i = 0; i < m_WarnList.size(); i++) { DeviceError tWarn = m_WarnList.item(i); SendWarn(tWarn.getCode(), tWarn.getDescription()); } } void FPDErrorWarning::ClearAllError() { mLog::Info("Clear All Error"); for (int i = 0; i < m_ErrList.size(); i++) { DeviceError tError = m_ErrList.item(i); ClearError(tError.getCode()); } } void FPDErrorWarning::ClearAllWarn() { mLog::Info("Clear All Warn"); for (int i = 0; i < m_WarnList.size(); i++) { DeviceError tWarn = m_WarnList.item(i); ClearWarn(tWarn.getCode()); } } RET_STATUS FPDErrorWarning::JSGetErrorList(std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; } bool FPDErrorWarning::IsErrorExist() { if (m_ErrList.size() > 0) { return true; } return false; }