-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQmlJsonRpcProvider.hpp
38 lines (25 loc) · 955 Bytes
/
QmlJsonRpcProvider.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef JSONRPCPROVIDER_HPP
#define JSONRPCPROVIDER_HPP
#include "Promise.hpp"
#include <memory>
#include <QtWebSockets>
class QmlJsonRpcProvider : public QObject {
Q_OBJECT
Q_PROPERTY(QObject* socket READ socket WRITE setSocket NOTIFY socketChanged)
int64_t nextQueryId = 0;
std::map<int64_t, std::unique_ptr<QmlPromise>> pendingRequests;
QObject* m_socket;
public:
QmlJsonRpcProvider(QObject* parent = nullptr);
Q_INVOKABLE QJSValue call(QString method, QVariantList params);
QObject* socket() const { return m_socket; }
public slots:
/// Set the socket to communicate RPC over. Technically, this can be any object with a textMessageReceived signal
/// and a sendTextMessage slot, each having a single QString argument.
void setSocket(QObject* socket);
protected slots:
void messageReceived(QString message);
signals:
void socketChanged(QObject* socket);
};
#endif // JSONRPCPROVIDER_HPP