acquire.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire.h,v 1.6 1998/10/30 07:53:38 jgg Exp $
  4. /* ######################################################################
  5. Acquire - File Acquiration
  6. This module contians the Acquire system. It is responsible for bringing
  7. files into the local pathname space. It deals with URIs for files and
  8. URI handlers responsible for downloading or finding the URIs.
  9. Each file to download is represented by an Acquire::Item class subclassed
  10. into a specialization. The Item class can add itself to several URI
  11. acquire queues each prioritized by the download scheduler. When the
  12. system is run the proper URI handlers are spawned and the the acquire
  13. queues are fed into the handlers by the schedular until the queues are
  14. empty. This allows for an Item to be downloaded from an alternate source
  15. if the first try turns out to fail. It also alows concurrent downloading
  16. of multiple items from multiple sources as well as dynamic balancing
  17. of load between the sources.
  18. Schedualing of downloads is done on a first ask first get basis. This
  19. preserves the order of the download as much as possible. And means the
  20. fastest source will tend to process the largest number of files.
  21. Internal methods and queues for performing gzip decompression,
  22. md5sum hashing and file copying are provided to allow items to apply
  23. a number of transformations to the data files they are working with.
  24. ##################################################################### */
  25. /*}}}*/
  26. #ifndef PKGLIB_ACQUIRE_H
  27. #define PKGLIB_ACQUIRE_H
  28. #include <vector>
  29. #include <string>
  30. #ifdef __GNUG__
  31. #pragma interface "apt-pkg/acquire.h"
  32. #endif
  33. #include <unistd.h>
  34. class pkgAcquire
  35. {
  36. public:
  37. class Item;
  38. class Queue;
  39. class Worker;
  40. struct MethodConfig;
  41. friend Item;
  42. friend Queue;
  43. protected:
  44. // List of items to fetch
  45. vector<Item *> Items;
  46. // List of active queues and fetched method configuration parameters
  47. Queue *Queues;
  48. Worker *Workers;
  49. MethodConfig *Configs;
  50. unsigned long ToFetch;
  51. // Configurable parameters for the schedular
  52. enum {QueueHost,QueueAccess} QueueMode;
  53. bool Debug;
  54. bool Running;
  55. void Add(Item *Item);
  56. void Remove(Item *Item);
  57. void Add(Worker *Work);
  58. void Remove(Worker *Work);
  59. void Enqueue(Item *Item,string URI,string Description);
  60. void Dequeue(Item *Item);
  61. string QueueName(string URI);
  62. // FDSET managers for derived classes
  63. void SetFds(int &Fd,fd_set *RSet,fd_set *WSet);
  64. void RunFds(fd_set *RSet,fd_set *WSet);
  65. // A queue calls this when it dequeues an item
  66. void Bump();
  67. public:
  68. MethodConfig *GetConfig(string Access);
  69. bool Run();
  70. pkgAcquire();
  71. ~pkgAcquire();
  72. };
  73. // List of possible items queued for download.
  74. class pkgAcquire::Queue
  75. {
  76. friend pkgAcquire;
  77. Queue *Next;
  78. protected:
  79. // Queued item
  80. struct QItem
  81. {
  82. QItem *Next;
  83. string URI;
  84. string Description;
  85. Item *Owner;
  86. pkgAcquire::Worker *Worker;
  87. };
  88. // Name of the queue
  89. string Name;
  90. // Items queued into this queue
  91. QItem *Items;
  92. pkgAcquire::Worker *Workers;
  93. pkgAcquire *Owner;
  94. public:
  95. // Put an item into this queue
  96. void Enqueue(Item *Owner,string URI,string Description);
  97. void Dequeue(Item *Owner);
  98. // Find a Queued item
  99. QItem *FindItem(string URI,pkgAcquire::Worker *Owner);
  100. bool ItemDone(QItem *Itm);
  101. bool Startup();
  102. bool Shutdown();
  103. bool Cycle();
  104. Queue(string Name,pkgAcquire *Owner);
  105. ~Queue();
  106. };
  107. // Configuration information from each method
  108. struct pkgAcquire::MethodConfig
  109. {
  110. MethodConfig *Next;
  111. string Access;
  112. string Version;
  113. bool SingleInstance;
  114. bool PreScan;
  115. bool Pipeline;
  116. bool SendConfig;
  117. MethodConfig();
  118. };
  119. #endif