2019-07-14 22:43:22 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// util
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <utils/VideoMode.h>
|
|
|
|
#include <utils/settings.h>
|
|
|
|
#include <utils/Components.h>
|
|
|
|
|
|
|
|
// qt
|
|
|
|
#include <QMap>
|
|
|
|
|
|
|
|
class Hyperion;
|
|
|
|
class InstanceTable;
|
|
|
|
|
2020-07-12 09:19:59 +02:00
|
|
|
enum class InstanceState{
|
2019-07-14 22:43:22 +02:00
|
|
|
H_STARTED,
|
|
|
|
H_ON_STOP,
|
|
|
|
H_STOPPED,
|
|
|
|
H_CREATED,
|
|
|
|
H_DELETED
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief HyperionInstanceManager manages the instances of the the Hyperion class
|
|
|
|
///
|
|
|
|
class HyperionIManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-10-18 17:05:07 +02:00
|
|
|
struct PendingRequests
|
|
|
|
{
|
|
|
|
QObject *caller;
|
|
|
|
int tan;
|
|
|
|
};
|
|
|
|
|
2019-07-14 22:43:22 +02:00
|
|
|
// global instance pointer
|
2020-07-12 09:19:59 +02:00
|
|
|
static HyperionIManager* getInstance() { return HIMinstance; }
|
2019-07-14 22:43:22 +02:00
|
|
|
static HyperionIManager* HIMinstance;
|
|
|
|
|
2020-03-26 17:59:41 +01:00
|
|
|
public slots:
|
2019-07-14 22:43:22 +02:00
|
|
|
///
|
|
|
|
/// @brief Is given instance running?
|
|
|
|
/// @param inst The instance to check
|
|
|
|
/// @return True when running else false
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool IsInstanceRunning(quint8 inst) const { return _runningInstances.contains(inst); }
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get a Hyperion instance by index
|
|
|
|
/// @param intance the index
|
|
|
|
/// @return Hyperion instance, if index is not found returns instance 0
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
Hyperion* getHyperionInstance(quint8 instance = 0);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Get instance data of all instaces in db + running state
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
QVector<QVariantMap> getInstanceData() const;
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Start a Hyperion instance
|
2020-10-18 17:05:07 +02:00
|
|
|
/// @param instance Instance index
|
|
|
|
/// @param block If true return when thread has been started
|
2019-07-14 22:43:22 +02:00
|
|
|
/// @return Return true on success, false if not found in db
|
|
|
|
///
|
2020-10-18 17:05:07 +02:00
|
|
|
bool startInstance(quint8 inst, bool block = false, QObject *caller = nullptr, int tan = 0);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Stop a Hyperion instance
|
|
|
|
/// @param instance Instance index
|
|
|
|
/// @return Return true on success, false if not found in db
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
bool stopInstance(quint8 inst);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
2020-03-26 19:37:39 +01:00
|
|
|
///
|
|
|
|
/// @brief Toggle the state of all Hyperion instances
|
|
|
|
/// @param pause If true all instances toggle to pause, else to resume
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void toggleStateAllInstances(bool pause = false);
|
2020-03-26 19:37:39 +01:00
|
|
|
|
2019-07-14 22:43:22 +02:00
|
|
|
///
|
|
|
|
/// @brief Create a new Hyperion instance entry in db
|
|
|
|
/// @param name The friendly name of the instance
|
|
|
|
/// @param start If true it will be started after creation (async)
|
|
|
|
/// @return Return true on success false if name is already in use or a db error occurred
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
bool createInstance(const QString& name, bool start = false);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Delete Hyperion instance entry in db. Cleanup also all associated table data for this instance
|
|
|
|
/// @param inst The instance index
|
|
|
|
/// @return Return true on success, false if not found or not allowed
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
bool deleteInstance(quint8 inst);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Assign a new name to the given instance
|
|
|
|
/// @param inst The instance index
|
|
|
|
/// @param name The instance name index
|
|
|
|
/// @return Return true on success, false if not found
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
bool saveName(quint8 inst, const QString& name);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
///
|
|
|
|
/// @brief Emits whenever the state of a instance changes according to enum instanceState
|
|
|
|
/// @param instaneState A state from enum
|
|
|
|
/// @param instance The index of instance
|
|
|
|
/// @param name The name of the instance, just available with H_CREATED
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void instanceStateChanged(InstanceState state, quint8 instance, const QString& name = QString());
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Emits whenever something changes, the lazy version of instanceStateChanged (- H_ON_STOP) + saveName() emit
|
|
|
|
///
|
|
|
|
void change();
|
|
|
|
|
2020-10-18 17:05:07 +02:00
|
|
|
///
|
|
|
|
/// @brief Emits when the user has requested to start a instance
|
|
|
|
/// @param caller The origin caller instance who requested
|
|
|
|
/// @param tan The tan that was part of the request
|
|
|
|
///
|
|
|
|
void startInstanceResponse(QObject *caller, const int &tan);
|
|
|
|
|
2019-07-14 22:43:22 +02:00
|
|
|
signals:
|
|
|
|
///////////////////////////////////////
|
|
|
|
/// FROM HYPERIONDAEMON TO HYPERION ///
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief PIPE videoMode back to Hyperion
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void newVideoMode(VideoMode mode);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////
|
|
|
|
/// FROM HYPERION TO HYPERIONDAEMON ///
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief PIPE settings events from Hyperion
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void settingsChanged(settings::type type, const QJsonDocument& data);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief PIPE videoMode request changes from Hyperion to HyperionDaemon
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void requestVideoMode(VideoMode mode);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief PIPE component state changes from Hyperion to HyperionDaemon
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void compStateChangeRequest(hyperion::Components component, bool enable);
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief handle started signal of Hyperion instances
|
|
|
|
///
|
|
|
|
void handleStarted();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief handle finished signal of Hyperion instances
|
|
|
|
///
|
|
|
|
void handleFinished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class HyperionDaemon;
|
|
|
|
///
|
|
|
|
/// @brief Construct the Manager
|
|
|
|
/// @param The root path of all userdata
|
|
|
|
///
|
|
|
|
HyperionIManager(const QString& rootPath, QObject* parent = nullptr);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Start all instances that are marked as enabled in db. Non blocking
|
|
|
|
///
|
|
|
|
void startAll();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Stop all instances, used from hyperiond
|
|
|
|
///
|
|
|
|
void stopAll();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief check if a instance is allowed for management. Instance 0 represents the root instance
|
|
|
|
/// @apram inst The instance to check
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool isInstAllowed(quint8 inst) const { return (inst > 0); }
|
2019-07-14 22:43:22 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Logger* _log;
|
|
|
|
InstanceTable* _instanceTable;
|
|
|
|
const QString _rootPath;
|
|
|
|
QMap<quint8, Hyperion*> _runningInstances;
|
|
|
|
QList<quint8> _startQueue;
|
2020-10-18 17:05:07 +02:00
|
|
|
/// All pending requests
|
|
|
|
QMap<quint8, PendingRequests> _pendingRequests;
|
2019-07-14 22:43:22 +02:00
|
|
|
};
|