API for retrieving bugzilla and security references using a nice iterator (thanks
[platform/upstream/libzypp.git] / zypp / Patch.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Patch.h
10  *
11 */
12 #ifndef ZYPP_PATCH_H
13 #define ZYPP_PATCH_H
14
15 #include "zypp/sat/SolvAttr.h"
16 #include "zypp/ResObject.h"
17
18 ///////////////////////////////////////////////////////////////////
19 namespace zypp
20 { /////////////////////////////////////////////////////////////////
21
22
23   DEFINE_PTR_TYPE(Patch);
24
25   
26   /** 
27    * Class representing a patch.
28    * 
29    * A patch represents a specific problem that
30    * can be fixed by pulling in the patch dependencies.
31    *
32    * Patches can be marked for installation but their
33    * installation is a no-op.
34    */
35   class Patch : public ResObject
36   {
37     public:
38       typedef Patch                    Self;
39       typedef ResTraits<Self>          TraitsType;
40       typedef TraitsType::PtrType      Ptr;
41       typedef TraitsType::constPtrType constPtr;
42
43     public:
44       typedef sat::SolvableSet Contents;
45
46     public:
47       /** 
48        * issue date time
49        */
50       Date timestamp() const
51       { return buildtime(); }
52
53       /**
54        * Patch category (recommended, security,...)
55        */
56       std::string category() const;
57
58       /**
59        * Does the system need to reboot to finish the update process?
60        */
61       bool reboot_needed() const;
62
63       /**
64        * Does the patch affect the package manager itself? 
65        */
66       bool affects_pkg_manager() const;
67
68       /**
69        * Is the patch installation interactive? (does it need user input?)
70        */
71       bool interactive() const;
72
73     public:
74       /**
75        * The collection of packages associated with this patch.
76        */
77       Contents contents() const;
78
79     public:
80      
81       /**
82        * Query class for Patch issue references
83        * like bugzilla and security issues the
84        * patch is supposed to fix.
85        *
86        * The iterator does not provide a dereference
87        * operator so you can do * on it, but you can
88        * access the attributes of each patch issue reference
89        * directly from the iterator.
90        *
91        * \code
92        * for ( Patch::ReferenceIterator it = patch->referencesBegin();
93        *       it != patch->referencesEnd();
94        *       ++it )
95        * {
96        *   cout << it.href() << endl;
97        * }
98        * \endcode
99        *
100        */
101       class ReferenceIterator : public boost::iterator_adaptor<
102         Patch::ReferenceIterator            // Derived
103         , sat::LookupAttr::iterator         // Base
104         , int                              // Value
105         , boost::forward_traversal_tag     // CategoryOrTraversal
106         , int
107         >
108       {
109       public:
110           ReferenceIterator();
111           explicit ReferenceIterator( const sat::Solvable & val_r );
112           
113           /**
114            * The id of the reference. For bugzilla entries
115            * this is the bug number as a string.
116            */
117           std::string id() const;
118           /**
119            * Url or ponter where to find more information
120            */
121           std::string href() const;
122           /**
123            * Title describing the issue
124            */
125           std::string title() const;
126           /**
127            * Type of the reference. For example
128            * "bugzilla"
129            */
130           std::string type() const;
131       private:
132         friend class boost::iterator_core_access;
133
134         int dereference() const;
135         void increment();
136       private:
137         sat::LookupAttr::iterator _hrefit;
138         sat::LookupAttr::iterator _titleit;
139         sat::LookupAttr::iterator _typeit;
140       };
141
142       /**
143        * Get an iterator to the beginning of the patch
144        * references. \see Patch::ReferenceIterator
145        */
146       ReferenceIterator referencesBegin() const;
147       /**
148        * Get an iterator to the end of the patch
149        * references. \see Patch::ReferenceIterator
150        */
151       ReferenceIterator referencesEnd() const;
152
153
154     public:
155       /** Patch ID
156        * \deprecated Seems to be unsused autobuild interal data?
157       */
158       ZYPP_DEPRECATED std::string id() const
159       { return std::string(); }
160
161       /** The list of all atoms building the patch
162        * \deprecated  Try contents().
163       */
164       typedef std::list<ResObject::Ptr> AtomList;
165       ZYPP_DEPRECATED AtomList atoms() const
166       { return AtomList(); }
167
168     protected:
169       friend Ptr make<Self>( const sat::Solvable & solvable_r );
170       /** Ctor */
171       Patch( const sat::Solvable & solvable_r );
172       /** Dtor */
173       virtual ~Patch();
174   };
175
176   /////////////////////////////////////////////////////////////////
177
178 } // namespace zypp
179 ///////////////////////////////////////////////////////////////////
180 #endif // ZYPP_PATCH_H