Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / ZYppCallbacks.h
index 0516a8c..bca1192 100644 (file)
 #ifndef ZYPP_ZYPPCALLBACKS_H
 #define ZYPP_ZYPPCALLBACKS_H
 
+#include "zypp/base/EnumClass.h"
 #include "zypp/Callback.h"
+#include "zypp/UserData.h"
 #include "zypp/Resolvable.h"
 #include "zypp/RepoInfo.h"
 #include "zypp/Pathname.h"
-#include "zypp/Message.h"
+#include "zypp/Package.h"
+#include "zypp/Patch.h"
 #include "zypp/Url.h"
 #include "zypp/ProgressData.h"
 #include "zypp/media/MediaUserAuth.h"
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
+  ///////////////////////////////////////////////////////////////////
+  namespace sat
+  {
+    class Queue;
+    class FileConflicts;
+  } // namespace sat
+  ///////////////////////////////////////////////////////////////////
+
   struct ProgressReport : public callback::ReportBase
   {
     virtual void start( const ProgressData &/*task*/ )
@@ -101,6 +112,12 @@ namespace zypp
         INVALID                // the downloaded file is invalid
       };
 
+      /** Hint that package is available in the local cache (no download needed).
+       * This will be the only trigger for an already cached package.
+       */
+      virtual void infoInCache( Resolvable::constPtr res_r, const Pathname & localfile_r )
+      {}
+
       virtual void start(
         Resolvable::constPtr /*resolvable_ptr*/
         , const Url &/*url*/
@@ -140,20 +157,20 @@ namespace zypp
       virtual void finishDeltaApply()
       {}
 
-      // Dowmload patch rpm:
-      // - path below url reported on start()
-      // - expected download size (0 if unknown)
-      // - download is interruptable
-      virtual void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
+      /** \deprecated Unused since 2008 */
+      virtual ZYPP_DEPRECATED void startPatchDownload( const Pathname & /*filename*/, const ByteCount & /*downloadsize*/ )
       {}
 
-      virtual bool progressPatchDownload( int /*value*/ )
+      /** \deprecated Unused since 2008 */
+      virtual ZYPP_DEPRECATED bool progressPatchDownload( int /*value*/ )
       { return true; }
 
-      virtual void problemPatchDownload( const std::string &/*description*/ )
+      /** \deprecated Unused since 2008 */
+      virtual ZYPP_DEPRECATED void problemPatchDownload( const std::string &/*description*/ )
       {}
 
-      virtual void finishPatchDownload()
+      /** \deprecated Unused since 2008 */
+      virtual ZYPP_DEPRECATED void finishPatchDownload()
       {}
 
 
@@ -167,6 +184,22 @@ namespace zypp
        , const std::string &/*description*/
       ) { return ABORT; }
 
+
+      /** Detail information about the result of a performed pkgGpgCheck.
+       *
+       * Userdata sent:
+       * \param "Package"      Package::constPtr of the package
+       * \param "Localpath"    Pathname to downloaded package on disk
+       * \param "CheckPackageResult"   RpmDb::CheckPackageResult of signature check
+       * \param "CheckPackageDetail"   RpmDb::CheckPackageDetail logmessages of rpm signature check
+       *
+       *  Userdata accepted:
+       * \param "Action"       DownloadResolvableReport::Action user advice how to behave on error (ABORT).
+       *                        If you set just an empty value here, a default probelm report will be triggered.
+       */
+      virtual void pkgGpgCheck( const UserData & userData_r = UserData() )
+      {}
+
       virtual void finish(Resolvable::constPtr /*resolvable_ptr*/
         , Error /*error*/
         , const std::string &/*reason*/
@@ -292,17 +325,47 @@ namespace zypp
         NOT_FOUND,  // the medie not found at all
         IO,    // error accessing the media
         INVALID, // media is broken
-        WRONG  // wrong media, need a different one
+        WRONG, // wrong media, need a different one
+        IO_SOFT       /**< IO error which can happen on worse connection like timeout exceed */
       };
 
