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