jigdo API
Last update by Admin on 2010-05-23
job/single-url.hh
Go to the documentation of this file.00001 /* $Id: single-url.hh,v 1.10 2003/09/03 19:28:13 atterer Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 2002-2003 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License, version 2. See 00008 the file COPYING for details. 00009 00010 */ 00018 #ifndef SINGLE_URL_HH 00019 #define SINGLE_URL_HH 00020 00021 #include <bstream-counted.hh> 00022 #include <datasource.hh> 00023 #include <download.hh> 00024 #include <nocopy.hh> 00025 #include <progress.hh> 00026 //______________________________________________________________________ 00027 00028 namespace Job { 00029 class SingleUrl; 00030 } 00031 00053 class Job::SingleUrl : public Job::DataSource, private Download::Output { 00054 public: 00057 static const unsigned RESUME_SIZE = 16*1024; 00060 static const int MAX_TRIES = 20; 00065 static const int RESUME_DELAY = 3000; 00066 00069 SingleUrl(/*IOPtr DataSource::IO* ioPtr, */const string& uri); 00070 virtual ~SingleUrl(); 00071 00084 void setResumeOffset(uint64 resumeOffset); 00085 00095 void setDestination(BfstreamCounted* destStream, 00096 uint64 destOffset, uint64 destEndOffset); 00097 00102 // inline void setPragmaNoCache(bool pragmaNoCache); 00103 00115 virtual void run(); 00116 00118 inline int currentTry() const; 00119 00121 virtual bool paused() const; 00123 virtual void pause(); 00125 virtual void cont(); 00127 inline void stop(); 00128 00131 inline bool resuming() const; 00132 00134 inline bool failed() const; 00135 00138 inline bool succeeded() const; 00139 00141 virtual const Progress* progress() const; 00143 virtual const string& location() const; 00144 00146 inline BfstreamCounted* destStream() const; 00147 00149 //inline void setDestStream(bfstream* destStream); 00150 00155 inline bool resumePossible() const; 00156 00160 inline void setNoResumePossible(); 00161 00162 private: 00163 // Virtual methods from Download::Output 00164 virtual void download_dataSize(uint64 n); 00165 virtual void download_data(const byte* data, unsigned size, 00166 uint64 currentSize); 00167 virtual void download_succeeded(); 00168 virtual void download_failed(string* message); 00169 virtual void download_message(string* message); 00170 00172 //void stopLater(); 00173 00174 /* Write bytes at specified offset. Return FAILURE and call 00175 io->job_failed() if error during writing or if written data would 00176 exceed destEndOff. */ 00177 inline bool writeToDestStream(uint64 off, const byte* data, unsigned size); 00178 00179 Download download; 00180 Progress progressVal; 00181 00182 // Call io->job_failed(), then stopLater() 00183 inline void resumeFailed(); 00184 00185 SmartPtr<BfstreamCounted> destStreamVal; 00186 uint64 destOff, destEndOff; 00187 unsigned resumeLeft; // >0: Nr of bytes of resume overlap left 00188 00189 /* Was setResumeOffset()/setDestination()/setPragmaNoCache() called before 00190 run()? If false, run() will call it with default values. */ 00191 bool haveResumeOffset, haveDestination; //, havePragmaNoCache; 00192 00193 int tries; // Nr of tries resuming after interrupted connection 00194 }; 00195 //====================================================================== 00196 00197 00198 // void Job::SingleUrl::setPragmaNoCache(bool pragmaNoCache) { 00199 // download.setPragmaNoCache(pragmaNoCache); 00200 // havePragmaNoCache = true; 00201 // } 00202 int Job::SingleUrl::currentTry() const { return tries; } 00203 bool Job::SingleUrl::resuming() const { return resumeLeft > 0; } 00204 bool Job::SingleUrl::failed() const { return download.failed(); } 00205 bool Job::SingleUrl::succeeded() const { return download.succeeded(); } 00206 BfstreamCounted* Job::SingleUrl::destStream() const { 00207 return destStreamVal.get(); } 00208 00209 bool Job::SingleUrl::resumePossible() const { 00210 // msg("Job::SingleUrl::resumePossible tries=%1 interr=%2 curSiz=%3", 00211 // tries, download.interrupted(), progressVal.currentSize()); 00212 if (tries >= MAX_TRIES || !download.interrupted()) return false; 00213 if (progressVal.currentSize() == 0 00214 || progressVal.dataSize() == 0) return true; 00215 return (progressVal.dataSize() > 0 00216 && progressVal.currentSize() < progressVal.dataSize()); 00217 } 00218 void Job::SingleUrl::setNoResumePossible() { 00219 tries = MAX_TRIES; // Download failed permanently, do not resume 00220 } 00221 void Job::SingleUrl::stop() { 00222 download.stop(); 00223 } 00224 00225 #endif
Generated on Tue Sep 23 14:27:41 2008 for jigdo by