+      /**
+       *
+       * \param url         in: url for which the media is requested,
+       *                    out: url to use instead of the original one
+       * \param mediumNr    requested medium number
+       * \param label       label of requested medium
+       * \param error       type of error from \ref Error enum
+       * \param description error message (media not desired or error foo occured)
+       * \param devices     list of the available devices (for eject)
+       * \param dev_current in: index of the currently used device in the \a devices list
+       *                    out: index of the devices to be ejected in the \a devices list
+       * \return \ref Action (ABORT by default)
+       */
       virtual Action requestMedia(
         Url & /* url (I/O parameter) */
         , unsigned /*mediumNr*/
+        , const std::string & /* label */
         , Error /*error*/
-        , const std::string &/*description*/
+        , const std::string & /*description*/
+        , const std::vector<std::string> & /* devices */
+        , unsigned int & /* dev_current (I/O param) */
       ) { return ABORT; }
     };
 
+    ///////////////////////////////////////////////////////////////////
+    /// \class ScopedDisableMediaChangeReport
+    /// \brief Temporarily disable MediaChangeReport
+    /// Sometimes helpful to suppress interactive messages connected to
+    /// MediaChangeReport while fallback URLs are avaialble.
+    struct ScopedDisableMediaChangeReport
+    {
+      /** Disbale MediaChangeReport if \a condition_r is \c true.*/
+      ScopedDisableMediaChangeReport( bool condition_r = true );
+    private:
+      shared_ptr<callback::TempConnect<media::MediaChangeReport> > _guard;
+    };
+
     // progress for downloading a file
     struct DownloadProgressReport : public callback::ReportBase
     {
@@ -322,7 +385,17 @@ namespace zypp
 
         virtual void start( const Url &/*file*/, Pathname /*localfile*/ ) {}
 
-        virtual bool progress(int /*value*/, const Url &/*file*/)
+        /**
+         * Download progress.
+         *
+         * \param value        Percentage value.
+         * \param file         File URI.
+         * \param dbps_avg     Average download rate so far. -1 if unknown.
+         * \param dbps_current Current download (cca last 1 sec). -1 if unknown.
+         */
+        virtual bool progress(int /*value*/, const Url &/*file*/,
+                              double dbps_avg = -1,
+                              double dbps_current = -1)
         { return true; }
 
         virtual Action problem(
@@ -370,41 +443,88 @@ namespace zypp
   ///////////////////////////////////////////////////////////////////
   namespace target
   {
-
-    // resolvable Message
-    struct MessageResolvableReport : public callback::ReportBase
+    /** Request to display the pre commit message of a patch. */
+    struct PatchMessageReport : public callback::ReportBase
     {
-        virtual void show(
-         Message::constPtr /*message*/
-        ) {}
+      /** Display \c patch->message().
+       * Return \c true to continue, \c false to abort commit.
+      */
+      virtual bool show( Patch::constPtr & /*patch*/ )
+      { return true; }
     };
 
-    // resolvable Script
-    struct ScriptResolvableReport : public callback::ReportBase
+    /** Indicate execution of a patch script. This is a sort of
+     * \c %post script shipped by a package and to be executed
+     * after the package was installed.
+    */
+    struct PatchScriptReport : public callback::ReportBase
     {
-      enum Task   { DO, UNDO };
       enum Notify { OUTPUT, PING };
+      enum Action {
+        ABORT,  // abort commit and return error
+        RETRY, // (re)try to execute this script
+        IGNORE // ignore any failue and continue
+      };
 
-      /** Whether executing do_script on install or undo_script on delete. */
-      virtual void start( const Resolvable::constPtr & /*script_r*/,
-                         const Pathname & /*path_r*/,
-                          Task )
+      /** Start executing the script provided by package.
+      */
+      virtual void start( const Package::constPtr & /*package*/,
+                          const Pathname & /*script path*/ )
       {}
       /** Progress provides the script output. If the script is quiet,
        * from time to time still-alive pings are sent to the ui. Returning \c FALSE
        * aborts script execution.
       */
-      virtual bool progress( Notify , const std::string & = std::string() )
+      virtual bool progress( Notify /*OUTPUT or PING*/,
+                             const std::string & /*output*/ = std::string() )
       { return true; }
       /** Report error. */
-      virtual void problem( const std::string & /*description*/ )
-      {}
+      virtual Action problem( const std::string & /*description*/ )
+      { return ABORT; }
       /** Report success. */
       virtual void finish()
       {}
     };
 
     ///////////////////////////////////////////////////////////////////
+    /// \class FindFileConflictstReport
+    /// \brief Check for package file conflicts in commit (after download)
+    ///
+    /// File conflict check requires that all packages are downloaded and
+    /// now available in the cache (need to access the filelists). Missing
+    /// packages are omitted from check and their number is reported in
+    /// \a noFilelist_r. This usually happens if download mode 'as-needed'
+    /// is used.
+    ///////////////////////////////////////////////////////////////////
+    struct FindFileConflictstReport : public callback::ReportBase
+    {
+      /**
+       * \param progress_r     Progress counter for packages to check.
+       * \return \c true to continue, \c false upon user abort request.
+       */
+      virtual bool start( const ProgressData & progress_r )
+      { return true; }
+
+      /**
+       * \param progress_r     Progress counter for packages to check.
+       * \param noFilelist_r   Queue of so far skipped solvables (no filelist/not yet downloaded).
+       * \return \c true to continue, \c false upon user abort request.
+       */
+      virtual bool progress( const ProgressData & progress_r, const sat::Queue & noFilelist_r )
+      { return true; }
+
+      /**
+       * \param progress_r     Progress counter for packages to check.
+       * \param noFilelist_r   Queue of skipped solvables (no filelist/not yet downloaded).
+       * \param conflicts_r    File conflits queue.
+       * \return \c true to continue, \c false upon user abort request.
+       */
+      virtual bool result( const ProgressData & progress_r, const sat::Queue & noFilelist_r, const sat::FileConflicts & conflicts_r )
+      { return true; }
+    };
+
+
+    ///////////////////////////////////////////////////////////////////
     namespace rpm
     {
 
@@ -429,7 +549,7 @@ namespace zypp
         enum RpmLevel {
             RPM,
             RPM_NODEPS,
-            RPM_NODEPS_FORCE
+            RPM_NODEPS_FORCE   //!< only this one used
         };
 
         virtual void start(
@@ -556,44 +676,178 @@ namespace zypp
         ) {}
       };
 
-       // progress for scanning the database
-      struct ScanDBReport : public callback::ReportBase
-      {
-        enum Action {
-          ABORT,  // abort and return error
-          RETRY,       // retry
-         IGNORE        // ignore the failure
-        };
+      /////////////////////////////////////////////////////////////////
+    } // namespace rpm
+    ///////////////////////////////////////////////////////////////////
 
-        enum Error {
-         NO_ERROR,
-         FAILED                // conversion failed
-        };
+    /////////////////////////////////////////////////////////////////
+  } // namespace target
+  ///////////////////////////////////////////////////////////////////
 
-        virtual void start(
-        ) {}
+  class PoolQuery;
 
-        virtual bool progress(int /*value*/)
-        { return true; }
+  /** \name Locks */
+  //@{
+  /**
+   * Callback for cleaning locks which doesn't lock anything in pool.
+   */
 
-        virtual Action problem(
-         Error /*error*/
-        , const std::string &/*description*/
-        ) { return ABORT; }
+  struct CleanEmptyLocksReport : public callback::ReportBase
+  {
+    /**
+     * action performed by cleaning api to specific lock
+     */
+    enum Action {
+      ABORT,  /**< abort and return error */
+      DELETE, /**< delete empty lock    */
+      IGNORE  /**< skip empty lock */
+    };
 
-        virtual void finish(
-          Error /*error*/
-         , const std::string &/*reason*/
-        ) {}
-      };
+    /**
+     * result of cleaning
+     */
+    enum Error {
+      NO_ERROR, /**< no problem */
+      ABORTED /** cleaning aborted by user */
+    };
 
-      /////////////////////////////////////////////////////////////////
-    } // namespace rpm
-    ///////////////////////////////////////////////////////////////////
+    /**
+     * cleaning is started
+     */
+    virtual void start(
+    ) {}
+
+    /**
+     * progress of cleaning specifies in percents
+     * \return if continue
+     */
+    virtual bool progress(int /*value*/)
+    { return true; }
 
-    /////////////////////////////////////////////////////////////////
-  } // namespace target
+    /**
+     * When find empty lock ask what to do with it
+     * \return action
+     */
+    virtual Action execute(
+        const PoolQuery& /*error*/
+     ) { return DELETE; }
+
+      /**
+       * cleaning is done
+       */
+     virtual void finish(
+       Error /*error*/
+      ) {}
+
+  };
+
+  /**
+   * this callback handles merging old locks with newly added or removed
+   */
+  struct SavingLocksReport : public callback::ReportBase
+  {
+    /**
+     * action for old lock which is in conflict
+     * \see ConflictState
+     */
+    enum Action {
+      ABORT,  /**< abort and return error*/
+      DELETE, /**< delete conflicted lock    */
+      IGNORE  /**< skip conflict lock */
+    };
+
+    /**
+     * result of merging
+     */
+    enum Error {
+      NO_ERROR, /**< no problem */
+      ABORTED  /**< cleaning aborted by user */
+    };
+
+    /**
+     * type of conflict of old and new lock
+     */
+    enum ConflictState{
+      SAME_RESULTS, /**< locks lock same item in pool but his parameters is different */
+      INTERSECT /**< locks lock some file and unlocking lock unlock only part
+      * of iti, so removing old lock can unlock more items in pool */
+    };
+
+    virtual void start() {}
+
+    /**
+     * merging still live
+     * \return if continue
+     */
+    virtual bool progress()
+    { return true; }
+
+    /**
+     * When user unlock something which is locked by non-identical query
+     */
+    virtual Action conflict(
+        const PoolQuery&, /**< problematic query*/
+       ConflictState
+     ) { return DELETE; }
+
+     virtual void finish(
+       Error /*error*/
+      ) {}
+  };
+
+  ///////////////////////////////////////////////////////////////////
+  /// \class JobReport
+  /// \brief Generic report for sending messages.
   ///////////////////////////////////////////////////////////////////
