Status.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "Status.hpp"
  14. void Status::addMsg(enum statusMsg::msgLevel level, const std::string &nodeId, const std::string &name, const std::string &msg)
  15. {
  16. statusMsg statusMsg(level, nodeId, name, msg);
  17. m_messages.insert({level, statusMsg });
  18. if (level > m_highestMsgLevel)
  19. m_highestMsgLevel = level;
  20. }
  21. void Status::addUniqueMsg(enum statusMsg::msgLevel level, const std::string &nodeId, const std::string &name, const std::string &msg)
  22. {
  23. bool duplicateFound = false;
  24. auto msgRange = m_messages.equal_range(level);
  25. for (auto msgIt = msgRange.first; msgIt != msgRange.second && !duplicateFound; ++msgIt)
  26. {
  27. duplicateFound = (msgIt->second.nodeId == nodeId) && (msgIt->second.attribute == name) && (msgIt->second.msg == msg);
  28. }
  29. if (!duplicateFound)
  30. addMsg(level, nodeId, name, msg);
  31. }
  32. std::vector<statusMsg> Status::getMessages() const
  33. {
  34. std::vector<statusMsg> msgs;
  35. for (auto it = m_messages.begin(); it != m_messages.end(); ++it)
  36. {
  37. msgs.push_back(it->second);
  38. }
  39. return msgs;
  40. }
  41. std::string Status::getStatusTypeString(enum statusMsg::msgLevel status) const
  42. {
  43. std::string result = "Not found";
  44. switch (status)
  45. {
  46. case statusMsg::info: result = "Info"; break;
  47. case statusMsg::change: result = "Change"; break;
  48. case statusMsg::warning: result = "Warning"; break;
  49. case statusMsg::error: result = "Error"; break;
  50. case statusMsg::fatal: result = "Fatal"; break;
  51. }
  52. return result;
  53. }
  54. enum statusMsg::msgLevel Status::getMsgLevelFromString(const std::string &status) const
  55. {
  56. enum statusMsg::msgLevel lvl;
  57. if (status == "info") { lvl = statusMsg::info; }
  58. else if (status == "warning") { lvl = statusMsg::warning; }
  59. else if (status == "error") { lvl = statusMsg::error; }
  60. else if (status == "fatal") { lvl = statusMsg::fatal; }
  61. else { lvl = statusMsg::fatal; }
  62. return lvl;
  63. }
  64. void Status::add(const std::vector<statusMsg> msgs)
  65. {
  66. for (auto msgIt = msgs.begin(); msgIt != msgs.end(); ++msgIt)
  67. {
  68. m_messages.insert({ (*msgIt).msgLevel, *msgIt });
  69. }
  70. }