aarch64 support
[tools/libzypp.git] / zypp / parser / HistoryLogReader.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 /** \file zypp/parser/HistoryLogReader.h
11  *
12  */
13 #ifndef ZYPP_PARSER_HISTORYLOGREADER_H_
14 #define ZYPP_PARSER_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 read.
40    *
41    * Example:
42    * <code>
43    *
44    * struct HistoryItemCollector
45    * {
46    *   vector<HistoryItem::Ptr> items;
47    *
48    *   bool operator()( 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      * \param progress An optional progress data receiver function.
87      */
88     void readAll(
89       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
90
91     /**
92      * Read log from specified \a date.
93      *
94      * \param date     Date from which to read.
95      * \param progress An optional progress data receiver function.
96      *
97      * \see readFromTo()
98      */
99     void readFrom( const Date & date,
100       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
101
102     /**
103      * Read log between \a fromDate and \a toDate.
104      *
105      * The date comparison's precision goes to seconds. Omitted time parts
106      * get replaced by zeroes, so if e.g. the time is not specified at all, the
107      * date means midnight of the specified date. So
108      *
109      * <code>
110      * fromDate = Date("2009-01-01", "%Y-%m-%d");
111      * toDate   = Date("2009-01-02", "%Y-%m-%d");
112      * </code>
113      *
114      * will yield log entries from midnight of January, 1st untill
115      * one second before midnight of January, 2nd.
116      *
117      * \param fromDate Date from which to read.
118      * \param toDate   Date on which to stop reading.
119      * \param progress An optional progress data receiver function.
120      */
121     void readFromTo( const Date & fromDate, const Date & toDate,
122       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() );
123
124     /**
125      * Set the reader to ignore invalid log entries and continue with the rest.
126      *
127      * \param ignoreInvalid <tt>true</tt> will cause the reader to ignore invalid entries
128      */
129     void setIgnoreInvalidItems( bool ignoreInvalid = false );
130
131     /**
132      * Whether the reader is set to ignore invalid log entries.
133      *
134      * \see setIngoreInvalidItems()
135      */
136     bool ignoreInvalidItems() const;
137
138   private:
139     /** Implementation */
140     class Impl;
141     RW_pointer<Impl,rw_pointer::Scoped<Impl> > _pimpl;
142   };
143   ///////////////////////////////////////////////////////////////////
144
145
146   /////////////////////////////////////////////////////////////////
147 } // namespace parser
148 ///////////////////////////////////////////////////////////////////
149 /////////////////////////////////////////////////////////////////
150 } // namespace zypp
151 ///////////////////////////////////////////////////////////////////
152
153 #endif /* ZYPP_PARSER_HISTORYLOGREADER_H_ */