Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / notification_persistent_service / server / include / ns_npp_persistence_manager.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_NPPService
19 /// \brief    The file contains declaration of CPersistenceManager class.
20 ///           This class acts as a manager for notification persistent data storage
21 ///           and file and folder persistence.
22 ///
23 ///
24 ////////////////////////////////////////////////////////////////////////////////////////////////////
25
26 #ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_MANAGER_H_
27 #define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_MANAGER_H_
28
29
30 #include <native_service/frameworkunified_types.h>
31 #include <native_service/ns_np_service.h>
32 #include <map>
33 #include <string>
34 #include <vector>
35 #include "ns_npp_types.h"
36 #include "ns_npp_persistent_accesser.h"
37
38 class CPersistence;
39 class CPersistentData;
40 class CNotificationsToPersist;
41
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
43 /// vector of all available persistent notification and its data.
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 typedef std::vector<CNotificationsToPersist *> Persistent_Notification_List_Type;
46
47 ////////////////////////////////////////////////////////////////////////////////////////////////////
48 /// Map of all persist file type. i.e. FilePersistence and FolderPersistence
49 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 typedef std::map<ENotificationpersistentservicePersistType, CPersistence *> Persist_Type;
51
52 typedef Persist_Type::iterator Persist_Type_Iter;
53
54 /**
55  *  This class acts as a manager for storing notification data,file and folder in
56  *  persistent memory.
57  */
58 class CPersistenceManager {
59  public:
60   /// Disable Persistence
61   static BOOL m_bPersistenceDisabled;  // NOLINT (readability/naming)
62
63   ////////////////////////////////////////////////////////////////////////////////////////////////
64   /// CPersistenceManager
65   /// Constructor of CPersistenceManager class
66   ///
67   /// \param
68   ///
69   /// \return
70   ///
71   ////////////////////////////////////////////////////////////////////////////////////////////////
72   CPersistenceManager();
73
74   ////////////////////////////////////////////////////////////////////////////////////////////////
75   /// ~CPersistenceManager
76   /// Destructor of CPersistenceManager class
77   ///
78   /// \param
79   ///
80   /// \return
81   ///
82   ////////////////////////////////////////////////////////////////////////////////////////////////
83   ~CPersistenceManager();
84
85   ////////////////////////////////////////////////////////////////////////////////////////////////
86   /// NotificationpersistentserviceRegister
87   /// Registers a tag for the file or folder. This tag will be used for releasing or loading a
88   /// file or folder.
89   ///
90   /// \param [IN] f_cappname
91   ///      string - Name of the application requesting for persistence
92   ///
93   /// \param [IN] f_ctag
94   ///      string - File/Folder will be persist against this tag.
95   ///
96   /// \param [IN] f_epersisttype
97   ///      ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Tag to register is for a file
98   ///                ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Tag to register is for a folder
99   ///
100   /// \param [IN] bisuserpersistence
101
102   ///      BOOL - TRUE if user persistence else FALSE
103   ///
104   /// \return EFrameworkunifiedStatus
105   ///     EFrameworkunifiedStatus - success or failure status
106   ///
107   ///
108   ////////////////////////////////////////////////////////////////////////////////////////////////
109   EFrameworkunifiedStatus NotificationpersistentserviceRegister(std::string f_cappname,
110                          std::string f_ctag,
111                          ENotificationpersistentservicePersistType f_epersisttype,
112                          BOOL bisuserpersistence);
113
114   ////////////////////////////////////////////////////////////////////////////////////////////////
115   /// NotificationpersistentserviceRelease
116   /// Entry for the file or folder is stored in map for persistence.
117   /// If f_bPersist is TRUE file or folder will be persist immediately else will be persist
118   /// on shutdown
119   ///
120   /// \param [IN] f_cappname
121   ///      string - Name of the application requesting for persistence
122   ///
123   /// \param [IN] f_ctag
124   ///      string - File/Folder will be persist against this tag.
125   ///
126   /// \param [IN] f_cmempath
127   ///      string - File/Folder which needs to persist.
128   ///
129   /// \param [IN] enotificationpersistentservicereleasetype
130   ///      EFrameworkunifiedReleaseType - eFrameworkunifiedNotOnRelease = 0  :not on release
131   ///                        eFrameworkunifiedPersistOnShutdown :persist on shutdown
132   ///                        eFrameworkunifiedPersistInstantly  :persist instantly
133   ///
134   /// \param [IN] f_epersisttype
135   ///      ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Persist a file to a persistent memory
136   ///                ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Persist a folder to a persistent memory
137   ///
138   /// \param [IN] f_cusername
139   ///      std::string - If tag is registered as user, then f_cusername holds the name of user,
140   ///            else an empty string
141   ///
142   /// \return EFrameworkunifiedStatus
143   //      EFrameworkunifiedStatus - success or failure status
144   ///
145   ////////////////////////////////////////////////////////////////////////////////////////////////
146   EFrameworkunifiedStatus NotificationpersistentserviceRelease(std::string f_cappname,
147                         std::string f_ctag,
148                         std::string f_cmempath,
149                         EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
150                         ENotificationpersistentservicePersistType f_epersisttype,
151                         std::string f_cusername);
152
153   ////////////////////////////////////////////////////////////////////////////////////////////////
154   /// NotificationpersistentserviceLoad
155   ///  Load file/folder from persistent memory to the specified location.
156   ///
157   /// \param [IN] f_cappname
158   ///      string - Name of the application requesting for persistence
159   ///
160   /// \param [IN] f_ctag
161   ///      string - File/Folder corresponding to this tag will be retrieved.
162   ///
163   /// \param [IN] f_cretrievepath
164   ///      string - Filepath for retrieved file/folder.
165   ///
166   /// \param [IN] f_epersisttype
167   ///      ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Load a file from persistent memory
168   ///                ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Load a folder from persistent memory
169   ///
170   /// \param [IN] f_cusername
171   ///      std::string - If tag is registered as user, then f_cusername holds the name of user,
172   ///            else an empty string
173   ///
174   /// \return
175   ///
176   ////////////////////////////////////////////////////////////////////////////////////////////////
177   EFrameworkunifiedStatus NotificationpersistentserviceLoad(std::string f_cappname,
178                      std::string f_ctag,
179                      std::string f_cretrievepath,
180                      ENotificationpersistentservicePersistType f_epersisttype,
181                      std::string f_cusername);
182
183   ////////////////////////////////////////////////////////////////////////////////////////////////
184   /// AckReceivedFromWorker
185   ///  Send release ack to file/folder persistence object.
186   ///
187   /// \param [IN] f_csource
188   ///      PCSTR - Source of released file/folder
189   ///
190   /// \param [IN] f_ctag
191   ///      PCSTR - Tag of released file/folder
192   ///
193   /// \param [IN] f_epersisttype
194   ///      ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Ack for file persistence object
195   ///                ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Ack for folder persistence object
196   ///
197   /// \param [in] f_bcopystatus
198   ///         BOOL - Status of file/folder copy by worker.
199   ///
200   /// \param [in] f_eloadtype
201   ///         ENPS_Loadtype - Type of load release or load.
202   ///
203   /// \return
204   ///
205   ////////////////////////////////////////////////////////////////////////////////////////////////
206   EFrameworkunifiedStatus AckReceivedFromWorker(PCSTR f_csource, PCSTR f_ctag, ENotificationpersistentservicePersistType f_epersisttype,
207                                    BOOL f_bcopystatus, ENPS_Loadtype f_eloadtype);
208
209   ////////////////////////////////////////////////////////////////////////////////////////////////
210   /// NotificationpersistentserviceSaveNotificationData
211   /// Save notification data in a persistent file.
212   ///
213   /// \param [IN] f_vpersistentnotificationlist
214   ///      Persistent_Notification_List_Type - List of all notifications and corresponding data.
215   ///
216   /// \return EFrameworkunifiedStatus
217   ///     EFrameworkunifiedStatus - success or failure status
218   ///
219   ////////////////////////////////////////////////////////////////////////////////////////////////
220   EFrameworkunifiedStatus NotificationpersistentserviceSaveNotificationData(Persistent_Notification_List_Type *f_vpersistentnotificationlist);
221
222   ////////////////////////////////////////////////////////////////////////////////////////////////
223   /// NotificationpersistentserviceSaveUserNotificationData
224   /// Save notification data of user in a persistent file.
225   ///
226   /// \param [IN] f_vpersistentnotificationlist
227   ///      Persistent_Notification_List_Type - List of all notifications and corresponding data.
228   ///
229   /// \return EFrameworkunifiedStatus
230   ///     EFrameworkunifiedStatus - success or failure status
231   ///
232   ////////////////////////////////////////////////////////////////////////////////////////////////
233   EFrameworkunifiedStatus NotificationpersistentserviceSaveUserNotificationData(Persistent_Notification_List_Type *f_vpersistentnotificationlist);
234
235   ////////////////////////////////////////////////////////////////////////////////////////////////
236   /// NotificationpersistentserviceReadNotificationData
237   /// Get the list of all persistent notifications from a persistent memory and store it in a map.
238   ///
239   /// \param [OUT] f_vpersistentnotificationlist
240   ///      Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
241   ///
242   /// \return EFrameworkunifiedStatus
243   ///     EFrameworkunifiedStatus - success or failure status
244   ///
245   ////////////////////////////////////////////////////////////////////////////////////////////////
246   EFrameworkunifiedStatus NotificationpersistentserviceReadNotificationData(Persistent_Notification_List_Type *&f_vnotificationlist); // NOLINT (runtime/references)
247
248   ////////////////////////////////////////////////////////////////////////////////////////////////
249   /// NotificationpersistentserviceReadUserNotificationData
250   /// Get the list of all user persistent notifications from a persistent memory and store it in a map.
251   ///
252   /// \param [OUT] f_vpersistentnotificationlist
253   ///      Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
254   ///
255   /// \return EFrameworkunifiedStatus
256   ///     EFrameworkunifiedStatus - success or failure status
257   ///
258   ////////////////////////////////////////////////////////////////////////////////////////////////
259   EFrameworkunifiedStatus NotificationpersistentserviceReadUserNotificationData(Persistent_Notification_List_Type *&f_vnotificationlist); // NOLINT (runtime/references)
260
261   ////////////////////////////////////////////////////////////////////////////////////////////////
262   /// NotificationpersistentserviceReadNorNotificationData
263   /// Get the list of all Nor persistent notifications from a persistent memory and store it in a map.
264   ///
265   /// \param [OUT] f_vpersistentnotificationlist
266   ///      Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
267   ///
268   /// \return EFrameworkunifiedStatus
269   ///     EFrameworkunifiedStatus - success or failure status
270   ///
271   ////////////////////////////////////////////////////////////////////////////////////////////////
272   EFrameworkunifiedStatus NotificationpersistentserviceReadNorNotificationData(Persistent_Notification_List_Type *&f_vnotificationlist); // NOLINT (runtime/references)
273
274   ////////////////////////////////////////////////////////////////////////////////////////////////
275   /// PersistAllReleaseRequests
276   /// Persist all files and folder contained in the map in persistent memory.
277   ///
278   /// \param [in] f_uinotificationpersistentservicepersistcategoryflag
279   ///     UI_32 - Hex value from enum EFrameworkunifiedPersistCategory, representing data to persist
280   ///     0 - persist orignal data and
281   ///     1 - persist default data
282   ///
283   /// \return EFrameworkunifiedStatus
284   ///     EFrameworkunifiedStatus - success or failure status
285   ///
286   ////////////////////////////////////////////////////////////////////////////////////////////////
287   EFrameworkunifiedStatus PersistAllReleaseRequests(UI_32 f_uinotificationpersistentservicepersistcategoryflag);
288
289   ////////////////////////////////////////////////////////////////////////////////////////////////
290   /// NotificationpersistentservicePersistAllUserRequests
291   /// Persist all user files and folder contained in the map in persistent memory.
292   ///
293   ///
294   /// \return EFrameworkunifiedStatus
295   ///     EFrameworkunifiedStatus - success or failure status
296   ///
297   ////////////////////////////////////////////////////////////////////////////////////////////////
298   EFrameworkunifiedStatus NotificationpersistentservicePersistAllUserRequests();
299
300   ////////////////////////////////////////////////////////////////////////////////////////////////
301   /// SetReadThreadHandle
302   /// Pass the handle of the read thread to the object of file/folder persistence
303   ///
304   /// \param [IN] f_hreadthread
305   ///      HANDLE - Handle of read thread.
306   ///
307   /// \return
308   ///
309   ///
310   ////////////////////////////////////////////////////////////////////////////////////////////////
311   VOID SetReadThreadHandle(HANDLE f_hreadthread);
312
313   ////////////////////////////////////////////////////////////////////////////////////////////////
314   /// SetWriteThreadHandle
315   /// Pass the handle of the write thread to the object of file/folder persistence
316   ///
317   /// \param [IN] f_hwritethread
318   ///      HANDLE - Handle of write thread.
319   ///
320   /// \return
321   ///
322   ///
323   ////////////////////////////////////////////////////////////////////////////////////////////////
324   VOID SetWriteThreadHandle(HANDLE f_hwritethread);
325
326   ////////////////////////////////////////////////////////////////////////////////////////////////
327   /// SetNorPersistenceThreadHandle
328   /// Pass the handle of the Nor persistence write thread to the object of file/folder persistence
329   ///
330   /// \param [IN] f_hwritethread
331   ///      HANDLE - Handle of write thread.
332   ///
333   ///
334   ////////////////////////////////////////////////////////////////////////////////////////////////
335   VOID SetNorPersistenceThreadHandle(HANDLE f_hwritethread);
336
337   ////////////////////////////////////////////////////////////////////////////////////////////////
338   /// SetUserPersistentPath
339   /// Set user persistent path.
340   ///
341   /// \param [IN] f_cusername
342   ///      std::string - Name of user
343   ///
344   /// \return
345   ///
346   ///
347   ////////////////////////////////////////////////////////////////////////////////////////////////
348   VOID SetUserPersistentPath(std::string f_cusername);
349
350   ////////////////////////////////////////////////////////////////////////////////////////////
351   /// IsUserPersistence
352   /// Check if the persistence is user specific
353   ///
354   /// \param [in] - f_ctag
355   ///         std::string - File/folder Tag
356   ///
357   /// \param [in] - f_epersisttype
358   ///         ENotificationpersistentservicePersistType - persistent type
359   ///
360   /// \return status
361   ///         BOOL - TRUE for user specific persistence
362   ///          FALSE  for global persistence
363   ///////////////////////////////////////////////////////////////////////////////////////////
364   BOOL IsUserPersistence(std::string f_ctag, ENotificationpersistentservicePersistType f_epersisttype);
365
366   ////////////////////////////////////////////////////////////////////////////////////////////
367   /// HaveAllReleaseRequestsPersisted
368   /// Checks if all files and immediate persistent data are persisted.
369   ///
370   /// \param
371   ///
372   /// \return BOOL
373   ///         TRUE if all release requests are processed else false
374   ////////////////////////////////////////////////////////////////////////////////////////////
375   BOOL HaveAllReleaseRequestsPersisted();
376
377   ////////////////////////////////////////////////////////////////////////////////////////////
378   /// ResetPersistFlag
379   /// Resets persist flag.
380   ///
381   /// \param none
382   ///
383   /// \return none
384   ////////////////////////////////////////////////////////////////////////////////////////////
385   VOID ResetPersistFlag();
386
387   ////////////////////////////////////////////////////////////////////////////////////////////////
388   /// ClearPersistenceData
389   ///  Deletes the data from the persistent memory
390   ///
391   /// \param [in] f_enotificationpersistentserviceclearpersistencescope
392   ///         EFrameworkunifiedClearPersistence - data to be deleted from memory
393   ///
394   /// \return EFrameworkunifiedStatus
395   ///     EFrameworkunifiedStatus - success or failure
396   ///
397   ////////////////////////////////////////////////////////////////////////////////////////////////
398   EFrameworkunifiedStatus ClearPersistenceData(const EFrameworkunifiedClearPersistence &f_enotificationpersistentserviceclearpersistencescope);
399
400   ////////////////////////////////////////////////////////////////////////////////////////////////
401   /// NotificationpersistentserviceSetPersistentCategory
402   /// Sets the persist type of file or folder
403   ///
404   /// \param [IN] f_crequestorname
405   ///      string - Application name
406   ///
407   /// \param [IN] f_ctag
408   ///      string - File/Folder will be persist against this tag.
409   ///
410   /// \param [IN] f_epersistcategory
411   ///      EFrameworkunifiedPersistCategory - persistent category
412   ///
413   /// \param [IN] f_bPersist
414   ///      ENotificationpersistentservicePersistType - file or folder
415   ///
416   /// \return EFrameworkunifiedStatus
417   //      EFrameworkunifiedStatus - success or failure status
418   ///
419   ////////////////////////////////////////////////////////////////////////////////////////////////
420   EFrameworkunifiedStatus NotificationpersistentserviceSetPersistentCategory(std::string f_crequestorname,
421                                       std::string f_ctag,
422                                       EFrameworkunifiedPersistCategory f_epersistcategory,
423                                       ENotificationpersistentservicePersistType f_epersisttype);
424
425   ////////////////////////////////////////////////////////////////////////////////////////////////
426   /// PersistNORData
427   /// Sends the message to Immediate Persistence Thread to Persists the data immediately or reset
428   /// the NOR data depending on persist category flag during shutdown irrespective of delay.
429   ///
430   /// \param f_eshutdowntype
431   ///        EFrameworkunifiedShutdownType - shutdown type - normal, quick, data reset
432   ///
433   /// \param f_uinotificationpersistentservicepersistcategoryflag
434   ///      UI_32 - flag representing whether to persist or reset data.
435   ///
436   /// \return EFrameworkunifiedStatus
437   //      EFrameworkunifiedStatus - success or failure status
438   ///
439   ////////////////////////////////////////////////////////////////////////////////////////////////
440   EFrameworkunifiedStatus PersistNORData(EFrameworkunifiedShutdownType f_eshutdowntype, UI_32 f_uinotificationpersistentservicepersistcategoryflag);
441
442   ////////////////////////////////////////////////////////////////////////////////////////////
443   /// SetImmediateDataPersistedStatus
444   /// Set/Reset the persistence status of immediate persistence data
445   ///
446   /// \param [in] - f_bstatus
447   ///               BOOL
448   ///                 TRUE  - immediate persistent data are persisted
449   ///                 FALSE - immediate persistent data not persisted
450   ///
451   /// \return
452   ///////////////////////////////////////////////////////////////////////////////////////////
453   VOID SetImmediateDataPersistedStatus(BOOL f_bstatus);
454
455   ////////////////////////////////////////////////////////////////////////////////////////////
456   /// SetFilePersistedStatus
457   /// Set/Reset the persistence status of files and folders
458   ///
459   /// \param [in] - f_bstatus
460   ///               BOOL
461   ///                 TRUE  - all files are persisted
462   ///                 FALSE - all files and folders are not persisted
463   ///
464   /// \return
465   ///////////////////////////////////////////////////////////////////////////////////////////
466   VOID SetFilePersistedStatus(BOOL f_bstatus);
467
468 #ifdef NPP_PROFILEINFO_ENABLE
469
470   ////////////////////////////////////////////////////////////////////////////////////////////////
471   /// GetPersistenceProfilingData
472   /// This function is used to get the persistence info
473   ///
474   /// \param [out] f_cpersistenceprofileinfo
475   ///         std::string - Persistence info concated in a string
476   ///
477   /// \return EFrameworkunifiedStatus
478   ///     EFrameworkunifiedStatus - success or failure
479   ///
480   ////////////////////////////////////////////////////////////////////////////////////////////////
481   EFrameworkunifiedStatus GetPersistenceProfilingData(std::string &f_cpersistenceprofileinfo); // NOLINT (runtime/references)
482
483 #endif
484
485  private:
486   ////////////////////////////////////////////////////////////////////////////////////////////////
487   /// ReadImmediateNotificationData
488   /// Get the list of all immediate persistent notifications of f_epersistcategory
489   /// from a persistent memory in a vector.
490   ///
491   /// \param [OUT] f_vpersistentnotificationlist
492   ///        Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
493   ///
494   /// \param [IN] f_epersistcategory
495   ///        const EFrameworkunifiedPersistCategory - persistent category
496   ///
497   /// \return EFrameworkunifiedStatus
498   ///         EFrameworkunifiedStatus - success or failure status
499   ///
500   ////////////////////////////////////////////////////////////////////////////////////////////////
501   EFrameworkunifiedStatus ReadImmediateNotificationData(Persistent_Notification_List_Type *&f_vpersistentnotificationlist, // NOLINT (runtime/references)
502                                            const EFrameworkunifiedPersistCategory f_epersistcategory);
503
504   std::string m_cUserNotificationTag;  ///< Tag associated with a file which is used
505   ///< for storing user related notification persistent data.
506
507   std::string m_cNotificationPersistFilepath;  ///< Persistent file path for storing persistent data
508
509   std::string m_cNotificationUserMemFilepath;  ///< Memory location of a file for storing persistent data of a user
510
511   Persist_Type m_mPersist_Type;  ///< Map holds the objects of file and folder persistency.
512
513   CPersistentAccesser *m_poDataAccesser;  ///< Object for persistent data accesser
514
515   HANDLE m_hNSImmediatePersistenceThread;  ///< Nor persistence thread handle
516
517   BOOL m_bAllFilePersisted;           // all files have been persisted
518
519   BOOL m_bImmediatedDataPersisted;    // all immediate peristence data have been persisted
520
521   EFrameworkunifiedStatus Init();
522 };
523
524 ////////////////////////////////////////////////////////////////////////////////////////////
525 /// NPServiceOnCpWorkerAckCmd
526 /// Handles when the CopyWorker sends an ack back for a message received .
527 ///
528 /// \param [in] f_happ
529 ///         HANDLE - Handle to notificationpersistentservice_application Framework.
530 ///
531 /// \return status
532 ///         EFrameworkunifiedStatus - success or error
533 ////////////////////////////////////////////////////////////////////////////////////////////
534 EFrameworkunifiedStatus NPServiceOnCpWorkerAckCmd(HANDLE f_happ);
535
536 #endif  // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_MANAGER_H_