00001 // -*- Mode: c++ -*- 00002 00003 #ifndef _HTTP_HANDLER_H_ 00004 #define _HTTP_HANDLER_H_ 00005 00006 // C++ headers 00007 #include <deque> 00008 using namespace std; 00009 00010 // Qt headers 00011 #include <QMutex> 00012 #include <QUrl> 00013 00014 typedef deque<QUrl> UrlQueue; 00015 00016 class QHttp; 00017 class QHttpResponseHeader; 00018 class MythHttpPool; 00019 00020 class MythHttpHandler : public QObject 00021 { 00022 Q_OBJECT 00023 public: 00024 MythHttpHandler(MythHttpPool *pool); 00025 virtual void deleteLater(void) { TeardownAll(); QObject::deleteLater(); } 00026 00027 bool HasPendingRequests(void) const; 00028 void AddUrlRequest(const QUrl &url); 00029 void RemoveUrlRequest(const QUrl &url); 00030 00031 protected slots: 00032 void Done(bool error); 00033 void ResponseHeaderReceived(const QHttpResponseHeader &resp); 00034 void RequestFinished(int id, bool error); 00035 void RequestStarted(int id); 00036 void StateChanged(int state); 00037 00038 private: 00039 ~MythHttpHandler() { TeardownAll(); } 00040 void TeardownAll(); 00041 void Get(const QUrl &url); 00042 00043 private: 00044 mutable QMutex m_lock; 00045 UrlQueue m_urls; 00046 QUrl m_cur_url; 00047 uint m_cur_status_id; 00048 QString m_cur_status_str; 00049 int m_cur_get_id; 00050 uint m_cur_redirect_cnt; 00051 MythHttpPool *m_pool; 00052 QHttp *m_qhttp; 00053 00054 static const uint kMaxRedirectCount; 00055 }; 00056 00057 #endif // _HTTP_HANDLER_H_
1.6.3