acquire-item.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-item.h,v 1.16 1999/02/01 02:22:11 jgg Exp $
  4. /* ######################################################################
  5. Acquire Item - Item to acquire
  6. When an item is instantiated it will add it self to the local list in
  7. the Owner Acquire class. Derived classes will then call QueueURI to
  8. register all the URI's they wish to fetch at the initial moment.
  9. Two item classes are provided to provide functionality for downloading
  10. of Index files and downloading of Packages.
  11. A Archive class is provided for downloading .deb files. It does Md5
  12. checking and source location as well as a retry algorithm.
  13. ##################################################################### */
  14. /*}}}*/
  15. #ifndef PKGLIB_ACQUIRE_ITEM_H
  16. #define PKGLIB_ACQUIRE_ITEM_H
  17. #include <apt-pkg/acquire.h>
  18. #include <apt-pkg/sourcelist.h>
  19. #include <apt-pkg/pkgrecords.h>
  20. #ifdef __GNUG__
  21. #pragma interface "apt-pkg/acquire-item.h"
  22. #endif
  23. // Item to acquire
  24. class pkgAcquire::Item
  25. {
  26. protected:
  27. // Some private helper methods for registering URIs
  28. pkgAcquire *Owner;
  29. inline void QueueURI(ItemDesc &Item)
  30. {Owner->Enqueue(Item);};
  31. inline void Dequeue() {Owner->Dequeue(this);};
  32. // Safe rename function with timestamp preservation
  33. void Rename(string From,string To);
  34. public:
  35. // State of the item
  36. enum {StatIdle, StatFetching, StatDone, StatError} Status;
  37. string ErrorText;
  38. unsigned long FileSize;
  39. char *Mode;
  40. unsigned long ID;
  41. bool Complete;
  42. bool Local;
  43. // Number of queues we are inserted into
  44. unsigned int QueueCounter;
  45. // File to write the fetch into
  46. string DestFile;
  47. // Action members invoked by the worker
  48. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  49. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  50. virtual void Start(string Message,unsigned long Size);
  51. virtual string Custom600Headers() {return string();};
  52. // Inquire functions
  53. virtual string MD5Sum() {return string();};
  54. virtual string Describe() = 0;
  55. Item(pkgAcquire *Owner);
  56. virtual ~Item();
  57. };
  58. // Item class for index files
  59. class pkgAcqIndex : public pkgAcquire::Item
  60. {
  61. protected:
  62. const pkgSourceList::Item *Location;
  63. bool Decompression;
  64. bool Erase;
  65. pkgAcquire::ItemDesc Desc;
  66. public:
  67. // Specialized action members
  68. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  69. virtual string Custom600Headers();
  70. virtual string Describe();
  71. pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location);
  72. };
  73. // Item class for index files
  74. class pkgAcqIndexRel : public pkgAcquire::Item
  75. {
  76. protected:
  77. const pkgSourceList::Item *Location;
  78. pkgAcquire::ItemDesc Desc;
  79. public:
  80. // Specialized action members
  81. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  82. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  83. virtual string Custom600Headers();
  84. virtual string Describe();
  85. pkgAcqIndexRel(pkgAcquire *Owner,const pkgSourceList::Item *Location);
  86. };
  87. // Item class for archive files
  88. class pkgAcqArchive : public pkgAcquire::Item
  89. {
  90. protected:
  91. // State information for the retry mechanism
  92. pkgCache::VerIterator Version;
  93. pkgAcquire::ItemDesc Desc;
  94. pkgSourceList *Sources;
  95. pkgRecords *Recs;
  96. string MD5;
  97. string &StoreFilename;
  98. pkgCache::VerFileIterator Vf;
  99. unsigned int Retries;
  100. // Queue the next available file for download.
  101. bool QueueNext();
  102. public:
  103. // Specialized action members
  104. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  105. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  106. virtual string Describe();
  107. virtual string MD5Sum() {return MD5;};
  108. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  109. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  110. string &StoreFilename);
  111. };
  112. #endif