- move typedefs PoolItemList/PoolItemSet into class
[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 #include <list>
17 #include <set>
18
19 #include "zypp/base/ReferenceCounted.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/PtrTypes.h"
22 #include "zypp/ResStore.h"
23 #include "zypp/PoolItem.h"
24
25 #include "zypp/Pathname.h"
26 #include "zypp/media/MediaAccess.h"
27 #include "zypp/Target.h"
28 #include "zypp/target/rpm/RpmDb.h"
29 #include "zypp/target/store/PersistentStorage.h"
30
31 ///////////////////////////////////////////////////////////////////
32 namespace zypp
33 { /////////////////////////////////////////////////////////////////
34   ///////////////////////////////////////////////////////////////////
35   namespace target
36   { /////////////////////////////////////////////////////////////////
37
38     DEFINE_PTR_TYPE(TargetImpl);
39
40     ///////////////////////////////////////////////////////////////////
41     //
42     //  CLASS NAME : TargetImpl
43     //
44     /** Base class for concrete Target implementations.
45      *
46      * Constructed by \ref TargetFactory. Public access via \ref Target
47      * interface.
48     */
49     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
50     {
51       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
52
53     public:
54       /** list of pool items  */
55       typedef std::list<PoolItem_Ref> PoolItemList;
56
57       /** set of pool items  */
58       typedef std::set<PoolItem_Ref> PoolItemSet;
59
60     public:
61       /** JUST FOR TESTSUITE */
62       /** Sort according to prereqs and media numbers */
63       void getResolvablesToInsDel ( const ResPool pool_r,
64                                     PoolItemList & dellist_r,
65                                     PoolItemList & instlist_r,
66                                     PoolItemList & srclist_r ) const;
67
68
69     public:
70       /** Ctor. */
71       TargetImpl(const Pathname & root_r = "/");
72       /** Dtor. */
73       virtual ~TargetImpl();
74
75       /** Null implementation */
76       static TargetImpl_Ptr nullimpl();
77
78     public:
79
80       /** All resolvables in the target. */
81       const ResStore & resolvables();
82
83       /** Commit changes in the pool
84           media = 0 means any/all medias
85           media > 0 means limit commits to this media */
86       int commit( ResPool pool_r, unsigned int medianr, PoolItemList & errors_r, PoolItemList & remaining_r, PoolItemList & srcremaining_r );
87
88       /** enables the storage target */
89       bool isStorageEnabled() const;
90       void enableStorage(const Pathname &root_r);
91
92       /** Commit ordered changes
93           return uncommitted ones (due to error) */
94       PoolItemList commit( const PoolItemList & items_r );
95
96       /** Overload to realize stream output. */
97       virtual std::ostream & dumpOn( std::ostream & str ) const
98       { return str << "TargetImpl"; }
99
100       /** The RPM database */
101       rpm::RpmDb & rpm();
102
103       /** If the package is installed and provides the file
104           Needed to evaluate split provides during Resolver::Upgrade() */
105       bool providesFile (const std::string & path_str, const std::string & name_str) const;
106
107       /** Return the resolvable which provides path_str (rpm -qf)
108           return NULL if no resolvable provides this file  */
109       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
110
111     protected:
112       /** All resolvables provided by the target. */
113       ResStore _store;
114       /** Path to the target */
115       Pathname _root;
116       /** RPM database */
117       rpm::RpmDb _rpm;
118 #ifndef STORAGE_DISABLED
119       zypp::storage::PersistentStorage _storage;
120 #endif
121     private:
122       /** Null implementation */
123       static TargetImpl_Ptr _nullimpl;
124       
125       /** wrapper with callback around getPlainRpm */
126       Pathname getRpmFile(Package::constPtr package);
127     };
128     ///////////////////////////////////////////////////////////////////
129
130     /** \relates TargetImpl Stream output */
131     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
132     { return obj.dumpOn( str ); }
133
134     /////////////////////////////////////////////////////////////////
135   } // namespace target
136   ///////////////////////////////////////////////////////////////////
137   /////////////////////////////////////////////////////////////////
138 } // namespace zypp
139 ///////////////////////////////////////////////////////////////////
140 #endif // ZYPP_TARGET_TARGETIMPL_H