You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
3.1 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. System - Abstraction for running on different systems.
  5. Basic general structure..
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <config.h>
  10. #include <apt-pkg/debsystem.h>
  11. #include <apt-pkg/error.h>
  12. #include <apt-pkg/macros.h>
  13. #include <apt-pkg/pkgsystem.h>
  14. #include <cassert>
  15. #include <cstring>
  16. #include <map>
  17. /*}}}*/
  18. pkgSystem *_system = 0;
  19. static pkgSystem *SysList[10];
  20. pkgSystem **pkgSystem::GlobalList = SysList;
  21. unsigned long pkgSystem::GlobalListLen = 0;
  22. class APT_HIDDEN pkgSystemPrivate /*{{{*/
  23. {
  24. public:
  25. typedef decltype(pkgCache::Version::ID) idtype;
  26. std::map<idtype,idtype> idmap;
  27. pkgSystemPrivate() {}
  28. };
  29. /*}}}*/
  30. // System::pkgSystem - Constructor /*{{{*/
  31. // ---------------------------------------------------------------------
  32. /* Add it to the global list.. */
  33. pkgSystem::pkgSystem(char const * const label, pkgVersioningSystem * const vs) :
  34. Label(label), VS(vs), d(new pkgSystemPrivate())
  35. {
  36. assert(GlobalListLen < sizeof(SysList)/sizeof(*SysList));
  37. SysList[GlobalListLen] = this;
  38. ++GlobalListLen;
  39. }
  40. /*}}}*/
  41. // System::GetSystem - Get the named system /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* */
  44. APT_PURE pkgSystem *pkgSystem::GetSystem(const char *Label)
  45. {
  46. for (unsigned I = 0; I != GlobalListLen; I++)
  47. if (strcmp(SysList[I]->Label,Label) == 0)
  48. return SysList[I];
  49. return 0;
  50. }
  51. /*}}}*/
  52. bool pkgSystem::MultiArchSupported() const /*{{{*/
  53. {
  54. debSystem const * const deb = dynamic_cast<debSystem const *>(this);
  55. if (deb != NULL)
  56. return deb->SupportsMultiArch();
  57. return true;
  58. }
  59. /*}}}*/
  60. std::vector<std::string> pkgSystem::ArchitecturesSupported() const /*{{{*/
  61. {
  62. debSystem const * const deb = dynamic_cast<debSystem const *>(this);
  63. if (deb != NULL)
  64. return deb->SupportedArchitectures();
  65. return {};
  66. }
  67. /*}}}*/
  68. // pkgSystem::Set/GetVersionMapping - for internal/external communication/*{{{*/
  69. void pkgSystem::SetVersionMapping(map_id_t const in, map_id_t const out)
  70. {
  71. if (in == out)
  72. return;
  73. d->idmap.emplace(in, out);
  74. }
  75. map_id_t pkgSystem::GetVersionMapping(map_id_t const in) const
  76. {
  77. auto const o = d->idmap.find(in);
  78. return (o == d->idmap.end()) ? in : o->second;
  79. }
  80. /*}}}*/
  81. bool pkgSystem::LockInner() /*{{{*/
  82. {
  83. debSystem * const deb = dynamic_cast<debSystem *>(this);
  84. if (deb != NULL)
  85. return deb->LockInner();
  86. return _error->Error("LockInner is not implemented");
  87. }
  88. /*}}}*/
  89. bool pkgSystem::UnLockInner(bool NoErrors) /*{{{*/
  90. {
  91. debSystem * const deb = dynamic_cast<debSystem *>(this);
  92. if (deb != NULL)
  93. return deb->UnLockInner(NoErrors);
  94. return _error->Error("UnLockInner is not implemented");
  95. }
  96. /*}}}*/
  97. bool pkgSystem::IsLocked() /*{{{*/
  98. {
  99. debSystem * const deb = dynamic_cast<debSystem *>(this);
  100. if (deb != NULL)
  101. return deb->IsLocked();
  102. return true;
  103. }
  104. /*}}}*/
  105. pkgSystem::~pkgSystem() {}