Status.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. change, // indicated node and attribute was changed by the operation generating this status
  24. warning,
  25. error,
  26. fatal
  27. };
  28. statusMsg(enum msgLevel _msgLevel, const std::string &_nodeId, const std::string &attrName, const std::string &_msg) :
  29. msgLevel(_msgLevel), nodeId(_nodeId), attribute(attrName), msg(_msg) { }
  30. msgLevel msgLevel; // Message level
  31. std::string nodeId; // if not '', the node ID to which this status applies
  32. std::string attribute; // possible name of attribute in nodeId
  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 &msg);
  42. void addUniqueMsg(enum statusMsg::msgLevel status, const std::string &nodeId, const std::string &name, 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. enum statusMsg::msgLevel getMsgLevelFromString(const std::string &status) const;
  48. std::vector<statusMsg> getMessages() const;
  49. void add(const std::vector<statusMsg> msgs);
  50. private:
  51. enum statusMsg::msgLevel m_highestMsgLevel;
  52. std::multimap<enum statusMsg::msgLevel, statusMsg> m_messages;
  53. };
  54. #endif