9ac49598df4561464963d0f6b728d76e337a1900
[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     /**
92      * Log installation (or update) of a package.
93      */
94     void install( const PoolItem & pi );
95
96     /**
97      * Log removal of a package
98      */
99     void remove( const PoolItem & pi );
100
101     /**
102      * Log a newly added repository.
103      *
104      * \param repo info about the added repository
105      */
106     void addRepository( const RepoInfo & repo );
107
108     /**
109      * Log recently removed repository.
110      *
111      * \param repo info about the removed repository
112      */
113     void removeRepository( const RepoInfo & repo );
114
115     /**
116      * Log certain modifications to a repository.
117      *
118      * \param oldrepo info about the old repository
119      * \param newrepo info about the new repository
120      */
121     void modifyRepository( const RepoInfo & oldrepo, const RepoInfo & newrepo );
122   };
123   ///////////////////////////////////////////////////////////////////
124
125 } // namespace zypp
126
127 #endif // ZYPP_TARGET_COMMITLOG_H