acquire.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire.cc,v 1.2 1998/10/20 02:39:15 jgg Exp $
  4. /* ######################################################################
  5. Acquire - File Acquiration
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #ifdef __GNUG__
  10. #pragma implementation "apt-pkg/acquire.h"
  11. #endif
  12. #include <apt-pkg/acquire.h>
  13. #include <apt-pkg/acquire-item.h>
  14. #include <apt-pkg/acquire-worker.h>
  15. #include <strutl.h>
  16. /*}}}*/
  17. // Acquire::pkgAcquire - Constructor /*{{{*/
  18. // ---------------------------------------------------------------------
  19. /* */
  20. pkgAcquire::pkgAcquire()
  21. {
  22. Queues = 0;
  23. Configs = 0;
  24. }
  25. /*}}}*/
  26. // Acquire::~pkgAcquire - Destructor /*{{{*/
  27. // ---------------------------------------------------------------------
  28. /* Free our memory */
  29. pkgAcquire::~pkgAcquire()
  30. {
  31. while (Items.size() != 0)
  32. delete Items[0];
  33. while (Configs != 0)
  34. {
  35. MethodConfig *Jnk = Configs;
  36. Configs = Configs->Next;
  37. delete Jnk;
  38. }
  39. }
  40. /*}}}*/
  41. // Acquire::Add - Add a new item /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* */
  44. void pkgAcquire::Add(Item *Itm)
  45. {
  46. Items.push_back(Itm);
  47. }
  48. /*}}}*/
  49. // Acquire::Remove - Remove a item /*{{{*/
  50. // ---------------------------------------------------------------------
  51. /* */
  52. void pkgAcquire::Remove(Item *Itm)
  53. {
  54. for (vector<Item *>::iterator I = Items.begin(); I < Items.end(); I++)
  55. {
  56. if (*I == Itm)
  57. Items.erase(I);
  58. }
  59. }
  60. /*}}}*/
  61. // Acquire::Enqueue - Queue an URI for fetching /*{{{*/
  62. // ---------------------------------------------------------------------
  63. /* */
  64. void pkgAcquire::Enqueue(Item *Item,string URI)
  65. {
  66. cout << "Fetching " << URI << endl;
  67. cout << " to " << Item->ToFile() << endl;
  68. cout << " Queue is: " << QueueName(URI) << endl;
  69. }
  70. /*}}}*/
  71. // Acquire::QueueName - Return the name of the queue for this URI /*{{{*/
  72. // ---------------------------------------------------------------------
  73. /* */
  74. string pkgAcquire::QueueName(string URI)
  75. {
  76. const MethodConfig *Config = GetConfig(URIAccess(URI));
  77. return string();
  78. }
  79. /*}}}*/
  80. // Acquire::GetConfig - Fetch the configuration information /*{{{*/
  81. // ---------------------------------------------------------------------
  82. /* This locates the configuration structure for an access method. If
  83. a config structure cannot be found a Worker will be created to
  84. retrieve it */
  85. const pkgAcquire::MethodConfig *pkgAcquire::GetConfig(string Access)
  86. {
  87. // Search for an existing config
  88. MethodConfig *Conf;
  89. for (Conf = Configs; Conf != 0; Conf = Conf->Next)
  90. if (Conf->Access == Access)
  91. return Conf;
  92. // Create the new config class
  93. Conf = new MethodConfig;
  94. Conf->Access = Access;
  95. Conf->Next = Configs;
  96. Configs = Conf;
  97. // Create the worker to fetch the configuration
  98. Worker Work(Conf);
  99. if (Work.Start() == false)
  100. return 0;
  101. return Conf;
  102. }
  103. /*}}}*/
  104. // Acquire::MethodConfig::MethodConfig - Constructor /*{{{*/
  105. // ---------------------------------------------------------------------
  106. /* */
  107. pkgAcquire::MethodConfig::MethodConfig()
  108. {
  109. SingleInstance = false;
  110. PreScan = false;
  111. }
  112. /*}}}*/