00001 #ifndef _HTTP_POOL_H_
00002 #define _HTTP_POOL_H_
00003
00004
00005 #include <set>
00006 #include <deque>
00007 using namespace std;
00008
00009
00010 #include <QString>
00011 #include <QMutex>
00012 #include <QHttp>
00013 #include <QUrl>
00014
00015
00016 #include "mythbaseexp.h"
00017
00018 class MBASE_PUBLIC MythHttpListener
00019 {
00020 public:
00021 virtual void Update(QHttp::Error error,
00022 const QString &error_str,
00023 const QUrl &url,
00024 uint http_status_id,
00025 const QString &http_status_str,
00026 const QByteArray &data) = 0;
00027 virtual ~MythHttpListener() { }
00028 };
00029
00030 class HttpRequest
00031 {
00032 public:
00033 HttpRequest(const QUrl &url, MythHttpListener *listener) :
00034 m_url(url), m_listener(listener) {}
00035
00036 QUrl m_url;
00037 MythHttpListener *m_listener;
00038 };
00039
00040 class MythHttpHandler;
00041 typedef QMap<QString,MythHttpHandler*> HostToHandler;
00042 typedef QMultiMap<QUrl,MythHttpListener*> UrlToListener;
00043
00044 class MBASE_PUBLIC MythHttpPool
00045 {
00046 public:
00047 MythHttpPool(uint max_connections = 20);
00048 ~MythHttpPool();
00049
00050 void AddUrlRequest(const QUrl &url, MythHttpListener *listener);
00051 void RemoveUrlRequest(const QUrl &url, MythHttpListener *listener);
00052 void RemoveListener(MythHttpListener *listener);
00053
00054 static MythHttpPool *GetSingleton();
00055
00056 void Update(QHttp::Error error,
00057 const QString &error_str,
00058 const QUrl &url,
00059 uint http_status_id,
00060 const QString &http_status_str,
00061 const QByteArray &data);
00062
00063 void Done(const QString &host, MythHttpHandler *handler);
00064
00065 private:
00066 mutable QMutex m_lock;
00067 uint m_maxConnections;
00068 deque<HttpRequest> m_httpQueue;
00069 set<MythHttpListener*> m_listeners;
00070 UrlToListener m_urlToListener;
00071 HostToHandler m_hostToHandler;
00072
00073 static MythHttpPool *singleton;
00074 };
00075
00076 #endif // _HTTP_POOL_H_