IpResolvingTransportFactory.h

Go to the documentation of this file.
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__GENERICS__IP_RESOLVING_TRANSPORT_FACTORY_H
00024 #define PROTOCOLS__GENERICS__IP_RESOLVING_TRANSPORT_FACTORY_H
00025 
00026 #include "Imports.h"
00027 #include "NameResolverStatus.h"
00028 #include "TransportFactory.h"
00029 #include "TransportFactoryStatus.h"
00030 
00031 namespace Protocols {
00032 namespace Generics {
00033 
00034 class NameResolver;
00035 
00037 
00058 class IpResolvingTransportFactory : public TransportFactory,
00059                                     public TransportFactoryStatus,
00060                                     public NameResolverStatus
00061 {
00062     CALITKO_TESTABLE
00063 public:
00064                         IpResolvingTransportFactory (TransportFactory *,
00065                                                      NameResolver *);
00066                         ~IpResolvingTransportFactory();
00067 
00068     // Implementation for the TransportFactory interface:
00069     void                createTransport (const Uri &, TransportFactoryStatus *);
00070     void                destroyTransport (Transport *);
00071 
00072     // Implementation for the TransportFactoryStatus interface:
00073     void                transportFactorySucceeded (const Uri &, Transport *);
00074     void                transportFactoryFailed (const Uri &);
00075 
00076     // Implementation for the NameResolverStatus interface:
00077     void                nameResolverResolvedName (
00078                                         const QByteArray &name,
00079                                         const QList <QHostAddress> &addresses);
00080 
00081 private:
00082     void                startNameResolution (const Uri &,
00083                                              TransportFactoryStatus *);
00084     void                createFailed (const QByteArray &host);
00085     void                tryCreateTransport (const QByteArray &host);
00086 
00087     struct ResolvingState
00088     {
00089         Uri                     uri;
00090         TransportFactoryStatus  *status;
00091         QList <QHostAddress>    addresses;
00092     };
00093 
00094     typedef QHash <QByteArray, ResolvingState *> ResolvingStates;
00095     typedef QHash <Uri, ResolvingState *> CreatingStates;
00096 
00097     TransportFactory    *otherFactory_;
00098     NameResolver        *nameResolver_;
00099     ResolvingStates     resolvingStates_;
00100     CreatingStates      creatingStates_;
00101 };
00102 
00103 } // namespace Generics
00104 } // namespace Protocols
00105 
00106 #endif // PROTOCOLS__GENERICS__IP_RESOLVING_TRANSPORT_FACTORY_H