TrackerManagerImpl.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__BIT_TORRENT__TRACKERS__TRACKER_MANAGER_IMPL_H
00024 #define PROTOCOLS__BIT_TORRENT__TRACKERS__TRACKER_MANAGER_IMPL_H
00025 
00026 #include "Imports.h"
00027 #include "TrackerManager.h"
00028 #include "TrackerRequest.h"
00029 #include "TrackerRequestSessionFactory.h"
00030 #include "TrackerResponse.h"
00031 
00032 namespace Protocols {
00033 namespace BitTorrent {
00034 namespace Trackers {
00035 
00037 
00044 class Timer
00045 {
00046     CALITKO_MOCKABLE
00047 
00048 public:
00049     virtual         ~Timer() {}
00050 
00051     virtual void    start (void *, qint64 timeout) = 0;
00052     virtual void    stop() = 0;
00053 };
00054 
00056 
00075 class TrackerManagerImpl : public TrackerManager
00076 {
00077     CALITKO_TESTABLE
00078     REFERENCE_OBJECT (TrackerManagerImpl)
00079 
00080 public:
00081             TrackerManagerImpl (TrackerRequestSessionFactory *,
00082                                 Timer *,
00083                                 TrackerManagerStatus *);
00084             ~TrackerManagerImpl();
00085 
00086     void    start (const Torrent &);
00087     void    stop();
00088     void    updateTime();
00089 
00090     // Implementation for the TrackerRequestSessionFactoryStatus interface:
00091     void    trackerRequestSessionFactorySessionEstablished (TrackerRequestSession *);
00092     void    trackerRequestSessionFactorySessionError (TrackerRequestSession *,
00093                                                       const QString &);
00094     void    trackerRequestSessionFactoryResponseRecieved (TrackerRequestSession *,
00095                                                           const TrackerResponse &);
00096     void    trackerRequestSessionFactorySessionClosing (TrackerRequestSession *);
00097     void    trackerRequestSessionFactorySessionClosed (TrackerRequestSession *);
00098 
00099 private:
00101     enum State
00102     {
00103         Started,
00104         Stopping,
00105         Stopped
00106     };
00107 
00108     TrackerRequest                  createTrackerRequest() const;
00109 
00110     TrackerRequestSessionFactory    *sessionFactory_;
00111     Timer                           *timer_;
00112     TrackerManagerStatus            *status_;
00113     TrackerRequestSession           *session_;
00114     State                           state_;
00115     Torrent                         torrent_;
00116     uint                            updateInterval_;
00117     QByteArray                      trackerId_;
00118 };
00119 
00120 } // namespace Trackers
00121 } // namespace BitTorrent
00122 } // namespace Protocols
00123 
00124 #endif // PROTOCOLS__BIT_TORRENT__TRACKERS__TRACKER_MANAGER_IMPL_H