1 /* $Id: datasource.hh,v 1.4 2003/08/28 23:21:00 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
7 it under the terms of the GNU General Public License, version 2. See
8 the file COPYING for details.
10 Interface for objects returning data from the network or from disk
20 #include <makeimagedl.fh>
22 #include <progress.fh>
23 //______________________________________________________________________
29 /** Interface for objects returning data from the network or from disk.
31 Implemented by SingleUrl and CachedUrl. MakeImageDl::dataSourceFor() is
32 the function which examines the local jigdo download's temporary
33 directory and creates a SingleUrl/CachedUrl as appropriate before putting
34 it inside a MakeImageDl::Child. */
35 class Job::DataSource : NoCopy {
38 /** User interaction for DataSource.
40 Instances of derived classes are attached to any DataSources that the
41 MakeImageDl creates. */
42 class IO : public Job::IO {
45 // Not overriding here:
46 // virtual IO* job_removeIo(IO* rmIo);
48 /** Called by the job when it is deleted or when a different IO object is
49 registered with it. If the IO object considers itself owned by its
50 job, it can delete itself. */
51 virtual void job_deleted() = 0;
53 /** Called when the job has successfully completed its task. */
54 virtual void job_succeeded() = 0;
56 /** Called when the job fails. The only remaining action after getting
57 this is to delete the job object. */
58 virtual void job_failed(string* message) = 0;
60 /** Informational message. */
61 virtual void job_message(string* message) = 0;
63 /** Called as soon as the size of the downloaded data is known. May not
64 be called at all if the size is unknown. Problem with libwww: Returns
65 size as long int - 2 GB size limit! */
66 virtual void dataSource_dataSize(uint64 n) = 0;
68 /** Called during download whenever data arrives, with the data that just
69 arrived. You can write the data to a file, copy it away etc.
70 currentSize is the offset into the downloaded data (including the
71 "size" new bytes) - useful for "x% done" messages. */
72 virtual void dataSource_data(const byte* data, unsigned size,
73 uint64 currentSize) = 0;
75 //____________________
79 inline DataSource(IO* ioPtr);
80 virtual ~DataSource();
82 /** Start delivering data. */
83 virtual void run() = 0;
85 /** Is the data stream currently paused? */
86 virtual bool paused() const = 0;
87 /** Pause the data stream. */
88 virtual void pause() = 0;
89 /** Continue after pause(). */
90 virtual void cont() = 0;
92 /** Return the internal progress object. */
93 virtual const Progress* progress() const = 0;
95 /** Return the URL used to download the data, or its filename on disc */
96 virtual const string& location() const = 0;
98 //______________________________________________________________________
100 Job::DataSource::DataSource(IO* ioPtr) : io(ioPtr) { }