KD SOAP
 All Classes Functions Enumerations Enumerator Pages
KDSoapClientThread_p.h
1 /****************************************************************************
2 ** Copyright (C) 2010-2014 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 
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() { m_semaphore.acquire(); }
49  KDSoapMessage response() const { return m_response; }
50  KDSoapHeaders responseHeaders() const { return m_responseHeaders; }
51 
52  KDSoapClientInterface* m_iface; // used by KDSoapThreadTask::process()
53  KDSoapAuthentication m_authentication;
54  QString m_method;
55  KDSoapMessage m_message;
56  QString m_action;
57  QSemaphore m_semaphore;
58  KDSoapMessage m_response;
59  KDSoapHeaders m_responseHeaders;
60  KDSoapHeaders m_headers;
61 };
62 
63 class KDSoapThreadTask : public QObject
64 {
65  Q_OBJECT
66 public:
67  explicit KDSoapThreadTask(KDSoapThreadTaskData* data)
68  : m_data(data) {}
69 
70  void process(QNetworkAccessManager& accessManager);
71 
72 signals:
73  void taskDone();
74 
75 private Q_SLOTS:
76  void slotFinished(KDSoapPendingCallWatcher* watcher);
77  void slotAuthenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator);
78 
79 private:
80  KDSoapThreadTaskData* m_data;
81 };
82 
83 class KDSoapClientThread : public QThread
84 {
85  Q_OBJECT
86 public:
87  explicit KDSoapClientThread(QObject *parent = 0);
88 
89  void enqueue(KDSoapThreadTaskData* taskData);
90 
91  void stop();
92 
93 protected:
94  virtual void run();
95 
96 private:
97  QMutex m_mutex;
98  QQueue<KDSoapThreadTaskData*> m_queue;
99  QWaitCondition m_queueNotEmpty;
100  bool m_stopThread;
101 };
102 
103 #endif // KDSOAPCLIENTTHREAD_P_H

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-soap/