]>
Commit | Line | Data |
---|---|---|
0118833a AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
c88edf1d | 3 | // $Id: acquire.h,v 1.4 1998/10/24 04:58:02 jgg Exp $ |
0118833a AL |
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 | ||
0a8a80e5 AL |
42 | #include <unistd.h> |
43 | ||
0118833a AL |
44 | class pkgAcquire |
45 | { | |
46 | public: | |
47 | ||
48 | class Item; | |
49 | class Queue; | |
50 | class Worker; | |
51 | struct MethodConfig; | |
52 | friend Item; | |
0a8a80e5 | 53 | friend Queue; |
0118833a AL |
54 | |
55 | protected: | |
56 | ||
0a8a80e5 | 57 | // List of items to fetch |
0118833a | 58 | vector<Item *> Items; |
0a8a80e5 AL |
59 | |
60 | // List of active queues and fetched method configuration parameters | |
0118833a | 61 | Queue *Queues; |
0a8a80e5 | 62 | Worker *Workers; |
0118833a | 63 | MethodConfig *Configs; |
0a8a80e5 AL |
64 | unsigned long ToFetch; |
65 | ||
66 | // Configurable parameters for the schedular | |
67 | enum {QueueHost,QueueAccess} QueueMode; | |
68 | bool Debug; | |
0118833a AL |
69 | |
70 | void Add(Item *Item); | |
71 | void Remove(Item *Item); | |
0a8a80e5 AL |
72 | void Add(Worker *Work); |
73 | void Remove(Worker *Work); | |
74 | ||
75 | void Enqueue(Item *Item,string URI,string Description); | |
76 | void Dequeue(Item *Item); | |
77 | string QueueName(string URI); | |
78 | ||
79 | // FDSET managers for derived classes | |
80 | void SetFds(int &Fd,fd_set *RSet,fd_set *WSet); | |
81 | void RunFds(fd_set *RSet,fd_set *WSet); | |
0118833a AL |
82 | |
83 | public: | |
3b5421b4 | 84 | |
0a8a80e5 AL |
85 | MethodConfig *GetConfig(string Access); |
86 | bool Run(); | |
0118833a AL |
87 | |
88 | pkgAcquire(); | |
89 | ~pkgAcquire(); | |
90 | }; | |
91 | ||
92 | // List of possible items queued for download. | |
93 | class pkgAcquire::Queue | |
94 | { | |
95 | friend pkgAcquire; | |
96 | Queue *Next; | |
97 | ||
98 | protected: | |
3b5421b4 | 99 | |
0a8a80e5 AL |
100 | // Queued item |
101 | struct QItem | |
102 | { | |
103 | QItem *Next; | |
104 | ||
105 | string URI; | |
106 | string Description; | |
107 | Item *Owner; | |
c88edf1d | 108 | pkgAcquire::Worker *Worker; |
0a8a80e5 AL |
109 | }; |
110 | ||
111 | // Name of the queue | |
112 | string Name; | |
113 | ||
114 | // Items queued into this queue | |
115 | QItem *Items; | |
116 | pkgAcquire::Worker *Workers; | |
117 | pkgAcquire *Owner; | |
0118833a AL |
118 | |
119 | public: | |
0a8a80e5 AL |
120 | |
121 | // Put an item into this queue | |
122 | void Enqueue(Item *Owner,string URI,string Description); | |
123 | void Dequeue(Item *Owner); | |
124 | ||
c88edf1d AL |
125 | // Find a Queued item |
126 | QItem *FindItem(string URI,pkgAcquire::Worker *Owner); | |
127 | bool ItemDone(QItem *Itm); | |
128 | ||
0a8a80e5 AL |
129 | bool Startup(); |
130 | bool Shutdown(); | |
131 | ||
132 | Queue(string Name,pkgAcquire *Owner); | |
133 | ~Queue(); | |
0118833a AL |
134 | }; |
135 | ||
136 | // Configuration information from each method | |
137 | struct pkgAcquire::MethodConfig | |
138 | { | |
3b5421b4 AL |
139 | MethodConfig *Next; |
140 | ||
0118833a AL |
141 | string Access; |
142 | ||
143 | string Version; | |
144 | bool SingleInstance; | |
145 | bool PreScan; | |
0a8a80e5 AL |
146 | bool Pipeline; |
147 | bool SendConfig; | |
0118833a AL |
148 | |
149 | MethodConfig(); | |
0118833a AL |
150 | }; |
151 | ||
152 | #endif |