Write userdata string to history log (fate#312521)
[platform/upstream/libzypp.git] / zypp / HistoryLogData.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9
10 /** \file zypp/HistoryLogData.h
11  *
12  */
13 #ifndef ZYPP_HISTORYLOGDATA_H_
14 #define ZYPP_HISTORYLOGDATA_H_
15
16 #include <iosfwd>
17
18 #include "zypp/Date.h"
19 #include "zypp/Edition.h"
20 #include "zypp/Arch.h"
21 #include "zypp/CheckSum.h"
22 #include "zypp/Url.h"
23
24 #define HISTORY_LOG_DATE_FORMAT "%Y-%m-%d %H:%M:%S"
25
26 namespace zypp
27 {
28   ///////////////////////////////////////////////////////////////////
29   /// \class HistoryActionID
30   /// \brief Enumeration of known history actions.
31   /// \ingroup g_EnumerationClass
32   /// \ingroup g_ZyppHistory
33   ///////////////////////////////////////////////////////////////////
34   struct HistoryActionID
35   {
36     static const HistoryActionID NONE;
37
38     static const HistoryActionID INSTALL;
39     static const HistoryActionID REMOVE;
40     static const HistoryActionID REPO_ADD;
41     static const HistoryActionID REPO_REMOVE;
42     static const HistoryActionID REPO_CHANGE_ALIAS;
43     static const HistoryActionID REPO_CHANGE_URL;
44
45     enum ID
46     {
47       NONE_e,
48
49       INSTALL_e,
50       REMOVE_e,
51       REPO_ADD_e,
52       REPO_REMOVE_e,
53       REPO_CHANGE_ALIAS_e,
54       REPO_CHANGE_URL_e
55     };
56
57     HistoryActionID() : _id(NONE_e) {}
58
59     HistoryActionID(ID id) : _id(id) {}
60
61     explicit HistoryActionID(const std::string & strval_r);
62
63     ID toEnum() const { return _id; }
64
65     static HistoryActionID::ID parse(const std::string & strval_r);
66
67     const std::string & asString(bool pad = false) const;
68
69     private:
70     ID _id;
71   };
72
73   /** \relates HistoryActionID */
74   std::ostream & operator << (std::ostream & str, const HistoryActionID & id);
75   ///////////////////////////////////////////////////////////////////
76
77
78   /////////////////////////////////////////////////////////////////////
79   //
80   // CLASS NAME: HistoryItem
81   //
82   class HistoryItem
83   {
84   public:
85     typedef shared_ptr<HistoryItem> Ptr;
86     typedef std::vector<std::string> FieldVector;
87
88   public:
89     HistoryItem(FieldVector & fields);
90     virtual ~HistoryItem()
91     {}
92
93     virtual void dumpTo(std::ostream & str) const;
94
95   public:
96     Date date;
97     HistoryActionID action;
98   };
99   /////////////////////////////////////////////////////////////////////
100
101
102   /////////////////////////////////////////////////////////////////////
103   //
104   // CLASS NAME: HistoryItemInstall
105   //
106   class HistoryItemInstall : public HistoryItem
107   {
108   public:
109     typedef shared_ptr<HistoryItemInstall> Ptr;
110
111     HistoryItemInstall(FieldVector & fields);
112     virtual ~HistoryItemInstall()
113     {}
114
115     virtual void dumpTo(std::ostream & str) const;
116
117   public:
118     std::string   name;
119     Edition       edition;
120     Arch          arch;
121     std::string   reqby; // TODO make this a class ReqBy
122     std::string   repoalias;
123     CheckSum      checksum;
124   };
125   /////////////////////////////////////////////////////////////////////
126
127
128   /////////////////////////////////////////////////////////////////////
129   //
130   // CLASS NAME: HistoryItemRemove
131   //
132   class HistoryItemRemove : public HistoryItem
133   {
134   public:
135     typedef shared_ptr<HistoryItemRemove> Ptr;
136
137     HistoryItemRemove(FieldVector & fields);
138     virtual ~HistoryItemRemove()
139     {}
140
141     virtual void dumpTo(std::ostream & str)  const;
142
143   public:
144     std::string name;
145     Edition     edition;
146     Arch        arch;
147     std::string reqby;
148   };
149   /////////////////////////////////////////////////////////////////////
150
151
152   /////////////////////////////////////////////////////////////////////
153   //
154   // CLASS NAME: HistoryItemRepoAdd
155   //
156   class HistoryItemRepoAdd : public HistoryItem
157   {
158   public:
159     typedef shared_ptr<HistoryItemRepoAdd> Ptr;
160
161     HistoryItemRepoAdd(FieldVector & fields);
162     virtual ~HistoryItemRepoAdd()
163     {}
164
165     virtual void dumpTo(std::ostream & str) const;
166
167   public:
168     std::string alias;
169     Url         url;
170   };
171   /////////////////////////////////////////////////////////////////////
172
173
174   /////////////////////////////////////////////////////////////////////
175   //
176   // CLASS NAME: HistoryItemRepoRemove
177   //
178   class HistoryItemRepoRemove : public HistoryItem
179   {
180   public:
181     typedef shared_ptr<HistoryItemRepoRemove> Ptr;
182
183     HistoryItemRepoRemove(FieldVector & fields);
184     virtual ~HistoryItemRepoRemove()
185     {}
186
187     virtual void dumpTo(std::ostream & str) const;
188
189   public:
190     std::string alias;
191   };
192   /////////////////////////////////////////////////////////////////////
193
194
195   /////////////////////////////////////////////////////////////////////
196   //
197   // CLASS NAME: HistoryItemRepoAliasChange
198   //
199   class HistoryItemRepoAliasChange : public HistoryItem
200   {
201   public:
202     typedef shared_ptr<HistoryItemRepoAliasChange> Ptr;
203
204     HistoryItemRepoAliasChange(FieldVector & fields);
205     virtual ~HistoryItemRepoAliasChange()
206     {}
207
208     virtual void dumpTo(std::ostream & str) const;
209
210   public:
211     std::string oldalias;
212     std::string newalias;
213   };
214   /////////////////////////////////////////////////////////////////////
215
216
217   /////////////////////////////////////////////////////////////////////
218   //
219   // CLASS NAME: HistoryItemRepoUrlChange
220   //
221   class HistoryItemRepoUrlChange : public HistoryItem
222   {
223   public:
224     typedef shared_ptr<HistoryItemRepoUrlChange> Ptr;
225
226     HistoryItemRepoUrlChange(FieldVector & fields);
227     virtual ~HistoryItemRepoUrlChange()
228     {}
229
230     virtual void dumpTo(std::ostream & str) const;
231
232   public:
233     std::string alias;
234     Url newurl;
235   };
236   /////////////////////////////////////////////////////////////////////
237
238   std::ostream & operator<<(std::ostream & str, const HistoryItem & obj);
239
240 }
241
242 #endif /* ZYPP_HISTORYLOGDATA_H_ */