]>
git.saurik.com Git - apt.git/blob - apt-pkg/acquire.h
   1 // -*- mode: cpp; mode: fold -*- 
   3 // $Id: acquire.h,v 1.18 1998/12/11 07:20:33 jgg Exp $ 
   4 /* ###################################################################### 
   6    Acquire - File Acquiration 
   8    This module contians the Acquire system. It is responsible for bringing 
   9    files into the local pathname space. It deals with URIs for files and 
  10    URI handlers responsible for downloading or finding the URIs. 
  12    Each file to download is represented by an Acquire::Item class subclassed 
  13    into a specialization. The Item class can add itself to several URI 
  14    acquire queues each prioritized by the download scheduler. When the  
  15    system is run the proper URI handlers are spawned and the the acquire  
  16    queues are fed into the handlers by the schedular until the queues are 
  17    empty. This allows for an Item to be downloaded from an alternate source 
  18    if the first try turns out to fail. It also alows concurrent downloading 
  19    of multiple items from multiple sources as well as dynamic balancing 
  20    of load between the sources. 
  22    Schedualing of downloads is done on a first ask first get basis. This 
  23    preserves the order of the download as much as possible. And means the 
  24    fastest source will tend to process the largest number of files. 
  26    Internal methods and queues for performing gzip decompression, 
  27    md5sum hashing and file copying are provided to allow items to apply 
  28    a number of transformations to the data files they are working with. 
  30    ##################################################################### */ 
  32 #ifndef PKGLIB_ACQUIRE_H 
  33 #define PKGLIB_ACQUIRE_H 
  39 #pragma interface "apt-pkg/acquire.h" 
  45 class pkgAcquireStatus
; 
  60    // List of items to fetch 
  63    // List of active queues and fetched method configuration parameters 
  66    MethodConfig 
*Configs
; 
  67    pkgAcquireStatus 
*Log
; 
  68    unsigned long ToFetch
; 
  70    // Configurable parameters for the schedular 
  71    enum {QueueHost
,QueueAccess
} QueueMode
; 
  76    void Remove(Item 
*Item
); 
  77    void Add(Worker 
*Work
); 
  78    void Remove(Worker 
*Work
); 
  80    void Enqueue(ItemDesc 
&Item
); 
  81    void Dequeue(Item 
*Item
); 
  82    string 
QueueName(string URI
,MethodConfig 
const *&Config
); 
  84    // FDSET managers for derived classes 
  85    void SetFds(int &Fd
,fd_set 
*RSet
,fd_set 
*WSet
); 
  86    void RunFds(fd_set 
*RSet
,fd_set 
*WSet
);    
  88    // A queue calls this when it dequeues an item 
  93    MethodConfig 
*GetConfig(string Access
); 
  96    // Simple iteration mechanism 
  97    inline Worker 
*WorkersBegin() {return Workers
;}; 
  98    Worker 
*WorkerStep(Worker 
*I
); 
  99    inline Item 
**ItemsBegin() {return Items
.begin();}; 
 100    inline Item 
**ItemsEnd() {return Items
.end();}; 
 102    // Cleans out the download dir 
 103    bool Clean(string Dir
); 
 105    // Returns the size of the total download set 
 106    unsigned long TotalNeeded(); 
 107    unsigned long FetchNeeded(); 
 109    pkgAcquire(pkgAcquireStatus 
*Log 
= 0); 
 113 // Description of an Item+URI 
 114 struct pkgAcquire::ItemDesc
 
 122 // List of possible items queued for download. 
 123 class pkgAcquire::Queue
 
 131    struct QItem 
: pkgAcquire::ItemDesc
 
 134       pkgAcquire::Worker 
*Worker
; 
 136       void operator =(pkgAcquire::ItemDesc 
const &I
) 
 139          Description 
= I
.Description
; 
 140          ShortDesc 
= I
.ShortDesc
; 
 148    // Items queued into this queue 
 150    pkgAcquire::Worker 
*Workers
; 
 152    signed long PipeDepth
; 
 153    unsigned long MaxPipeDepth
; 
 157    // Put an item into this queue 
 158    void Enqueue(ItemDesc 
&Item
); 
 159    bool Dequeue(Item 
*Owner
); 
 161    // Find a Queued item 
 162    QItem 
*FindItem(string URI
,pkgAcquire::Worker 
*Owner
); 
 163    bool ItemStart(QItem 
*Itm
,unsigned long Size
); 
 164    bool ItemDone(QItem 
*Itm
); 
 171    Queue(string Name
,pkgAcquire 
*Owner
); 
 175 // Configuration information from each method 
 176 struct pkgAcquire::MethodConfig
 
 191 class pkgAcquireStatus
 
 196    struct timeval StartTime
; 
 197    unsigned long LastBytes
; 
 199    unsigned long CurrentBytes
; 
 200    unsigned long TotalBytes
; 
 201    unsigned long FetchedBytes
; 
 202    unsigned long ElapsedTime
; 
 203    unsigned long TotalItems
; 
 204    unsigned long CurrentItems
; 
 210    // Called by items when they have finished a real download 
 211    virtual void Fetched(unsigned long Size
,unsigned long ResumePoint
); 
 213    // Called to change media 
 214    virtual bool MediaChange(string Media
,string Drive
) = 0; 
 216    // Each of these is called by the workers when an event occures 
 217    virtual void IMSHit(pkgAcquire::ItemDesc 
&Itm
) {}; 
 218    virtual void Fetch(pkgAcquire::ItemDesc 
&Itm
) {}; 
 219    virtual void Done(pkgAcquire::ItemDesc 
&Itm
) {}; 
 220    virtual void Fail(pkgAcquire::ItemDesc 
&Itm
) {}; 
 221    virtual void Pulse(pkgAcquire 
*Owner
); 
 222    virtual void Start(); 
 226    virtual ~pkgAcquireStatus() {};