Merge branch 'master' of ssh://git@git.opensuse.org/projects/zypp/libzypp
[platform/upstream/libzypp.git] / zypp / parser / HistoryLogReader.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 /** \file HistoryLogReader.h
11  *
12  */
13 #ifndef ZYPP_HISTORYLOGREADER_H_
14 #define ZYPP_HISTORYLOGREADER_H_
15
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/ProgressData.h"
18 #include "zypp/Pathname.h"
19
20 #include "zypp/HistoryLogData.h"
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   class Date;
27
28   ///////////////////////////////////////////////////////////////////
29   namespace parser
30   { /////////////////////////////////////////////////////////////////
31
32
33   /////////////////////////////////////////////////////////////////////
34   //
35   // CLASS NAME: HistoryLogReader
36   //
37   /**
38    * Reads a zypp history log file and calls the ProcessItem function passed
39    * in the constructor for each item found.
40    *
41    * Example:
42    * <code>
43    *
44    * struct HistoryItemCollector
45    * {
46    *   vector<HistoryItem::Ptr> items;
47    *
48    *   bool processEntry( const HistoryItem::Ptr & item_ptr )
49    *   {
50    *     items.push_back(item_ptr);
51    *     return true;
52    *   }
53    * }
54    *
55    * ...
56    *
57    * HistoryItemCollector ic;
58    * HistoryLogReader reader("/var/log/zypp/history", boost::ref(ic));
59    *
60    * try
61    * {
62    *   reader.readAll();
63    * }
64    * catch (const Exception & e)
65    * {
66    *   cout << e.asUserHistory() << endl;
67    * }
68    *
69    * </code>
70    *
71    * \see http://en.opensuse.org/Libzypp/Package_History
72    */
73   class HistoryLogReader
74   {
75   public:
76     typedef function< bool( const HistoryItem::Ptr & )> ProcessItem;
77
78   public:
79     HistoryLogReader( const Pathname & repo_file,
80                       const ProcessItem & callback );
81     ~HistoryLogReader();
82
83     /**
84      * Read the whole log file.
85      */
86     void readAll(
87       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
88
89     /**
90      * Read log from specified \a date.
91      */
92     void readFrom( const Date & date,
93       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
94
95     /**
96      * Read log between \a fromDate and \a toDate.
97      */
98     void readFromTo( const Date & fromDate, const Date & toDate,
99       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
100
101     /**
102      * Set the reader to ignore invalid log entries and continue with the rest.
103      *
104      * \param ignoreInvalid <tt>true</tt> will cause the reader to ignore invalid entries
105      */
106     void setIgnoreInvalidItems( bool ignoreInvalid = false );
107
108     /**
109      * Whether the reader is set to ignore invalid log entries.
110      */
111     bool ignoreInvalidItems() const;
112
113   private:
114     /** Implementation */
115     class Impl;
116     RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
117   };
118   ///////////////////////////////////////////////////////////////////
119
120
121   /////////////////////////////////////////////////////////////////
122 } // namespace parser
123 ///////////////////////////////////////////////////////////////////
124 /////////////////////////////////////////////////////////////////
125 } // namespace zypp
126 ///////////////////////////////////////////////////////////////////
127
128 #endif /* ZYPP_HISTORYLOGREADER_H_ */