complete commit()
[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           return uncommitted ones (due to error) */
79       PoolItemList commit( const PoolItemList & items_r );
80
81       /** Overload to realize stream output. */
82       virtual std::ostream & dumpOn( std::ostream & str ) const
83       { return str << "TargetImpl"; }
84
85       /** The RPM database */
86       rpm::RpmDb & rpm();
87
88       /** If the package is installed and provides the file
89           Needed to evaluate split provides during Resolver::Upgrade() */
90       bool providesFile (const std::string & path_str, const std::string & name_str) const;
91
92       /** Return the resolvable which provides path_str (rpm -qf)
93           return NULL if no resolvable provides this file  */
94       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
95
96     protected:
97       /** All resolvables provided by the target. */
98       ResStore _store;
99       /** Path to the target */
100       Pathname _root;
101       /** RPM database */
102       rpm::RpmDb _rpm;
103     private:
104       /** Null implementation */
105       static TargetImpl_Ptr _nullimpl;
106       
107       /** wrapper with callback around getPlainRpm */
108       Pathname getRpmFile(Package::constPtr package);
109     };
110     ///////////////////////////////////////////////////////////////////
111
112     /** \relates TargetImpl Stream output */
113     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
114     { return obj.dumpOn( str ); }
115
116     /////////////////////////////////////////////////////////////////
117   } // namespace target
118   ///////////////////////////////////////////////////////////////////
119   /////////////////////////////////////////////////////////////////
120 } // namespace zypp
121 ///////////////////////////////////////////////////////////////////
122 #endif // ZYPP_TARGET_TARGETIMPL_H