acquire.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Acquire - File Acquiration
  5. This module contains the Acquire system. It is responsible for bringing
  6. files into the local pathname space. It deals with URIs for files and
  7. URI handlers responsible for downloading or finding the URIs.
  8. Each file to download is represented by an Acquire::Item class subclassed
  9. into a specialization. The Item class can add itself to several URI
  10. acquire queues each prioritized by the download scheduler. When the
  11. system is run the proper URI handlers are spawned and the the acquire
  12. queues are fed into the handlers by the schedular until the queues are
  13. empty. This allows for an Item to be downloaded from an alternate source
  14. if the first try turns out to fail. It also alows concurrent downloading
  15. of multiple items from multiple sources as well as dynamic balancing
  16. of load between the sources.
  17. Schedualing of downloads is done on a first ask first get basis. This
  18. preserves the order of the download as much as possible. And means the
  19. fastest source will tend to process the largest number of files.
  20. Internal methods and queues for performing gzip decompression,
  21. md5sum hashing and file copying are provided to allow items to apply
  22. a number of transformations to the data files they are working with.
  23. ##################################################################### */
  24. /*}}}*/
  25. /** \defgroup acquire Acquire system {{{
  26. *
  27. * \brief The Acquire system is responsible for retrieving files from
  28. * local or remote URIs and postprocessing them (for instance,
  29. * verifying their authenticity). The core class in this system is
  30. * pkgAcquire, which is responsible for managing the download queues
  31. * during the download. There is at least one download queue for
  32. * each supported protocol; protocols such as http may provide one
  33. * queue per host.
  34. *
  35. * Each file to download is represented by a subclass of
  36. * pkgAcquire::Item. The files add themselves to the download
  37. * queue(s) by providing their URI information to
  38. * pkgAcquire::Item::QueueURI, which calls pkgAcquire::Enqueue.
  39. *
  40. * Once the system is set up, the Run method will spawn subprocesses
  41. * to handle the enqueued URIs; the scheduler will then take items
  42. * from the queues and feed them into the handlers until the queues
  43. * are empty.
  44. *
  45. * \todo Acquire supports inserting an object into several queues at
  46. * once, but it is not clear what its behavior in this case is, and
  47. * no subclass of pkgAcquire::Item seems to actually use this
  48. * capability.
  49. */ /*}}}*/
  50. /** \addtogroup acquire
  51. *
  52. * @{
  53. *
  54. * \file acquire.h
  55. */
  56. #ifndef PKGLIB_ACQUIRE_H
  57. #define PKGLIB_ACQUIRE_H
  58. #include <apt-pkg/macros.h>
  59. #include <apt-pkg/weakptr.h>
  60. #include <apt-pkg/hashes.h>
  61. #include <string>
  62. #include <vector>
  63. #include <stddef.h>
  64. #include <sys/time.h>
  65. #include <sys/select.h>
  66. #ifndef APT_10_CLEANER_HEADERS
  67. #include <unistd.h>
  68. #endif
  69. #ifndef APT_8_CLEANER_HEADERS
  70. using std::vector;
  71. using std::string;
  72. #endif
  73. class pkgAcquireStatus;
  74. /** \brief The core download scheduler. {{{
  75. *
  76. * This class represents an ongoing download. It manages the lists
  77. * of active and pending downloads and handles setting up and tearing
  78. * down download-related structures.
  79. *
  80. * \todo Why all the protected data items and methods?
  81. */
  82. class pkgAcquire
  83. {
  84. private:
  85. /** \brief FD of the Lock file we acquire in Setup (if any) */
  86. int LockFD;
  87. /** \brief dpointer placeholder (for later in case we need it) */
  88. void * const d;
  89. public:
  90. class Item;
  91. class Queue;
  92. class Worker;
  93. struct MethodConfig;
  94. struct ItemDesc;
  95. friend class Item;
  96. friend class pkgAcqMetaBase;
  97. friend class Queue;
  98. typedef std::vector<Item *>::iterator ItemIterator;
  99. typedef std::vector<Item *>::const_iterator ItemCIterator;
  100. protected:
  101. /** \brief A list of items to download.
  102. *
  103. * This is built monotonically as items are created and only
  104. * emptied when the download shuts down.
  105. */
  106. std::vector<Item *> Items;
  107. /** \brief The head of the list of active queues.
  108. *
  109. * \todo why a hand-managed list of queues instead of std::list or
  110. * std::set?
  111. */
  112. Queue *Queues;
  113. /** \brief The head of the list of active workers.
  114. *
  115. * \todo why a hand-managed list of workers instead of std::list
  116. * or std::set?
  117. */
  118. Worker *Workers;
  119. /** \brief The head of the list of acquire method configurations.
  120. *
  121. * Each protocol (http, ftp, gzip, etc) via which files can be
  122. * fetched can have a representation in this list. The
  123. * configuration data is filled in by parsing the 100 Capabilities
  124. * string output by a method on startup (see
  125. * pkgAcqMethod::pkgAcqMethod and pkgAcquire::GetConfig).
  126. *
  127. * \todo why a hand-managed config dictionary instead of std::map?
  128. */
  129. MethodConfig *Configs;
  130. /** \brief The progress indicator for this download. */
  131. pkgAcquireStatus *Log;
  132. /** \brief The number of files which are to be fetched. */
  133. unsigned long ToFetch;
  134. // Configurable parameters for the scheduler
  135. /** \brief Represents the queuing strategy for remote URIs. */
  136. enum QueueStrategy {
  137. /** \brief Generate one queue for each protocol/host combination; downloads from
  138. * multiple hosts can proceed in parallel.
  139. */
  140. QueueHost,
  141. /** \brief Generate a single queue for each protocol; serialize
  142. * downloads from multiple hosts.
  143. */
  144. QueueAccess} QueueMode;
  145. /** \brief If \b true, debugging information will be dumped to std::clog. */
  146. bool const Debug;
  147. /** \brief If \b true, a download is currently in progress. */
  148. bool Running;
  149. /** \brief Add the given item to the list of items. */
  150. void Add(Item *Item);
  151. /** \brief Remove the given item from the list of items. */
  152. void Remove(Item *Item);
  153. /** \brief Add the given worker to the list of workers. */
  154. void Add(Worker *Work);
  155. /** \brief Remove the given worker from the list of workers. */
  156. void Remove(Worker *Work);
  157. /** \brief Insert the given fetch request into the appropriate queue.
  158. *
  159. * \param Item The URI to download and the item to download it
  160. * for. Copied by value into the queue; no reference to Item is
  161. * retained.
  162. */
  163. void Enqueue(ItemDesc &Item);
  164. /** \brief Remove all fetch requests for this item from all queues. */
  165. void Dequeue(Item *Item);
  166. /** \brief Determine the fetch method and queue of a URI.
  167. *
  168. * \param URI The URI to fetch.
  169. *
  170. * \param[out] Config A location in which to place the method via
  171. * which the URI is to be fetched.
  172. *
  173. * \return the string-name of the queue in which a fetch request
  174. * for the given URI should be placed.
  175. */
  176. std::string QueueName(std::string URI,MethodConfig const *&Config);
  177. /** \brief Build up the set of file descriptors upon which select() should
  178. * block.
  179. *
  180. * The default implementation inserts the file descriptors
  181. * corresponding to active downloads.
  182. *
  183. * \param[out] Fd The largest file descriptor in the generated sets.
  184. *
  185. * \param[out] RSet The set of file descriptors that should be
  186. * watched for input.
  187. *
  188. * \param[out] WSet The set of file descriptors that should be
  189. * watched for output.
  190. */
  191. virtual void SetFds(int &Fd,fd_set *RSet,fd_set *WSet);
  192. /** Handle input from and output to file descriptors which select()
  193. * has determined are ready. The default implementation
  194. * dispatches to all active downloads.
  195. *
  196. * \param RSet The set of file descriptors that are ready for
  197. * input.
  198. *
  199. * \param WSet The set of file descriptors that are ready for
  200. * output.
  201. *
  202. * \return false if there is an error condition on one of the fds
  203. */
  204. bool RunFdsSane(fd_set *RSet,fd_set *WSet);
  205. // just here for compatbility, needs to be removed on the next
  206. // ABI/API break. RunFdsSane() is what should be used as it
  207. // returns if there is an error condition on one of the fds
  208. virtual void RunFds(fd_set *RSet,fd_set *WSet);
  209. /** \brief Check for idle queues with ready-to-fetch items.
  210. *
  211. * Called by pkgAcquire::Queue::Done each time an item is dequeued
  212. * but remains on some queues; i.e., another queue should start
  213. * fetching it.
  214. */
  215. void Bump();
  216. public:
  217. /** \brief Retrieve information about a fetch method by name.
  218. *
  219. * \param Access The name of the method to look up.
  220. *
  221. * \return the method whose name is Access, or \b NULL if no such method exists.
  222. */
  223. MethodConfig *GetConfig(std::string Access);
  224. /** \brief Provides information on how a download terminated. */
  225. enum RunResult {
  226. /** \brief All files were fetched successfully. */
  227. Continue,
  228. /** \brief Some files failed to download. */
  229. Failed,
  230. /** \brief The download was cancelled by the user (i.e., #Log's
  231. * pkgAcquireStatus::Pulse() method returned \b false).
  232. */
  233. Cancelled};
  234. /** \brief Download all the items that have been Add()ed to this
  235. * download process.
  236. *
  237. * This method will block until the download completes, invoking
  238. * methods on #Log to report on the progress of the download.
  239. *
  240. * \param PulseInterval The method pkgAcquireStatus::Pulse will be
  241. * invoked on #Log at intervals of PulseInterval milliseconds.
  242. *
  243. * \return the result of the download.
  244. */
  245. RunResult Run(int PulseInterval=500000);
  246. /** \brief Remove all items from this download process, terminate
  247. * all download workers, and empty all queues.
  248. */
  249. void Shutdown();
  250. /** \brief Get the first Worker object.
  251. *
  252. * \return the first active worker in this download process.
  253. */
  254. inline Worker *WorkersBegin() {return Workers;};
  255. /** \brief Advance to the next Worker object.
  256. *
  257. * \return the worker immediately following I, or \b NULL if none
  258. * exists.
  259. */
  260. Worker *WorkerStep(Worker *I) APT_PURE;
  261. /** \brief Get the head of the list of items. */
  262. inline ItemIterator ItemsBegin() {return Items.begin();};
  263. inline ItemCIterator ItemsBegin() const {return Items.begin();};
  264. /** \brief Get the end iterator of the list of items. */
  265. inline ItemIterator ItemsEnd() {return Items.end();};
  266. inline ItemCIterator ItemsEnd() const {return Items.end();};
  267. // Iterate over queued Item URIs
  268. class UriIterator;
  269. /** \brief Get the head of the list of enqueued item URIs.
  270. *
  271. * This iterator will step over every element of every active
  272. * queue.
  273. */
  274. UriIterator UriBegin();
  275. /** \brief Get the end iterator of the list of enqueued item URIs. */
  276. UriIterator UriEnd();
  277. /** Deletes each entry in the given directory that is not being
  278. * downloaded by this object. For instance, when downloading new
  279. * list files, calling Clean() will delete the old ones.
  280. *
  281. * \param Dir The directory to be cleaned out.
  282. *
  283. * \return \b true if the directory exists and is readable.
  284. */
  285. bool Clean(std::string Dir);
  286. /** \return the total size in bytes of all the items included in
  287. * this download.
  288. */
  289. unsigned long long TotalNeeded();
  290. /** \return the size in bytes of all non-local items included in
  291. * this download.
  292. */
  293. unsigned long long FetchNeeded();
  294. /** \return the amount of data to be fetched that is already
  295. * present on the filesystem.
  296. */
  297. unsigned long long PartialPresent();
  298. /** \brief Delayed constructor
  299. *
  300. * \param Progress indicator associated with this download or
  301. * \b NULL for none. This object is not owned by the
  302. * download process and will not be deleted when the pkgAcquire
  303. * object is destroyed. Naturally, it should live for at least as
  304. * long as the pkgAcquire object does.
  305. * \param Lock defines a lock file that should be acquired to ensure
  306. * only one Acquire class is in action at the time or an empty string
  307. * if no lock file should be used. If set also all needed directories
  308. * will be created.
  309. */
  310. APT_DEPRECATED_MSG("Use constructors, .SetLog and .GetLock as needed") bool Setup(pkgAcquireStatus *Progress = NULL, std::string const &Lock = "");
  311. void SetLog(pkgAcquireStatus *Progress) { Log = Progress; }
  312. /** \brief acquire lock and perform directory setup
  313. *
  314. * \param Lock defines a lock file that should be acquired to ensure
  315. * only one Acquire class is in action at the time or an empty string
  316. * if no lock file should be used. If set also all needed directories
  317. * will be created and setup.
  318. */
  319. bool GetLock(std::string const &Lock);
  320. /** \brief Construct a new pkgAcquire. */
  321. explicit pkgAcquire(pkgAcquireStatus *Log);
  322. pkgAcquire();
  323. /** \brief Destroy this pkgAcquire object.
  324. *
  325. * Destroys all queue, method, and item objects associated with
  326. * this download.
  327. */
  328. virtual ~pkgAcquire();
  329. private:
  330. APT_HIDDEN void Initialize();
  331. };
  332. /** \brief Represents a single download source from which an item
  333. * should be downloaded.
  334. *
  335. * An item may have several assocated ItemDescs over its lifetime.
  336. */
  337. struct pkgAcquire::ItemDesc : public WeakPointable
  338. {
  339. /** \brief URI from which to download this item. */
  340. std::string URI;
  341. /** \brief description of this item. */
  342. std::string Description;
  343. /** \brief shorter description of this item. */
  344. std::string ShortDesc;
  345. /** \brief underlying item which is to be downloaded. */
  346. Item *Owner;
  347. };
  348. /*}}}*/
  349. /** \brief A single download queue in a pkgAcquire object. {{{
  350. *
  351. * \todo Why so many protected values?
  352. */
  353. class pkgAcquire::Queue
  354. {
  355. friend class pkgAcquire;
  356. friend class pkgAcquire::UriIterator;
  357. friend class pkgAcquire::Worker;
  358. /** \brief dpointer placeholder (for later in case we need it) */
  359. void * const d;
  360. /** \brief The next queue in the pkgAcquire object's list of queues. */
  361. Queue *Next;
  362. protected:
  363. /** \brief A single item placed in this queue. */
  364. struct QItem : public ItemDesc
  365. {
  366. /** \brief The next item in the queue. */
  367. QItem *Next;
  368. /** \brief The worker associated with this item, if any. */
  369. pkgAcquire::Worker *Worker;
  370. /** \brief The underlying items interested in the download */
  371. std::vector<Item*> Owners;
  372. typedef std::vector<Item*>::const_iterator owner_iterator;
  373. /** \brief Assign the ItemDesc portion of this QItem from
  374. * another ItemDesc
  375. */
  376. void operator =(pkgAcquire::ItemDesc const &I)
  377. {
  378. URI = I.URI;
  379. Description = I.Description;
  380. ShortDesc = I.ShortDesc;
  381. Owners.clear();
  382. Owners.push_back(I.Owner);
  383. Owner = I.Owner;
  384. };
  385. /** @return the sum of all expected hashes by all owners */
  386. HashStringList GetExpectedHashes() const;
  387. /** @return smallest maximum size of all owners */
  388. unsigned long long GetMaximumSize() const;
  389. /** \brief get partial files in order */
  390. void SyncDestinationFiles() const;
  391. /** @return the custom headers to use for this item */
  392. std::string Custom600Headers() const;
  393. /** @return the maximum priority of this item */
  394. int APT_HIDDEN GetPriority() const;
  395. };
  396. /** \brief The name of this queue. */
  397. std::string Name;
  398. /** \brief The head of the list of items contained in this queue.
  399. *
  400. * \todo why a by-hand list instead of an STL structure?
  401. */
  402. QItem *Items;
  403. /** \brief The head of the list of workers associated with this queue.
  404. *
  405. * \todo This is plural because support exists in Queue for
  406. * multiple workers. However, it does not appear that there is
  407. * any way to actually associate more than one worker with a
  408. * queue.
  409. *
  410. * \todo Why not just use a std::set?
  411. */
  412. pkgAcquire::Worker *Workers;
  413. /** \brief the download scheduler with which this queue is associated. */
  414. pkgAcquire *Owner;
  415. /** \brief The number of entries in this queue that are currently
  416. * being downloaded.
  417. */
  418. signed long PipeDepth;
  419. /** \brief The maximum number of entries that this queue will
  420. * attempt to download at once.
  421. */
  422. unsigned long MaxPipeDepth;
  423. public:
  424. /** \brief Insert the given fetch request into this queue.
  425. *
  426. * \return \b true if the queuing was successful. May return
  427. * \b false if the Item is already in the queue
  428. */
  429. bool Enqueue(ItemDesc &Item);
  430. /** \brief Remove all fetch requests for the given item from this queue.
  431. *
  432. * \return \b true if at least one request was removed from the queue.
  433. */
  434. bool Dequeue(Item *Owner);
  435. /** \brief Locate an item in this queue.
  436. *
  437. * \param URI A URI to match against.
  438. * \param Owner A pkgAcquire::Worker to match against.
  439. *
  440. * \return the first item in the queue whose URI is #URI and that
  441. * is being downloaded by #Owner.
  442. */
  443. QItem *FindItem(std::string URI,pkgAcquire::Worker *Owner) APT_PURE;
  444. /** Presumably this should start downloading an item?
  445. *
  446. * \todo Unimplemented. Implement it or remove?
  447. */
  448. bool ItemStart(QItem *Itm,unsigned long long Size);
  449. /** \brief Remove the given item from this queue and set its state
  450. * to pkgAcquire::Item::StatDone.
  451. *
  452. * If this is the only queue containing the item, the item is also
  453. * removed from the main queue by calling pkgAcquire::Dequeue.
  454. *
  455. * \param Itm The item to remove.
  456. *
  457. * \return \b true if no errors are encountered.
  458. */
  459. bool ItemDone(QItem *Itm);
  460. /** \brief Start the worker process associated with this queue.
  461. *
  462. * If a worker process is already associated with this queue,
  463. * this is equivalent to calling Cycle().
  464. *
  465. * \return \b true if the startup was successful.
  466. */
  467. bool Startup();
  468. /** \brief Shut down the worker process associated with this queue.
  469. *
  470. * \param Final If \b true, then the process is stopped unconditionally.
  471. * Otherwise, it is only stopped if it does not need cleanup
  472. * as indicated by the pkgAcqMethod::NeedsCleanup member of
  473. * its configuration.
  474. *
  475. * \return \b true.
  476. */
  477. bool Shutdown(bool Final);
  478. /** \brief Send idle items to the worker process.
  479. *
  480. * Fills up the pipeline by inserting idle items into the worker's queue.
  481. */
  482. bool Cycle();
  483. /** \brief Check for items that could be enqueued.
  484. *
  485. * Call this after an item placed in multiple queues has gone from
  486. * the pkgAcquire::Item::StatFetching state to the
  487. * pkgAcquire::Item::StatIdle state, to possibly refill an empty queue.
  488. * This is an alias for Cycle().
  489. *
  490. * \todo Why both this and Cycle()? Are they expected to be
  491. * different someday?
  492. */
  493. void Bump();
  494. /** \brief Create a new Queue.
  495. *
  496. * \param Name The name of the new queue.
  497. * \param Owner The download process that owns the new queue.
  498. */
  499. Queue(std::string const &Name,pkgAcquire * const Owner);
  500. /** Shut down all the worker processes associated with this queue
  501. * and empty the queue.
  502. */
  503. virtual ~Queue();
  504. };
  505. /*}}}*/
  506. /** \brief Iterates over all the URIs being fetched by a pkgAcquire object. {{{*/
  507. class pkgAcquire::UriIterator
  508. {
  509. /** \brief dpointer placeholder (for later in case we need it) */
  510. void * const d;
  511. /** The next queue to iterate over. */
  512. pkgAcquire::Queue *CurQ;
  513. /** The item that we currently point at. */
  514. pkgAcquire::Queue::QItem *CurItem;
  515. public:
  516. inline void operator ++() {operator ++(0);};
  517. void operator ++(int)
  518. {
  519. CurItem = CurItem->Next;
  520. while (CurItem == 0 && CurQ != 0)
  521. {
  522. CurItem = CurQ->Items;
  523. CurQ = CurQ->Next;
  524. }
  525. };
  526. inline pkgAcquire::Queue::QItem const *operator ->() const {return CurItem;};
  527. inline bool operator !=(UriIterator const &rhs) const {return rhs.CurQ != CurQ || rhs.CurItem != CurItem;};
  528. inline bool operator ==(UriIterator const &rhs) const {return rhs.CurQ == CurQ && rhs.CurItem == CurItem;};
  529. /** \brief Create a new UriIterator.
  530. *
  531. * \param Q The queue over which this UriIterator should iterate.
  532. */
  533. explicit UriIterator(pkgAcquire::Queue *Q);
  534. virtual ~UriIterator();
  535. };
  536. /*}}}*/
  537. /** \brief Information about the properties of a single acquire method. {{{*/
  538. struct pkgAcquire::MethodConfig
  539. {
  540. /** \brief dpointer placeholder (for later in case we need it) */
  541. void * const d;
  542. /** \brief The next link on the acquire method list.
  543. *
  544. * \todo Why not an STL container?
  545. */
  546. MethodConfig *Next;
  547. /** \brief The name of this acquire method (e.g., http). */
  548. std::string Access;
  549. /** \brief The implementation version of this acquire method. */
  550. std::string Version;
  551. /** \brief If \b true, only one download queue should be created for this
  552. * method.
  553. */
  554. bool SingleInstance;
  555. /** \brief If \b true, this method supports pipelined downloading. */
  556. bool Pipeline;
  557. /** \brief If \b true, the worker process should send the entire
  558. * APT configuration tree to the fetch subprocess when it starts
  559. * up.
  560. */
  561. bool SendConfig;
  562. /** \brief If \b true, this fetch method does not require network access;
  563. * all files are to be acquired from the local disk.
  564. */
  565. bool LocalOnly;
  566. /** \brief If \b true, the subprocess has to carry out some cleanup
  567. * actions before shutting down.
  568. *
  569. * For instance, the cdrom method needs to unmount the CD after it
  570. * finishes.
  571. */
  572. bool NeedsCleanup;
  573. /** \brief If \b true, this fetch method acquires files from removable media. */
  574. bool Removable;
  575. /** \brief Set up the default method parameters.
  576. *
  577. * All fields are initialized to NULL, "", or \b false as
  578. * appropriate.
  579. */
  580. MethodConfig();
  581. virtual ~MethodConfig();
  582. };
  583. /*}}}*/
  584. /** \brief A monitor object for downloads controlled by the pkgAcquire class. {{{
  585. *
  586. * \todo Why protected members?
  587. */
  588. class pkgAcquireStatus
  589. {
  590. /** \brief dpointer placeholder (for later in case we need it) */
  591. void * const d;
  592. protected:
  593. /** \brief The last time at which this monitor object was updated. */
  594. struct timeval Time;
  595. /** \brief The time at which the download started. */
  596. struct timeval StartTime;
  597. /** \brief The number of bytes fetched as of the previous call to
  598. * pkgAcquireStatus::Pulse, including local items.
  599. */
  600. unsigned long long LastBytes;
  601. /** \brief The current rate of download as of the most recent call
  602. * to pkgAcquireStatus::Pulse, in bytes per second.
  603. */
  604. unsigned long long CurrentCPS;
  605. /** \brief The number of bytes fetched as of the most recent call
  606. * to pkgAcquireStatus::Pulse, including local items.
  607. */
  608. unsigned long long CurrentBytes;
  609. /** \brief The total number of bytes that need to be fetched.
  610. *
  611. * \warning This member is inaccurate, as new items might be
  612. * enqueued while the download is in progress!
  613. */
  614. unsigned long long TotalBytes;
  615. /** \brief The total number of bytes accounted for by items that
  616. * were successfully fetched.
  617. */
  618. unsigned long long FetchedBytes;
  619. /** \brief The amount of time that has elapsed since the download
  620. * started.
  621. */
  622. unsigned long long ElapsedTime;
  623. /** \brief The total number of items that need to be fetched.
  624. *
  625. * \warning This member is inaccurate, as new items might be
  626. * enqueued while the download is in progress!
  627. */
  628. unsigned long TotalItems;
  629. /** \brief The number of items that have been successfully downloaded. */
  630. unsigned long CurrentItems;
  631. /** \brief The estimated percentage of the download (0-100)
  632. */
  633. double Percent;
  634. public:
  635. /** \brief If \b true, the download scheduler should call Pulse()
  636. * at the next available opportunity.
  637. */
  638. bool Update;
  639. /** \brief If \b true, extra Pulse() invocations will be performed.
  640. *
  641. * With this option set, Pulse() will be called every time that a
  642. * download item starts downloading, finishes downloading, or
  643. * terminates with an error.
  644. */
  645. bool MorePulses;
  646. /** \brief Invoked when a local or remote file has been completely fetched.
  647. *
  648. * \param Size The size of the file fetched.
  649. *
  650. * \param ResumePoint How much of the file was already fetched.
  651. */
  652. virtual void Fetched(unsigned long long Size,unsigned long long ResumePoint);
  653. /** \brief Invoked when the user should be prompted to change the
  654. * inserted removable media.
  655. *
  656. * This method should not return until the user has confirmed to
  657. * the user interface that the media change is complete.
  658. *
  659. * \param Media The name of the media type that should be changed.
  660. *
  661. * \param Drive The identifying name of the drive whose media
  662. * should be changed.
  663. *
  664. * \return \b true if the user confirms the media change, \b
  665. * false if it is cancelled.
  666. *
  667. * \todo This is a horrible blocking monster; it should be CPSed
  668. * with prejudice.
  669. */
  670. virtual bool MediaChange(std::string Media,std::string Drive) = 0;
  671. /** \brief Invoked when an item is confirmed to be up-to-date.
  672. * For instance, when an HTTP download is informed that the file on
  673. * the server was not modified.
  674. */
  675. virtual void IMSHit(pkgAcquire::ItemDesc &/*Itm*/) {};
  676. /** \brief Invoked when some of an item's data is fetched. */
  677. virtual void Fetch(pkgAcquire::ItemDesc &/*Itm*/) {};
  678. /** \brief Invoked when an item is successfully and completely fetched. */
  679. virtual void Done(pkgAcquire::ItemDesc &/*Itm*/) {};
  680. /** \brief Invoked when the process of fetching an item encounters
  681. * a fatal error.
  682. */
  683. virtual void Fail(pkgAcquire::ItemDesc &/*Itm*/) {};
  684. /** \brief Periodically invoked while the Acquire process is underway.
  685. *
  686. * Subclasses should first call pkgAcquireStatus::Pulse(), then
  687. * update their status output. The download process is blocked
  688. * while Pulse() is being called.
  689. *
  690. * \return \b false if the user asked to cancel the whole Acquire process.
  691. *
  692. * \see pkgAcquire::Run
  693. */
  694. virtual bool Pulse(pkgAcquire *Owner);
  695. /** \brief Invoked when the Acquire process starts running. */
  696. virtual void Start();
  697. /** \brief Invoked when the Acquire process stops running. */
  698. virtual void Stop();
  699. /** \brief Initialize all counters to 0 and the time to the current time. */
  700. pkgAcquireStatus();
  701. virtual ~pkgAcquireStatus();
  702. };
  703. /*}}}*/
  704. /** @} */
  705. #endif