12b3a8af69a1e325e5a4997e3442c6059b7d417b
[platform/upstream/libzypp.git] / zypp2 / cache / CacheStore.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 #ifndef ZYPP_CacheStore_H
11 #define ZYPP_CacheStore_H
12
13 #include <iosfwd>
14 #include <string>
15
16 #include "zypp/base/ReferenceCounted.h"
17 #include "zypp/base/NonCopyable.h"
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/Pathname.h"
20 #include "zypp/NVRA.h"
21 #include "zypp/capability/CapabilityImpl.h"
22 #include "zypp/capability/Capabilities.h"
23
24 #include "zypp/data/ResolvableDataConsumer.h"
25 #include "zypp/data/RecordId.h"
26
27 #include "zypp/base/PtrTypes.h"
28
29 ///////////////////////////////////////////////////////////////////
30 namespace zypp
31 { /////////////////////////////////////////////////////////////////
32   ///////////////////////////////////////////////////////////////////
33   namespace cache
34   { /////////////////////////////////////////////////////////////////
35         
36     /**
37      * The cache store caches resolvable data into some backend.
38     */
39     class CacheStore
40     {
41     public:
42       
43       CacheStore();
44       ~CacheStore();
45       
46       /**
47        * Constructor for the CacheStore
48        *
49        * \note a transaction will be started from the moment the
50        * CacheStore is instanciated.
51        * 
52        * The data will be saved in the directory specified in
53        * \a dbdir
54        */
55       CacheStore( const Pathname &dbdir );
56       
57       /**
58        * Implements the ResolvableConsumer consumePackage interface
59        * Consumer a package and inserts it into the database.
60        * Don't use this method yet
61       */
62       virtual void consumePackage( const data::Package &package);
63       
64       /**
65        * Appends a resolvable to the store.
66        *
67        * You have to specify with \a kind of resolvable are you inserting
68        * and its \c NVRA (name version release and architecture ).
69        * Optionaly you can pass a list of \c CapabilityImpl::Ptr
70        * as dependencies for the resolvable.
71        * 
72        * You have to specify the RecordId for the catalog owning
73        * this resolvable. Yuu can obtain it with
74        * \ref lookupOrAppendCatalog
75        * 
76        * You can create those \a deps using \ref capability::parse
77        * functions, or the build methods to create specific types
78        * of capabilities:
79        * \ref capability::buildVersioned for \c VersionedCap
80        * \ref capability::buildNamed for \c NamedCap
81        * etc.
82        *
83        * Once the resolvable is inserted, you will get back the id
84        * if it in the store. Which you can use for later adding
85        * other properties.
86        *
87        */
88       data::RecordId appendResolvable( const data::RecordId &catalog_id,
89                                        const Resolvable::Kind &kind,
90                                        const NVRA &nvra,
91                                        const data::Dependencies &deps );
92       
93       /**
94        * Adds dependencies to the store
95        *
96        * A map of dependency lists has to be specified. The map contains
97        * list of capablities for each dependency type \ref zypp::Dep
98        *
99        * \a resolvable_id is the resolvable Id in the CacheStore
100        * that will own those capabilities.
101        *
102        * FIXME should it \throw if the resolvable does not exist?
103        */
104       void appendDependencies( const data::RecordId &resolvable_id,
105                                const data::Dependencies &dependencies );
106       
107       /**
108        * Adds dependencies to the store
109        *
110        * A lists of dependencies \a dlist to be specified. Among
111        * which type of dependencies \ref zypp::Dep it is as
112        * the \a deptype argument.
113        * 
114        * \a resolvable_id is the resolvable Id in the CacheStore
115        * that will own those capabilities.
116        *
117        * FIXME should it \throw if the resolvable does not exist?
118        */
119       void appendDependencyList( const data::RecordId &resolvable_id, 
120                                  zypp::Dep deptype,
121                                  const data::DependencyList &dlist );
122       
123       /**
124        * Adds a dependency to the store.
125        *
126        * A \ref CapabilityImpl::Ptr argument \a cap has to be specified. 
127        * Among which type of dependency \ref zypp::Dep it is as
128        * the \a deptype argument.
129        * 
130        * \a resolvable_id is the resolvable Id in the CacheStore
131        * that will own the capability
132        *
133        * FIXME should it \throw if the resolvable does not exist?
134        */
135       void appendDependency( const data::RecordId &resolvable_id,
136                              zypp::Dep deptype,
137                              capability::CapabilityImpl::Ptr cap );
138       
139       /**
140        * Adds a Named dependency to the store.
141        *
142        * A \ref NamedCap::Ptr \a dlist to be specified. Among
143        * which type of dependency \ref zypp::Dep it is as
144        * the \a deptype argument.
145        * 
146        * \a resolvable_id is the resolvable Id in the CacheStore
147        * that will own the capability
148        *
149        * You can create the named capability using either
150        * \ref capability::parse or \ref capability::buildNamed
151        *
152        * FIXME should it \throw if the resolvable does not exist?
153        */
154       void appendNamedDependency( const data::RecordId &, zypp::Dep,
155                                   capability::NamedCap::Ptr);
156       
157       /**
158        * Adds a file dependency to the store.
159        *
160        * A \ref FileCap::Ptr \a dlist to be specified. Among
161        * which type of dependency \ref zypp::Dep it is as
162        * the \a deptype argument.
163        * 
164        * \a resolvable_id is the resolvable Id in the CacheStore
165        * that will own the capability
166        *
167        * You can create the file capability using either
168        * \ref capability::parse or \ref capability::buildFile
169        *
170        * FIXME should it \throw if the resolvable does not exist?
171        */
172       void appendFileDependency( const data::RecordId &, zypp::Dep, 
173                                  capability::FileCap::Ptr);
174       
175       /**
176        * Adds a Modalias dependency to the store.
177        *
178        * A \ref ModaliasCap::Ptr \a cap to be specified. Among
179        * which type of dependency \ref zypp::Dep it is as
180        * the \a deptype argument.
181        * 
182        * \a resolvable_id is the resolvable Id in the CacheStore
183        * that will own the capability
184        *
185        * You can create the modalias capability using either
186        * \ref capability::parse or \ref capability::buildModalias
187        *
188        * FIXME should it \throw if the resolvable does not exist?
189        */
190       void appendModaliasDependency( const data::RecordId &resolvable_id,
191                                      zypp::Dep deptype,
192                                      capability::ModaliasCap::Ptr cap);
193       
194       /**
195        * Adds a Hal dependency to the store.
196        *
197        * A \ref HalCap::Ptr \a cap to be specified. Among
198        * which type of dependency \ref zypp::Dep it is as
199        * the \a deptype argument.
200        * 
201        * \a resolvable_id is the resolvable Id in the CacheStore
202        * that will own the capability
203        *
204        * You can create the modalias capability using either
205        * \ref capability::parse or \ref capability::buildHal
206        *
207        * FIXME should it \throw if the resolvable does not exist?
208        */
209       void appendHalDependency( const data::RecordId &resolvable_id,
210                                       zypp::Dep deptype,
211                                       capability::HalCap::Ptr cap );
212       
213       /**
214        * Adds a unknown dependency to the store.
215        *
216        * A \ref Capability::Ptr \a cap to be specified. Among
217        * which type of dependency \ref zypp::Dep it is as
218        * the \a deptype argument.
219        * 
220        * \a resolvable_id is the resolvable Id in the CacheStore
221        * that will own the capability
222        *
223        * You can create the capability using either
224        * \ref capability::parse
225        *
226        * FIXME should it \throw if the resolvable does not exist?
227        */
228       void appendUnknownDependency( const data::RecordId &resolvable_id,
229                                           zypp::Dep deptype,
230                                           capability::CapabilityImpl::Ptr cap );
231       
232       /**
233        * Returns the record id of a catalog (Source) \a path
234        *
235        * \note If the catalog entry does not exist, it will
236        * be created and the new inserted entry's id will
237        * be returned.
238        */
239       data::RecordId lookupOrAppendCatalog( const Url &url, 
240                                             const Pathname &path );
241       
242        /**
243        * Update a known catalog checksum and timestamp
244        *
245        * \note If you don't provide timestamp it defaults
246        * to now.
247        *
248        * It is responsability of the caller to operate with
249        * a valid record id. You can get one
250        * Using \ref lookupOrAppendCatalog
251        */
252       void updateCatalog( const data::RecordId &id, 
253                                     const std::string &checksum, 
254                                     const Date &timestamp = Date::now() );
255       
256       /**
257        * Returns the record id of a file entry \a path
258        *
259        * \note If the file entry does not exist, it will
260        * be created and the new inserted entry's id will
261        * be returned.
262        */
263       data::RecordId lookupOrAppendFile( const Pathname &path );
264       
265       /**
266        * Returns the record id of a name entry \a name
267        *
268        * \note If the name entry does not exist, it will
269        * be created and the new inserted entry's id will
270        * be returned.
271        */
272       data::RecordId lookupOrAppendName( const std::string &name );
273       
274       /**
275        * Returns the record id of a directory name  entry \a name
276        *
277        * \note If the directory name entry does not exist, it will
278        * be created and the new inserted entry's id will
279        * be returned.
280        */
281       data::RecordId lookupOrAppendDirName( const std::string &name );
282       
283       /**
284        * Returns the record id of a file name entry \a name
285        *
286        * \note If the file name entry does not exist, it will
287        * be created and the new inserted entry's id will
288        * be returned.
289        */
290       data::RecordId lookupOrAppendFileName( const std::string &name );
291       
292     protected:
293       /**
294        * Internally used function that appends a entry in
295        * the capabilities table for a specific capability
296        * entry.
297        */
298 //       data::RecordId appendDependencyEntry( const data::RecordId &, 
299 //                                             zypp::Dep, const Resolvable::Kind & );
300       
301     private:
302       /** Implementation. */
303       class Impl;
304       /** Pointer to implementation. */
305       RW_pointer<Impl> _pimpl;
306     };
307   }
308 }
309
310 #endif
311