Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Product.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Product.h
10  *
11 */
12 #ifndef ZYPP_PRODUCT_H
13 #define ZYPP_PRODUCT_H
14
15 #include <list>
16 #include <string>
17
18 #include "zypp/ResObject.h"
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   DEFINE_PTR_TYPE(Product);
25
26   ///////////////////////////////////////////////////////////////////
27   //
28   //    CLASS NAME : Product
29   //
30   /** Product interface.
31   */
32   class Product : public ResObject
33   {
34   public:
35     typedef Product                  Self;
36     typedef ResTraits<Self>          TraitsType;
37     typedef TraitsType::PtrType      Ptr;
38     typedef TraitsType::constPtrType constPtr;
39
40   public:
41     /** The reference package providing the product metadata,
42      *  if such a package exists.
43      */
44     sat::Solvable referencePackage() const;
45
46     /** For installed products the name of the corresponding
47      * \c /etc/products.d entry.
48     .*/
49     std::string referenceFilename() const;
50
51     /** List of packages included in older versions of this product and now dropped.
52      *
53      * This evaluates the \ref referencePackage \c weakremover namespace. It actually
54      * returns a \ref CapabilitySet, because we support to drop specific versions or
55      * version ranges of a package. Use \ref sat::WhatProvides to get the actually
56      * installed and available packages matching this list.
57      * \code
58      *   const Product & openSUSE;
59      *   sat::WhatProvides dropped( openSUSE.droplist() );
60      *   for_( it, dropped.poolItemBegin(), dropped.poolItemEnd() )
61      *   {
62      *     if ( it->status().isInstalled() )
63      *     {
64      *       MIL << "Installed but no longer supported package: " << *it << endl;
65      *     }
66      *   }
67      * \endcode
68      */
69     CapabilitySet droplist() const;
70
71   public:
72     /***/
73     typedef std::vector<constPtr> ReplacedProducts;
74
75     /** Array of \b installed Products that would be replaced by
76      *  installing this one.
77      */
78     ReplacedProducts replacedProducts() const;
79
80     /** Vendor specific string denoting the product line. */
81     std::string productLine() const;
82
83   public:
84     /** Untranslated short name like <tt>SLES 10</tt> (fallback: name) */
85     std::string shortName() const;
86
87     /** The product flavor (LiveCD Demo, FTP edition,...). */
88     std::string flavor() const;
89
90     /** Get the product type
91      * Well, in an ideal world there is only one base product.
92      * It's the installed product denoted by a symlink in
93      * \c /etc/products.d.
94      */
95     std::string type() const;
96
97     /** The product flags */
98     std::list<std::string> flags() const;
99
100     /** The date when this Product goes out of support as indicated by it's medadata.
101      * Use \ref hasEOfLife if it's important to distinguish whether the value
102      * is not defined in the metadata, or defined but empty/invalid/TBD.
103      */
104     Date endOfLife() const;
105
106     /** Return whether an EndOfLife value is actually defined in the metadata.
107      * A missing value (\c false) usually indicates that there will be no EOL,
108      * while an empty/invalid value indicates that there will be an  EOL date,
109      * but it's not yet known (FATE#320699).
110      */
111     bool hasEndOfLife() const;
112     /** \overload additionally returning the date (0 if TBD)
113      *  false, ( unchanged )    : no EOL
114      *  true,  ( 0 )            : EOL is still TBD
115      *  true,  ( !=0 )          : a valid EOL date
116      */
117     bool hasEndOfLife( Date & value ) const;
118
119     /** ContentIdentifier of required update repositories. */
120     std::vector<Repository::ContentIdentifier> updateContentIdentifier() const;
121
122     /** Whether \a cident_r is listed as required update repository. */
123     bool hasUpdateContentIdentifier( const Repository::ContentIdentifier & cident_r ) const;
124
125     /** Whether one of the ContentIdentifier is listed as required update repository. */
126     template <class TIterator>
127     bool hasUpdateContentIdentifier( TIterator begin, TIterator end ) const
128     {
129       for_( it, begin, end )
130         if ( hasUpdateContentIdentifier( *it ) )
131           return true;
132       return false;
133     }
134
135   public:
136     /** This is the \b installed product that is also targeted by the
137      *  \c /etc/products.d/baseproduct symlink.
138     */
139     bool isTargetDistribution() const;
140
141     /** This is \c register.target attribute of a product.
142       * Used for registration and filtering service repos.
143       */
144     std::string registerTarget() const;
145
146     /** This is \c register.release attribute of an \b installed product.
147       * Used for registration.
148       */
149     std::string registerRelease() const;
150
151     /** This is \c register.flavor attribute of a product.
152       * Used for registration.
153       */
154     std::string registerFlavor() const;
155
156   public:
157     /***/
158     class UrlList;
159
160     /** Retrieve URLs flagged with \c key_r for this product.
161      *
162      * This is the most common interface. There are convenience methods for
163      * wellknown flags like \c "releasenotes", \c "register", \c "updateurls",
164      * \c "extraurls", \c "optionalurls" and \c "smolt" below.
165      */
166     UrlList urls( const std::string & key_r ) const;
167
168     /** The URL to download the release notes for this product. */
169     UrlList releaseNotesUrls() const;
170
171     /** The URL for registration. */
172     UrlList registerUrls() const;
173
174     /** The URL for SMOLT \see http://smolts.org/wiki/Main_Page. */
175     UrlList smoltUrls() const;
176
177     /**
178      * Online updates for the product.
179      * They are complementary, not alternatives. #163192
180      */
181     UrlList updateUrls() const;
182
183     /**
184      * Additional software for the product
185      * They are complementary, not alternatives.
186      */
187     UrlList extraUrls() const;
188
189     /**
190      * Optional software for the product.
191      * (for example. Non OSS repositories)
192      * They are complementary, not alternatives.
193      */
194     UrlList optionalUrls() const;
195
196   protected:
197     friend Ptr make<Self>( const sat::Solvable & solvable_r );
198     /** Ctor */
199     Product( const sat::Solvable & solvable_r );
200     /** Dtor */
201     virtual ~Product();
202   };
203
204   /** Helper to iterate a products URL lists.
205    * \ref first is a convenience for 'lists' with just
206    * one entry (e.g. releaseNotesUrls)
207    */
208   class Product::UrlList
209   {
210     private:
211       /** \todo Change to directly iterate the .solv */
212       typedef std::list<Url> ListType;
213
214     public:
215       typedef ListType::value_type     value_type;
216       typedef ListType::size_type      size_type;
217       typedef ListType::const_iterator const_iterator;
218
219       bool empty() const
220       { return _list.empty(); }
221
222       size_type size() const
223       { return _list.size(); }
224
225       const_iterator begin() const
226       { return _list.begin(); }
227
228       const_iterator end() const
229       { return _list.end(); }
230
231       /** The first Url or an empty Url. */
232       Url first() const
233       { return empty() ? value_type() : _list.front(); }
234
235     public:
236       /** The key used to retrieve this list (for debug) */
237       std::string key() const
238       { return _key; }
239
240     private:
241       friend class Product;
242       /** Change to directly iterate the .solv */
243       std::string _key;
244       ListType    _list;
245   };
246
247   /** \relates Product::UrlList Stream output. */
248   std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj );
249
250   /////////////////////////////////////////////////////////////////
251 } // namespace zypp
252 ///////////////////////////////////////////////////////////////////
253 #endif // ZYPP_PRODUCT_H