ConfigNotifications.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2015 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 "SchemaCommon.hpp"
  14. #include "ConfigNotifications.hpp"
  15. #include "jlib.hpp"
  16. #include "jhash.ipp"
  17. #include "jhash.hpp"
  18. #include "jstring.hpp"
  19. using namespace CONFIGURATOR;
  20. CNotificationManager* CNotificationManager::s_pNotificationManager = NULL;
  21. CNotificationManager::CNotificationManager()
  22. {
  23. }
  24. CNotificationManager *CNotificationManager::getInstance()
  25. {
  26. if (s_pNotificationManager == NULL)
  27. s_pNotificationManager = new CNotificationManager();
  28. return s_pNotificationManager;
  29. }
  30. int CNotificationManager::getNumberOfNotifications(enum ENotificationType eNotifyType) const
  31. {
  32. int nCount = 0;
  33. HashIterator iterHash(m_EnvXPathToNotification);
  34. ForEach(iterHash)
  35. {
  36. CNotification *pNotification = m_EnvXPathToNotification.mapToValue(&iterHash.query());
  37. for (int i = 0; i < eUnknown; i++)
  38. {
  39. nCount += pNotification->m_NotificationMessagesArrays[i].length();
  40. }
  41. }
  42. return nCount;
  43. }
  44. void CNotificationManager::setNotification(const CXSDNodeBase *pNodeBase, enum ENotificationType eNotifyType, const char* pNotificationText)
  45. {
  46. assert (pNodeBase != NULL);
  47. assert (pNotificationText != NULL);
  48. if (pNodeBase != NULL)
  49. {
  50. const char* pEnvXPath = pNodeBase->getEnvXPath();
  51. assert(pEnvXPath != NULL && *pEnvXPath != 0);
  52. if (pEnvXPath != NULL)
  53. {
  54. CNotification *pNotification = m_EnvXPathToNotification.getValue(pEnvXPath);
  55. if (pNotification == NULL)
  56. {
  57. pNotification = new CNotification();
  58. m_EnvXPathToNotification.setValue(pEnvXPath, pNotification);
  59. }
  60. pNotification->m_NotificationMessagesArrays[eNotifyType].append(pNotificationText);
  61. }
  62. }
  63. }
  64. void CNotificationManager::resetNotifications(const CXSDNodeBase *pNodeBase)
  65. {
  66. assert(pNodeBase != NULL);
  67. if (pNodeBase != NULL)
  68. {
  69. const char* pEnvXPath = pNodeBase->getEnvXPath();
  70. assert(pEnvXPath != NULL && *pEnvXPath != 0);
  71. if (pEnvXPath != NULL && *pEnvXPath != 0)
  72. {
  73. CNotification *pNotification = m_EnvXPathToNotification.getValue(pEnvXPath);
  74. if (pNotification != NULL)
  75. {
  76. m_EnvXPathToNotification.remove(pEnvXPath);
  77. delete pNotification;
  78. }
  79. }
  80. }
  81. }
  82. const char* CNotificationManager::getNotification(enum ENotificationType eNotifyType, int idx) const
  83. {
  84. return NULL;
  85. }