merge REFACTORING-10_3 back to trunk
[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/DefaultFalseBool.h"
22 #include "zypp/base/PtrTypes.h"
23 #include "zypp/ResStore.h"
24 #include "zypp/PoolItem.h"
25 #include "zypp/ZYppCommit.h"
26
27 #include "zypp/Pathname.h"
28 #include "zypp/media/MediaAccess.h"
29 #include "zypp/Target.h"
30 #include "zypp/target/rpm/RpmDb.h"
31 #include "zypp/target/store/PersistentStorage.h"
32 #include "zypp/target/TargetException.h"
33
34 ///////////////////////////////////////////////////////////////////
35 namespace zypp
36 { /////////////////////////////////////////////////////////////////
37   ///////////////////////////////////////////////////////////////////
38   namespace target
39   { /////////////////////////////////////////////////////////////////
40
41     DEFINE_PTR_TYPE(TargetImpl);
42
43     ///////////////////////////////////////////////////////////////////
44     //
45     //  CLASS NAME : TargetImpl
46     //
47     /** Base class for concrete Target implementations.
48      *
49      * Constructed by \ref TargetFactory. Public access via \ref Target
50      * interface.
51     */
52     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
53     {
54       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
55
56     public:
57       /** list of pool items  */
58       typedef std::list<PoolItem_Ref> PoolItemList;
59
60       /** set of pool items  */
61       typedef std::set<PoolItem_Ref> PoolItemSet;
62
63     public:
64       /** Ctor. */
65       TargetImpl(const Pathname & root_r = "/");
66       /** Dtor. */
67       virtual ~TargetImpl();
68
69       /** Null implementation */
70       static TargetImpl_Ptr nullimpl();
71
72     public:
73
74       /** All resolvables in the target. */
75       const ResStore & resolvables();
76
77       /**
78        * load resolvables of certain kind in the internal store
79        * and return a iterator
80        * successive calls will be faster as resolvables are cached-
81        */
82       ResStore::resfilter_const_iterator byKindBegin( const ResObject::Kind & kind_r  ) const;
83       ResStore::resfilter_const_iterator byKindEnd( const ResObject::Kind & kind_r ) const;
84
85       /** The root set for this target */
86       Pathname root() const;
87
88       /** Commit changes in the pool */
89       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
90
91       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
92                                   PoolItemList & errors_r,
93                                   PoolItemList & remaining_r,
94                                   PoolItemList & srcremaining_r,
95                                   bool dry_run = false )
96       {
97         ZYppCommitPolicy policy;
98         policy.restrictToMedia( medianr ).dryRun( dry_run );
99         ZYppCommitResult res = commit( pool_r, policy );
100         errors_r.swap( res._errors );
101         remaining_r.swap( res._remaining );
102         srcremaining_r.swap( res._srcremaining );
103         return res._result;
104       }
105
106       /** enables the storage target */
107       bool isStorageEnabled() const;
108       void enableStorage(const Pathname &root_r);
109
110       /** Commit ordered changes
111        *  @param pool_r only needed for #160792
112        *  @return uncommitted ones (due to error)
113        */
114       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
115
116       /** Overload to realize stream output. */
117       virtual std::ostream & dumpOn( std::ostream & str ) const
118       {
119         return str << "TargetImpl";
120       }
121
122       /** The RPM database */
123       rpm::RpmDb & rpm();
124
125       /** If the package is installed and provides the file
126       Needed to evaluate split provides during Resolver::Upgrade() */
127       bool providesFile (const std::string & path_str, const std::string & name_str) const;
128
129       /** Return the resolvable which provides path_str (rpm -qf)
130       return NULL if no resolvable provides this file  */
131       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
132
133       /** Set the log file for target */
134       bool setInstallationLogfile(const Pathname & path_r);
135
136       /** return the last modification date of the target */
137       Date timestamp() const;
138       
139      /** 
140       * reload the target in future calls if
141       * needed.
142       * note the loading can actually be delayed, but
143       * the next call to resolvables must reflect the 
144       * status of the system.
145      */
146      void reset();
147
148     protected:
149       void loadKindResolvables( const Resolvable::Kind kind );
150       /** All resolvables provided by the target. */
151       ResStore _store;
152       /** Path to the target */
153       Pathname _root;
154       /** RPM database */
155       rpm::RpmDb _rpm;
156 #ifndef STORAGE_DISABLED
157       zypp::storage::PersistentStorage _storage;
158       bool _storage_enabled;
159       std::map< const Resolvable::Kind, DefaultFalseBool> _resstore_loaded;
160 #endif
161     private:
162       /** Null implementation */
163       static TargetImpl_Ptr _nullimpl;
164     };
165     ///////////////////////////////////////////////////////////////////
166
167     /** \relates TargetImpl Stream output */
168     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
169     {
170       return obj.dumpOn( str );
171     }
172
173     /////////////////////////////////////////////////////////////////
174   } // namespace target
175   ///////////////////////////////////////////////////////////////////
176   /////////////////////////////////////////////////////////////////
177 } // namespace zypp
178 ///////////////////////////////////////////////////////////////////
179 #endif // ZYPP_TARGET_TARGETIMPL_H