1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
15 #include "zypp/base/Flags.h"
16 #include "zypp/sat/SolvAttr.h"
17 #include "zypp/ResObject.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
24 DEFINE_PTR_TYPE(Patch);
28 * Class representing a patch.
30 * A patch represents a specific problem that
31 * can be fixed by pulling in the patch dependencies.
33 * Patches can be marked for installation but their
34 * installation is a no-op.
36 class Patch : public ResObject
40 typedef ResTraits<Self> TraitsType;
41 typedef TraitsType::PtrType Ptr;
42 typedef TraitsType::constPtrType constPtr;
45 typedef sat::SolvableSet Contents;
57 * Flags defining if and why this
58 * patch is interactive.
60 enum InteractiveFlag {
66 ZYPP_DECLARE_FLAGS(InteractiveFlags, InteractiveFlag);
69 * \brief Possible severity levels for (security) patches.
70 * Metadata string values are mapped to this enum to ease
71 * computations. For a string representation call
72 * \ref asSring( const Patch::SeverityFlag & ).
75 SEV_NONE = 0, //!< no value specified
76 SEV_OTHER = 1, //!< unknown value specified
77 SEV_LOW = 1<<1, //!< Low
78 SEV_MODERATE = 1<<2, //!< Moderate
79 SEV_IMPORTANT = 1<<3, //!< Important
80 SEV_CRITICAL = 1<<4 //!< Critical
82 ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
86 * Issue date time. For now it is the same as
89 Date timestamp() const
90 { return buildtime(); }
93 * Patch category (recommended, security,...)
95 std::string category() const;
97 /** Patch category as enum of wellknown categories.
98 * Unknown values are mapped to \ref CAT_OTHER.
100 Category categoryEnum() const;
103 * Severity string as specified in metadata.
104 * For use in computaions see \ref severityFlag.
106 std::string severity() const;
109 * Severity string mapped to an enum.
110 * Unknown string values are mapped to \ref SEV_OTHER
112 SeverityFlag severityFlag() const;
115 * Does the system need to reboot to finish the update process?
117 bool rebootSuggested() const;
120 * Does the patch affect the package manager itself?
121 * restart is suggested then
123 bool restartSuggested() const;
126 * Does the patch needs the user to relogin to take effect?
127 * relogin is suggested then
129 bool reloginSuggested() const;
132 * \short Information or warning to be displayed to the user
134 std::string message( const Locale & lang_r = Locale() ) const;
137 * Get the InteractiveFlags of this Patch
139 InteractiveFlags interactiveFlags() const;
142 * Is the patch still interactive when ignoring this flags?
144 bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
147 * Is the patch installation interactive? (does it need user input?)
149 * For security reasons patches requiring a reboot are not
150 * installed in an unattended mode. They are considered to be
151 * \c interactive so the user gets informed about the need for
152 * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
153 * off this behavior and include those patches (unless they actually
154 * contain interactive components as well, like messages or licenses).
156 bool interactive() const;
160 * The collection of packages associated with this patch.
162 Contents contents() const;
166 /** Query class for Patch issue references */
167 class ReferenceIterator;
169 * Get an iterator to the beginning of the patch
170 * references. \see Patch::ReferenceIterator
172 ReferenceIterator referencesBegin() const;
174 * Get an iterator to the end of the patch
175 * references. \see Patch::ReferenceIterator
177 ReferenceIterator referencesEnd() const;
180 friend Ptr make<Self>( const sat::Solvable & solvable_r );
182 Patch( const sat::Solvable & solvable_r );
186 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
187 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
189 /** \relates Patch::SeverityFlag string representation.*/
190 std::string asString( const Patch::SeverityFlag & obj );
193 * Query class for Patch issue references
194 * like bugzilla and security issues the
195 * patch is supposed to fix.
197 * The iterator does not provide a dereference
198 * operator so you can do * on it, but you can
199 * access the attributes of each patch issue reference
200 * directly from the iterator.
203 * for ( Patch::ReferenceIterator it = patch->referencesBegin();
204 * it != patch->referencesEnd();
207 * cout << it.href() << endl;
212 class Patch::ReferenceIterator : public boost::iterator_adaptor<
213 Patch::ReferenceIterator // Derived
214 , sat::LookupAttr::iterator // Base
216 , boost::forward_traversal_tag // CategoryOrTraversal
221 ReferenceIterator() {}
222 explicit ReferenceIterator( const sat::Solvable & val_r );
225 * The id of the reference. For bugzilla entries
226 * this is the bug number as a string.
228 std::string id() const;
230 * Url or pointer where to find more information
232 std::string href() const;
234 * Title describing the issue
236 std::string title() const;
238 * Type of the reference. For example
241 std::string type() const;
244 friend class boost::iterator_core_access;
245 int dereference() const { return 0; }
248 inline Patch::ReferenceIterator Patch::referencesBegin() const
249 { return ReferenceIterator(satSolvable()); }
251 inline Patch::ReferenceIterator Patch::referencesEnd() const
252 { return ReferenceIterator(); }
254 /////////////////////////////////////////////////////////////////
257 ///////////////////////////////////////////////////////////////////
258 #endif // ZYPP_PATCH_H