1 /* $Id: cached-url.hh,v 1.3 2004/09/09 23:50:21 atterer Exp $ -*- C++ -*-
3 |_) /| Copyright (C) 2003 | richard@
4 | \/¯| Richard Atterer | atterer.net
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License, version 2. See the file
12 Spool data from cache file
14 A CachedUrl is started when MakeImageDl::childFor() was instructed to
15 return a DataSource for an URL/md5sum, but that data was already present on
29 #include <datasource.hh>
31 #include <progress.hh>
32 //______________________________________________________________________
38 /** Spool data from cache file */
39 class Job::CachedUrl : public Job::DataSource {
41 /** Create object, but don't start outputting data yet - use run() to do
43 @param filename File to spool from
44 @param prio "Priority" - if >1 CachedUrls are running, the ones with
45 lower prio get spooled first. */
46 CachedUrl(const string& filename, uint64 prio);
51 /** Is the download currently paused? From DataSource. */
52 virtual bool paused() const;
53 /** Pause the download. From DataSource. */
55 /** Continue downloading. From DataSource. */
59 /** Return the internal progress object. From DataSource. */
60 virtual const Progress* progress() const;
61 /** Return the URL used to download the data. From DataSource. */
62 virtual const string& location() const;
64 //inline const string& filename() const;
67 /* Set of all active (non-paused) downloads. After construction, CachedUrls
68 are initially paused, run() and cont() are identical. */
70 inline bool operator()(const CachedUrl* a, const CachedUrl* b) const;
73 typedef set<CachedUrl*, Cmp> Set;
75 static unsigned readSpeed; // Bytes per sec read from active.front()->file
77 // glib callback, spools data when main loop is otherwise idle.
78 static gboolean spoolDataCallback(gpointer);
79 static int spoolDataCallbackId; // glib event source ID for above
86 //______________________________________________________________________
88 //const string& Job::CachedUrl::filename() const { return filenameVal; }
90 bool Job::CachedUrl::Cmp::operator()(const CachedUrl* a, const CachedUrl* b)
92 if (a->priority == b->priority) return (a < b);
93 else return (a->priority < b->priority);