ComponentRegister.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <utils/Components.h>
  3. #include <utils/Logger.h>
  4. // STL includes
  5. #include <map>
  6. #include <QObject>
  7. #include <QVector>
  8. class Hyperion;
  9. typedef QVector<hyperion::Components> ComponentList;
  10. ///
  11. /// @brief The component register reflects and manages the current state of all components and Hyperion as a whole
  12. /// It emits also real component state changes (triggered from the specific component), which can be used for listening APIs (Network Clients/Plugins)
  13. ///
  14. class ComponentRegister : public QObject
  15. {
  16. Q_OBJECT
  17. public:
  18. ComponentRegister(Hyperion* hyperion);
  19. ~ComponentRegister() override;
  20. ///
  21. /// @brief Check if a component is currently enabled
  22. /// @param comp The component from enum
  23. /// @return True if component is running else false. Not found is -1
  24. ///
  25. int isComponentEnabled(hyperion::Components comp) const;
  26. /// contains all components and their state
  27. std::map<hyperion::Components, bool> getRegister() const { return _componentStates; }
  28. signals:
  29. ///
  30. /// @brief Emits whenever a component changed (really) the state
  31. /// @param comp The component
  32. /// @param isActive The new state of the component
  33. ///
  34. void updatedComponentState(hyperion::Components comp, bool isActive);
  35. public slots:
  36. ///
  37. /// @brief is called whenever a component change a state, DO NOT CALL FROM API, use signal hyperion->compStateChangeRequest
  38. /// @param comp The component
  39. /// @param isActive The new state of the component
  40. ///
  41. void setNewComponentState(hyperion::Components comp, bool isActive);
  42. private slots:
  43. ///
  44. /// @brief Handle COMP_ALL changes from Hyperion->compStateChangeRequest
  45. /// @param comp COMP_ALL
  46. /// @param isActive The new state for all components
  47. ///
  48. void handleCompStateChangeRequest(hyperion::Components comps, bool isActive);
  49. ///
  50. /// @brief Activate/Deactivate all components, except those provided by the list of excluded components
  51. /// @param isActive The new state for all components
  52. /// @param execludeList of excluded components
  53. ///
  54. void handleCompStateChangeRequestAll(bool isActive, const ComponentList& excludeList = ComponentList{});
  55. private:
  56. /// Hyperion instance
  57. Hyperion * _hyperion;
  58. /// Logger instance
  59. Logger * _log;
  60. /// current state of all components
  61. std::map<hyperion::Components, bool> _componentStates;
  62. /// on hyperion off we save the previous states of all components
  63. std::map<hyperion::Components, bool> _prevComponentStates;
  64. // helper to prevent self emit chains
  65. bool _inProgress = false;
  66. };