Status.hpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "Cfgmgrlib.hpp"
  20. struct CFGMGRLIB_API statusMsg {
  21. enum msgLevel
  22. {
  23. info = 0, // informational messages mainly
  24. change, // indicated node and attribute was changed by the operation generating this status
  25. warning,
  26. error,
  27. fatal
  28. };
  29. statusMsg(enum msgLevel _msgLevel, const std::string &_nodeId, const std::string &attrName, const std::string &_msg) :
  30. msgLevel(_msgLevel), nodeId(_nodeId), attribute(attrName), msg(_msg) { }
  31. msgLevel msgLevel; // Message level
  32. std::string nodeId; // if not '', the node ID to which this status applies
  33. std::string attribute; // possible name of attribute in nodeId
  34. std::string msg; // message for user
  35. };
  36. class CFGMGRLIB_API Status
  37. {
  38. public:
  39. Status() : m_highestMsgLevel(statusMsg::info) { }
  40. Status(const Status &status, const std::string &nodeId);
  41. ~Status() {}
  42. void addMsg(const statusMsg &msg);
  43. void addMsg(enum statusMsg::msgLevel status, const std::string &msg) { addMsg(status, "", "", msg); }
  44. void addMsg(enum statusMsg::msgLevel status, const std::string &nodeId, const std::string &name, const std::string &msg);
  45. void addUniqueMsg(enum statusMsg::msgLevel status, const std::string &nodeId, const std::string &name, const std::string &msg);
  46. enum statusMsg::msgLevel getHighestMsgLevel() const { return m_highestMsgLevel; }
  47. bool isOk() const { return m_highestMsgLevel <= statusMsg::warning; }
  48. bool isError() const { return m_highestMsgLevel >= statusMsg::error; }
  49. std::string getStatusTypeString(enum statusMsg::msgLevel status) const;
  50. enum statusMsg::msgLevel getMsgLevelFromString(const std::string &status) const;
  51. std::vector<statusMsg> getMessages(enum statusMsg::msgLevel level = statusMsg::fatal, bool andBelow = true,
  52. const std::string &nodeId = std::string(), const std::string &attribute = std::string()) const;
  53. void add(const std::vector<statusMsg> msgs);
  54. private:
  55. enum statusMsg::msgLevel m_highestMsgLevel;
  56. std::multimap<enum statusMsg::msgLevel, statusMsg> m_messages;
  57. };
  58. #endif