libapt-pkg-dev  v0.9.7.5ubuntu5.4
Debian+Ubuntu APT Package Management
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pkgAcquire::Worker Class Reference

A fetch subprocess. More...

#include <acquire-worker.h>

Inheritance diagram for pkgAcquire::Worker:
Collaboration diagram for pkgAcquire::Worker:

Public Member Functions

 Worker (Queue *OwnerQ, MethodConfig *Config, pkgAcquireStatus *Log)
 Create a new Worker to download files. More...
 
 Worker (MethodConfig *Config)
 Create a new Worker that should just retrieve information about the fetch method. More...
 
virtual ~Worker ()
 Clean up this worker. More...
 
void AddWeakPointer (WeakPointable **weakptr)
 Add a new weak pointer. More...
 
const MethodConfigGetConf () const
 
void Pulse ()
 Update the worker statistics (CurrentSize, TotalSize, etc). More...
 
bool QueueItem (pkgAcquire::Queue::QItem *Item)
 Tell the subprocess to download the given item. More...
 
void RemoveWeakPointer (WeakPointable **weakptr)
 Remove the weak pointer from the list of weak pointers. More...
 
bool Start ()
 Start up the worker and fill in Config. More...
 

Public Attributes

pkgAcquire::Queue::QItemCurrentItem
 The queue entry that is currently being downloaded. More...
 
unsigned long long CurrentSize
 How many bytes of the file have been downloaded. More...
 
unsigned long long ResumePoint
 How much of the file was already downloaded prior to starting this worker. More...
 
std::string Status
 The most recent status string received from the subprocess. More...
 
unsigned long long TotalSize
 The total number of bytes to be downloaded. More...
 

Protected Member Functions

bool Capabilities (std::string Message)
 Handle a 100 Capabilities response from the subprocess. More...
 
void Construct ()
 Common code for the constructor. More...
 
bool InFdReady ()
 Read and dispatch any pending messages from the subprocess. More...
 
void ItemDone ()
 Invoked when a fetch job is completed, either successfully or unsuccessfully. More...
 
bool MediaChange (std::string Message)
 Handle a 403 Media Change message. More...
 
bool MethodFailure ()
 Invoked when the worked process dies unexpectedly. More...
 
bool OutFdReady ()
 Send any pending commands to the subprocess. More...
 
bool ReadMessages ()
 Retrieve any available messages from the subprocess. More...
 
bool RunMessages ()
 Parse and dispatch pending messages. More...
 
bool SendConfiguration ()
 Send a 601 Configuration message (containing the APT configuration) to the subprocess. More...
 

Protected Attributes

std::string Access
 The access method to be used by this worker. More...
 
MethodConfigConfig
 The configuration of this method. More...
 
bool Debug
 If true, debugging output will be sent to std::clog. More...
 
int InFd
 A file descriptor connected to the standard output of the subprocess. More...
 
bool InReady
 Set to true if the worker is in a state in which it might generate data or command responses. More...
 
pkgAcquireStatusLog
 The download progress indicator to which progress messages should be sent. More...
 
std::vector< std::string > MessageQueue
 The raw text values of messages received from the worker, in sequence. More...
 
WorkerNextAcquire
 The next link on the Acquire list. More...
 
WorkerNextQueue
 The next link on the Queue list. More...
 
int OutFd
 A file descriptor connected to the standard input of the subprocess. More...
 
std::string OutQueue
 Buffers pending writes to the subprocess. More...
 
bool OutReady
 Set to true if the worker is in a state in which it is legal to send commands to it. More...
 
QueueOwnerQ
 The Queue with which this worker is associated. More...
 
pid_t Process
 The PID of the subprocess. More...
 

Private Attributes

void * d
 dpointer placeholder (for later in case we need it) More...
 

Friends

class pkgAcquire
 
class Queue
 

Detailed Description

A fetch subprocess.

A worker process is responsible for one stage of the fetch. This class encapsulates the communications protocol between the master process and the worker, from the master end.

