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