]>
git.saurik.com Git - apt.git/blob - apt-pkg/acquire.h
   1 // -*- mode: cpp; mode: fold -*- 
   3 // $Id: acquire.h,v 1.28 2001/02/20 07:03:17 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    virtual void SetFds(int &Fd
,fd_set 
*RSet
,fd_set 
*WSet
); 
  86    virtual void RunFds(fd_set 
*RSet
,fd_set 
*WSet
);    
  88    // A queue calls this when it dequeues an item 
  93    MethodConfig 
*GetConfig(string Access
); 
  95    enum RunResult 
{Continue
,Failed
,Cancelled
}; 
 100    // Simple iteration mechanism 
 101    inline Worker 
*WorkersBegin() {return Workers
;}; 
 102    Worker 
*WorkerStep(Worker 
*I
); 
 103    inline Item 
**ItemsBegin() {return Items
.begin();}; 
 104    inline Item 
**ItemsEnd() {return Items
.end();}; 
 106    // Iterate over queued Item URIs 
 108    UriIterator 
UriBegin(); 
 109    UriIterator 
UriEnd(); 
 111    // Cleans out the download dir 
 112    bool Clean(string Dir
); 
 114    // Returns the size of the total download set 
 115    double TotalNeeded(); 
 116    double FetchNeeded(); 
 117    double PartialPresent(); 
 119    pkgAcquire(pkgAcquireStatus 
*Log 
= 0); 
 120    virtual ~pkgAcquire(); 
 123 // Description of an Item+URI 
 124 struct pkgAcquire::ItemDesc
 
 132 // List of possible items queued for download. 
 133 class pkgAcquire::Queue
 
 135    friend class pkgAcquire
; 
 136    friend class pkgAcquire::UriIterator
; 
 137    friend class pkgAcquire::Worker
; 
 143    struct QItem 
: pkgAcquire::ItemDesc
 
 146       pkgAcquire::Worker 
*Worker
; 
 148       void operator =(pkgAcquire::ItemDesc 
const &I
) 
 151          Description 
= I
.Description
; 
 152          ShortDesc 
= I
.ShortDesc
; 
 160    // Items queued into this queue 
 162    pkgAcquire::Worker 
*Workers
; 
 164    signed long PipeDepth
; 
 165    unsigned long MaxPipeDepth
; 
 169    // Put an item into this queue 
 170    void Enqueue(ItemDesc 
&Item
); 
 171    bool Dequeue(Item 
*Owner
); 
 173    // Find a Queued item 
 174    QItem 
*FindItem(string URI
,pkgAcquire::Worker 
*Owner
); 
 175    bool ItemStart(QItem 
*Itm
,unsigned long Size
); 
 176    bool ItemDone(QItem 
*Itm
); 
 179    bool Shutdown(bool Final
); 
 183    Queue(string Name
,pkgAcquire 
*Owner
); 
 187 class pkgAcquire::UriIterator
 
 189    pkgAcquire::Queue 
*CurQ
; 
 190    pkgAcquire::Queue::QItem 
*CurItem
; 
 194    // Advance to the next item 
 195    inline void operator ++() {operator ++();}; 
 196    void operator ++(int) 
 198       CurItem 
= CurItem
->Next
; 
 199       while (CurItem 
== 0 && CurQ 
!= 0) 
 201          CurItem 
= CurQ
->Items
; 
 207    inline pkgAcquire::ItemDesc 
const *operator ->() const {return CurItem
;}; 
 208    inline bool operator !=(UriIterator 
const &rhs
) const {return rhs
.CurQ 
!= CurQ 
|| rhs
.CurItem 
!= CurItem
;}; 
 209    inline bool operator ==(UriIterator 
const &rhs
) const {return rhs
.CurQ 
== CurQ 
&& rhs
.CurItem 
== CurItem
;}; 
 211    UriIterator(pkgAcquire::Queue 
*Q
) : CurQ(Q
), CurItem(0) 
 213       while (CurItem 
== 0 && CurQ 
!= 0) 
 215          CurItem 
= CurQ
->Items
; 
 221 // Configuration information from each method 
 222 struct pkgAcquire::MethodConfig
 
 239 class pkgAcquireStatus
 
 244    struct timeval StartTime
; 
 250    unsigned long ElapsedTime
; 
 251    unsigned long TotalItems
; 
 252    unsigned long CurrentItems
; 
 259    // Called by items when they have finished a real download 
 260    virtual void Fetched(unsigned long Size
,unsigned long ResumePoint
); 
 262    // Called to change media 
 263    virtual bool MediaChange(string Media
,string Drive
) = 0; 
 265    // Each of these is called by the workers when an event occures 
 266    virtual void IMSHit(pkgAcquire::ItemDesc 
&/*Itm*/) {}; 
 267    virtual void Fetch(pkgAcquire::ItemDesc 
&/*Itm*/) {}; 
 268    virtual void Done(pkgAcquire::ItemDesc 
&/*Itm*/) {}; 
 269    virtual void Fail(pkgAcquire::ItemDesc 
&/*Itm*/) {}; 
 270    virtual bool Pulse(pkgAcquire 
*Owner
); // returns false on user cancel 
 271    virtual void Start(); 
 275    virtual ~pkgAcquireStatus() {};