Kstars

nodemanager.h
1/*
2 SPDX-FileCopyrightText: 2023 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 Node Manager
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#pragma once
10
11#include <QtWebSockets/QWebSocket>
12#include <QJsonObject>
13#include <QNetworkAccessManager>
14#include <QPointer>
15#include <QNetworkReply>
16#include <memory>
17
18#include "node.h"
19
20namespace EkosLive
21{
22class NodeManager : public QObject
23{
24 Q_PROPERTY(QUrl serviceURL MEMBER m_ServiceURL)
25 Q_PROPERTY(QUrl websocketURL MEMBER m_WebsocketURL)
27
28 public:
29 explicit NodeManager(uint32_t mask);
30 virtual ~NodeManager() = default;
31
32 bool isConnected() const;
33
34 typedef enum
35 {
36 Message = 1 << 0,
37 Media = 1 << 1,
38 Cloud = 1 << 2
39 } Channels;
40
41 void setURLs(const QUrl &service, const QUrl &websocket);
42 void setCredentials(const QString &username, const QString &password);
43 void setAuthResponse(const QJsonObject &response)
44 {
45 m_AuthResponse = response;
46 }
47
48 Node *message() {return m_Nodes[Message];}
49 Node *media() {return m_Nodes[Media];}
50 Node *cloud() {return m_Nodes.contains(Cloud) ? m_Nodes[Cloud] : nullptr;}
51
52 signals:
53 void connected();
54 void disconnected();
55 void authenticationError(QString);
56
57 public slots:
58 void authenticate();
59 void disconnectNodes();
60
61 void setConnected();
62 void setDisconnected();
63
64 protected slots:
65 void onResult(QNetworkReply *reply);
66
67 private:
68 QJsonObject m_AuthResponse;
69 uint16_t m_ReconnectTries {0};
70 QUrl m_ServiceURL, m_WebsocketURL;
71 QString m_Username, m_Password;
72
73 QPointer<QNetworkAccessManager> m_NetworkManager;
75
76 // Retry every 5 seconds in case remote server is down
77 static const uint16_t RECONNECT_INTERVAL = 5000;
78 // Retry authentication up to 3 times
79 static const uint16_t RECONNECT_MAX_TRIES = 3;
80 // Throttle interval
81 static const uint16_t THROTTLE_INTERVAL = 1000;
82};
83}
Generic record interfaces and implementations.
Definition cloud.cpp:23
bool contains(const Key &key) const const
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:49:50 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.