2016-09-07 20:10:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
#include <utils/Components.h>
|
2016-09-07 20:10:37 +02:00
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
class Hyperion;
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief The component register reflects and manages the current state of all components and Hyperion as a whole
|
|
|
|
/// It emits also real component state changes (triggert from the specific component), which can be used for listening APIs (Network Clients/Plugins)
|
|
|
|
///
|
2016-09-07 20:10:37 +02:00
|
|
|
class ComponentRegister : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-12-27 23:11:32 +01:00
|
|
|
ComponentRegister(Hyperion* hyperion);
|
2020-08-08 23:12:43 +02:00
|
|
|
~ComponentRegister() override;
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Check if a component is currently enabled
|
|
|
|
/// @param comp The component from enum
|
2018-12-28 18:12:45 +01:00
|
|
|
/// @return True if component is running else false. Not found is -1
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
int isComponentEnabled(hyperion::Components comp) const;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
/// contains all components and their state
|
2020-08-08 23:12:43 +02:00
|
|
|
std::map<hyperion::Components, bool> getRegister() const { return _componentStates; }
|
2016-09-07 20:10:37 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// @brief Emits whenever a component changed (really) the state
|
|
|
|
/// @param comp The component
|
|
|
|
/// @param state The new state of the component
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void updatedComponentState(hyperion::Components comp, bool state);
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-09-07 20:10:37 +02:00
|
|
|
public slots:
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
2020-02-26 18:54:56 +01:00
|
|
|
/// @brief is called whenever a component change a state, DO NOT CALL FROM API, use signal hyperion->compStateChangeRequest
|
2018-12-27 23:11:32 +01:00
|
|
|
/// @param comp The component
|
|
|
|
/// @param state The new state of the component
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void setNewComponentState(hyperion::Components comp, bool activated);
|
2020-02-26 18:54:56 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief Handle COMP_ALL changes from Hyperion->compStateChangeRequest
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void handleCompStateChangeRequest(hyperion::Components comps, bool activated);
|
2016-09-07 20:10:37 +02:00
|
|
|
|
|
|
|
private:
|
2018-12-27 23:11:32 +01:00
|
|
|
/// Hyperion instance
|
|
|
|
Hyperion * _hyperion;
|
|
|
|
/// Logger instance
|
2016-09-07 20:10:37 +02:00
|
|
|
Logger * _log;
|
2018-12-27 23:11:32 +01:00
|
|
|
/// current state of all components
|
|
|
|
std::map<hyperion::Components, bool> _componentStates;
|
|
|
|
/// on hyperion off we save the previous states of all components
|
|
|
|
std::map<hyperion::Components, bool> _prevComponentStates;
|
2020-02-26 18:54:56 +01:00
|
|
|
// helper to prevent self emit chains
|
|
|
|
bool _inProgress = false;
|
2016-09-07 20:10:37 +02:00
|
|
|
};
|