status-desktop/src-cpp/app/include/signals.h

62 lines
1.0 KiB
C
Raw Normal View History

2022-01-06 19:29:19 +00:00
#pragma once
#include <QObject>
#include <QString>
#include <QVariant>
#include <QVariantList>
namespace Signals
{
Q_NAMESPACE
enum SignalType
{
Unknown,
NodeLogin,
NodeReady,
NodeStarted,
NodeStopped,
NodeCrashed
2022-01-06 19:29:19 +00:00
};
Q_ENUM_NS(SignalType)
struct Signal
{
SignalType signalType;
2022-01-06 19:29:19 +00:00
};
struct NodeSignal : Signal
{
QString error;
2022-01-06 19:29:19 +00:00
};
class Manager : public QObject
{
Q_OBJECT
2022-01-06 19:29:19 +00:00
public:
static Manager* instance();
2022-01-06 19:29:19 +00:00
signals:
void signal(SignalType signal);
2022-01-06 19:29:19 +00:00
void nodeReady(NodeSignal signal);
void nodeStarted(NodeSignal signal);
void nodeStopped(NodeSignal signal);
void nodeLogin(NodeSignal signal);
void nodeCrashed(NodeSignal signal);
2022-01-06 19:29:19 +00:00
private:
explicit Manager(QObject* parent = nullptr);
static std::map<QString, SignalType> signalMap;
static void signalCallback(const char* data);
void processSignal(QString ev);
void decode(const QJsonObject& signalEvent);
2022-01-06 19:29:19 +00:00
};
} // namespace Signals
Q_DECLARE_METATYPE(Signals::Signal)
Q_DECLARE_METATYPE(Signals::NodeSignal)