\---------------------------------------------------------------------*/
/** \file zypp/sat/Transaction.h
*/
-extern "C"
-{
- struct _Transaction;
-}
#ifndef ZYPP_SAT_TRANSACTION_H
#define ZYPP_SAT_TRANSACTION_H
#include <iosfwd>
#include "zypp/base/PtrTypes.h"
-#include "zypp/base/SafeBool.h"
+#include "zypp/base/Flags.h"
#include "zypp/base/Iterator.h"
#include "zypp/base/DefaultIntegral.h"
-#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/sat/SolvIterMixin.h"
#include "zypp/sat/Solvable.h"
+#include "zypp/sat/Queue.h"
#include "zypp/PoolItem.h"
class Transaction_const_iterator;
}
- /** Satsolver transaction wrapper.
+ /** Libsolv transaction wrapper.
* \note Note that Transaction is derived from \ref sat::SolvIterMixin which
* makes PoolItem and Selectable iterators automatically available.
* \note Changing the \ref ResPool content (loading/unloading repositories)
* invalidates all outstanding transaction data. \see \ref valid.
+ * \note.The transaction may inlude steps of type \ref TRANSACTION_IGNORE which
+ * do not cause/require any specific action. To skip those informal steps
+ * when iterating, use the \ref actionBegin /\ref actionEnd methods.
*/
class Transaction : public SolvIterMixin<Transaction, detail::Transaction_const_iterator>
- , protected base::SafeBool<Transaction>
{
friend std::ostream & operator<<( std::ostream & str, const Transaction & obj );
friend std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
/** Type of (rpm) action to perform in a \ref Step. */
enum StepType
{
- TRANSACTION_IGNORE, /**< [ ] Nothing (includes implicit deletes due to obsoletes and non-package actions) */
- TRANSACTION_ERASE, /**< [-] Delete item */
- TRANSACTION_INSTALL, /**< [+] Install(update) item */
- TRANSACTION_MULTIINSTALL /**< [M] Install(multiversion) item (\see \ref ZConfig::multiversion) */
+ TRANSACTION_IGNORE = 0x00, /**< [ ] Nothing (includes implicit deletes due to obsoletes and non-package actions) */
+ TRANSACTION_ERASE = 0x10, /**< [-] Delete item */
+ TRANSACTION_INSTALL = 0x20, /**< [+] Install(update) item */
+ TRANSACTION_MULTIINSTALL = 0x30 /**< [M] Install(multiversion) item (\see \ref ZConfig::multiversion) */
};
/** \ref Step action result. */
enum StepStage
{
- STEP_TODO, /**< [__] unprocessed */
- STEP_DONE, /**< [OK] success */
- STEP_ERROR, /**< [**] error */
+ STEP_TODO = (1 << 0), /**< [__] unprocessed */
+ STEP_DONE = (1 << 1), /**< [OK] success */
+ STEP_ERROR = (1 << 2), /**< [**] error */
};
+ ZYPP_DECLARE_FLAGS(StepStages,StepStage);
+
+ public:
+ struct LoadFromPoolType {}; ///< Ctor arg type
+ static constexpr LoadFromPoolType loadFromPool = LoadFromPoolType();
+
public:
/** Default ctor: empty transaction. */
Transaction();
- /** Ctor cloning a sat transaction. */
- Transaction( ::_Transaction & trans_r );
+ /** Ctor loading the default pools transaction. */
+ Transaction( LoadFromPoolType );
/** Dtor */
~Transaction();
bool valid() const;
/** Validate object in a boolean context: valid */
- using base::SafeBool<Transaction>::operator bool_type;
+ explicit operator bool() const
+ { return valid(); }
/** Order transaction steps for commit.
* It's cheap to call it for an aleready ordered \ref Transaction.
/** Number of steps in transaction steps. */
size_t size() const;
- typedef detail::Transaction_iterator iterator;
- typedef detail::Transaction_const_iterator const_iterator;
+ typedef detail::Transaction_iterator iterator;
+ typedef detail::Transaction_const_iterator const_iterator;
/** Iterator to the first \ref TransactionStep */
const_iterator begin() const;
iterator find( const PoolItem & pi_r );
public:
- /** \name Omit iterating TRANSACTION_IGNORE steps.
+ /** \name Iterate action steps (omit TRANSACTION_IGNORE steps).
+ *
+ * All these methods allow to pass an optional OR'd combination of
+ * \ref StepStages as filter. Per default all steps are processed/counted.
+ *
+ * \code
+ * Transaction trans;
+ * for_( it, trans.actionBegin(~sat::Transaction::STEP_DONE), trans.actionEnd() )
+ * {
+ * ... // process all steps not DONE (ERROR and TODO)
+ * }
+ * \endcode
*/
//@{
struct FilterAction;
typedef filter_iterator<FilterAction,const_iterator> action_iterator;
- action_iterator actionBegin() const;
+
+ /** Whether the [filtered] transaction contains any steps . */
+ bool actionEmpty( StepStages filter_r = StepStages() ) const;
+
+ /** Number of steps in [filtered] transaction steps. */
+ size_t actionSize( StepStages filter_r = StepStages() ) const;
+
+ /** Pointer to the 1st action step in [filtered] transaction. */
+ action_iterator actionBegin( StepStages filter_r = StepStages() ) const;
+
+ /** Pointer behind the last action step in transaction. */
action_iterator actionEnd() const;
+
//@}
- private:
- friend base::SafeBool<Transaction>::operator bool_type() const;
- /** Validate object in a boolean context. */
- bool boolTest() const
- { return valid(); }
+ public:
+ /** Return all packages that would be installed after the transaction is run.
+ * The new packages are put at the head of the queue, the number of new
+ * packages is returned. (wraps libsolv::transaction_installedresult) */
+ int installedResult( Queue & result_r ) const;
+
+ /** Return the ident strings of all packages that would be auto-installed after the transaction is run. */
+ StringQueue autoInstalled() const;
+
+ /** Set the ident strings of all packages that would be auto-installed after the transaction is run. */
+ void autoInstalled( const StringQueue & queue_r );
+
public:
/** Implementation */
- class Impl;
+ struct Impl;
private:
/** Pointer to implementation */
RW_pointer<Impl> _pimpl;
};
+ ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages);
+
/** \relates Transaction Stream output */
std::ostream & operator<<( std::ostream & str, const Transaction & obj );
/** Set step action result. */
void stepStage( StepStage val_r );
- /** Return the corresponding \ref Solvable (or.
- *
+ /** Return the corresponding \ref Solvable.
+ * Returns \ref Solvable::noSolvable if the item is meanwhile deleted and
+ * was removed from the pool. \see Post mortem acccess to @System solvables.
*/
Solvable satSolvable() const
{ return _solv; }
struct Transaction::FilterAction
{
+ FilterAction() {}
+ FilterAction( StepStages filter_r ) : _filter( filter_r ) {}
+
bool operator()( const Transaction::Step & step_r ) const
- { return step_r.stepType() != Transaction::TRANSACTION_IGNORE; }
+ {
+ if ( step_r.stepType() == Transaction::TRANSACTION_IGNORE )
+ return false; // no action
+ return !_filter || _filter.testFlag( step_r.stepStage() );
+ }
+
+ StepStages _filter;
};
- inline Transaction::action_iterator Transaction::actionBegin() const
- { return make_filter_begin( FilterAction(), *this ); }
+ inline Transaction::action_iterator Transaction::actionBegin( StepStages filter_r ) const
+ { return make_filter_begin( FilterAction( filter_r ), *this ); }
inline Transaction::action_iterator Transaction::actionEnd() const
{ return make_filter_end( FilterAction(), *this ); }
+ inline bool Transaction::actionEmpty( StepStages filter_r ) const
+ { return( actionBegin( filter_r ) == actionEnd() ); }
+
+ inline size_t Transaction::actionSize( StepStages filter_r ) const
+ {
+ size_t cnt = 0;
+ for_( it, actionBegin( filter_r ), actionEnd() )
+ ++cnt;
+ return cnt;
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////