KDSoapClientThread_p.h

00001 /****************************************************************************
00002 ** Copyright (C) 2010-2010 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD SOAP library.
00005 **
00006 ** Licensees holding valid commercial KD Soap licenses may use this file in
00007 ** accordance with the KD Soap Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #ifndef KDSOAPCLIENTTHREAD_P_H
00024 #define KDSOAPCLIENTTHREAD_P_H
00025 
00026 #include "KDSoapMessage.h"
00027 #include "KDSoapAuthentication.h"
00028 #include <QWaitCondition>
00029 #include <QQueue>
00030 #include <QThread>
00031 #include <QMutex>
00032 #include <QSemaphore>
00033 #include <QNetworkAccessManager>
00034 
00035 class KDSoapPendingCallWatcher;
00036 class KDSoapClientInterface;
00037 class QEventLoop;
00038 
00039 class KDSoapThreadTaskData
00040 {
00041 public:
00042     KDSoapThreadTaskData(KDSoapClientInterface* iface, const QString& method, const KDSoapMessage &message, const QString& action, const KDSoapHeaders& headers)
00043         : m_iface(iface), m_method(method), m_message(message), m_action(action), m_headers(headers) {}
00044 
00045     void waitForCompletion() { m_semaphore.acquire(); }
00046     KDSoapMessage returnArguments() const { return m_returnArguments; }
00047 
00048     KDSoapClientInterface* m_iface; // used by KDSoapThreadTask::process()
00049     KDSoapAuthentication m_authentication;
00050     QString m_method;
00051     KDSoapMessage m_message;
00052     QString m_action;
00053     QSemaphore m_semaphore;
00054     KDSoapMessage m_returnArguments;
00055     KDSoapHeaders m_headers;
00056 };
00057 
00058 class KDSoapThreadTask : public QObject
00059 {
00060     Q_OBJECT
00061 public:
00062     KDSoapThreadTask(KDSoapThreadTaskData* data)
00063         : m_data(data) {}
00064 
00065     void process(QNetworkAccessManager& accessManager);
00066 
00067 signals:
00068     void taskDone();
00069 
00070 private Q_SLOTS:
00071     void slotFinished(KDSoapPendingCallWatcher* watcher);
00072     void slotAuthenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator);
00073 
00074 private:
00075     KDSoapThreadTaskData* m_data;
00076 };
00077 
00078 class KDSoapClientThread : public QThread
00079 {
00080     Q_OBJECT
00081 public:
00082     explicit KDSoapClientThread(QObject *parent = 0);
00083 
00084     void enqueue(KDSoapThreadTaskData* taskData);
00085 
00086     void stop();
00087 
00088 protected:
00089     virtual void run();
00090 
00091 private:
00092     QMutex m_mutex;
00093     QQueue<KDSoapThreadTaskData*> m_queue;
00094     QWaitCondition m_queueNotEmpty;
00095     bool m_stopThread;
00096 };
00097 
00098 #endif // KDSOAPCLIENTTHREAD_P_H
 All Classes Functions Enumerations Enumerator Friends

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