policy.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: policy.h,v 1.4 2001/05/07 04:24:08 jgg Exp $
  4. /* ######################################################################
  5. Package Version Policy implementation
  6. This implements the more advanced 'Version 4' APT policy engine. The
  7. standard 'Version 0' engine is included inside the DepCache which is
  8. it's historical location.
  9. The V4 engine allows the user to completly control all aspects of
  10. version selection. There are three primary means to choose a version
  11. * Selection by version match
  12. * Selection by Release file match
  13. * Selection by origin server
  14. Each package may be 'pinned' with a single criteria, which will ultimately
  15. result in the selection of a single version, or no version, for each
  16. package.
  17. Furthermore, the default selection can be influenced by specifying
  18. the ordering of package files. The order is derived by reading the
  19. package file preferences and assigning a priority to each package
  20. file.
  21. A special flag may be set to indicate if no version should be returned
  22. if no matching versions are found, otherwise the default matching
  23. rules are used to locate a hit.
  24. ##################################################################### */
  25. /*}}}*/
  26. #ifndef PKGLIB_POLICY_H
  27. #define PKGLIB_POLICY_H
  28. #include <apt-pkg/depcache.h>
  29. #include <apt-pkg/pkgcache.h>
  30. #include <apt-pkg/cacheiterators.h>
  31. #include <apt-pkg/versionmatch.h>
  32. #include <vector>
  33. #include <string>
  34. #ifndef APT_8_CLEANER_HEADERS
  35. using std::vector;
  36. #endif
  37. class pkgPolicy : public pkgDepCache::Policy
  38. {
  39. protected:
  40. struct Pin
  41. {
  42. pkgVersionMatch::MatchType Type;
  43. std::string Data;
  44. signed short Priority;
  45. Pin() : Type(pkgVersionMatch::None), Priority(0) {};
  46. };
  47. struct PkgPin : Pin
  48. {
  49. std::string Pkg;
  50. PkgPin(std::string const &Pkg) : Pin(), Pkg(Pkg) {};
  51. };
  52. Pin *Pins;
  53. signed short *PFPriority;
  54. std::vector<Pin> Defaults;
  55. std::vector<PkgPin> Unmatched;
  56. pkgCache *Cache;
  57. bool StatusOverride;
  58. public:
  59. // Things for manipulating pins
  60. void CreatePin(pkgVersionMatch::MatchType Type,std::string Pkg,
  61. std::string Data,signed short Priority);
  62. pkgCache::VerIterator GetMatch(pkgCache::PkgIterator const &Pkg);
  63. // Things for the cache interface.
  64. virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator const &Pkg);
  65. virtual signed short GetPriority(pkgCache::PkgIterator const &Pkg);
  66. virtual signed short GetPriority(pkgCache::PkgFileIterator const &File);
  67. bool InitDefaults();
  68. pkgPolicy(pkgCache *Owner);
  69. virtual ~pkgPolicy() {delete [] PFPriority; delete [] Pins;};
  70. };
  71. bool ReadPinFile(pkgPolicy &Plcy, std::string File = "");
  72. bool ReadPinDir(pkgPolicy &Plcy, std::string Dir = "");
  73. #endif