repoindex/network/connection.h

48 lines
1.2 KiB
C++

#ifndef CONNECTION_H
#define CONNECTION_H
#include <QObject>
#include <QJsonValue>
#include <map>
QT_FORWARD_DECLARE_CLASS(QWebSocket)
namespace RepoIndex {
class Manager;
class Connection : public QObject
{
Q_OBJECT
public:
Connection(Manager &alpmManager, QWebSocket *socket, QObject *parent = nullptr);
private slots:
void processTextMessage(const QString &message);
void processBinaryMessage(const QByteArray &message);
void socketDisconnected();
void sendResult(const QJsonValue &what, const QJsonValue &id, const QJsonValue &value);
void sendResults(const QJsonValue &what, const QJsonValue &id, const QJsonValue &values);
void updatedAvailable();
private:
void sendJson(const QJsonObject &obj);
void sendError(const QString &msg, const QJsonValue &id = QJsonValue());
void handleQuery(const QJsonObject &obj);
void handleCmd(const QJsonObject &obj);
template<class Lookup, typename... Args> void performLookup(const QJsonObject &request, Args &&...args);
QWebSocket *m_socket;
RepoIndex::Manager &m_manager;
bool m_repoInfoUpdatesRequested;
bool m_groupInfoUpdatesRequested;
};
}
#endif // CONNECTION_H