2cf6220bb22849949209e8f240ac56df1d23bc3a
[platform/upstream/libzypp.git] / zypp / target / CommitPackageCache.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/target/CommitPackageCache.h
10  *
11 */
12 #ifndef ZYPP_TARGET_COMMITPACKAGECACHE_H
13 #define ZYPP_TARGET_COMMITPACKAGECACHE_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/PtrTypes.h"
18 #include "zypp/base/Function.h"
19
20 #include "zypp/PoolItem.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/ManagedFile.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   ///////////////////////////////////////////////////////////////////
28   namespace target
29   { /////////////////////////////////////////////////////////////////
30
31     ///////////////////////////////////////////////////////////////////
32     /// \class RepoProvidePackage
33     /// \short Default PackageProvider for \ref CommitPackageCache
34     ///
35     /// \p pool_r \ref ResPool used to get candidates
36     /// \p pi item to be commited
37     ///////////////////////////////////////////////////////////////////
38     class RepoProvidePackage
39     {
40     public:
41       RepoProvidePackage();
42       ~RepoProvidePackage();
43
44       /** Provide package optionally fron cache only. */
45       ManagedFile operator()( const PoolItem & pi, bool fromCache_r );
46
47     private:
48       struct Impl;
49       RW_pointer<Impl> _impl;
50     };
51
52     ///////////////////////////////////////////////////////////////////
53     //
54     //  CLASS NAME : CommitPackageCache
55     //
56     /** Target::commit helper optimizing package provision.
57     */
58     class CommitPackageCache
59     {
60       friend std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj );
61
62     public:
63       typedef function<ManagedFile( const PoolItem & pi, bool fromCache_r )> PackageProvider;
64
65     public:
66       /** Ctor */
67       CommitPackageCache( const Pathname &        rootDir_r,
68                           const PackageProvider & packageProvider_r = RepoProvidePackage() );
69
70       /** Dtor */
71       ~CommitPackageCache();
72
73     public:
74       /** Download(commit) sequence of solvables to compute read ahead. */
75       void setCommitList( std::vector<sat::Solvable> commitList_r );
76       /** \overload */
77       template <class _Iterator>
78       void setCommitList( _Iterator begin_r, _Iterator end_r )
79       { setCommitList( std::vector<sat::Solvable>( begin_r, end_r  ) ); }
80
81       /** Provide a package. */
82       ManagedFile get( const PoolItem & citem_r );
83       /** \overload */
84       ManagedFile get( sat::Solvable citem_r )
85       { return get( PoolItem(citem_r) ); }
86
87       /** Whether preloaded hint is set.
88        * If preloaded the cache tries to avoid trigering the infoInCache CB,
89        * based on the assumption this was already done when preloading the cache.
90        */
91       bool preloaded() const;
92       /** Set preloaded hint. */
93       void preloaded( bool newval_r );
94
95     public:
96       /** Implementation. */
97       class Impl;
98       /** Ctor taking an implementation. */
99       explicit CommitPackageCache( Impl * pimpl_r );
100     private:
101       /** Pointer to implementation. */
102       RW_pointer<Impl> _pimpl;
103     };
104     ///////////////////////////////////////////////////////////////////
105
106     /** \relates CommitPackageCache Stream output */
107     std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj );
108
109     /////////////////////////////////////////////////////////////////
110   } // namespace target
111   ///////////////////////////////////////////////////////////////////
112   /////////////////////////////////////////////////////////////////
113 } // namespace zypp
114 ///////////////////////////////////////////////////////////////////
115 #endif // ZYPP_TARGET_COMMITPACKAGECACHE_H