Each worker is intrinsically placed on two linked lists. The Queue list (maintained in the NextQueue variable) is maintained by the pkgAcquire::Queue class; it represents the set of workers assigned to a particular queue. The Acquire list (maintained in the NextAcquire variable) is maintained by the pkgAcquire class; it represents the set of active workers for a particular pkgAcquire object.

Todo:
Like everything else in the Acquire system, this has way too many protected items.
See Also
pkgAcqMethod, pkgAcquire::Item, pkgAcquire

Constructor & Destructor Documentation

pkgAcquire::Worker::Worker ( Queue OwnerQ,
MethodConfig Config,
pkgAcquireStatus Log 
)

Create a new Worker to download files.

Parameters
OwnerQThe queue into which this worker should be placed.
ConfigA location in which to store information about the fetch method.
LogThe download progress indicator that should be used to report the progress of this worker.
pkgAcquire::Worker::Worker ( MethodConfig Config)

Create a new Worker that should just retrieve information about the fetch method.

Nothing in particular forces you to refrain from actually downloading stuff, but the various status callbacks won't be invoked.

Parameters
ConfigA location in which to store information about the fetch method.
virtual pkgAcquire::Worker::~Worker ( )
virtual

Clean up this worker.

Closes the file descriptors; if MethodConfig::NeedsCleanup is false, also rudely interrupts the worker with a SIGINT.

Member Function Documentation

void WeakPointable::AddWeakPointer ( WeakPointable **  weakptr)
inlineinherited

Add a new weak pointer.

References WeakPointable::pointers.

bool pkgAcquire::Worker::Capabilities ( std::string  Message)
protected

Handle a 100 Capabilities response from the subprocess.

Parameters
Messagethe raw text of the message from the subprocess.

The message will be parsed and its contents used to fill Config. If Config is NULL, this routine is a NOP.

Returns
true.
void pkgAcquire::Worker::Construct ( )
protected

Common code for the constructor.

Initializes NextQueue and NextAcquire to NULL; Process, InFd, and OutFd to -1, OutReady and InReady to false, and Debug from _config.

const MethodConfig* pkgAcquire::Worker::GetConf ( ) const
inline
Returns
The fetch method configuration.

References Config.

bool pkgAcquire::Worker::InFdReady ( )
protected

Read and dispatch any pending messages from the subprocess.

Returns
false if the subprocess died unexpectedly while a message was being transmitted.
void pkgAcquire::Worker::ItemDone ( )
protected

Invoked when a fetch job is completed, either successfully or unsuccessfully.

Resets the status information for the worker process.

bool pkgAcquire::Worker::MediaChange ( std::string  Message)
protected

Handle a 403 Media Change message.

Parameters
Messagethe raw text of the message; the Media field indicates what type of media should be changed, and the Drive field indicates where the media is located.

Invokes pkgAcquireStatus::MediaChange(Media, Drive) to ask the user to swap disks; informs the subprocess of the result (via 603 Media Changed, with the Failed field set to true if the user cancelled the media change).

bool pkgAcquire::Worker::MethodFailure ( )
protected

Invoked when the worked process dies unexpectedly.

Waits for the subprocess to terminate and generates an error if it terminated abnormally, then closes and blanks out all file descriptors. Discards all pending messages from the subprocess.

Returns
false.
bool pkgAcquire::Worker::OutFdReady ( )
protected

Send any pending commands to the subprocess.

This method will fail if there is no pending output.

Returns
true if all commands were succeeded, false if an error occurred (in which case MethodFailure() will be invoked).
void pkgAcquire::Worker::Pulse ( )

Update the worker statistics (CurrentSize, TotalSize, etc).

bool pkgAcquire::Worker::QueueItem ( pkgAcquire::Queue::QItem Item)

Tell the subprocess to download the given item.

Parameters
Itemthe item to queue up.
Returns
true if the item was successfully enqueued.

Queues up a 600 URI Acquire message for the given item to be sent at the next possible moment. Does not flush the output queue.

bool pkgAcquire::Worker::ReadMessages ( )
protected

