~mvo/apt/dep8

« back to all changes in this revision

Viewing changes to apt-pkg/acquire-worker.h


* merged the debian/experimental changes back
  into the debian/sid branch
* merged from Christian Perrier:
  * mr.po: New Marathi translation  Closes: #416806
  * zh_CN.po: Updated by Eric Pareja  Closes: #416822
  * tl.po: Updated by Eric Pareja   Closes: #416638
  * gl.po: Updated by Jacobo Tarrio
  * da.po: Updated by Claus Hindsgaul
  * fr.po: Remove a non-breakable space for usability
  * ru.po: Updated Russian translation. Closes: #405476
  * *.po: Unfuzzy after upstream typo corrections
* buildlib/archtable:
  - added support for sh3/sh4 (closes: #424870)
  - added support for m32r (closes: #394096)
* buildlib/systemtable:
  - added support for lpia
* configure.in:
  - check systemtable for architecture mapping too

* Package that contains tall the new features
* Removed all #pragma interface/implementation
* Branch that contains tall the new features:
* translated package descriptions
* task install support
* automatic dependency removal (thanks to Daniel Burrows)
* merged support for the new dpkg "Breaks" field 
  (thanks to Ian Jackson)
* handle network failures more gracefully on "update"
* support for unattended-upgrades (via unattended-upgrades
  package)
* added apt-transport-https method
* merged "install-recommends" branch (ABI break): 
  - new "--install-recommends"
  - install new recommends on "upgrade" if --install-recommends is 
    given
  - new "--fix-policy" option to install all packages with unmet
    important dependencies (usefull with --install-recommends to
    see what not-installed recommends are on the system)
  - fix of recommended packages display (only show CandidateVersion
    fix or-group handling)
* merged "install-task" branch (use with "apt-get install taskname^")
* Applied patch from Daniel Schepler to make apt bin-NMU able.
  * eu.po: Updated
* fix apt-get dist-upgrade
* fix warning if no /var/lib/apt/extended_states is present
* don't download Translations for deb-src sources.list lines
* apt-pkg/tagfile.cc:
  - support not-mmapable files again
* added support for i18n of the package descriptions
* added support for aptitude like auto-install tracking (a HUGE
  HUGE thanks to Daniel Burrows who made this possible) 
* synced with the http://people.debian.org/~mvo/bzr/apt/debian-sid branch
* build from http://people.debian.org/~mvo/bzr/apt/debian-experimental
* apt-pkg/depcache.cc:
  - added Debug::pkgDepCache::AutoInstall (thanks to infinity)
* apt-pkg/acquire-item.cc:
  - fix missing chmod() in the new aquire code 
    (thanks to Bastian Blank, Closes: #367425)
* merged from 
  http://www.perrier.eu.org/debian/packages/d-i/level4/apt-main:
  * sk.po: Completed to 512t
  * eu.po: Completed to 512t
  * fr.po: Completed to 512t
  * sv.po: Completed to 512t
  * Update all PO and the POT. Gives 506t6f for formerly
    complete translations
* Fix a incorrect example in the man-page (closes: #282918)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
   
10
10
   ##################################################################### */
11
11
                                                                        /*}}}*/
 
12
 
 
13
/** \addtogroup acquire
 
14
 *  @{
 
15
 *
 
16
 *  \file acquire-worker.h
 
17
 */
 
18
 
12
19
#ifndef PKGLIB_ACQUIRE_WORKER_H
13
20
#define PKGLIB_ACQUIRE_WORKER_H
14
21
 
15
22
#include <apt-pkg/acquire.h>
16
23
 
17
 
#ifdef __GNUG__
18
 
#pragma interface "apt-pkg/acquire-worker.h"
19
 
#endif 
20
24
 
21
 
// Interfacing to the method process
 
25
/** \brief A fetch subprocess.
 
26
 *
 
27
 *  A worker process is responsible for one stage of the fetch.  This
 
28
 *  class encapsulates the communications protocol between the master
 
29
 *  process and the worker, from the master end.
 
30
 *
 
31
 *  Each worker is intrinsically placed on two linked lists.  The
 
32
 *  Queue list (maintained in the #NextQueue variable) is maintained
 
33
 *  by the pkgAcquire::Queue class; it represents the set of workers
 
34
 *  assigned to a particular queue.  The Acquire list (maintained in
 
35
 *  the #NextAcquire variable) is maintained by the pkgAcquire class;
 
36
 *  it represents the set of active workers for a particular
 
37
 *  pkgAcquire object.
 
38
 *
 
39
 *  \todo Like everything else in the Acquire system, this has way too
 
40
 *  many protected items.
 
41
 *
 
42
 *  \sa pkgAcqMethod, pkgAcquire::Item, pkgAcquire
 
43
 */
22
44
class pkgAcquire::Worker
23
45
{
24
46
   friend class pkgAcquire;
26
48
   protected:
27
49
   friend class Queue;
28
50
 
29
 
   /* Linked list starting at a Queue and a linked list starting
30
 
      at Acquire */
 
51
   /** \brief The next link on the Queue list.
 
52
    *
 
53
    *  \todo This is always NULL; is it just for future use?
 
54
    */
31
55
   Worker *NextQueue;
 
56
 
 
57
   /** \brief The next link on the Acquire list. */
32
58
   Worker *NextAcquire;
33
59
   
34
 
   // The access association
 
60
   /** \brief The Queue with which this worker is associated. */
35
61
   Queue *OwnerQ;
 
62
 
 
63
   /** \brief The download progress indicator to which progress
 
64
    *  messages should be sent.
 
65
    */
36
66
   pkgAcquireStatus *Log;
 
67
 
 
68
   /** \brief The configuration of this method.  On startup, the
 
69
    *  target of this pointer is filled in with basic data about the
 
70
    *  method, as reported by the worker.
 
71
    */
37
72
   MethodConfig *Config;
 
73
 
 
74
   /** \brief The access method to be used by this worker.
 
75
    *
 
76
    *  \todo Doesn't this duplicate Config->Access?
 
77
    */
38
78
   string Access;
39
79
 
40
 
   // This is the subprocess IPC setup
 
80
   /** \brief The PID of the subprocess. */
41
81
   pid_t Process;
 
82
 
 
83
   /** \brief A file descriptor connected to the standard output of
 
84
    *  the subprocess.
 
85
    *
 
86
    *  Used to read messages and data from the subprocess.
 
87
    */
42
88
   int InFd;
 
89
 
 
90
   /** \brief A file descriptor connected to the standard input of the
 
91
    *  subprocess.
 
92
    *
 
93
    *  Used to send commands and configuration data to the subprocess.
 
94
    */
43
95
   int OutFd;
 
96
 
 
97
   /** \brief Set to \b true if the worker is in a state in which it
 
98
    *  might generate data or command responses.
 
99
    *
 
100
    *  \todo Is this right?  It's a guess.
 
101
    */
44
102
   bool InReady;
 
103
 
 
104
   /** \brief Set to \b true if the worker is in a state in which it
 
105
    *  is legal to send commands to it.
 
106
    *
 
107
    *  \todo Is this right?
 
108
    */
45
109
   bool OutReady;
46
110
   
47
 
   // Various internal things
 
111
   /** If \b true, debugging output will be sent to std::clog. */
48
112
   bool Debug;
 
113
 
 
114
   /** \brief The raw text values of messages received from the
 
115
    *  worker, in sequence.
 
116
    */
49
117
   vector<string> MessageQueue;
 
118
 
 
119
   /** \brief Buffers pending writes to the subprocess.
 
120
    *
 
121
    *  \todo Wouldn't a std::dequeue be more appropriate?
 
122
    */
50
123
   string OutQueue;
51
124
   
52
 
   // Private constructor helper
 
125
   /** \brief Common code for the constructor.
 
126
    *
 
127
    *  Initializes NextQueue and NextAcquire to NULL; Process, InFd,
 
128
    *  and OutFd to -1, OutReady and InReady to \b false, and Debug
 
129
    *  from _config.
 
130
    */
53
131
   void Construct();
54
132
   
55
 
   // Message handling things
 
133
   /** \brief Retrieve any available messages from the subprocess.
 
134
    *
 
135
    *  The messages are retrieved as in ::ReadMessages(), and
 
136
    *  MessageFailure() is invoked if an error occurs; in particular,
 
137
    *  if the pipe to the subprocess dies unexpectedly while a message
 
138
    *  is being read.
 
139
    *
 
140
    *  \return \b true if the messages were successfully read, \b
 
141
    *  false otherwise.
 
142
    */
56
143
   bool ReadMessages();
 
144
 
 
145
   /** \brief Parse and dispatch pending messages.
 
146
    *
 
147
    *  This dispatches the message in a manner appropriate for its
 
148
    *  type.
 
149
    *
 
150
    *  \todo Several message types lack separate handlers.
 
151
    *
 
152
    *  \sa Capabilities(), SendConfiguration(), MediaChange()
 
153
    */
57
154
   bool RunMessages();
 
155
 
 
156
   /** \brief Read and dispatch any pending messages from the
 
157
    *  subprocess.
 
158
    *
 
159
    *  \return \b false if the subprocess died unexpectedly while a
 
160
    *  message was being transmitted.
 
161
    */
58
162
   bool InFdReady();
 
163
 
 
164
   /** \brief Send any pending commands to the subprocess.
 
165
    *
 
166
    *  This method will fail if there is no pending output.
 
167
    *
 
168
    *  \return \b true if all commands were succeeded, \b false if an
 
169
    *  error occurred (in which case MethodFailure() will be invoked).
 
170
    */
59
171
   bool OutFdReady();
60
172
   
61
 
   // The message handlers
 
173
   /** \brief Handle a 100 Capabilities response from the subprocess.
 
174
    *
 
175
    *  \param Message the raw text of the message from the subprocess.
 
176
    *
 
177
    *  The message will be parsed and its contents used to fill
 
178
    *  #Config.  If #Config is NULL, this routine is a NOP.
 
179
    *
 
180
    *  \return \b true.
 
181
    */
62
182
   bool Capabilities(string Message);
 
183
 
 
184
   /** \brief Send a 601 Configuration message (containing the APT
 
185
    *  configuration) to the subprocess.
 
186
    *
 
187
    *  The APT configuration will be send to the subprocess in a
 
188
    *  message of the following form:
 
189
    *
 
190
    *  <pre>
 
191
    *  601 Configuration
 
192
    *  Config-Item: Fully-Qualified-Item=Val
 
193
    *  Config-Item: Fully-Qualified-Item=Val
 
194
    *  ...
 
195
    *  </pre>
 
196
    *
 
197
    *  \return \b true if the command was successfully sent, \b false
 
198
    *  otherwise.
 
199
    */
63
200
   bool SendConfiguration();
 
201
 
 
202
   /** \brief Handle a 403 Media Change message.
 
203
    *
 
204
    *  \param Message the raw text of the message; the Media field
 
205
    *  indicates what type of media should be changed, and the Drive
 
206
    *  field indicates where the media is located.
 
207
    *
 
208
    *  Invokes pkgAcquireStatus::MediaChange(Media, Drive) to ask the
 
209
    *  user to swap disks; informs the subprocess of the result (via
 
210
    *  603 Media Changed, with the Failed field set to \b true if the
 
211
    *  user cancelled the media change).
 
212
    */
64
213
   bool MediaChange(string Message);
65
214
   
 
215
   /** \brief Invoked when the worked process dies unexpectedly.
 
216
    *
 
217
    *  Waits for the subprocess to terminate and generates an error if
 
218
    *  it terminated abnormally, then closes and blanks out all file
 
219
    *  descriptors.  Discards all pending messages from the
 
220
    *  subprocess.
 
221
    *
 
222
    *  \return \b false.
 
223
    */
66
224
   bool MethodFailure();
 
225
 
 
226
   /** \brief Invoked when a fetch job is completed, either
 
227
    *  successfully or unsuccessfully.
 
228
    *
 
229
    *  Resets the status information for the worker process.
 
230
    */
67
231
   void ItemDone();
68
232
   
69
233
   public:
70
234
   
71
 
   // The curent method state
 
235
   /** \brief The queue entry that is currently being downloaded. */
72
236
   pkgAcquire::Queue::QItem *CurrentItem;
 
237
 
 
238
   /** \brief The most recent status string received from the
 
239
    *  subprocess.
 
240
    */
73
241
   string Status;
 
242
 
 
243
   /** \brief How many bytes of the file have been downloaded.  Zero
 
244
    *  if the current progress of the file cannot be determined.
 
245
    */
74
246
   unsigned long CurrentSize;
 
247
 
 
248
   /** \brief The total number of bytes to be downloaded.  Zero if the
 
249
    *  total size of the final is unknown.
 
250
    */
75
251
   unsigned long TotalSize;
 
252
 
 
253
   /** \brief How much of the file was already downloaded prior to
 
254
    *  starting this worker.
 
255
    */
76
256
   unsigned long ResumePoint;
77
257
   
78
 
   // Load the method and do the startup 
 
258
   /** \brief Tell the subprocess to download the given item.
 
259
    *
 
260
    *  \param Item the item to queue up.
 
261
    *  \return \b true if the item was successfully enqueued.
 
262
    *
 
263
    *  Queues up a 600 URI Acquire message for the given item to be
 
264
    *  sent at the next possible moment.  Does \e not flush the output
 
265
    *  queue.
 
266
    */
79
267
   bool QueueItem(pkgAcquire::Queue::QItem *Item);
 
268
 
 
269
   /** \brief Start up the worker and fill in #Config.
 
270
    *
 
271
    *  Reads the first message from the worker, which is assumed to be
 
272
    *  a 100 Capabilities message.
 
273
    *
 
274
    *  \return \b true if all operations completed successfully.
 
275
    */
80
276
   bool Start();
 
277
 
 
278
   /** \brief Update the worker statistics (CurrentSize, TotalSize,
 
279
    *  etc).
 
280
    */
81
281
   void Pulse();
 
282
 
 
283
   /** \return The fetch method configuration. */
82
284
   inline const MethodConfig *GetConf() const {return Config;};
83
 
   
 
285
 
 
286
   /** \brief Create a new Worker to download files.
 
287
    *
 
288
    *  \param OwnerQ The queue into which this worker should be
 
289
    *  placed.
 
290
    *
 
291
    *  \param Config A location in which to store information about
 
292
    *  the fetch method.
 
293
    *
 
294
    *  \param Log The download progress indicator that should be used
 
295
    *  to report the progress of this worker.
 
296
    */
84
297
   Worker(Queue *OwnerQ,MethodConfig *Config,pkgAcquireStatus *Log);
 
298
 
 
299
   /** \brief Create a new Worker that should just retrieve
 
300
    *  information about the fetch method.
 
301
    *
 
302
    *  Nothing in particular forces you to refrain from actually
 
303
    *  downloading stuff, but the various status callbacks won't be
 
304
    *  invoked.
 
305
    *
 
306
    *  \param Config A location in which to store information about
 
307
    *  the fetch method.
 
308
    */
85
309
   Worker(MethodConfig *Config);
 
310
 
 
311
   /** \brief Clean up this worker.
 
312
    *
 
313
    *  Closes the file descriptors; if MethodConfig::NeedsCleanup is
 
314
    *  \b false, also rudely interrupts the worker with a SIGINT.
 
315
    */
86
316
   ~Worker();
87
317
};
88
318
 
 
319
/** @} */
 
320
 
89
321
#endif