KDSoapClientThread_p.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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;
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