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