7c9bb3f17e3d20c9b898ed1e062b1b8abb631688
[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 coddesponding
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     Date endOfLife() const;
102
103     /** ContentIdentifier of required update repositories. */
104     std::vector<Repository::ContentIdentifier> updateContentIdentifier() const;
105
106     /** Whether \a cident_r is listed as required update repository. */
107     bool hasUpdateContentIdentifier( const Repository::ContentIdentifier & cident_r ) const;
108
109     /** Whether one of the ContentIdentifier is listed as required update repository. */
110     template <class _Iterator>
111     bool hasUpdateContentIdentifier( _Iterator begin, _Iterator end ) const
112     {
113       for_( it, begin, end )
114         if ( hasUpdateContentIdentifier( *it ) )
115           return true;
116       return false;
117     }
118
119   public:
120     /** This is the \b installed product that is also targeted by the
121      *  \c /etc/products.d/baseproduct symlink.
122     */
123     bool isTargetDistribution() const;
124
125     /** This is \c register.target attribute of a product.
126       * Used for registration and filtering service repos.
127       */
128     std::string registerTarget() const;
129
130     /** This is \c register.release attribute of an \b installed product.
131       * Used for registration.
132       */
133     std::string registerRelease() const;
134
135     /** This is \c register.flavor attribute of a product.
136       * Used for registration.
137       */
138     std::string registerFlavor() const;
139
140   public:
141     /***/
142     class UrlList;
143
144     /** Rerieve urls flagged with \c key_r for this product.
145      *
146      * This is the most common interface. There are convenience methods for
147      * wellknown flags like \c "releasenotes", \c "register", \c "updateurls",
148      * \c "extraurls", \c "optionalurls" and \c "smolt" below.
149      */
150     UrlList urls( const std::string & key_r ) const;
151
152     /** The URL to download the release notes for this product. */
153     UrlList releaseNotesUrls() const;
154
155     /** The URL for registration. */
156     UrlList registerUrls() const;
157
158     /** The URL for SMOLT \see http://smolts.org/wiki/Main_Page. */
159     UrlList smoltUrls() const;
160
161     /**
162      * Online updates for the product.
163      * They are complementary, not alternatives. #163192
164      */
165     UrlList updateUrls() const;
166
167     /**
168      * Additional software for the product
169      * They are complementary, not alternatives.
170      */
171     UrlList extraUrls() const;
172
173     /**
174      * Optional software for the product.
175      * (for example. Non OSS repositories)
176      * They are complementary, not alternatives.
177      */
178     UrlList optionalUrls() const;
179
180   protected:
181     friend Ptr make<Self>( const sat::Solvable & solvable_r );
182     /** Ctor */
183     Product( const sat::Solvable & solvable_r );
184     /** Dtor */
185     virtual ~Product();
186   };
187
188   /** Helper to iterate a products URL lists.
189    * \ref first is a convenience for 'lists' with just
190    * one entry (e.g. releaseNotesUrls)
191    */
192   class Product::UrlList
193   {
194     private:
195       /** \todo Change to directly iterate the .solv */
196       typedef std::list<Url> ListType;
197
198     public:
199       typedef ListType::value_type     value_type;
200       typedef ListType::size_type      size_type;
201       typedef ListType::const_iterator const_iterator;
202
203       bool empty() const
204       { return _list.empty(); }
205
206       size_type size() const
207       { return _list.size(); }
208
209       const_iterator begin() const
210       { return _list.begin(); }
211
212       const_iterator end() const
213       { return _list.end(); }
214
215       /** The first Url or an empty Url. */
216       Url first() const
217       { return empty() ? value_type() : _list.front(); }
218
219     public:
220       /** The key used to retrieve this list (for debug) */
221       std::string key() const
222       { return _key; }
223
224     private:
225       friend class Product;
226       /** Change to directly iterate the .solv */
227       std::string _key;
228       ListType    _list;
229   };
230
231   /** \relates Product::UrlList Stream output. */
232   std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj );
233
234   /////////////////////////////////////////////////////////////////
235 } // namespace zypp
236 ///////////////////////////////////////////////////////////////////
237 #endif // ZYPP_PRODUCT_H