2018-09-23 17:54:20 +02:00
|
|
|
#ifndef BASECONN_H
|
|
|
|
#define BASECONN_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QEventLoop>
|
2018-10-04 18:35:29 +02:00
|
|
|
#include <QSemaphore>
|
2018-10-14 18:39:39 +02:00
|
|
|
#include <QThread>
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QtConcurrent/QtConcurrent>
|
|
|
|
#include <string.h>
|
2018-10-04 18:35:29 +02:00
|
|
|
|
|
|
|
#include "headers/appsettings.h"
|
|
|
|
#include "headers/speedtimer.h"
|
2018-09-23 17:54:20 +02:00
|
|
|
|
|
|
|
class BaseConn : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit BaseConn(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
// values for the socket connection
|
|
|
|
int connection_progress;
|
|
|
|
QString ip;
|
|
|
|
qint16 port = 3563;
|
|
|
|
int errors;
|
|
|
|
int errors_until_disconnect = 4;
|
|
|
|
|
|
|
|
// the current state
|
|
|
|
QString state;
|
|
|
|
// can be:
|
|
|
|
// - 'disconnected'
|
|
|
|
// - 'connecting'
|
|
|
|
// - 'connected'
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
QVariant connections;
|
2018-10-04 18:35:29 +02:00
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
QString latestReadReply;
|
2018-10-04 18:35:29 +02:00
|
|
|
|
|
|
|
//---general status values---//
|
|
|
|
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
private:
|
|
|
|
QDateTime *date;
|
|
|
|
//to get the current time
|
|
|
|
|
|
|
|
QTcpSocket *socket;
|
|
|
|
//socket for communication with the extention
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
QSemaphore remoteSessions;
|
|
|
|
|
|
|
|
int nextConnectionId;
|
|
|
|
|
|
|
|
struct waitingRequest {
|
|
|
|
int id;
|
|
|
|
QEventLoop * loop;
|
2019-03-02 20:20:13 +01:00
|
|
|
QJsonObject reply;
|
2018-10-14 18:39:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
QList<waitingRequest> waitingRequests;
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
signals:
|
|
|
|
void stateChanged();
|
|
|
|
//is emitted, when the connection state changes
|
|
|
|
|
|
|
|
void progressChanged();
|
|
|
|
//is emmited during the connection process when the progress changes
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
void gotUnexpectedReply(QString reply);
|
2018-09-23 17:54:20 +02:00
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
void connectionsChanged();
|
|
|
|
|
2018-10-14 18:39:39 +02:00
|
|
|
void connectionSlotReleased();
|
|
|
|
|
|
|
|
void nextRemoteActionChanged();
|
|
|
|
|
|
|
|
void nextRemoteActionDelayProgChanged();
|
|
|
|
|
2019-03-02 20:20:13 +01:00
|
|
|
void gotError(QString error);
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
Q_INVOKABLE bool connectToHost();
|
|
|
|
//function to connect to the base station
|
|
|
|
|
2019-03-02 20:20:13 +01:00
|
|
|
Q_INVOKABLE void closeConnection();
|
|
|
|
|
|
|
|
void gotError(QAbstractSocket::SocketError err);
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
Q_INVOKABLE QVariantMap sendCommand(int header, QJsonValue data = "");
|
2018-09-23 17:54:20 +02:00
|
|
|
|
2019-03-03 17:31:24 +01:00
|
|
|
Q_INVOKABLE int writeRemoteSetting(QString key, QString value);
|
|
|
|
|
2018-10-04 18:35:29 +02:00
|
|
|
Q_INVOKABLE bool refreshConnections();
|
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
// functions for the qml adapter
|
|
|
|
QString getIP() const;
|
|
|
|
void setIP(const QString &ipAdress);
|
|
|
|
|
|
|
|
QString getState() const;
|
|
|
|
void setState(QString newState);
|
|
|
|
|
|
|
|
int getProgress() const;
|
|
|
|
|
2019-03-07 17:18:24 +01:00
|
|
|
QVariant getConnections();
|
2018-10-14 18:39:39 +02:00
|
|
|
|
2018-09-23 17:54:20 +02:00
|
|
|
private slots:
|
|
|
|
void readyRead();
|
|
|
|
};
|
2019-03-07 17:18:24 +01:00
|
|
|
extern BaseConn * pGlobalBaseConn;
|
2018-09-23 17:54:20 +02:00
|
|
|
|
|
|
|
#endif // BASECONN_H
|