Retrieve any available messages from the subprocess.

The messages are retrieved as in ReadMessages(), and MessageFailure() is invoked if an error occurs; in particular, if the pipe to the subprocess dies unexpectedly while a message is being read.

Returns
true if the messages were successfully read, false otherwise.
void WeakPointable::RemoveWeakPointer ( WeakPointable **  weakptr)
inlineinherited

Remove the weak pointer from the list of weak pointers.

References WeakPointable::pointers.

bool pkgAcquire::Worker::RunMessages ( )
protected

Parse and dispatch pending messages.

This dispatches the message in a manner appropriate for its type.

Todo:
Several message types lack separate handlers.
See Also
Capabilities(), SendConfiguration(), MediaChange()
bool pkgAcquire::Worker::SendConfiguration ( )
protected

Send a 601 Configuration message (containing the APT configuration) to the subprocess.

The APT configuration will be send to the subprocess in a message of the following form:

601 Configuration
Config-Item: Fully-Qualified-Item=Val
Config-Item: Fully-Qualified-Item=Val
...
Returns
true if the command was successfully sent, false otherwise.
bool pkgAcquire::Worker::Start ( )

Start up the worker and fill in Config.

Reads the first message from the worker, which is assumed to be a 100 Capabilities message.

Returns
true if all operations completed successfully.

Friends And Related Function Documentation

friend class pkgAcquire
friend
friend class Queue
friend

Member Data Documentation

std::string pkgAcquire::Worker::Access
protected

The access method to be used by this worker.

Todo:
Doesn't this duplicate Config->Access?
MethodConfig* pkgAcquire::Worker::Config
protected

The configuration of this method.

On startup, the target of this pointer is filled in with basic data about the method, as reported by the worker.

Referenced by GetConf().

pkgAcquire::Queue::QItem* pkgAcquire::Worker::CurrentItem

The queue entry that is currently being downloaded.

unsigned long long pkgAcquire::Worker::CurrentSize

How many bytes of the file have been downloaded.

Zero if the current progress of the file cannot be determined.

void* pkgAcquire::Worker::d
private

dpointer placeholder (for later in case we need it)

bool pkgAcquire::Worker::Debug
protected

If true, debugging output will be sent to std::clog.

int pkgAcquire::Worker::InFd
protected

A file descriptor connected to the standard output of the subprocess.

Used to read messages and data from the subprocess.

bool pkgAcquire::Worker::InReady
protected

Set to true if the worker is in a state in which it might generate data or command responses.

Todo:
Is this right? It's a guess.
pkgAcquireStatus* pkgAcquire::Worker::Log
protected

The download progress indicator to which progress messages should be sent.

std::vector<std::string> pkgAcquire::Worker::MessageQueue
protected

The raw text values of messages received from the worker, in sequence.

Worker* pkgAcquire::Worker::NextAcquire
protected

The next link on the Acquire list.

Worker* pkgAcquire::Worker::NextQueue
protected

The next link on the Queue list.

Todo:
This is always NULL; is it just for future use?
int pkgAcquire::Worker::OutFd
protected

A file descriptor connected to the standard input of the subprocess.

Used to send commands and configuration data to the subprocess.

std::string pkgAcquire::Worker::OutQueue
protected

Buffers pending writes to the subprocess.

Todo:
Wouldn't a std::dequeue be more appropriate?
bool pkgAcquire::Worker::OutReady
protected

Set to true if the worker is in a state in which it is legal to send commands to it.

Todo:
Is this right?
Queue* pkgAcquire::Worker::OwnerQ
protected

The Queue with which this worker is associated.

pid_t pkgAcquire::Worker::Process
protected

The PID of the subprocess.

unsigned long long pkgAcquire::Worker::ResumePoint

How much of the file was already downloaded prior to starting this worker.

std::string pkgAcquire::Worker::Status

The most recent status string received from the subprocess.

unsigned long long pkgAcquire::Worker::TotalSize

The total number of bytes to be downloaded.

Zero if the total size of the final is unknown.


The documentation for this class was generated from the following file: