KDSOAP
|
00001 #ifndef KDSOAPCLIENTTHREAD_P_H 00002 #define KDSOAPCLIENTTHREAD_P_H 00003 00004 #include "KDSoapMessage.h" 00005 #include "KDSoapAuthentication.h" 00006 #include <QWaitCondition> 00007 #include <QQueue> 00008 #include <QThread> 00009 #include <QMutex> 00010 #include <QSemaphore> 00011 #include <QNetworkAccessManager> 00012 00013 class KDSoapPendingCallWatcher; 00014 class KDSoapClientInterface; 00015 class QEventLoop; 00016 00017 class KDSoapThreadTaskData 00018 { 00019 public: 00020 KDSoapThreadTaskData(KDSoapClientInterface* iface, const QString& method, const KDSoapMessage &message, const QString& action, const KDSoapHeaders& headers) 00021 : m_iface(iface), m_method(method), m_message(message), m_action(action), m_headers(headers) {} 00022 00023 void waitForCompletion() { m_semaphore.acquire(); } 00024 KDSoapMessage response() const { return m_response; } 00025 KDSoapHeaders responseHeaders() const { return m_responseHeaders; } 00026 00027 KDSoapClientInterface* m_iface; // used by KDSoapThreadTask::process() 00028 KDSoapAuthentication m_authentication; 00029 QString m_method; 00030 KDSoapMessage m_message; 00031 QString m_action; 00032 QSemaphore m_semaphore; 00033 KDSoapMessage m_response; 00034 KDSoapHeaders m_responseHeaders; 00035 KDSoapHeaders m_headers; 00036 }; 00037 00038 class KDSoapThreadTask : public QObject 00039 { 00040 Q_OBJECT 00041 public: 00042 KDSoapThreadTask(KDSoapThreadTaskData* data) 00043 : m_data(data) {} 00044 00045 void process(QNetworkAccessManager& accessManager); 00046 00047 signals: 00048 void taskDone(); 00049 00050 private Q_SLOTS: 00051 void slotFinished(KDSoapPendingCallWatcher* watcher); 00052 void slotAuthenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator); 00053 00054 private: 00055 KDSoapThreadTaskData* m_data; 00056 }; 00057 00058 class KDSoapClientThread : public QThread 00059 { 00060 Q_OBJECT 00061 public: 00062 explicit KDSoapClientThread(QObject *parent = 0); 00063 00064 void enqueue(KDSoapThreadTaskData* taskData); 00065 00066 void stop(); 00067 00068 protected: 00069 virtual void run(); 00070 00071 private: 00072 QMutex m_mutex; 00073 QQueue<KDSoapThreadTaskData*> m_queue; 00074 QWaitCondition m_queueNotEmpty; 00075 bool m_stopThread; 00076 }; 00077 00078 #endif // KDSOAPCLIENTTHREAD_P_H