+  struct JobReport : public callback::ReportBase
+  {
+  public:
+    /** message type (use like 'enum class \ref MsgType') */
+    struct _MsgTypeDef {
+      enum Enum { debug, info, warning, error, important, data };
+    };
+    typedef base::EnumClass<_MsgTypeDef> MsgType;      ///< 'enum class MsgType'
+
+    /** typsafe map of userdata */
+    typedef callback::UserData UserData;
+
+  public:
+    /** Send a ready to show message text. */
+    virtual bool message( MsgType type_r, const std::string & msg_r, const UserData & userData_r ) const
+    { return true; }
+
+
+    /** \name Static sender instance */
+    //@{
+    /** Singleton sender instance */
+    static callback::SendReport<JobReport> & instance();       // impl in ZYppImpl.cc
+
+    /** send debug message text */
+    static bool debug( const MessageString & msg_r, const UserData & userData_r = UserData() )
+    { return instance()->message( MsgType::debug, msg_r, userData_r ); }
+
+    /** send message text */
+    static bool info( const MessageString & msg_r, const UserData & userData_r = UserData() )
+    { return instance()->message( MsgType::info, msg_r, userData_r ); }
+
+    /** send warning text */
+    static bool warning( const MessageString & msg_r, const UserData & userData_r = UserData() )
+    { return instance()->message( MsgType::warning, msg_r, userData_r ); }
+
+    /** send error text */
+    static bool error( const MessageString & msg_r, const UserData & userData_r = UserData() )
+    { return instance()->message( MsgType::error, msg_r, userData_r ); }
+
+    /** send important message text */
+    static bool important( const MessageString & msg_r, const UserData & userData_r = UserData() )
+    { return instance()->message( MsgType::important, msg_r, userData_r ); }
+
+    /** send data message */
+    static bool data( const MessageString & msg_r, const UserData & userData_r = UserData() )
+    { return instance()->message( MsgType::data, msg_r, userData_r ); }
+    //@}
+  };
+
 
   /////////////////////////////////////////////////////////////////
 } // namespace zypp