pkgsystem.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. System - Abstraction for running on different systems.
  5. Instances of this class can be thought of as factories or meta-classes
  6. for a variety of more specialized classes. Together this class and
  7. it's specialized offspring completely define the environment and how
  8. to access resources for a specific system. There are several sub
  9. areas that are all orthogonal - each system has a unique combination of
  10. these sub areas:
  11. - Versioning. Different systems have different ideas on versions.
  12. Within a system all sub classes must follow the same versioning
  13. rules.
  14. - Local tool locking to prevent multiple tools from accessing the
  15. same database.
  16. - Candidate Version selection policy - this is probably almost always
  17. managed using a standard APT class
  18. - Actual Package installation
  19. * Indication of what kind of binary formats are supported
  20. - Selection of local 'status' indexes that make up the pkgCache.
  21. It is important to note that the handling of index files is not a
  22. function of the system. Index files are handled through a separate
  23. abstraction - the only requirement is that the index files have the
  24. same idea of versioning as the target system.
  25. Upon startup each supported system instantiates an instance of the
  26. pkgSystem class (using a global constructor) which will make itself
  27. available to the main APT init routine. That routine will select the
  28. proper system and make it the global default.
  29. ##################################################################### */
  30. /*}}}*/
  31. #ifndef PKGLIB_PKGSYSTEM_H
  32. #define PKGLIB_PKGSYSTEM_H
  33. #include <apt-pkg/pkgcache.h>
  34. #include <apt-pkg/cacheiterators.h>
  35. #include <vector>
  36. #ifndef APT_8_CLEANER_HEADERS
  37. #include <apt-pkg/depcache.h>
  38. #endif
  39. class pkgDepCache;
  40. class pkgPackageManager;
  41. class pkgVersioningSystem;
  42. class Configuration;
  43. class pkgIndexFile;
  44. class pkgSystemPrivate;
  45. class pkgSystem
  46. {
  47. public:
  48. // Global list of supported systems
  49. static pkgSystem **GlobalList;
  50. static unsigned long GlobalListLen;
  51. static pkgSystem *GetSystem(const char *Label);
  52. const char * const Label;
  53. pkgVersioningSystem * const VS;
  54. /* Prevent other programs from touching shared data not covered by
  55. other locks (cache or state locks) */
  56. virtual bool Lock() = 0;
  57. virtual bool UnLock(bool NoErrors = false) = 0;
  58. /* Various helper classes to interface with specific bits of this
  59. environment */
  60. virtual pkgPackageManager *CreatePM(pkgDepCache *Cache) const = 0;
  61. /* Load environment specific configuration and perform any other setup
  62. necessary */
  63. virtual bool Initialize(Configuration &/*Cnf*/) {return true;};
  64. /* Type is some kind of Globally Unique way of differentiating
  65. archive file types.. */
  66. virtual bool ArchiveSupported(const char *Type) = 0;
  67. // Return a list of system index files..
  68. virtual bool AddStatusFiles(std::vector<pkgIndexFile *> &List) = 0;
  69. virtual bool FindIndex(pkgCache::PkgFileIterator File,
  70. pkgIndexFile *&Found) const = 0;
  71. /* Evauluate how 'right' we are for this system based on the filesystem
  72. etc.. */
  73. virtual signed Score(Configuration const &/*Cnf*/) {
  74. return 0;
  75. };
  76. //FIXME: these methods should be virtual
  77. /** does this system has support for MultiArch?
  78. *
  79. * Systems supporting only single arch (not systems which are single arch)
  80. * are considered legacy systems and support for it will likely degrade over
  81. * time.
  82. *
  83. * The default implementation returns always \b true.
  84. *
  85. * @return \b true if the system supports MultiArch, \b false if not.
  86. */
  87. bool MultiArchSupported() const;
  88. /** architectures supported by this system
  89. *
  90. * A MultiArch capable system might be configured to use
  91. * this capability.
  92. *
  93. * @return a list of all architectures (native + foreign) configured
  94. * for on this system (aka: which can be installed without force)
  95. */
  96. std::vector<std::string> ArchitecturesSupported() const;
  97. APT_HIDDEN void SetVersionMapping(map_id_t const in, map_id_t const out);
  98. APT_HIDDEN map_id_t GetVersionMapping(map_id_t const in) const;
  99. pkgSystem(char const * const Label, pkgVersioningSystem * const VS);
  100. virtual ~pkgSystem();
  101. private:
  102. pkgSystemPrivate * const d;
  103. };
  104. // The environment we are operating in.
  105. extern pkgSystem *_system;
  106. #endif