1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef DMEVENTLOGGER_H
18#define DMEVENTLOGGER_H
19
20#ifndef __cplusplus
21#error "This is a C++ header file; it requires C++ to compile."
22#endif
23
24#include "dmstring.h"
25#include "dmvector.h"
26#include "dmEvent.h"
27#include "dmConfigItem.h"
28#include "dmPlugin.h"
29
30class DMTree;
31
32typedef  DMMap<PDMConfigItem, DMEventMap> DMPostEventMap;
33typedef  DMMap<PDMPlugin, DMEventMap> DMPluginEventMap;
34
35/**
36 * DMEventLogger represents event storage for broadcast events and commit plug-ins events.
37 */
38class DMEventLogger
39{
40public:
41  /**
42  * Default constructor
43  */
44  DMEventLogger();
45
46  /**
47  * Default destructor
48  */
49  ~DMEventLogger();
50
51  /**
52  * Initializes event logger
53  * \param pTree [in] - pointer on DM tree object
54  * \return Return Type (SYNCML_DM_RET_STATUS_T)
55  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
56  * - All other codes indicate failure.
57  */
58  SYNCML_DM_RET_STATUS_T Init( DMTree* tree );
59
60 /**
61  * Adds a commit-plug-in event
62  * \param szPath [in/out] - path of updated node
63  * \param nAction [in] - action performed on a node
64  * \param pPlugin [in] - smart pointer on commit plug-in
65  * \param bIsEnabledByParent [in] - specifies if action is enabled by parent node
66  * \param szNewName [in] - new node name in case of "Rename" operation
67  * \return Return Type (SYNCML_DM_RET_STATUS_T)
68  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
69  * - All other codes indicate failure.
70  */
71  SYNCML_DM_RET_STATUS_T OnNodeChanged(CPCHAR szPath ,
72                                       SYNCML_DM_EVENT_ACTION_T nAction,
73                                       const PDMPlugin & pPlugin,
74                                       BOOLEAN bIsEnabledByParent,
75                                       CPCHAR szNewName = NULL );
76
77 /**
78  * Adds a broadcast event
79  * \param szPath [in/out] - path of updated node
80  * \param nAction [in] - action performed on a node
81  * \param pItem [in] - smart pointer on event subscription
82  * \param bIsEnabledByParent [in] - specifies if action is enabled by parent node
83  * \param szNewName [in] - new node name in case of "Rename" operation
84  * \return Return Type (SYNCML_DM_RET_STATUS_T)
85  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
86  * - All other codes indicate failure.
87  */
88  SYNCML_DM_RET_STATUS_T OnNodeChanged(CPCHAR szPath ,
89                                       SYNCML_DM_EVENT_ACTION_T nAction,
90                                       const PDMConfigItem & pItem,
91                                       BOOLEAN bIsEnabledByParent,
92                                       CPCHAR szNewName = NULL );
93
94 /**
95  * Post broadcast events via XPL layer.
96  */
97  void OnTreeSaved();
98
99 /**
100  * Reset internal storage.
101  */
102  void Reset();
103
104  /**
105  * Retrieves events map for specified commit plug-in
106  * \param pPlugin [in] - smart pointer on commit plug-in
107  * \param aUpdatedNodes [out] - events to be passed to commit plug-in
108  */
109  void GetCommitPluginEvents(const PDMPlugin & pPlugin,
110                             DmtEventMap & aUpdatedNodes ) const;
111
112
113  /**
114  * Deserializes events map
115  * \param oBuffer [in] - binary buffer that contains events data
116  * \param aEventMap [out] - events map
117  * \param pItem [in] - smart pointer on event subscription
118  * \param bIsEnabledByParent [in] - specifies if action is enabled by parent node
119  * \param szNewName [in] - new node name in case of "Rename" operation
120  * \return Return Type (SYNCML_DM_RET_STATUS_T)
121  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
122  * - All other codes indicate failure.
123  */
124  static SYNCML_DM_RET_STATUS_T Deserialize(DMBufferReader & oBuffer,
125                                            DmtEventMap & aEventMap);
126
127
128 /**
129  * Deserializes event data for leaf node
130  * \param oBuffer [in] - binary buffer that contains events data
131  * \param strParent [out] - parent node path
132  * \param aData [out] - smart pointer on event data (update description)
133  * \return Return Type (SYNCML_DM_RET_STATUS_T)
134  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
135  * - All other codes indicate failure.
136  */
137  static SYNCML_DM_RET_STATUS_T Deserialize(DMBufferReader & oBuffer,
138                                            DMString & strParent,
139                                            PDmtEventData & aData);
140
141  /**
142  * Cleans records in the Event Logger in case of "Delete" operation performed on node.
143  * \param szPath [in] - path of deleted node
144  * \return Return Type (SYNCML_DM_RET_STATUS_T)
145  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
146  * - All other codes indicate failure.
147  */
148  SYNCML_DM_RET_STATUS_T CleanEvents(CPCHAR szPath);
149
150  /**
151  * Updates records in the Event Logger in case of "Rename" operation performed on node.
152  * \param szPath [in] - path of updated node
153  * \param szNewName [in] - new node name
154  * \return Return Type (SYNCML_DM_RET_STATUS_T)
155  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
156  * - All other codes indicate failure.
157  */
158  SYNCML_DM_RET_STATUS_T UpdateEvents(CPCHAR szPath,
159                                      CPCHAR szNewName);
160
161
162  /**
163  * Verifies if update on node should be ignored (because it was already logged)
164  * \param szPath [in] - path of updated node
165  * \param nAction [in] - action performed on a node
166  * \param szNewName [in] - new node name
167  * \return TRUE if should be ignored
168  */
169  BOOLEAN IsIgnoreSubscriptionEvent(CPCHAR szPath,
170                                    SYNCML_DM_EVENT_ACTION_T nAction,
171                                    CPCHAR szNewName = NULL);
172
173  /**
174  * Verifies if update on node should be ignored (because it was already logged)
175  * \param szPath [in] - path of updated node
176  * \param nAction [in] - action performed on a node
177  * \param szNewName [in] - new node name
178  * \return TRUE if should be ignored
179  */
180  BOOLEAN IsIgnorePluginEvent(CPCHAR szPath,
181                              SYNCML_DM_EVENT_ACTION_T nAction,
182                              CPCHAR szNewName = NULL);
183
184
185private:
186  /* Map to store broadcast events */
187  DMPostEventMap m_aPostEvents;
188  /* Map to store commit plug-ins events */
189  DMPluginEventMap m_aPluginEvents;
190  /* Pointer on DM tree */
191  DMTree*   m_pTree;
192
193   /**
194  * Calculates size of map for serialization
195  * \param aEventMap [in] - map of events
196  * \return Return Type (UINT32)
197  */
198  static UINT32 GetSize(const DMEventMap & aEventMap);
199
200
201  /**
202  * Finds records in the map by specified parent path
203  * \param szPath [in] - parent path to search
204  * \param aEventMap [in] - map of events
205  * \param pEventPath [out] - smart pointer on found path to parent node ( key )
206  * \param aVector [out] - found events vector ( value )
207  * \return TRUE if found
208  */
209  BOOLEAN Find(CPCHAR szPath,
210               const DMEventMap & aEventMap,
211               PDMEventPath & pEventPath,
212               DmtEventDataVector & aVector);
213
214   /**
215  * Finds record in the vector by specified name
216  * \param aVector [in] - vector of logged events
217  * \param nAction [in] - action performed on a node
218  * \param bIsCumulative [in] - specifies if event is a Cumulative
219  * \param bIsEnabledByParent [in] - specifies if event is enabled by parent node (Cumulative or Detailed)
220  * \param szName [in] - node name
221  * \param szNewName [in] - new node name in case of "Rename"
222  * \return Return Type (PDmtEventData)
223  *  returns smart pointer on event data if found, null otherwise
224  */
225  PDmtEventData Find(const DmtEventDataVector & aVector,
226                     SYNCML_DM_EVENT_ACTION_T nAction,
227                     BOOLEAN bIsCumulative,
228                     BOOLEAN bIsEnabledByParent,
229                     CPCHAR szName,
230                     CPCHAR szNewName);
231
232 /**
233  * Adds action into existing event data
234  * \param pEventData [in/out] - smart pointer on event data
235  * \param nAction [in] - action performed on a node
236  * \param szNewName [in] - new node name in case of "Rename"
237  * \return Return Type (SYNCML_DM_RET_STATUS_T)
238  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
239  * - All other codes indicate failure.
240  */
241  SYNCML_DM_RET_STATUS_T AddEvent(PDmtEventData & pEventData,
242                                  SYNCML_DM_EVENT_ACTION_T nAction,
243                                  CPCHAR szNewName);
244
245  /**
246  * Adds new event data into storage
247  * \param aVector [in] - vector of logged events
248  * \param nAction [in] - action performed on a node
249  * \param bIsLeaf [in] - specifies if node is a leaf
250  * \param bIsEnabledByParent [in] - specifies if event is enabled by parent node (Cumulative or Detailed)
251  * \param szName [in] - node name
252  * \param szNewName [in] - new node name in case of "Rename"
253  * \return Return Type (SYNCML_DM_RET_STATUS_T)
254  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
255  * - All other codes indicate failure.
256  */
257  SYNCML_DM_RET_STATUS_T AddEvent(DmtEventDataVector & aVector,
258                                  SYNCML_DM_EVENT_ACTION_T nAction,
259                                  BOOLEAN bIsLeaf,
260                                  BOOLEAN bIsEnabledByParent,
261                                  CPCHAR szName,
262                                  CPCHAR szNewName);
263
264
265   /**
266  * Adds an event (new event data or new action on existing record)
267  * \param szPath [in/out] - path of updated node
268  * \param nAction [in] - action performed on a node
269  * \param aEventMap [in/out] - map of events
270  * \param bIsCumulative [in] - specifies if event is a Cumulative
271  * \param bIsEnabledByParent [in] - specifies if action is enabled by parent node
272  * \param szNewName [in] - new node name in case of "Rename" operation
273  * \return Return Type (SYNCML_DM_RET_STATUS_T)
274  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
275  * - All other codes indicate failure.
276  */
277  SYNCML_DM_RET_STATUS_T OnNodeChanged(CPCHAR szPath ,
278                                       SYNCML_DM_EVENT_ACTION_T nAction,
279                                       DMEventMap & aEventMap,
280                                       BOOLEAN bIsCumulative,
281                                       BOOLEAN bIsEnabledByParent,
282                                       CPCHAR szNewName );
283
284
285   /**
286  * Cleans broadcast records in the Event Logger in case of "Delete" operation performed on node.
287  * \param szPath [in] - path of deleted node
288  * \return Return Type (SYNCML_DM_RET_STATUS_T)
289  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
290  * - All other codes indicate failure.
291  */
292  SYNCML_DM_RET_STATUS_T CleanConfigEvents(CPCHAR szPath);
293
294   /**
295  * Cleans commit plug-ins records in the Event Logger in case of "Delete" operation performed on node.
296  * \param szPath [in] - path of deleted node
297  * \return Return Type (SYNCML_DM_RET_STATUS_T)
298  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
299  * - All other codes indicate failure.
300  */
301  SYNCML_DM_RET_STATUS_T CleanPluginEvents(CPCHAR szPath);
302
303  /**
304  * Cleans records in the event map in case of "Delete" operation performed on node.
305  * \param aEventMap [in/out] - events map
306  * \param szPath [in] - path of deleted node
307  * \return Return Type (SYNCML_DM_RET_STATUS_T)
308  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
309  * - All other codes indicate failure.
310  */
311 SYNCML_DM_RET_STATUS_T CleanEvents(DMEventMap & aEventMap,
312                                     CPCHAR szPath);
313
314  /**
315  * Cleans event data records in the vectore in case of "Delete" operation performed on node.
316  * It removes only data enabled by parent node
317  * \param aVector [in/out] - events data vector
318  * \return Return Type (SYNCML_DM_RET_STATUS_T)
319  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
320  * - All other codes indicate failure.
321  */
322 SYNCML_DM_RET_STATUS_T CleanEvents(DmtEventDataVector & aVector);
323
324
325   /**
326  * Updates records in the Event Logger in case of "Rename" operation performed on node.
327  * \param aEventMap [in/out] - events map
328  * \param szPath [in] - path of updated node
329  * \param szNewName [in] - new node name
330  * \return Return Type (SYNCML_DM_RET_STATUS_T)
331  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
332  * - All other codes indicate failure.
333  */
334 SYNCML_DM_RET_STATUS_T UpdateEvents(DMEventMap & aEventMap,
335                                     CPCHAR szPath,
336                                     CPCHAR szNewName);
337
338   /**
339  * Updates broadcast records in the Event Logger in case of "Rename" operation performed on node.
340  * \param szPath [in] - path of updated node
341  * \param szNewName [in] - new node name
342  * \return Return Type (SYNCML_DM_RET_STATUS_T)
343  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
344  * - All other codes indicate failure.
345  */
346 SYNCML_DM_RET_STATUS_T UpdateSubscriptionEvents(CPCHAR szPath,
347                                                 CPCHAR szNewName);
348
349  /**
350  * Updates commit plug-ins records in the Event Logger in case of "Rename" operation performed on node.
351  * \param szPath [in] - path of updated node
352  * \param szNewName [in] - new node name
353  * \return Return Type (SYNCML_DM_RET_STATUS_T)
354  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
355  * - All other codes indicate failure.
356  */
357 SYNCML_DM_RET_STATUS_T UpdatePluginEvents(CPCHAR szPath,
358                                           CPCHAR szNewName);
359
360
361   /**
362  * Finds and updates record for node in case of "Add" operation
363  * "Delete"-"Add" sequence on leaf node converted into "Replace"
364  * \param aVector [in/out] - events data vector
365  * \param szName [in] - node name
366  * \return TRUE if found
367  */
368 BOOLEAN FindRecordForAdd(const DmtEventDataVector & aVector, CPCHAR szName);
369
370  /**
371  * Finds record for node in case of "Replace" operation
372  * \param aVector [in/out] - events data vector
373  * \param szName [in] - node name
374  * \return TRUE if found
375  */
376 BOOLEAN FindRecordForReplace(const DmtEventDataVector & aVector,
377                              CPCHAR szName);
378
379
380  /**
381  * Finds and updates record for node in case of "Rename" operation
382  * \param aVector [in/out] - events data vector
383  * \param szName [in] - node name
384  * \param szNewName [in] - node name
385 * \return TRUE if found
386  */
387 BOOLEAN FindRecordForRename(DmtEventDataVector & aVector,
388                             CPCHAR szName,
389                             CPCHAR szNewName);
390
391  /**
392  * Finds and remove rocord about add operation in case of "Delete" operation
393  * \param aVector [in/out] - events data vector
394  * \param szName [in] - node name
395 * \return TRUE if found
396  */
397 BOOLEAN FindRecordForDelete(DmtEventDataVector & aVector,
398                             CPCHAR szName);
399
400 /**
401  * Finds and updates record for same node (Only 'Rename" checked in case of Cumulative events)
402  * \param aVector [in/out] - events data vector
403  * \param nAction [in] - action performed on a node
404  * \param szName [in] - node name
405  * \param bIsCumulative [in] - specifies if event is a Cumulative
406  * \param szNewName [in] - node name
407 * \return TRUE if found
408  */
409 BOOLEAN CheckEventOnSameNode(DmtEventDataVector & aVector,
410                              SYNCML_DM_EVENT_ACTION_T nAction,
411                              CPCHAR szName,
412                              BOOLEAN bIsCumulative,
413                              CPCHAR szNewName);
414
415/**
416  * Checks if update should be ignored by Event Logger
417  * \param szPath [in/out] - path of updated node
418  * \param nAction [in] - action performed on a node
419  * \param aEventMap [in/out] - events map
420  * \param bIsCumulative [in] - specifies if event is a Cumulative
421  * \param szNewName [in] - node name
422  * \return TRUE if event should be ignored
423  */
424 BOOLEAN IsIgnoreEvent(CPCHAR szPath ,
425                        SYNCML_DM_EVENT_ACTION_T nAction,
426                        DMEventMap & aEventMap,
427                        BOOLEAN bIsCumulative,
428                        CPCHAR szNewName);
429
430
431  /**
432  * Deserializes events data vector
433  * \param oBuffer [in] - binary buffer that contains events data
434  * \param aVector [out] - events data vector
435  * \return Return Type (SYNCML_DM_RET_STATUS_T)
436  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
437  * - All other codes indicate failure.
438  */
439 static SYNCML_DM_RET_STATUS_T Deserialize(DMBufferReader & oBuffer,
440                                           DmtEventDataVector & aVector);
441
442 /**
443  * Serializes events data vector into a binary buffer
444  * \param aVector [in] - events data vector
445  * \param oBuffer [out] - binary buffer
446  * \return Return Type (SYNCML_DM_RET_STATUS_T)
447  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
448  * - All other codes indicate failure.
449  */
450 static SYNCML_DM_RET_STATUS_T Serialize(const DmtEventDataVector & aVector,
451                                         DMBufferWriter & oBuffer);
452
453 /**
454  * Serializes events map into a binary buffer
455  * \param aEventMap [in] - events map
456  * \param oBuffer [out] - binary buffer
457  * \return Return Type (SYNCML_DM_RET_STATUS_T)
458  * - SYNCML_DM_SUCCESS - indicate that operation is completed successfully.
459  * - All other codes indicate failure.
460  */
461static SYNCML_DM_RET_STATUS_T Serialize(const DMEventMap & aEventMap,
462                                         DMBufferWriter & oBuffer);
463
464
465};
466
467#endif
468