Status.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2017 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _CONFIG2_NODESTATUS_HPP_
  14. #define _CONFIG2_NODESTATUS_HPP_
  15. #include <map>
  16. #include <vector>
  17. #include <string>
  18. #include "platform.h"
  19. struct DECL_EXPORT statusMsg {
  20. enum msgLevel
  21. {
  22. info = 0, // informational messages mainly
  23. warning,
  24. error,
  25. fatal
  26. };
  27. statusMsg(enum msgLevel _msgLevel, const std::string &_nodeId, const std::string &_name, const std::string &_referNodeId, const std::string &_msg) :
  28. msgLevel(_msgLevel), nodeId(_nodeId), attribute(_name), referNodeId(_referNodeId), msg(_msg) { }
  29. msgLevel msgLevel; // Message level
  30. std::string nodeId; // if not '', the node ID to which this status applies
  31. std::string attribute; // possible name of attribute in nodeId
  32. std::string referNodeId; // refernece node to which this status may also apply
  33. std::string msg; // message for user
  34. };
  35. class DECL_EXPORT Status
  36. {
  37. public:
  38. Status() : m_highestMsgLevel(statusMsg::info) { }
  39. ~Status() {}
  40. void addMsg(enum statusMsg::msgLevel status, const std::string &msg) { addMsg(status, "", "", "", msg); }
  41. void addMsg(enum statusMsg::msgLevel status, const std::string &nodeId, const std::string &name, const std::string &referNodeId, const std::string &msg);
  42. void addUniqueMsg(enum statusMsg::msgLevel status, const std::string &nodeId, const std::string &name, const std::string &referNodeId, const std::string &msg);
  43. enum statusMsg::msgLevel getHighestMsgLevel() const { return m_highestMsgLevel; }
  44. bool isOk() const { return m_highestMsgLevel <= statusMsg::warning; }
  45. bool isError() const { return m_highestMsgLevel >= statusMsg::error; }
  46. std::string getStatusTypeString(enum statusMsg::msgLevel status) const;
  47. std::vector<statusMsg> getMessages() const;
  48. void add(const std::vector<statusMsg> msgs);
  49. private:
  50. enum statusMsg::msgLevel m_highestMsgLevel;
  51. std::multimap<enum statusMsg::msgLevel, statusMsg> m_messages;
  52. };
  53. #endif