Imported Upstream version 15.0.0
[platform/upstream/libzypp.git] / zypp / ZYppCommitResult.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ZYppCommitResult.h
10  *
11 */
12 #ifndef ZYPP_ZYPPCOMMITRESULT_H
13 #define ZYPP_ZYPPCOMMITRESULT_H
14
15 #include <iosfwd>
16 #include <vector>
17 #include <list>
18
19 #include "zypp/PoolItem.h"
20 #include "zypp/sat/Transaction.h"
21 #include "zypp/base/DefaultIntegral.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26
27   namespace sat
28   {
29     class Transaction;
30   }
31
32   /** Pair of \ref sat::Solvable and \ref Pathname. */
33   class UpdateNotificationFile
34   {
35     public:
36       UpdateNotificationFile( sat::Solvable solvable_r, const Pathname & file_r )
37       : _solvable( solvable_r ), _file( file_r )
38       {}
39     public:
40       sat::Solvable solvable() const { return _solvable; }
41       const Pathname & file() const { return _file; }
42     private:
43       sat::Solvable _solvable;
44       Pathname      _file;
45   };
46
47   typedef std::list<UpdateNotificationFile> UpdateNotifications;
48
49   ///////////////////////////////////////////////////////////////////
50   //
51   //    CLASS NAME : ZYppCommitResult
52   //
53   /** Result returned from ZYpp::commit.
54    *
55    * \note Transaction data are provided and maintained during commit.
56    * Though the interface does not inhibit manipulation of transaction
57    * data outside commit (those methods could have been made \c private:),
58    * this is not recommended as you may easily mess up things.
59    *
60    * \see \ref ZYpp::commit
61    */
62   class ZYppCommitResult
63   {
64     public:
65       typedef std::vector<sat::Transaction::Step> TransactionStepList;
66
67     public:
68       ZYppCommitResult();
69       ZYppCommitResult( const ZYppCommitResult & lhs_r );
70       ZYppCommitResult( const Pathname & root_r );
71       ~ZYppCommitResult();
72
73     public:
74       /** Remembered root directory of the target.
75        *  \Note Pathnames within this class are relative to the
76        * targets root directory.
77       */
78       const Pathname & root() const;
79
80       /** The full transaction list.
81        * The complete list including transaction steps that do not require
82        * any action (like obsoletes or non-package actions). Depending on
83        * \ref ZYppCommitPolicy::restrictToMedia only a subset of this
84        * transaction might have been executed.
85        * \see \ref transactionStepList.
86        */
87       const sat::Transaction & transaction() const;
88
89       /** Manipulate \ref transaction */
90       sat::Transaction & rTransaction();
91
92       /** List of \ref sat::Transaction::Step to be executed by commit.
93        * The list of transaction step commit actually tried to execute.
94        */
95       const TransactionStepList & transactionStepList() const;
96
97       /** Manipulate \ref transactionStepList. */
98       TransactionStepList & rTransactionStepList();
99
100       /** List of update messages installed during this commit.
101        * \Note Pathnames are relative to the targets root directory.
102        * \code
103        *   ZYppCommitResult result;
104        *   ...
105        *   if ( ! result.updateMessages().empty() )
106        *   {
107        *     MIL << "Received " << result.updateMessages().size() << " update notification(s):" << endl;
108        *     for_( it, result.updateMessages().begin(), result.updateMessages().end() )
109        *     {
110        *       MIL << "- From " << it->solvable().asString() << " in file " << Pathname::showRootIf( result.root(), it->file() ) << ":" << endl;
111        *       {
112        *         // store message files content in a string:
113        *         InputStream istr( Pathname::assertprefix( result.root(), it->file() ) );
114        *         std::ostringstream strstr;
115        *         iostr::copy( istr, strstr );
116        *         std::string message( strstr.str() ); // contains the message
117        *       }
118        *       {
119        *         // or write out the message file indented:
120        *         InputStream istr( Pathname::assertprefix( result.root(), it->file() ) );
121        *         iostr::copyIndent( istr, MIL, "> " ) << endl;
122        *       }
123        *     }
124        *   }
125        * \endcode
126        */
127       const UpdateNotifications & updateMessages() const;
128
129       /** Manipulate \ref updateMessages
130        * \Note Pathnames are relative to the targets root directory.
131        */
132       UpdateNotifications & rUpdateMessages();
133
134     public:
135
136       /** \name Some statistics based on \ref Transaction
137        *
138        * Class \ref Transaction allows to count and iterate the action steps to
139        * get more detailed information about the transaction result. Here are just
140        * a few convenience methods for easy evaluation.
141        *
142        * \code
143        *    ZYppCommitResult result;
144        *    const sat::Transaction & trans( result.transaction() );
145        *    for_( it, trans.actionBegin(~sat::Transaction::STEP_DONE), trans.actionEnd() )
146        *    {
147        *       // process all steps not DONE (ERROR and TODO)
148        *       if ( it->satSolvable() )
149        *         std::cout << it->satSolvable() << endl;
150        *       else // deleted @System solvable: print post mortem data available
151        *         std::cout << it->ident() << endl;
152        *    }
153        * \endcode
154        * \see \ref Transaction, \ref transaction()
155        */
156       //@{
157         /** Whether all steps were performed successfully (none skipped or error) */
158         bool allDone() const
159         { return transaction().actionEmpty( ~sat::Transaction::STEP_DONE ); }
160
161         /** Whether an error ocurred (skipped streps are ok). */
162         bool noError() const
163         { return transaction().actionEmpty( sat::Transaction::STEP_ERROR ); }
164       //@}
165
166     public:
167       /** Implementation  */
168       class Impl;
169     private:
170       /** Pointer to data. */
171       RWCOW_pointer<Impl> _pimpl;
172   };
173   ///////////////////////////////////////////////////////////////////
174
175   /** \relates ZYppCommitResult Stream output. */
176   std::ostream & operator<<( std::ostream & str, const ZYppCommitResult & obj );
177
178   /////////////////////////////////////////////////////////////////
179 } // namespace zypp
180 ///////////////////////////////////////////////////////////////////
181 #endif // ZYPP_ZYPPCOMMITRESULT_H