Imported Upstream version 16.4.0
[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/APIConfig.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     void reload();
74     
75     /**
76      * unload target resolvables from the
77      * pool
78      */
79     void unload();
80
81     /** Refference to the RPM database */
82     target::rpm::RpmDb & rpmDb();
83
84     /** If the package is installed and provides the file
85      Needed to evaluate split provides during Resolver::Upgrade() */
86     bool providesFile (const std::string & name_str, const std::string & path_str) const;
87
88     /** Return name of package owning \a path_str
89      * or empty string if no installed package owns \a path_str.
90      **/
91     std::string whoOwnsFile (const std::string & path_str) const;
92
93     /** Return the root set for this target */
94     Pathname root() const;
95
96     /** Return the path prefixed by the target root, unless it already is prefixed. */
97     Pathname assertRootPrefix( const Pathname & path_r ) const
98     { return Pathname::assertprefix( root(), path_r ); }
99
100     /** return the last modification date of the target */
101     Date timestamp() const;
102
103     /**
104      * returns the target base installed product, also known as
105      * the distribution or platform.
106      *
107      * returns 0 if there is no base installed product in the
108      * pool.
109      *
110      * \note this method requires the target to be loaded,
111      * otherwise it will return 0 as no product is found.
112      *
113      * if you require some base product attributes when the
114      * target is not loaded into the pool, see
115      * \ref targetDistribution , \ref targetDistributionRelease
116      * and \ref distributionVersion that obtain the data
117      * on demand from the installed product information.
118      */
119     Product::constPtr baseProduct() const;
120
121     /**
122      * \brief Languages to be supported by the system.
123      * E.g. language specific packages to be installed.
124      */
125     LocaleSet requestedLocales() const;
126     /** \overload Use a specific root_r, if empty the default targets root, or '/'
127      */
128     static LocaleSet requestedLocales( const Pathname & root_r );
129
130     /** Update the database of autoinstalled packages.
131      * This is done on commit, so you usually don't need to call this explicitly.
132      */
133     void updateAutoInstalled();
134
135   public:
136     /** \name Base product and registration.
137      *
138      * Static methods herein allow to retrieve the values without explicitly
139      * initializing the \ref Target. They take a targets root directory as
140      * argument. If an empty \ref Pathname is passed, an already existing
141      * Targets root is used, otherwise \c "/" is assumed.
142      */
143     //@{
144     /** This is \c register.target attribute of the installed base product.
145      * Used for registration and \ref Service refresh.
146      */
147     std::string targetDistribution() const;
148     /** \overload */
149     static std::string targetDistribution( const Pathname & root_r );
150
151     /** This is \c register.release attribute of the installed base product.
152      * Used for registration.
153      */
154     std::string targetDistributionRelease() const;
155     /** \overload */
156     static std::string targetDistributionRelease( const Pathname & root_r );
157
158     /** This is \c register.flavor attribute of the installed base product.
159      * Used for registration.
160      * \note don't mistake this for \ref distributionFlavor
161      */
162     std::string targetDistributionFlavor() const;
163     /** \overload */
164     static std::string targetDistributionFlavor( const Pathname & root_r );
165
166     struct DistributionLabel { std::string shortName; std::string summary; };
167     /** This is \c shortName and \c summary attribute of the installed base product.
168      * Used e.g. for the bootloader menu.
169      */
170     DistributionLabel distributionLabel() const;
171     /** \overload */
172     static DistributionLabel distributionLabel( const Pathname & root_r );
173
174     /** This is \c version attribute of the installed base product.
175      * For example http://download.opensue.org/update/11.0
176      * The 11.0 corresponds to the base product version.
177      */
178     std::string distributionVersion() const;
179     /** \overload */
180     static std::string distributionVersion( const Pathname & root_r );
181
182     /**
183      * This is \c flavor attribute of the installed base product
184      * but does not require the target to be loaded as it remembers
185      * the last used one. It can be empty is the target has never
186      * been loaded, as the value is not present in the system
187      * but computer from a package provides
188      * \note don't mistake this for \ref targetDistributionFlavor
189      */
190     std::string distributionFlavor() const;
191     /** \overload */
192     static std::string distributionFlavor( const Pathname & root_r );
193
194     /**
195      * anonymous unique id
196      *
197      * This id is generated once and stays in the
198      * saved in the target.
199      * It is unique and is used only for statistics.
200      *
201      */
202     std::string anonymousUniqueId() const;
203     /** \overload */
204     static std::string anonymousUniqueId( const Pathname & root_r );
205     //@}
206
207   public:
208     /** Ctor. If \c doRebuild_r is \c true, an already existing
209      * database is rebuilt (rpm --rebuilddb ).
210     */
211     explicit
212     Target( const Pathname & root = "/", bool doRebuild_r = false );
213     /** Ctor */
214     explicit
215     Target( const Impl_Ptr & impl_r );
216
217   private:
218     friend std::ostream & operator<<( std::ostream & str, const Target & obj );
219     /** Stream output. */
220     std::ostream & dumpOn( std::ostream & str ) const;
221
222   private:
223     /** Direct access to Impl. */
224     friend class zypp_detail::ZYppImpl;
225
226     /** Pointer to implementation */
227     RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
228   };
229   ///////////////////////////////////////////////////////////////////
230
231   /** \relates Target Stream output. */
232   inline std::ostream & operator<<( std::ostream & str, const Target & obj )
233   { return obj.dumpOn( str ); }
234
235   /** \relates Target::DistributionLabel Stream output.
236    * Write out the content as key/value pairs:
237    * \code
238    * summary=Beautiful Name
239    * shortName=BN
240    * \endcode
241    */
242   std::ostream & operator<<( std::ostream & str, const Target::DistributionLabel & obj );
243
244   /////////////////////////////////////////////////////////////////
245 } // namespace zypp
246 ///////////////////////////////////////////////////////////////////
247 #endif // ZYPP_TARGET_H