policy.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifdef __GNUG__
  29. #pragma interface "apt-pkg/policy.h"
  30. #endif
  31. #include <apt-pkg/depcache.h>
  32. #include <apt-pkg/versionmatch.h>
  33. #include <vector>
  34. using std::vector;
  35. class pkgPolicy : public pkgDepCache::Policy
  36. {
  37. protected:
  38. struct Pin
  39. {
  40. pkgVersionMatch::MatchType Type;
  41. string Data;
  42. signed short Priority;
  43. Pin() : Type(pkgVersionMatch::None), Priority(0) {};
  44. };
  45. struct PkgPin : Pin
  46. {
  47. string Pkg;
  48. };
  49. Pin *Pins;
  50. signed short *PFPriority;
  51. vector<Pin> Defaults;
  52. vector<PkgPin> Unmatched;
  53. pkgCache *Cache;
  54. bool StatusOverride;
  55. public:
  56. // Things for manipulating pins
  57. void CreatePin(pkgVersionMatch::MatchType Type,string Pkg,
  58. string Data,signed short Priority);
  59. inline signed short GetPriority(pkgCache::PkgFileIterator const &File)
  60. {return PFPriority[File->ID];};
  61. signed short GetPriority(pkgCache::PkgIterator const &Pkg);
  62. pkgCache::VerIterator GetMatch(pkgCache::PkgIterator Pkg);
  63. // Things for the cache interface.
  64. virtual pkgCache::VerIterator GetCandidateVer(pkgCache::PkgIterator Pkg);
  65. virtual bool IsImportantDep(pkgCache::DepIterator Dep) {return pkgDepCache::Policy::IsImportantDep(Dep);};
  66. bool InitDefaults();
  67. pkgPolicy(pkgCache *Owner);
  68. virtual ~pkgPolicy() {delete [] PFPriority; delete [] Pins;};
  69. };
  70. bool ReadPinFile(pkgPolicy &Plcy,string File = "");
  71. #endif