]>
Commit | Line | Data |
---|---|---|
7939f6d1 RC |
1 | /* |
2 | * Copyright (c) 2001, Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
fa0c0d10 | 16 | /* This is a package version abstrct class, that should be able to |
7939f6d1 RC |
17 | * arbitrate acceess to cygwin binary packages, cygwin source package, |
18 | * and the rpm and deb equivalents of the same. | |
19 | */ | |
20 | ||
fa0c0d10 RC |
21 | #ifndef _PACKAGE_VERSION_H_ |
22 | #define _PACKAGE_VERSION_H_ | |
7939f6d1 RC |
23 | |
24 | /* standard binary package metadata: | |
25 | * Name (ie mutt | |
26 | * Vendor Version (ie 2.5.1) | |
27 | * Package Version (ie 16) | |
28 | * Stability | |
29 | * Files | |
30 | */ | |
31 | ||
32 | /* For non installed files, this class can be populated via information about | |
33 | * what is available on the net, or by parsing a specific package file. | |
34 | * for installed packages, this class should represent what is currently installed, | |
35 | * - updated by what net metadata has about it. | |
36 | * i.e. the stability of this version will change simply because the net mirrors | |
37 | * now consider it old. | |
38 | */ | |
39 | ||
7b606ae5 | 40 | class CategoryList; |
3c196821 RC |
41 | |
42 | /*Required for parsing */ | |
bb849dbd | 43 | #include "package_source.h" |
3c054baf | 44 | #include "String++.h" |
aa1e3b4d | 45 | #include "PackageSpecification.h" |
4f591f9d | 46 | #include "PackageTrust.h" |
ad646f43 | 47 | #include "script.h" |
aa1e3b4d | 48 | #include <vector> |
bb849dbd | 49 | |
7939f6d1 RC |
50 | typedef enum |
51 | { | |
52 | package_invalid, | |
53 | package_old, | |
54 | package_current, | |
55 | package_experimental | |
56 | } | |
57 | package_stability_t; | |
58 | ||
59 | typedef enum | |
60 | { | |
61 | package_notinstalled, | |
62 | package_installed | |
63 | } | |
64 | package_status_t; | |
65 | ||
66 | typedef enum | |
67 | { | |
68 | package_binary, | |
69 | package_source | |
70 | } | |
71 | package_type_t; | |
72 | ||
3c196821 RC |
73 | /* A wrapper class to be copied by value that |
74 | references the same package. | |
75 | Nothing is virtual, because the wrapper cannot be inherited. | |
76 | However, as all the methods are implemented in the referenced | |
77 | _packageversion, that class allows virtual overriding. | |
78 | */ | |
79 | ||
80 | class _packageversion; | |
81 | ||
82 | /* This class has pointer semantics | |
83 | Specifically: a=b does not alter the value of *a. | |
84 | */ | |
fa0c0d10 | 85 | class packageversion |
7939f6d1 RC |
86 | { |
87 | public: | |
3c196821 RC |
88 | packageversion (); /* creates an empty packageversion */ |
89 | packageversion (_packageversion *); /* used when creating an instance */ | |
90 | packageversion (packageversion const &); | |
91 | ~packageversion (); | |
92 | packageversion &operator= (packageversion const &); | |
93 | bool operator ! () const; /* true if the package is invalid. (i.e. | |
94 | uninitialised */ | |
95 | operator bool () const; /* returns ! !() */ | |
96 | bool operator == (packageversion const &) const; /* equality */ | |
97 | bool operator != (packageversion const &) const; | |
98 | bool operator < (packageversion const &) const; | |
99 | bool operator <= (packageversion const &) const; | |
100 | bool operator > (packageversion const &) const; | |
101 | bool operator >= (packageversion const &) const; | |
102 | ||
103 | String const Name () const; | |
104 | String const Vendor_version () const; | |
105 | String const Package_version () const; | |
106 | String const Canonical_version () const; | |
107 | void setCanonicalVersion (String const &); | |
108 | package_status_t Status () const; | |
109 | package_type_t Type () const; | |
110 | String const getfirstfile (); | |
111 | String const getnextfile (); | |
112 | String const SDesc () const; | |
113 | void set_sdesc (String const &); | |
114 | String const LDesc () const; | |
115 | void set_ldesc (String const &); | |
116 | packageversion sourcePackage (); | |
117 | PackageSpecification & sourcePackageSpecification (); | |
118 | void setSourcePackageSpecification (PackageSpecification const &); | |
119 | ||
120 | /* invariant: these never return NULL */ | |
666bf37d | 121 | std::vector <std::vector <PackageSpecification *> *> *depends(), *predepends(), |
b1ff53ed | 122 | *recommends(), *suggests(), *replaces(), *conflicts(), *provides(), *binaries(); |
3c196821 RC |
123 | |
124 | bool picked() const; /* true if this version is to be installed */ | |
125 | void pick(bool); /* trigger an install/reinsall */ | |
126 | /* a change - install/uninstall/reinstall/source install | |
127 | has been requested */ | |
128 | bool changeRequested () const; | |
129 | ||
130 | void uninstall (); | |
131 | /* invariant: never null */ | |
e5662e0a RC |
132 | packagesource *source(); /* where can we source the file from */ |
133 | /* invariant: never null */ | |
666bf37d | 134 | std::vector <packagesource> *sources(); /* expose the list of files. |
e5662e0a RC |
135 | source() returns the 'default' file |
136 | sources() allows managing multiple files | |
137 | in a single package | |
138 | */ | |
3c196821 RC |
139 | |
140 | bool accessible () const; | |
4f591f9d RC |
141 | |
142 | /* ensure that the depends clause is satisfied */ | |
143 | int set_requirements (trusts deftrust = TRUST_CURR, size_t depth = 0); | |
05c5b8a6 | 144 | |
ad646f43 RC |
145 | void addScript(Script const &); |
146 | std::vector <Script> &scripts(); | |
147 | ||
3c196821 RC |
148 | private: |
149 | _packageversion *data; /* Invariant: * data is always valid */ | |
150 | }; | |
151 | ||
152 | class _packageversion | |
153 | { | |
154 | public: | |
155 | _packageversion(); | |
156 | virtual ~_packageversion(); | |
bb849dbd | 157 | /* for list inserts/mgmt. */ |
3c054baf | 158 | String key; |
7939f6d1 RC |
159 | /* name is needed here, because if we are querying a file, the data may be embedded in |
160 | the file */ | |
3c054baf RC |
161 | virtual String const Name () = 0; |
162 | virtual String const Vendor_version () = 0; | |
163 | virtual String const Package_version () = 0; | |
164 | virtual String const Canonical_version () = 0; | |
3c196821 | 165 | virtual void setCanonicalVersion (String const &) = 0; |
7939f6d1 RC |
166 | virtual package_status_t Status () = 0; |
167 | // virtual package_stability_t Stability () = 0; | |
168 | virtual package_type_t Type () = 0; | |
169 | /* TODO: we should probably return a metaclass - file name & path & size & type | |
170 | - ie doc/script/binary | |
171 | */ | |
3c054baf RC |
172 | virtual String const getfirstfile () = 0; |
173 | virtual String const getnextfile () = 0; | |
174 | virtual String const SDesc () = 0; | |
175 | virtual void set_sdesc (String const &) = 0; | |
176 | virtual String const LDesc () = 0; | |
177 | virtual void set_ldesc (String const &) = 0; | |
aa1e3b4d | 178 | /* only semantically meaningful for binary packages */ |
3c196821 RC |
179 | /* direct link to the source package for this binary */ |
180 | /* if multiple versions exist and the source doesn't discriminate | |
181 | then the most recent is used | |
182 | */ | |
183 | virtual packageversion sourcePackage (); | |
184 | virtual PackageSpecification & sourcePackageSpecification (); | |
185 | virtual void setSourcePackageSpecification (PackageSpecification const &); | |
aa1e3b4d | 186 | |
666bf37d | 187 | std::vector <std::vector <PackageSpecification *> *> depends, predepends, recommends, |
b1ff53ed | 188 | suggests, replaces, conflicts, provides, binaries; |
aa1e3b4d | 189 | |
6e754226 | 190 | virtual void pick(bool const &newValue) { picked = newValue;} |
3c196821 RC |
191 | bool picked; /* non zero if this version is to be installed */ |
192 | /* This will also trigger reinstalled if it is set */ | |
193 | /* a change - install/uninstall/reinstall/source install | |
194 | has been requested */ | |
195 | bool changeRequested (); | |
bb849dbd | 196 | |
7939f6d1 | 197 | |
bb849dbd | 198 | virtual void uninstall () = 0; |
666bf37d | 199 | std::vector<packagesource> sources; /* where can we source the files from */ |
fa0c0d10 | 200 | |
3c196821 | 201 | bool accessible () const; |
7939f6d1 | 202 | |
bb849dbd RC |
203 | /* TODO: Implement me: |
204 | static package_meta * scan_package (io_stream *); | |
205 | */ | |
3c196821 | 206 | size_t references; |
ad646f43 RC |
207 | virtual void addScript(Script const &); |
208 | virtual std::vector <Script> &scripts(); | |
aa1e3b4d | 209 | protected: |
3c196821 | 210 | /* only meaningful for binary packages */ |
aa1e3b4d | 211 | PackageSpecification _sourcePackage; |
3c196821 | 212 | packageversion sourceVersion; |
ad646f43 | 213 | std::vector <Script> scripts_; |
7939f6d1 RC |
214 | }; |
215 | ||
fa0c0d10 | 216 | #endif /* _PACKAGE_VERSION_H_ */ |