27
49
friend class Queue;
29
/* Linked list starting at a Queue and a linked list starting
51
/** \brief The next link on the Queue list.
53
* \todo This is always NULL; is it just for future use?
57
/** \brief The next link on the Acquire list. */
32
58
Worker *NextAcquire;
34
// The access association
60
/** \brief The Queue with which this worker is associated. */
63
/** \brief The download progress indicator to which progress
64
* messages should be sent.
36
66
pkgAcquireStatus *Log;
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.
37
72
MethodConfig *Config;
74
/** \brief The access method to be used by this worker.
76
* \todo Doesn't this duplicate Config->Access?
40
// This is the subprocess IPC setup
80
/** \brief The PID of the subprocess. */
83
/** \brief A file descriptor connected to the standard output of
86
* Used to read messages and data from the subprocess.
90
/** \brief A file descriptor connected to the standard input of the
93
* Used to send commands and configuration data to the subprocess.
97
/** \brief Set to \b true if the worker is in a state in which it
98
* might generate data or command responses.
100
* \todo Is this right? It's a guess.
104
/** \brief Set to \b true if the worker is in a state in which it
105
* is legal to send commands to it.
107
* \todo Is this right?
47
// Various internal things
111
/** If \b true, debugging output will be sent to std::clog. */
114
/** \brief The raw text values of messages received from the
115
* worker, in sequence.
49
117
vector<string> MessageQueue;
119
/** \brief Buffers pending writes to the subprocess.
121
* \todo Wouldn't a std::dequeue be more appropriate?
52
// Private constructor helper
125
/** \brief Common code for the constructor.
127
* Initializes NextQueue and NextAcquire to NULL; Process, InFd,
128
* and OutFd to -1, OutReady and InReady to \b false, and Debug
55
// Message handling things
133
/** \brief Retrieve any available messages from the subprocess.
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
140
* \return \b true if the messages were successfully read, \b
56
143
bool ReadMessages();
145
/** \brief Parse and dispatch pending messages.
147
* This dispatches the message in a manner appropriate for its
150
* \todo Several message types lack separate handlers.
152
* \sa Capabilities(), SendConfiguration(), MediaChange()
57
154
bool RunMessages();
156
/** \brief Read and dispatch any pending messages from the
159
* \return \b false if the subprocess died unexpectedly while a
160
* message was being transmitted.
164
/** \brief Send any pending commands to the subprocess.
166
* This method will fail if there is no pending output.
168
* \return \b true if all commands were succeeded, \b false if an
169
* error occurred (in which case MethodFailure() will be invoked).
59
171
bool OutFdReady();
61
// The message handlers
173
/** \brief Handle a 100 Capabilities response from the subprocess.
175
* \param Message the raw text of the message from the subprocess.
177
* The message will be parsed and its contents used to fill
178
* #Config. If #Config is NULL, this routine is a NOP.
62
182
bool Capabilities(string Message);
184
/** \brief Send a 601 Configuration message (containing the APT
185
* configuration) to the subprocess.
187
* The APT configuration will be send to the subprocess in a
188
* message of the following form:
192
* Config-Item: Fully-Qualified-Item=Val
193
* Config-Item: Fully-Qualified-Item=Val
197
* \return \b true if the command was successfully sent, \b false
63
200
bool SendConfiguration();
202
/** \brief Handle a 403 Media Change message.
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.
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).
64
213
bool MediaChange(string Message);
215
/** \brief Invoked when the worked process dies unexpectedly.
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
66
224
bool MethodFailure();
226
/** \brief Invoked when a fetch job is completed, either
227
* successfully or unsuccessfully.
229
* Resets the status information for the worker process.
71
// The curent method state
235
/** \brief The queue entry that is currently being downloaded. */
72
236
pkgAcquire::Queue::QItem *CurrentItem;
238
/** \brief The most recent status string received from the
243
/** \brief How many bytes of the file have been downloaded. Zero
244
* if the current progress of the file cannot be determined.
74
246
unsigned long CurrentSize;
248
/** \brief The total number of bytes to be downloaded. Zero if the
249
* total size of the final is unknown.
75
251
unsigned long TotalSize;
253
/** \brief How much of the file was already downloaded prior to
254
* starting this worker.
76
256
unsigned long ResumePoint;
78
// Load the method and do the startup
258
/** \brief Tell the subprocess to download the given item.
260
* \param Item the item to queue up.
261
* \return \b true if the item was successfully enqueued.
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
79
267
bool QueueItem(pkgAcquire::Queue::QItem *Item);
269
/** \brief Start up the worker and fill in #Config.
271
* Reads the first message from the worker, which is assumed to be
272
* a 100 Capabilities message.
274
* \return \b true if all operations completed successfully.
278
/** \brief Update the worker statistics (CurrentSize, TotalSize,
283
/** \return The fetch method configuration. */
82
284
inline const MethodConfig *GetConf() const {return Config;};
286
/** \brief Create a new Worker to download files.
288
* \param OwnerQ The queue into which this worker should be
291
* \param Config A location in which to store information about
294
* \param Log The download progress indicator that should be used
295
* to report the progress of this worker.
84
297
Worker(Queue *OwnerQ,MethodConfig *Config,pkgAcquireStatus *Log);
299
/** \brief Create a new Worker that should just retrieve
300
* information about the fetch method.
302
* Nothing in particular forces you to refrain from actually
303
* downloading stuff, but the various status callbacks won't be
306
* \param Config A location in which to store information about
85
309
Worker(MethodConfig *Config);
311
/** \brief Clean up this worker.
313
* Closes the file descriptors; if MethodConfig::NeedsCleanup is
314
* \b false, also rudely interrupts the worker with a SIGINT.