EnvironmentEventHandlers.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 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_CONFIGEVENTS_HPP_
  14. #define _CONFIG2_CONFIGEVENTS_HPP_
  15. #include <string>
  16. #include <map>
  17. #include <memory>
  18. #include <vector>
  19. #include "NameValue.hpp"
  20. class EnvironmentNode;
  21. class EnvironmentEventHandler
  22. {
  23. public:
  24. EnvironmentEventHandler(const std::string &type) : m_eventType(type) {}
  25. virtual ~EnvironmentEventHandler() {}
  26. virtual void processEvent(const std::string &eventType, std::shared_ptr<EnvironmentNode> pEventNode) = 0;
  27. virtual void doHandleEvent(std::shared_ptr<EnvironmentNode> pEventNode) = 0;
  28. protected:
  29. std::string m_eventType;
  30. };
  31. class MatchEnvironmentEventHandler : public EnvironmentEventHandler
  32. {
  33. public:
  34. MatchEnvironmentEventHandler() : EnvironmentEventHandler("create") {}
  35. virtual ~MatchEnvironmentEventHandler() {}
  36. void setItemType(const std::string &type) { m_itemType = type; }
  37. void setEventNodeAttributeName(const std::string &name);
  38. void setTargetAttributeName(const std::string &name) { m_targetAttribute = name; }
  39. void setTargetPath(const std::string &path) { m_targetPath = path; }
  40. virtual void processEvent(const std::string &eventType, std::shared_ptr<EnvironmentNode> pEventNode);
  41. protected:
  42. std::string m_itemType;
  43. std::string m_targetPath;
  44. std::string m_eventNodeAttribute;
  45. std::string m_targetAttribute;
  46. };
  47. class AttributeDependencyCreateEventHandler : public MatchEnvironmentEventHandler
  48. {
  49. public:
  50. AttributeDependencyCreateEventHandler() {}
  51. virtual ~AttributeDependencyCreateEventHandler() {}
  52. void addDependency(const std::string &attrName, const std::string &attrValr, const std::string &depAttr, const std::string &depVal);
  53. virtual void doHandleEvent(std::shared_ptr<EnvironmentNode> pEventNode);
  54. protected:
  55. std::map<std::string, std::map<std::string, std::pair<std::string, std::string>>> m_depAttrVals;
  56. };
  57. class InsertEnvironmentDataCreateEventHandler : public MatchEnvironmentEventHandler
  58. {
  59. public:
  60. InsertEnvironmentDataCreateEventHandler() {}
  61. virtual ~InsertEnvironmentDataCreateEventHandler() {}
  62. void setEnvironmentInsertData(const std::string &envData) { m_envData = envData; }
  63. virtual void doHandleEvent(std::shared_ptr<EnvironmentNode> pEventNode);
  64. protected:
  65. std::string m_envData;
  66. };
  67. class AttributeSetValueCreateEventHandler : public MatchEnvironmentEventHandler
  68. {
  69. public:
  70. AttributeSetValueCreateEventHandler() {}
  71. virtual ~AttributeSetValueCreateEventHandler() {}
  72. void addAttributeValue(const std::string &attrName, const std::string &attrValr);
  73. virtual void doHandleEvent(std::shared_ptr<EnvironmentNode> pEventNode);
  74. protected:
  75. std::vector<NameValue> m_attrVals;
  76. };
  77. #endif