GENErrorWarningProcess.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include "DIOS.Dev.IODevice.Detail.hpp"
  3. #include "DIOS.Dev.MSGMould.hpp"
  4. namespace nDetail = DIOS::Dev::Detail;
  5. struct ErrorConfig {
  6. std::string code;
  7. int level;
  8. std::string message;
  9. std::string type;
  10. };
  11. class DeviceErrorHandler {
  12. public:
  13. DeviceErrorHandler(std::shared_ptr <DIOS::Dev::IOEventCenter> EventCenter, std::string DevInstance, std::string strInfoPath);
  14. ~DeviceErrorHandler();
  15. bool LoadConfig(const std::string& configPath);
  16. std::string ParseAndReport(const std::string& rawCode);
  17. void ClearAllErrors();
  18. void ClearAllWarnings();
  19. bool HasActiveErrors() const;
  20. bool HasActiveWarnings() const;
  21. private:
  22. struct ActiveError {
  23. std::string code;
  24. int level;
  25. std::string message;
  26. };
  27. std::unordered_map<std::string, ErrorConfig> m_errorConfigs;
  28. std::vector<ActiveError> m_activeErrors;
  29. std::vector<ActiveError> m_activeWarnings;
  30. mutable std::mutex m_mutex;
  31. std::unique_ptr <nDetail::MSGUnit> m_MSGUnit;
  32. std::shared_ptr <DIOS::Dev::IOEventCenter> m_EventCenter;
  33. void AddError(std::string code, int level, const std::string& message);
  34. void AddWarning(std::string code, int level, const std::string& message);
  35. };