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