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