limit commits to media, return uncommited PoolItems
[platform/upstream/libzypp.git] / zypp / target / TargetImpl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/target/TargetImpl.h
10  *
11 */
12 #ifndef ZYPP_TARGET_TARGETIMPL_H
13 #define ZYPP_TARGET_TARGETIMPL_H
14
15 #include <iosfwd>
16
17 #include "zypp/base/ReferenceCounted.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/ResStore.h"
21
22 #include "zypp/Pathname.h"
23 #include "zypp/media/MediaAccess.h"
24 #include "zypp/Target.h"
25 #include "zypp/target/rpm/RpmDb.h"
26 #include "zypp/solver/detail/Types.h"
27
28 ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31   ///////////////////////////////////////////////////////////////////
32   namespace target
33   { /////////////////////////////////////////////////////////////////
34
35     DEFINE_PTR_TYPE(TargetImpl);
36
37     ///////////////////////////////////////////////////////////////////
38     //
39     //  CLASS NAME : TargetImpl
40     //
41     /** Base class for concrete Target implementations.
42      *
43      * Constructed by \ref TargetFactory. Public access via \ref Target
44      * interface.
45     */
46     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
47     {
48       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
49
50     private:
51       /** Sort according to prereqs and media numbers */
52       void getResolvablesToInsDel ( const ResPool pool_r,
53                                     PoolItemList & dellist_r,
54                                     PoolItemList & instlist_r,
55                                     PoolItemList & srclist_r );
56
57
58     public:
59       /** Ctor. */
60       TargetImpl(const Pathname & root_r = "/");
61       /** Dtor. */
62       virtual ~TargetImpl();
63
64       /** Null implementation */
65       static TargetImpl_Ptr nullimpl();
66
67     public:
68
69       /** All resolvables in the target. */
70       const ResStore & resolvables();
71
72       /** Commit changes in the pool
73           media = 0 means any/all medias
74           media > 0 means limit commits to this media */
75       void commit( ResPool pool_r, unsigned int medianr, PoolItemList & errors_r, PoolItemList & remaining_r, PoolItemList & srcremaining_r );
76
77       /** Commit ordered changes */
78       void commit( const PoolItemList & items_r );
79
80       /** Overload to realize stream output. */
81       virtual std::ostream & dumpOn( std::ostream & str ) const
82       { return str << "TargetImpl"; }
83
84       /** The RPM database */
85       rpm::RpmDb & rpm();
86
87       /** If the package is installed and provides the file
88           Needed to evaluate split provides during Resolver::Upgrade() */
89       bool providesFile (const std::string & path_str, const std::string & name_str) const;
90
91       /** Return the resolvable which provides path_str (rpm -qf)
92           return NULL if no resolvable provides this file  */
93       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
94
95     protected:
96       /** All resolvables provided by the target. */
97       ResStore _store;
98       /** Path to the target */
99       Pathname _root;
100       /** RPM database */
101       rpm::RpmDb _rpm;
102     private:
103       /** Null implementation */
104       static TargetImpl_Ptr _nullimpl;
105       
106       /** wrapper with callback around getPlainRpm */
107       Pathname getRpmFile(Package::constPtr package);
108     };
109     ///////////////////////////////////////////////////////////////////
110
111     /** \relates TargetImpl Stream output */
112     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
113     { return obj.dumpOn( str ); }
114
115     /////////////////////////////////////////////////////////////////
116   } // namespace target
117   ///////////////////////////////////////////////////////////////////
118   /////////////////////////////////////////////////////////////////
119 } // namespace zypp
120 ///////////////////////////////////////////////////////////////////
121 #endif // ZYPP_TARGET_TARGETIMPL_H