ControllerChangeNotifier.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef CONTROLLERCHANGENOTIFIER_HPP
  2. #define CONTROLLERCHANGENOTIFIER_HPP
  3. #include <memory>
  4. #include <nlohmann/json.hpp>
  5. #include <string>
  6. namespace ZeroTier {
  7. class PubSubWriter;
  8. class ControllerChangeNotifier {
  9. public:
  10. virtual ~ControllerChangeNotifier() = default;
  11. virtual void notifyNetworkChange(
  12. const nlohmann::json& oldNetwork,
  13. const nlohmann::json& newNetwork,
  14. const std::string& frontend = "") = 0;
  15. virtual void notifyMemberChange(
  16. const nlohmann::json& oldMember,
  17. const nlohmann::json newMember,
  18. const std::string& frontend = "") = 0;
  19. };
  20. class PubSubChangeNotifier : public ControllerChangeNotifier {
  21. public:
  22. PubSubChangeNotifier(
  23. std::string controllerID,
  24. std::string project,
  25. std::string memberChangeTopic,
  26. std::string networkChangeTopic);
  27. virtual ~PubSubChangeNotifier();
  28. virtual void notifyNetworkChange(
  29. const nlohmann::json& oldNetwork,
  30. const nlohmann::json& newNetwork,
  31. const std::string& frontend = "") override;
  32. virtual void notifyMemberChange(
  33. const nlohmann::json& oldMember,
  34. const nlohmann::json newMember,
  35. const std::string& frontend = "") override;
  36. private:
  37. std::shared_ptr<PubSubWriter> _networkChangeWriter;
  38. std::shared_ptr<PubSubWriter> _memberChangeWriter;
  39. };
  40. } // namespace ZeroTier
  41. #endif // CONTROLLERCHANGENOTIFIER_HPP