acquire-item.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: acquire-item.h,v 1.17 1999/03/27 03:02:38 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. unsigned long PartialSize;
  40. char *Mode;
  41. unsigned long ID;
  42. bool Complete;
  43. bool Local;
  44. // Number of queues we are inserted into
  45. unsigned int QueueCounter;
  46. // File to write the fetch into
  47. string DestFile;
  48. // Action members invoked by the worker
  49. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  50. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  51. virtual void Start(string Message,unsigned long Size);
  52. virtual string Custom600Headers() {return string();};
  53. // Inquire functions
  54. virtual string MD5Sum() {return string();};
  55. virtual string Describe() = 0;
  56. Item(pkgAcquire *Owner);
  57. virtual ~Item();
  58. };
  59. // Item class for index files
  60. class pkgAcqIndex : public pkgAcquire::Item
  61. {
  62. protected:
  63. const pkgSourceList::Item *Location;
  64. bool Decompression;
  65. bool Erase;
  66. pkgAcquire::ItemDesc Desc;
  67. public:
  68. // Specialized action members
  69. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  70. virtual string Custom600Headers();
  71. virtual string Describe();
  72. pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location);
  73. };
  74. // Item class for index files
  75. class pkgAcqIndexRel : public pkgAcquire::Item
  76. {
  77. protected:
  78. const pkgSourceList::Item *Location;
  79. pkgAcquire::ItemDesc Desc;
  80. public:
  81. // Specialized action members
  82. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  83. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  84. virtual string Custom600Headers();
  85. virtual string Describe();
  86. pkgAcqIndexRel(pkgAcquire *Owner,const pkgSourceList::Item *Location);
  87. };
  88. // Item class for archive files
  89. class pkgAcqArchive : public pkgAcquire::Item
  90. {
  91. protected:
  92. // State information for the retry mechanism
  93. pkgCache::VerIterator Version;
  94. pkgAcquire::ItemDesc Desc;
  95. pkgSourceList *Sources;
  96. pkgRecords *Recs;
  97. string MD5;
  98. string &StoreFilename;
  99. pkgCache::VerFileIterator Vf;
  100. unsigned int Retries;
  101. // Queue the next available file for download.
  102. bool QueueNext();
  103. public:
  104. // Specialized action members
  105. virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
  106. virtual void Done(string Message,unsigned long Size,string Md5Hash);
  107. virtual string Describe();
  108. virtual string MD5Sum() {return MD5;};
  109. pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
  110. pkgRecords *Recs,pkgCache::VerIterator const &Version,
  111. string &StoreFilename);
  112. };
  113. #endif