2dd9d3cf62ba6cfeaa8658b04fd49631a0995e6c
[platform/upstream/libzypp.git] / zypp / Target.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Target.h
10  *
11 */
12 #ifndef ZYPP_TARGET_H
13 #define ZYPP_TARGET_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/base/Deprecated.h"
21
22 #include "zypp/Product.h"
23 #include "zypp/Pathname.h"
24 #include "zypp/ResPool.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29   namespace target
30   {
31     class TargetImpl;
32     namespace rpm {
33       class RpmDb;
34     }
35   }
36   namespace zypp_detail
37   {
38     class ZYppImpl;
39   }
40
41   DEFINE_PTR_TYPE(Target);
42
43   ///////////////////////////////////////////////////////////////////
44   //
45   //    CLASS NAME : Target
46   //
47   /**
48   */
49   class Target : public base::ReferenceCounted, public base::NonCopyable
50   {
51   public:
52     typedef target::TargetImpl  Impl;
53     typedef intrusive_ptr<Impl> Impl_Ptr;
54     typedef std::list<PoolItem> PoolItemList;
55
56   public:
57
58     /**
59      * builds or refreshes the target cache
60      */
61     void buildCache();
62
63     /**
64      * cleans the target cache (.solv files)
65      */
66     void cleanCache();
67
68    /**
69      * load resolvables into the pool
70      */
71     void load();
72
73     /**
74      * unload target resolvables from the
75      * pool
76      */
77     void unload();
78
79     /** \deprecated NOOP
80     */
81     ZYPP_DEPRECATED void reset() {}
82
83     /** Null implementation */
84     static Target_Ptr nullimpl();
85
86     /** Refference to the RPM database */
87     target::rpm::RpmDb & rpmDb();
88
89     /** If the package is installed and provides the file
90      Needed to evaluate split provides during Resolver::Upgrade() */
91     bool providesFile (const std::string & name_str, const std::string & path_str) const;
92
93     /** Return name of package owning \a path_str
94      * or empty string if no installed package owns \a path_str.
95      **/
96     std::string whoOwnsFile (const std::string & path_str) const;
97
98     /** Return the root set for this target */
99     Pathname root() const;
100
101     /** Return the path prefixed by the target root, unless it already is prefixed. */
102     Pathname assertRootPrefix( const Pathname & path_r ) const
103     { return Pathname::assertprefix( root(), path_r ); }
104
105     /** return the last modification date of the target */
106     Date timestamp() const;
107
108     /**
109      * returns the target base installed product, also known as
110      * the distribution or platform.
111      *
112      * returns 0 if there is no base installed product in the
113      * pool.
114      *
115      * \note this method requires the target to be loaded,
116      * otherwise it will return 0 as no product is found.
117      *
118      * if you require some base product attributes when the
119      * target is not loaded into the pool, see
120      * \ref targetDistribution , \ref targetDistributionRelease
121      * and \ref distributionVersion that obtain the data 
122      * on demand from the installed product information.
123      */
124     Product::constPtr baseProduct() const;
125
126     /** \name Base product and registration. */
127     //@{
128     /** The targets distribution release string (/etc/SuSE-release)
129      * \code
130      *   openSUSE 10.3 (i586)
131      * \endcode
132      * \deprecated \ref targetDistribution might be a better choice as it does not depend on /etc/SuSE-release.
133     */
134     std::string release() const ZYPP_DEPRECATED;
135
136     /** This is \c register.target attribute of the installed base product.
137      * Used for registration and \ref Service refresh.
138      */
139     std::string targetDistribution() const;
140
141     /** This is \c register.release attribute of the installed base product.
142      * Used for registration.
143      */
144     std::string targetDistributionRelease() const;
145     //@}
146
147     /** This is \c version attribute of the installed base product.
148      * For example http://download.opensue.org/update/11.0
149      * The 11.0 corresponds to the base product version.
150      */
151     std::string distributionVersion() const;
152     //@}
153     
154
155     /**
156      * This is \flavor attribute of the installed base product
157      * but does not require the target to be loaded as it remembers
158      * the last used one. It can be empty is the target has never
159      * been loaded, as the value is not present in the system
160      * but computer from a package provides
161      */
162     std::string distributionFlavor() const;    
163     
164     /**
165      * anonymous unique id
166      *
167      * This id is generated once and stays in the
168      * saved in the target.
169      * It is unique and is used only for statistics.
170      *
171      */
172     std::string anonymousUniqueId() const;
173
174   public:
175     /** Ctor. If \c doRebuild_r is \c true, an already existing
176      * database is rebuilt (rpm --rebuilddb ).
177     */
178     explicit
179     Target( const Pathname & root = "/", bool doRebuild_r = false );
180     /** Ctor */
181     explicit
182     Target( const Impl_Ptr & impl_r );
183
184   private:
185     friend std::ostream & operator<<( std::ostream & str, const Target & obj );
186     /** Stream output. */
187     std::ostream & dumpOn( std::ostream & str ) const;
188
189   private:
190     /** Direct access to Impl. */
191     friend class zypp_detail::ZYppImpl;
192
193     /** Pointer to implementation */
194     RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
195
196     static Target_Ptr _nullimpl;
197   };
198   ///////////////////////////////////////////////////////////////////
199
200   /** \relates Target Stream output. */
201   inline std::ostream & operator<<( std::ostream & str, const Target & obj )
202   { return obj.dumpOn( str ); }
203
204
205   /////////////////////////////////////////////////////////////////
206 } // namespace zypp
207 ///////////////////////////////////////////////////////////////////
208 #endif // ZYPP_TARGET_H