00001 /* 00002 00003 Copyright (C) 2006-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef PROTOCOLS__HTTP__CLIENT_HTTP_SESSION_FACTORY_H 00024 #define PROTOCOLS__HTTP__CLIENT_HTTP_SESSION_FACTORY_H 00025 00026 #include "Imports.h" 00027 #include "ClientHttpSession.h" 00028 00029 namespace Protocols { 00030 namespace Http { 00031 00036 class ClientHttpSessionFactoryStatus 00037 { 00038 CALITKO_MOCKABLE 00039 00040 public: 00041 virtual ~ClientHttpSessionFactoryStatus() {}; 00042 virtual void clientHttpSessionFactorySucceeded (const Uri &, 00043 ClientHttpSession *) = 0; 00044 virtual void clientHttpSessionFactoryFailed (const Uri &) = 0; 00045 }; 00046 00047 class ClientHttpSessionStatus; 00048 00050 00055 class ClientHttpSessionFactory : public TransportFactoryStatus 00056 { 00057 CALITKO_TESTABLE 00058 00059 public: 00060 ClientHttpSessionFactory (TransportFactory *); 00061 ~ClientHttpSessionFactory(); 00062 00063 static Uri makeTransportUri (const Uri &httpUri); 00064 00065 // \todo extract ClientHttpSession interface: 00066 ClientHttpSession * createSession (Transport *, 00067 ClientHttpSessionStatus *); 00068 void createSession (const Uri &, 00069 ClientHttpSessionStatus *, 00070 ClientHttpSessionFactoryStatus *); 00071 void destroySession (ClientHttpSession *); 00072 00073 // Implementation for TransportEstablisherStatus interface: 00074 void transportFactorySucceeded (const Uri &, 00075 Transport *); 00076 void transportFactoryFailed (const Uri &); 00077 00078 00079 private: 00080 static Uri makeTcpUriFromHttpUri (const Uri &uri); 00081 00082 struct EstablishingSession 00083 { 00084 Uri uri; 00085 ClientHttpSessionStatus * sessionStatus; 00086 ClientHttpSessionFactoryStatus * factoryStatus; 00087 }; 00088 00089 typedef QHash <Uri, EstablishingSession *> EstablishingSessions; 00090 typedef QHash <ClientHttpSession *, Transport *> Sessions; 00091 00092 TransportFactory *transportFactory_; 00093 EstablishingSessions establishingSessions_; 00094 Sessions sessions_; 00095 }; 00096 00097 } // namespace Http 00098 } // namespace Protocols 00099 00100 #endif // PROTOCOLS__HTTP__CLIENT_HTTP_SESSION_FACTORY_H