d956a3920f1ec642e907ee4c989bb239c10057bb
[platform/upstream/libzypp.git] / zypp / HistoryLog.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/HistoryLog.h
10  *
11  */
12 #ifndef ZYPP_TARGET_COMMITLOG_H
13 #define ZYPP_TARGET_COMMITLOG_H
14
15 #include <iosfwd>
16
17 #include "zypp/Pathname.h"
18
19 namespace zypp
20 {
21   class PoolItem;
22   class RepoInfo;
23
24   ///////////////////////////////////////////////////////////////////
25   /// \class HistoryLog
26   /// \brief Writing the zypp history file
27   /// \ingroup g_ZyppHistory
28   ///
29   /// Reference counted signleton for writhing the zypp history file.
30   /// The history file is opened on demand and closed when the last
31   /// HistoryLog object drops its reference. Thus HistoryLog objects
32   /// should be local to those functions, writing the log, and must
33   /// not be stored permanently.
34   ///
35   /// \code
36   /// some method ()
37   /// {
38   ///   PoolItem pi;
39   ///   ...
40   ///   HistoryLog().install(pi);
41   ///   ...
42   ///   HistoryLog().comment(someMessage);
43   /// }
44   /// \endcode
45   ///
46   /// \note Take care to set proper target root dir if needed. Either pass
47   /// it via the constructor, or set it via setRoot(Pathname) method.
48   /// The default location of the file is determined by
49   /// \ref zypp::ZConfig::historyLogPath (default: \c /var/log/zypp/history).
50   ///
51   /// \todo The implementation as pseudo signleton is questionable.
52   /// Use shared_ptr instead of handcrafted ref/unref. Manage multiple
53   /// logs at different locations.
54   ///////////////////////////////////////////////////////////////////
55   class HistoryLog
56   {
57     HistoryLog( const HistoryLog & );
58     HistoryLog & operator=( const HistoryLog & );
59   public:
60     /**
61      * Constructor with an optional root directory.
62      *
63      * \param rootdir actual target root directory
64      */
65     HistoryLog( const Pathname & rootdir = Pathname() );
66     ~HistoryLog();
67
68     /**
69      * Set new root directory to the default history log file path.
70      *
71      * This path will be prepended to the default log file path. This should
72      * be done where there is a potential that the target root has changed.
73      *
74      * \param root new root directory.
75      */
76     static void setRoot( const Pathname & root );
77
78     /**
79      * Get the current log file path.
80      */
81     static const Pathname & fname();
82
83     /**
84      * Log a comment (even multiline).
85      *
86      * \param comment the comment
87      * \param timestamp whether to include a timestamp at the start of the comment
88      */
89     void comment( const std::string & comment, bool timestamp = false );
90
91     /** Log info about the current process.  */
92     void stampCommand();
93
94     /**
95      * Log installation (or update) of a package.
96      */
97     void install( const PoolItem & pi );
98
99     /**
100      * Log removal of a package
101      */
102     void remove( const PoolItem & pi );
103
104     /**
105      * Log a newly added repository.
106      *
107      * \param repo info about the added repository
108      */
109     void addRepository( const RepoInfo & repo );
110
111     /**
112      * Log recently removed repository.
113      *
114      * \param repo info about the removed repository
115      */
116     void removeRepository( const RepoInfo & repo );
117
118     /**
119      * Log certain modifications to a repository.
120      *
121      * \param oldrepo info about the old repository
122      * \param newrepo info about the new repository
123      */
124     void modifyRepository( const RepoInfo & oldrepo, const RepoInfo & newrepo );
125
126     /**
127      * Log state changes in patches
128      *
129      * \param oldstate info about the old state
130      */
131     void patchStateChange ( const PoolItem & pi, const std::string &oldstate );
132
133   };
134   ///////////////////////////////////////////////////////////////////
135
136 } // namespace zypp
137
138 #endif // ZYPP_TARGET_COMMITLOG_H