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