]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire.h
0d8803c1d708eb999a85664e84a72a816869d395
[apt.git] / apt-pkg / acquire.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire.h,v 1.9 1998/11/09 01:09:26 jgg Exp $
4 /* ######################################################################
5
6 Acquire - File Acquiration
7
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.
11
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.
21
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.
25
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.
29
30 ##################################################################### */
31 /*}}}*/
32 #ifndef PKGLIB_ACQUIRE_H
33 #define PKGLIB_ACQUIRE_H
34
35 #include <vector>
36 #include <string>
37
38 #ifdef __GNUG__
39 #pragma interface "apt-pkg/acquire.h"
40 #endif
41
42 #include <unistd.h>
43
44 class pkgAcquireStatus;
45 class pkgAcquire
46 {
47 public:
48
49 class Item;
50 class Queue;
51 class Worker;
52 struct MethodConfig;
53 struct ItemDesc;
54 friend Item;
55 friend Queue;
56
57 protected:
58
59 // List of items to fetch
60 vector<Item *> Items;
61
62 // List of active queues and fetched method configuration parameters
63 Queue *Queues;
64 Worker *Workers;
65 MethodConfig *Configs;
66 pkgAcquireStatus *Log;
67 unsigned long ToFetch;
68
69 // Configurable parameters for the schedular
70 enum {QueueHost,QueueAccess} QueueMode;
71 bool Debug;
72 bool Running;
73
74 void Add(Item *Item);
75 void Remove(Item *Item);
76 void Add(Worker *Work);
77 void Remove(Worker *Work);
78
79 void Enqueue(ItemDesc &Item);
80 void Dequeue(Item *Item);
81 string QueueName(string URI);
82
83 // FDSET managers for derived classes
84 void SetFds(int &Fd,fd_set *RSet,fd_set *WSet);
85 void RunFds(fd_set *RSet,fd_set *WSet);
86
87 // A queue calls this when it dequeues an item
88 void Bump();
89
90 public:
91
92 MethodConfig *GetConfig(string Access);
93 bool Run();
94
95 // Simple iteration mechanism
96 inline Worker *WorkersBegin() {return Workers;};
97 Worker *WorkerStep(Worker *I);
98 inline Item **ItemsBegin() {return Items.begin();};
99 inline Item **ItemsEnd() {return Items.end();};
100
101 pkgAcquire(pkgAcquireStatus *Log = 0);
102 ~pkgAcquire();
103 };
104
105 // Description of an Item+URI
106 struct pkgAcquire::ItemDesc
107 {
108 string URI;
109 string Description;
110 string ShortDesc;
111 Item *Owner;
112 };
113
114 // List of possible items queued for download.
115 class pkgAcquire::Queue
116 {
117 friend pkgAcquire;
118 Queue *Next;
119
120 protected:
121
122 // Queued item
123 struct QItem : pkgAcquire::ItemDesc
124 {
125 QItem *Next;
126 pkgAcquire::Worker *Worker;
127
128 void operator =(pkgAcquire::ItemDesc const &I)
129 {
130 URI = I.URI;
131 Description = I.Description;
132 ShortDesc = I.ShortDesc;
133 Owner = I.Owner;
134 };
135 };
136
137 // Name of the queue
138 string Name;
139
140 // Items queued into this queue
141 QItem *Items;
142 pkgAcquire::Worker *Workers;
143 pkgAcquire *Owner;
144
145 public:
146
147 // Put an item into this queue
148 void Enqueue(ItemDesc &Item);
149 bool Dequeue(Item *Owner);
150
151 // Find a Queued item
152 QItem *FindItem(string URI,pkgAcquire::Worker *Owner);
153 bool ItemStart(QItem *Itm,unsigned long Size);
154 bool ItemDone(QItem *Itm);
155
156 bool Startup();
157 bool Shutdown();
158 bool Cycle();
159 void Bump();
160
161 Queue(string Name,pkgAcquire *Owner);
162 ~Queue();
163 };
164
165 // Configuration information from each method
166 struct pkgAcquire::MethodConfig
167 {
168 MethodConfig *Next;
169
170 string Access;
171
172 string Version;
173 bool SingleInstance;
174 bool PreScan;
175 bool Pipeline;
176 bool SendConfig;
177
178 MethodConfig();
179 };
180
181 class pkgAcquireStatus
182 {
183 public:
184
185 bool Update;
186
187 // Each of these is called by the workers when an event occures
188 virtual void IMSHit(pkgAcquire::ItemDesc &Itm) {};
189 virtual void Fetch(pkgAcquire::ItemDesc &Itm) {};
190 virtual void Done(pkgAcquire::ItemDesc &Itm) {};
191 virtual void Fail(pkgAcquire::ItemDesc &Itm) {};
192 virtual void Pulse(pkgAcquire *Owner) {};
193
194 pkgAcquireStatus() : Update(false) {};
195 virtual ~pkgAcquireStatus() {};
196 };
197
198 #endif