hyperion.ng
JsonAPI.h
1 #pragma once
2 
3 // hyperion includes
4 #include <utils/Logger.h>
5 #include <utils/jsonschema/QJsonSchemaChecker.h>
6 #include <utils/Components.h>
7 #include <hyperion/Hyperion.h>
8 
9 // qt includes
10 #include <QJsonObject>
11 #include <QMutex>
12 #include <QString>
13 
14 class JsonCB;
15 
16 class JsonAPI : public QObject
17 {
18  Q_OBJECT
19 
20 public:
29  JsonAPI(QString peerAddress, Logger* log, QObject* parent, bool noListener = false);
30 
36  void handleMessage(const QString & message);
37 
38 public slots:
43  void streamLedcolorsUpdate(const std::vector<ColorRgb>& ledColors);
44 
46  void setImage(const Image<ColorRgb> & image);
47 
50 
51 signals:
55  void callbackMessage(QJsonObject);
56 
60  void forwardJsonMessage(QJsonObject);
61 
62 private:
63  // true if further callbacks are forbidden (http)
64  bool _noListener;
65 
67  QString _peerAddress;
68 
70  Logger* _log;
71 
73  Hyperion* _hyperion;
74 
75  // The JsonCB instance which handles data subscription/notifications
76  JsonCB* _jsonCB;
77 
78  // streaming buffers
79  QJsonObject _streaming_leds_reply;
80  QJsonObject _streaming_image_reply;
81  QJsonObject _streaming_logging_reply;
82 
84  bool _streaming_logging_activated;
85 
87  QMutex _image_stream_mutex;
88 
90  QMutex _led_stream_mutex;
91 
93  volatile qint64 _image_stream_timeout;
94 
96  volatile qint64 _led_stream_timeout;
97 
103  void handleColorCommand(const QJsonObject & message, const QString &command, const int tan);
104 
110  void handleImageCommand(const QJsonObject & message, const QString &command, const int tan);
111 
117  void handleEffectCommand(const QJsonObject &message, const QString &command, const int tan);
118 
124  void handleCreateEffectCommand(const QJsonObject & message, const QString &command, const int tan);
125 
131  void handleDeleteEffectCommand(const QJsonObject & message, const QString &command, const int tan);
132 
138  void handleSysInfoCommand(const QJsonObject & message, const QString &command, const int tan);
139 
145  void handleServerInfoCommand(const QJsonObject & message, const QString &command, const int tan);
146 
152  void handleClearCommand(const QJsonObject & message, const QString &command, const int tan);
153 
159  void handleAdjustmentCommand(const QJsonObject & message, const QString &command, const int tan);
160 
166  void handleSourceSelectCommand(const QJsonObject & message, const QString &command, const int tan);
167 
172  void handleConfigCommand(const QJsonObject & message, const QString &command, const int tan);
173 
178  void handleSchemaGetCommand(const QJsonObject & message, const QString &command, const int tan);
179 
184  void handleConfigSetCommand(const QJsonObject & message, const QString &command, const int tan);
185 
191  void handleComponentStateCommand(const QJsonObject & message, const QString &command, const int tan);
192 
197  void handleLedColorsCommand(const QJsonObject & message, const QString &command, const int tan);
198 
203  void handleLoggingCommand(const QJsonObject & message, const QString &command, const int tan);
204 
209  void handleProcessingCommand(const QJsonObject & message, const QString &command, const int tan);
210 
215  void handleVideoModeCommand(const QJsonObject & message, const QString &command, const int tan);
216 
222  void handleClearallCommand(const QJsonObject & message, const QString &command, const int tan);
223 
227  void handleNotImplemented();
228 
232  void sendSuccessReply(const QString &command="", const int tan=0);
233 
237  void sendSuccessDataReply(const QJsonDocument &doc, const QString &command="", const int &tan=0);
238 
244  void sendErrorReply(const QString & error, const QString &command="", const int tan=0);
245 };
Definition: Logger.h:32
The main class of Hyperion.
Definition: Hyperion.h:57
Definition: Logger.h:39
void streamLedcolorsUpdate(const std::vector< ColorRgb > &ledColors)
is called whenever the current Hyperion instance pushes new led raw values (if enabled) ...
Definition: JsonAPI.cpp:1008
Definition: JsonCB.h:21
JsonAPI(QString peerAddress, Logger *log, QObject *parent, bool noListener=false)
Constructor.
Definition: JsonAPI.cpp:40
void forwardJsonMessage(QJsonObject)
Signal emits whenever a jsonmessage should be forwarded.
void handleMessage(const QString &message)
Handle an incoming JSON message.
Definition: JsonAPI.cpp:60
void setImage(const Image< ColorRgb > &image)
push images whenever hyperion emits (if enabled)
Definition: JsonAPI.cpp:1035
void incommingLogMessage(const Logger::T_LOG_MESSAGE &)
process and push new log messages from logger (if enabled)
Definition: JsonAPI.cpp:1055
void callbackMessage(QJsonObject)
Signal emits with the reply message provided with handleMessage()
Definition: JsonAPI.h:16