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