2015-08-10 22:46:01 +02:00
|
|
|
#ifndef CONNECTION_H
|
|
|
|
#define CONNECTION_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2015-09-11 21:59:47 +02:00
|
|
|
#include <QJsonValue>
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
|
|
|
|
2015-09-05 17:25:05 +02:00
|
|
|
namespace RepoIndex {
|
2015-08-10 22:46:01 +02:00
|
|
|
|
2015-09-05 17:25:05 +02:00
|
|
|
class Manager;
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
class Connection : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2016-02-25 22:53:33 +01:00
|
|
|
Connection(Manager &alpmManager, QWebSocket *socket, QObject *parent = nullptr);
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void processTextMessage(const QString &message);
|
|
|
|
void processBinaryMessage(const QByteArray &message);
|
|
|
|
void socketDisconnected();
|
2015-09-04 14:37:01 +02:00
|
|
|
void sendResult(const QJsonValue &what, const QJsonValue &id, const QJsonValue &value);
|
2016-02-25 22:53:33 +01:00
|
|
|
void sendResults(const QJsonValue &what, const QJsonValue &id, const QJsonValue &values);
|
|
|
|
void updatedAvailable();
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void sendJson(const QJsonObject &obj);
|
2015-09-11 21:59:47 +02:00
|
|
|
void sendError(const QString &msg, const QJsonValue &id = QJsonValue());
|
2015-08-10 22:46:01 +02:00
|
|
|
void handleQuery(const QJsonObject &obj);
|
2015-09-11 21:59:47 +02:00
|
|
|
void handleCmd(const QJsonObject &obj);
|
2015-09-29 21:52:30 +02:00
|
|
|
template<class Lookup, typename... Args> void performLookup(const QJsonObject &request, Args &&...args);
|
2015-08-10 22:46:01 +02:00
|
|
|
|
|
|
|
QWebSocket *m_socket;
|
2015-09-21 22:16:19 +02:00
|
|
|
RepoIndex::Manager &m_manager;
|
2015-08-10 22:46:01 +02:00
|
|
|
bool m_repoInfoUpdatesRequested;
|
|
|
|
bool m_groupInfoUpdatesRequested;
|
|
|
|
};
|
|
|
|
|
2016-02-25 22:53:33 +01:00
|
|
|
|
|
|
|
|
2015-08-10 22:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CONNECTION_H
|