cdrom.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef PKGLIB_CDROM_H
  2. #define PKGLIB_CDROM_H
  3. #include <apt-pkg/macros.h>
  4. #include<string>
  5. #include<vector>
  6. #include <stddef.h>
  7. #ifndef APT_8_CLEANER_HEADERS
  8. #include <apt-pkg/init.h>
  9. using namespace std;
  10. #endif
  11. class Configuration;
  12. class OpProgress;
  13. class pkgCdromStatus /*{{{*/
  14. {
  15. void * const d;
  16. protected:
  17. int totalSteps;
  18. public:
  19. pkgCdromStatus();
  20. virtual ~pkgCdromStatus();
  21. // total steps
  22. virtual void SetTotal(int total) { totalSteps = total; };
  23. // update steps, will be called regularly as a "pulse"
  24. virtual void Update(std::string text="", int current=0) = 0;
  25. // ask for cdrom insert
  26. virtual bool ChangeCdrom() = 0;
  27. // ask for cdrom name
  28. virtual bool AskCdromName(std::string &Name) = 0;
  29. // Progress indicator for the Index rewriter
  30. virtual OpProgress* GetOpProgress() {return NULL; };
  31. };
  32. /*}}}*/
  33. class pkgCdrom /*{{{*/
  34. {
  35. protected:
  36. enum {
  37. STEP_PREPARE = 1,
  38. STEP_UNMOUNT,
  39. STEP_WAIT,
  40. STEP_MOUNT,
  41. STEP_IDENT,
  42. STEP_SCAN,
  43. STEP_COPY,
  44. STEP_WRITE,
  45. STEP_UNMOUNT3,
  46. STEP_LAST
  47. };
  48. bool FindPackages(std::string CD,
  49. std::vector<std::string> &List,
  50. std::vector<std::string> &SList,
  51. std::vector<std::string> &SigList,
  52. std::vector<std::string> &TransList,
  53. std::string &InfoDir, pkgCdromStatus *log,
  54. unsigned int Depth = 0);
  55. bool DropBinaryArch(std::vector<std::string> &List);
  56. bool DropRepeats(std::vector<std::string> &List,const char *Name);
  57. bool DropTranslation(std::vector<std::string> &List);
  58. void ReduceSourcelist(std::string CD,std::vector<std::string> &List);
  59. bool WriteDatabase(Configuration &Cnf);
  60. bool WriteSourceList(std::string Name,std::vector<std::string> &List,bool Source);
  61. int Score(std::string Path);
  62. public:
  63. bool Ident(std::string &ident, pkgCdromStatus *log);
  64. bool Add(pkgCdromStatus *log);
  65. pkgCdrom();
  66. virtual ~pkgCdrom();
  67. private:
  68. void * const d;
  69. APT_HIDDEN bool MountAndIdentCDROM(Configuration &Database, std::string &CDROM,
  70. std::string &ident, pkgCdromStatus * const log, bool const interactive);
  71. APT_HIDDEN bool UnmountCDROM(std::string const &CDROM, pkgCdromStatus * const log);
  72. };
  73. /*}}}*/
  74. // class that uses libudev to find cdrom/removable devices dynamically
  75. struct CdromDevice /*{{{*/
  76. {
  77. std::string DeviceName;
  78. bool Mounted;
  79. std::string MountPath;
  80. };
  81. /*}}}*/
  82. class pkgUdevCdromDevices /*{{{*/
  83. {
  84. void * const d;
  85. protected:
  86. // libudev dlopen structure
  87. void *libudev_handle;
  88. struct udev* (*udev_new)(void);
  89. int (*udev_enumerate_add_match_property)(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
  90. int (*udev_enumerate_scan_devices)(struct udev_enumerate *udev_enumerate);
  91. struct udev_list_entry* (*udev_enumerate_get_list_entry)(struct udev_enumerate *udev_enumerate);
  92. struct udev_device* (*udev_device_new_from_syspath)(struct udev *udev, const char *syspath);
  93. struct udev* (*udev_enumerate_get_udev)(struct udev_enumerate *udev_enumerate);
  94. const char* (*udev_list_entry_get_name)(struct udev_list_entry *list_entry);
  95. const char* (*udev_device_get_devnode)(struct udev_device *udev_device);
  96. struct udev_enumerate *(*udev_enumerate_new) (struct udev *udev);
  97. struct udev_list_entry *(*udev_list_entry_get_next)(struct udev_list_entry *list_entry);
  98. const char* (*udev_device_get_property_value)(struct udev_device *udev_device, const char *key);
  99. int (*udev_enumerate_add_match_sysattr)(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
  100. // end libudev dlopen
  101. public:
  102. pkgUdevCdromDevices();
  103. virtual ~pkgUdevCdromDevices();
  104. // try to open
  105. bool Dlopen();
  106. // convenience interface, this will just call ScanForRemovable
  107. // with "APT::cdrom::CdromOnly"
  108. std::vector<CdromDevice> Scan();
  109. std::vector<CdromDevice> ScanForRemovable(bool CdromOnly);
  110. };
  111. /*}}}*/
  112. #endif