KD SOAP  1.10.0
KDSoapClientThread_p.h
1 /****************************************************************************
2 **
3 ** This file is part of the KD Soap library.
4 **
5 ** SPDX-FileCopyrightText: 2010-2020 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDAB-KDSoap OR LicenseRef-KDAB-KDSoap-US
8 **
9 ** Licensees holding valid commercial KD Soap licenses may use this file in
10 ** accordance with the KD Soap Commercial License Agreement provided with
11 ** the Software.
12 **
13 ** Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 **
15 ****************************************************************************/
16 
17 #ifndef KDSOAPCLIENTTHREAD_P_H
18 #define KDSOAPCLIENTTHREAD_P_H
19 
20 #include "KDSoapMessage.h"
21 #include "KDSoapAuthentication.h"
22 #include <QtCore/QWaitCondition>
23 #include <QtCore/QQueue>
24 #include <QtCore/QThread>
25 #include <QtCore/QMutex>
26 #include <QtCore/QSemaphore>
27 #include <QtNetwork/QNetworkAccessManager>
28 
31 QT_BEGIN_NAMESPACE
32 class QEventLoop;
33 QT_END_NAMESPACE
34 
35 class KDSoapThreadTaskData
36 {
37 public:
38  KDSoapThreadTaskData(KDSoapClientInterface *iface, const QString &method, const KDSoapMessage &message, const QString &action, const KDSoapHeaders &headers)
39  : m_iface(iface), m_method(method), m_message(message), m_action(action), m_headers(headers) {}
40 
41  void waitForCompletion()
42  {
43  m_semaphore.acquire();
44  }
45  KDSoapMessage response() const
46  {
47  return m_response;
48  }
49  KDSoapHeaders responseHeaders() const
50  {
51  return m_responseHeaders;
52  }
53 
54  KDSoapClientInterface *m_iface; // used by KDSoapThreadTask::process()
55  KDSoapAuthentication m_authentication;
56  QString m_method;
57  KDSoapMessage m_message;
58  QString m_action;
59  QSemaphore m_semaphore;
60  KDSoapMessage m_response;
61  KDSoapHeaders m_responseHeaders;
62  KDSoapHeaders m_headers;
63 };
64 
65 class KDSoapThreadTask : public QObject
66 {
67  Q_OBJECT
68 public:
69  explicit KDSoapThreadTask(KDSoapThreadTaskData *data)
70  : m_data(data) {}
71 
72  void process(QNetworkAccessManager &accessManager);
73 
74 signals:
75  void taskDone();
76 
77 private Q_SLOTS:
78  void slotFinished(KDSoapPendingCallWatcher *watcher);
79  void slotAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
80 
81 private:
82  KDSoapThreadTaskData *m_data;
83 };
84 
85 class KDSoapClientThread : public QThread
86 {
87  Q_OBJECT
88 public:
89  explicit KDSoapClientThread(QObject *parent = nullptr);
90 
91  void enqueue(KDSoapThreadTaskData *taskData);
92 
93  void stop();
94 
95 protected:
96  virtual void run() override;
97 
98 private:
99  QMutex m_mutex;
100  QQueue<KDSoapThreadTaskData *> m_queue;
101  QWaitCondition m_queueNotEmpty;
102  bool m_stopThread;
103 };
104 
105 #endif // KDSOAPCLIENTTHREAD_P_H
Definition: KDSoapPendingCallWatcher.h:41
Definition: KDSoapMessage.h:188
Definition: KDSoapAuthentication.h:36
Definition: KDSoapMessage.h:34
Definition: KDSoapClientInterface.h:56

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/