nx_server_plugin_sdk 1.0 Server Plugin SDK

sync_http_client_delegate.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <QtCore/QMutex>
6 #include <QtCore/QObject>
7 #include <QtCore/QWaitCondition>
8 #include <QtNetwork/QNetworkAccessManager>
9 #include <QtNetwork/QNetworkReply>
10
12
15 class SyncHttpClientDelegate
16 :
17 public QObject
18 {
19 Q_OBJECT
20
21 public:
22 SyncHttpClientDelegate( QNetworkAccessManager* networkAccessManager );
23
25 void get( const QNetworkRequest& request );
26
28
31 QByteArray readWholeMessageBody();
32
33 QNetworkReply::NetworkError resultCode() const;
34 int statusCode() const;
35
36 protected:
37 virtual ~SyncHttpClientDelegate();
38
39 private:
40 enum RequestState
41 {
42 rsInit,
43 rsWaitingResponse,
44 rsReadingMessageBody,
45 rsDone,
46 rsFailed
47 };
48
49 QNetworkAccessManager* m_networkAccessManager;
50 mutable QMutex m_mutex;
51 QWaitCondition m_cond;
52 QNetworkReply* m_reply;
53 QByteArray m_messageBody;
54 RequestState m_requestState;
55
56 private:
60 void getPriv( const QNetworkRequest& request );
61 void onReplyReadyRead();
62 void onConnectionFinished( QNetworkReply* reply );
64 void readWholeMessageBodyPriv();
65 };
SyncHttpClientDelegate
Helper class, used by SyncHttpClient.
Definition: sync_http_client_delegate.h:15
SyncHttpClientDelegate::readWholeMessageBody
QByteArray readWholeMessageBody()
Blocks till all message body read.
Definition: sync_http_client_delegate.cpp:60