jigdo API
Last update by Admin on 2010-05-23
job/cached-url.hh
Go to the documentation of this file.00001 /* $Id: cached-url.hh,v 1.1 2003/08/31 23:52:46 richard Exp $ -*- C++ -*- 00002 __ _ 00003 |_) /| Copyright (C) 2003 | richard@ 00004 | \/¯| Richard Atterer | atterer.net 00005 ¯ '` ¯ 00006 This program is free software; you can redistribute it and/or modify it 00007 under the terms of the GNU General Public License, version 2. See the file 00008 COPYING for details. 00009 00010 */ 00020 #ifndef CACHED_URL_HH 00021 #define CACHED_URL_HH 00022 00023 #include <config.h> 00024 00025 #include <glib.h> 00026 #include <set> 00027 00028 #include <bstream.hh> 00029 #include <datasource.hh> 00030 #include <nocopy.hh> 00031 #include <progress.hh> 00032 //______________________________________________________________________ 00033 00034 namespace Job { 00035 class CachedUrl; 00036 } 00037 00039 class Job::CachedUrl : public Job::DataSource { 00040 public: 00046 CachedUrl(const string& filename, uint64 prio); 00047 virtual ~CachedUrl(); 00048 00049 virtual void run(); 00050 00052 virtual bool paused() const; 00054 virtual void pause(); 00056 virtual void cont(); 00057 00058 00060 virtual const Progress* progress() const; 00062 virtual const string& location() const; 00063 00064 //inline const string& filename() const; 00065 00066 private: 00067 /* Set of all active (non-paused) downloads. After construction, CachedUrls 00068 are initially paused, run() and cont() are identical. */ 00069 struct Cmp { 00070 inline bool operator()(const CachedUrl* a, const CachedUrl* b) const; 00071 }; 00072 friend struct Cmp; 00073 typedef set<CachedUrl*, Cmp> Set; 00074 static Set active; 00075 static unsigned readSpeed; // Bytes per sec read from active.front()->file 00076 00077 // glib callback, spools data when main loop is otherwise idle. 00078 static gboolean spoolDataCallback(gpointer); 00079 static int spoolDataCallbackId; // glib event source ID for above 00080 00081 string filenameVal; 00082 uint64 priority; 00083 Progress progressVal; 00084 bifstream* file; 00085 }; 00086 //______________________________________________________________________ 00087 00088 //const string& Job::CachedUrl::filename() const { return filenameVal; } 00089 00090 bool Job::CachedUrl::Cmp::operator()(const CachedUrl* a, const CachedUrl* b) 00091 const { 00092 if (a->priority == b->priority) return (a < b); 00093 else return (a->priority < b->priority); 00094 } 00095 00096 #endif
Generated on Tue Sep 23 14:27:41 2008 for jigdo by
