Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Patch.h
index cd1bc05..b3d240b 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef ZYPP_PATCH_H
 #define ZYPP_PATCH_H
 
+#include "zypp/base/Flags.h"
 #include "zypp/sat/SolvAttr.h"
 #include "zypp/ResObject.h"
 
@@ -44,13 +45,42 @@ namespace zypp
       typedef sat::SolvableSet Contents;
 
       enum Category {
-        CAT_OTHER,
-        CAT_YAST,
-        CAT_SECURITY,
-        CAT_RECOMMENDED,
-        CAT_OPTIONAL,
-        CAT_DOCUMENT
+        CAT_OTHER      = 1,    //!< unknown value specified
+        CAT_YAST       = 1<<1, //!<
+        CAT_SECURITY   = 1<<2, //!<
+        CAT_RECOMMENDED        = 1<<3, //!<
+        CAT_OPTIONAL   = 1<<4, //!<
+        CAT_DOCUMENT   = 1<<5  //!<
       };
+      ZYPP_DECLARE_FLAGS(Categories, Category);
+
+      /**
+       * Flags defining if and why this
+       * patch is interactive.
+       */
+      enum InteractiveFlag {
+        NoFlags = 0x0000,
+        Reboot  = 0x0001,
+        Message = 0x0002,
+        License = 0x0004
+      };
+      ZYPP_DECLARE_FLAGS(InteractiveFlags, InteractiveFlag);
+
+      /**
+       * \brief Possible severity levels for (security) patches.
+       * Metadata string values are mapped to this enum to ease
+       * computations. For a string representation call
+       * \ref asSring( const Patch::SeverityFlag & ).
+       */
+      enum SeverityFlag {
+       SEV_OTHER       = 1,    //!< unknown value specified
+       SEV_NONE        = 1<<1, //!< no value specified
+       SEV_LOW         = 1<<2, //!< Low
+       SEV_MODERATE    = 1<<3, //!< Moderate
+       SEV_IMPORTANT   = 1<<4, //!< Important
+       SEV_CRITICAL    = 1<<5  //!< Critical
+      };
+      ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
 
     public:
       /**
@@ -60,16 +90,76 @@ namespace zypp
       Date timestamp() const
       { return buildtime(); }
 
+      /** \name Patch Category */
+      //@{
       /**
        * Patch category (recommended, security,...)
        */
       std::string category() const;
 
-      /** Patch category as enum of wellknown categories.
+      /** This patch's category as enum of wellknown categories.
        * Unknown values are mapped to \ref CAT_OTHER.
        */
       Category categoryEnum() const;
 
+      /** Whether this patch's category matches \a category_r */
+      bool isCategory( const std::string & category_r ) const;
+      /** \overload taking OR'ed \ref Categories */
+      bool isCategory( Categories category_r ) const;
+#ifndef SWIG // Swig treats it as syntax error
+      /** \overload taking container of category strings
+       * 2nd template arg just to prevent instantiation for Category
+       */
+      template <class TContainer, typename = typename TContainer::value_type>
+      bool isCategory( const TContainer & categories_r ) const
+      {
+       for ( const std::string & el : categories_r )
+       { if ( isCategory( el ) ) return true; }
+       return false;
+      }
+#endif
+      /** Patch category as enum of wellknown categories.
+       * Unknown values are mapped to \ref CAT_OTHER.
+       */
+      static Category categoryEnum( const std::string & category_r );
+      //@}
+
+      /** \name Patch Severity */
+      //@{
+      /**
+       * Severity string as specified in metadata.
+       * For use in computaions see \ref severityFlag.
+       */
+      std::string severity() const;
+
+      /**
+       * Severity string mapped to an enum.
+       * Unknown string values are mapped to \ref SEV_OTHER
+       */
+      SeverityFlag severityFlag() const;
+
+      /** Whether this patch's severity matches \a severity_r */
+      bool isSeverity( const std::string & severity_r ) const;
+      /** \overload taking OR'ed \ref SeverityFlags */
+      bool isSeverity( SeverityFlags severity_r ) const;
+#ifndef SWIG // Swig treats it as syntax error
+      /** \overload taking container of severity strings
+       * 2nd template arg just to prevent instantiation for SeverityFlag
+       */
+      template <class TContainer, typename = typename TContainer::value_type>
+      bool isSeverity( const TContainer & severities_r ) const
+      {
+       for ( const std::string & el : severities_r )
+       { if ( isSeverity( el ) ) return true; }
+       return false;
+      }
+#endif
+      /** Severity string mapped to an enum.
+       * Unknown string values are mapped to \ref SEV_OTHER
+       */
+      static SeverityFlag severityFlag( const std::string & category_r );
+      //@}
+
       /**
        * Does the system need to reboot to finish the update process?
        */
@@ -93,19 +183,24 @@ namespace zypp
       std::string message( const Locale & lang_r = Locale() ) const;
 
       /**
-       * Use \ref rebootSuggested()
+       * Get the InteractiveFlags of this Patch
        */
-      ZYPP_DEPRECATED bool reboot_needed() const
-      { return rebootSuggested(); }
+      InteractiveFlags interactiveFlags() const;
 
       /**
-       * Use \ref restartSuggested()
+       * Is the patch still interactive when ignoring this flags?
        */
-      ZYPP_DEPRECATED bool affects_pkg_manager() const
-      { return restartSuggested(); }
+      bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
 
       /**
        * Is the patch installation interactive? (does it need user input?)
+       *
+       * For security reasons patches requiring a reboot are not
+       * installed in an unattended mode. They are considered to be
+       * \c interactive so the user gets informed about the need for
+       * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
+       * off this behavior and include those patches (unless they actually
+       * contain interactive components as well, like messages or licenses).
        */
       bool interactive() const;
 
@@ -130,13 +225,6 @@ namespace zypp
        */
       ReferenceIterator referencesEnd() const;
 
-    public:
-      /** Patch ID
-       * \deprecated Seems to be unsused autobuild interal data?
-      */
-      ZYPP_DEPRECATED std::string id() const
-      { return std::string(); }
-
     protected:
       friend Ptr make<Self>( const sat::Solvable & solvable_r );
       /** Ctor */
@@ -144,7 +232,18 @@ namespace zypp
       /** Dtor */
       virtual ~Patch();
   };
+  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::Categories);
+  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
+  ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
+
+  /** \relates Patch::Category string representation.*/
+  std::string asString( const Patch::Category & obj );
+
+  /** \relates Patch::InteractiveFlag string representation.*/
+  std::string asString( const Patch::InteractiveFlag & obj );
 
+  /** \relates Patch::SeverityFlag string representation.*/
+  std::string asString( const Patch::SeverityFlag & obj );
 
   /**
    * Query class for Patch issue references