KD SOAP: src/KDSoapClient/KDSoapClientThread_p.h Source File

| KD SOAP 1.9.1

KDSoapClientThread_p.h
1 /****************************************************************************
2 ** Copyright (C) 2010-2020 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com.
3 ** All rights reserved.
4 **
5 ** This file is part of the KD Soap library.
6 **
7 ** Licensees holding valid commercial KD Soap licenses may use this file in
8 ** accordance with the KD Soap Commercial License Agreement provided with
9 ** the Software.
10 **
11 **
12 ** This file may be distributed and/or modified under the terms of the
13 ** GNU Lesser General Public License version 2.1 and version 3 as published by the
14 ** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
15 **
16 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 **
19 ** Contact info@kdab.com if any conditions of this licensing are not
20 ** clear to you.
21 **
22 **********************************************************************/
23
24 #ifndef KDSOAPCLIENTTHREAD_P_H
25 #define KDSOAPCLIENTTHREAD_P_H
26
27 #include "KDSoapMessage.h"
28 #include "KDSoapAuthentication.h"
29 #include <QtCore/QWaitCondition>
30 #include <QtCore/QQueue>
31 #include <QtCore/QThread>
32 #include <QtCore/QMutex>
33 #include <QtCore/QSemaphore>
34 #include <QtNetwork/QNetworkAccessManager>
35
36 class KDSoapPendingCallWatcher;
37 class KDSoapClientInterface;
38 QT_BEGIN_NAMESPACE
39 class QEventLoop;
40 QT_END_NAMESPACE
41
42 class KDSoapThreadTaskData
43 {
44 public:
45 KDSoapThreadTaskData(KDSoapClientInterface *iface, const QString &method, const KDSoapMessage &message, const QString &action, const KDSoapHeaders &headers)
46 : m_iface(iface), m_method(method), m_message(message), m_action(action), m_headers(headers) {}
47
48 void waitForCompletion()
49 {
50 m_semaphore.acquire();
51 }
52 KDSoapMessage response() const
53 {
54 return m_response;
55 }
56 KDSoapHeaders responseHeaders() const
57 {
58 return m_responseHeaders;
59 }
60
61 KDSoapClientInterface *m_iface; // used by KDSoapThreadTask::process()
62 KDSoapAuthentication m_authentication;
63 QString m_method;
64 KDSoapMessage m_message;
65 QString m_action;
66 QSemaphore m_semaphore;
67 KDSoapMessage m_response;
68 KDSoapHeaders m_responseHeaders;
69 KDSoapHeaders m_headers;
70 };
71
72 class KDSoapThreadTask : public QObject
73 {
74 Q_OBJECT
75 public:
76 explicit KDSoapThreadTask(KDSoapThreadTaskData *data)
77 : m_data(data) {}
78
79 void process(QNetworkAccessManager &accessManager);
80
81 signals:
82 void taskDone();
83
84 private Q_SLOTS:
85 void slotFinished(KDSoapPendingCallWatcher *watcher);
86 void slotAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
87
88 private:
89 KDSoapThreadTaskData *m_data;
90 };
91
92 class KDSoapClientThread : public QThread
93 {
94 Q_OBJECT
95 public:
96 explicit KDSoapClientThread(QObject *parent = nullptr);
97
98 void enqueue(KDSoapThreadTaskData *taskData);
99
100 void stop();
101
102 protected:
103 virtual void run() override;
104
105 private:
106 QMutex m_mutex;
107 QQueue<KDSoapThreadTaskData *> m_queue;
108 QWaitCondition m_queueNotEmpty;
109 bool m_stopThread;
110 };
111
112 #endif // KDSOAPCLIENTTHREAD_P_H
KDSoapHeaders
Definition: KDSoapMessage.h:196
KDSoapPendingCallWatcher
Definition: KDSoapPendingCallWatcher.h:49
KDSoapAuthentication
Definition: KDSoapAuthentication.h:44
KDSoapClientInterface
Definition: KDSoapClientInterface.h:64
KDSoapMessage
Definition: KDSoapMessage.h:42

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-soap/