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