-
Notifications
You must be signed in to change notification settings - Fork 0
/
QXMLRpc.h
49 lines (38 loc) · 1.28 KB
/
QXMLRpc.h
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
39
40
41
42
43
44
45
46
47
48
49
#ifndef QXMLRPC_H
# define QXMLRPC_H
# include <QtNetwork/QNetworkAccessManager>
# include <QtNetwork/QNetworkReply>
# include <QString>
# include <QUrl>
class QXMLRpcFault
{
public:
QXMLRpcFault(QVariant value) : value(value.toMap()) {}
int code() const;
QString message() const;
static bool isFault(QVariant value);
private:
QVariantMap value;
};
class QXMLRpcClient : public QNetworkAccessManager
{
Q_OBJECT
public:
QXMLRpcClient(QObject* parent = nullptr);
static bool debugMode;
void setEndpoint(const QUrl& value);
void call(const QString& methodName, const QVariantList& parameters) { call(methodName, parameters, std::function<void(QVariant)>()); }
void call(const QString& methodName, const QVariantList& parameters, std::function<void (QVariant)> callback);
signals:
void endpointChanged();
void responseReceived(QVariant);
void faultReceived(QXMLRpcFault);
private:
QUrl endpoint;
static QString getXmlForMethodCall(const QString& methodName, const QVariantList& parameters);
static QString fromVariantToXmlValue(const QVariant& variant);
static QString fromVariantListToXmlValue(const QVariantList& list);
static QString fromVariantHashToXmlValue(const QVariantHash& hash);
static QVariant getReturnValueFromReply(QNetworkReply& reply);
};
#endif