2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
24 ////////////////////////////////////////////////////////////////////////////////////////////////////
26 #ifndef NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_MANAGER_H_
27 #define NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_MANAGER_H_
30 #include <native_service/frameworkunified_types.h>
31 #include <native_service/ns_np_service.h>
35 #include "ns_npp_types.h"
36 #include "ns_npp_persistent_accesser.h"
39 class CPersistentData;
40 class CNotificationsToPersist;
42 ////////////////////////////////////////////////////////////////////////////////////////////////////
43 /// vector of all available persistent notification and its data.
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 typedef std::vector<CNotificationsToPersist *> Persistent_Notification_List_Type;
47 ////////////////////////////////////////////////////////////////////////////////////////////////////
48 /// Map of all persist file type. i.e. FilePersistence and FolderPersistence
49 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 typedef std::map<ENotificationpersistentservicePersistType, CPersistence *> Persist_Type;
52 typedef Persist_Type::iterator Persist_Type_Iter;
55 * This class acts as a manager for storing notification data,file and folder in
58 class CPersistenceManager {
60 /// Disable Persistence
61 static BOOL m_bPersistenceDisabled; // NOLINT (readability/naming)
63 ////////////////////////////////////////////////////////////////////////////////////////////////
64 /// CPersistenceManager
65 /// Constructor of CPersistenceManager class
71 ////////////////////////////////////////////////////////////////////////////////////////////////
72 CPersistenceManager();
74 ////////////////////////////////////////////////////////////////////////////////////////////////
75 /// ~CPersistenceManager
76 /// Destructor of CPersistenceManager class
82 ////////////////////////////////////////////////////////////////////////////////////////////////
83 ~CPersistenceManager();
85 ////////////////////////////////////////////////////////////////////////////////////////////////
86 /// NotificationpersistentserviceRegister
87 /// Registers a tag for the file or folder. This tag will be used for releasing or loading a
90 /// \param [IN] f_cappname
91 /// string - Name of the application requesting for persistence
93 /// \param [IN] f_ctag
94 /// string - File/Folder will be persist against this tag.
96 /// \param [IN] f_epersisttype
97 /// ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Tag to register is for a file
98 /// ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Tag to register is for a folder
100 /// \param [IN] bisuserpersistence
102 /// BOOL - TRUE if user persistence else FALSE
104 /// \return EFrameworkunifiedStatus
105 /// EFrameworkunifiedStatus - success or failure status
108 ////////////////////////////////////////////////////////////////////////////////////////////////
109 EFrameworkunifiedStatus NotificationpersistentserviceRegister(std::string f_cappname,
111 ENotificationpersistentservicePersistType f_epersisttype,
112 BOOL bisuserpersistence);
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
120 /// \param [IN] f_cappname
121 /// string - Name of the application requesting for persistence
123 /// \param [IN] f_ctag
124 /// string - File/Folder will be persist against this tag.
126 /// \param [IN] f_cmempath
127 /// string - File/Folder which needs to persist.
129 /// \param [IN] enotificationpersistentservicereleasetype
130 /// EFrameworkunifiedReleaseType - eFrameworkunifiedNotOnRelease = 0 :not on release
131 /// eFrameworkunifiedPersistOnShutdown :persist on shutdown
132 /// eFrameworkunifiedPersistInstantly :persist instantly
134 /// \param [IN] f_epersisttype
135 /// ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Persist a file to a persistent memory
136 /// ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Persist a folder to a persistent memory
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
142 /// \return EFrameworkunifiedStatus
143 // EFrameworkunifiedStatus - success or failure status
145 ////////////////////////////////////////////////////////////////////////////////////////////////
146 EFrameworkunifiedStatus NotificationpersistentserviceRelease(std::string f_cappname,
148 std::string f_cmempath,
149 EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
150 ENotificationpersistentservicePersistType f_epersisttype,
151 std::string f_cusername);
153 ////////////////////////////////////////////////////////////////////////////////////////////////
154 /// NotificationpersistentserviceLoad
155 /// Load file/folder from persistent memory to the specified location.
157 /// \param [IN] f_cappname
158 /// string - Name of the application requesting for persistence
160 /// \param [IN] f_ctag
161 /// string - File/Folder corresponding to this tag will be retrieved.
163 /// \param [IN] f_cretrievepath
164 /// string - Filepath for retrieved file/folder.
166 /// \param [IN] f_epersisttype
167 /// ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Load a file from persistent memory
168 /// ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Load a folder from persistent memory
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
176 ////////////////////////////////////////////////////////////////////////////////////////////////
177 EFrameworkunifiedStatus NotificationpersistentserviceLoad(std::string f_cappname,
179 std::string f_cretrievepath,
180 ENotificationpersistentservicePersistType f_epersisttype,
181 std::string f_cusername);
183 ////////////////////////////////////////////////////////////////////////////////////////////////
184 /// AckReceivedFromWorker
185 /// Send release ack to file/folder persistence object.
187 /// \param [IN] f_csource
188 /// PCSTR - Source of released file/folder
190 /// \param [IN] f_ctag
191 /// PCSTR - Tag of released file/folder
193 /// \param [IN] f_epersisttype
194 /// ENotificationpersistentservicePersistType - ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE - Ack for file persistence object
195 /// ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER - Ack for folder persistence object
197 /// \param [in] f_bcopystatus
198 /// BOOL - Status of file/folder copy by worker.
200 /// \param [in] f_eloadtype
201 /// ENPS_Loadtype - Type of load release or load.
205 ////////////////////////////////////////////////////////////////////////////////////////////////
206 EFrameworkunifiedStatus AckReceivedFromWorker(PCSTR f_csource, PCSTR f_ctag, ENotificationpersistentservicePersistType f_epersisttype,
207 BOOL f_bcopystatus, ENPS_Loadtype f_eloadtype);
209 ////////////////////////////////////////////////////////////////////////////////////////////////
210 /// NotificationpersistentserviceSaveNotificationData
211 /// Save notification data in a persistent file.
213 /// \param [IN] f_vpersistentnotificationlist
214 /// Persistent_Notification_List_Type - List of all notifications and corresponding data.
216 /// \return EFrameworkunifiedStatus
217 /// EFrameworkunifiedStatus - success or failure status
219 ////////////////////////////////////////////////////////////////////////////////////////////////
220 EFrameworkunifiedStatus NotificationpersistentserviceSaveNotificationData(Persistent_Notification_List_Type *f_vpersistentnotificationlist);
222 ////////////////////////////////////////////////////////////////////////////////////////////////
223 /// NotificationpersistentserviceSaveUserNotificationData
224 /// Save notification data of user in a persistent file.
226 /// \param [IN] f_vpersistentnotificationlist
227 /// Persistent_Notification_List_Type - List of all notifications and corresponding data.
229 /// \return EFrameworkunifiedStatus
230 /// EFrameworkunifiedStatus - success or failure status
232 ////////////////////////////////////////////////////////////////////////////////////////////////
233 EFrameworkunifiedStatus NotificationpersistentserviceSaveUserNotificationData(Persistent_Notification_List_Type *f_vpersistentnotificationlist);
235 ////////////////////////////////////////////////////////////////////////////////////////////////
236 /// NotificationpersistentserviceReadNotificationData
237 /// Get the list of all persistent notifications from a persistent memory and store it in a map.
239 /// \param [OUT] f_vpersistentnotificationlist
240 /// Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
242 /// \return EFrameworkunifiedStatus
243 /// EFrameworkunifiedStatus - success or failure status
245 ////////////////////////////////////////////////////////////////////////////////////////////////
246 EFrameworkunifiedStatus NotificationpersistentserviceReadNotificationData(Persistent_Notification_List_Type *&f_vnotificationlist); // NOLINT (runtime/references)
248 ////////////////////////////////////////////////////////////////////////////////////////////////
249 /// NotificationpersistentserviceReadUserNotificationData
250 /// Get the list of all user persistent notifications from a persistent memory and store it in a map.
252 /// \param [OUT] f_vpersistentnotificationlist
253 /// Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
255 /// \return EFrameworkunifiedStatus
256 /// EFrameworkunifiedStatus - success or failure status
258 ////////////////////////////////////////////////////////////////////////////////////////////////
259 EFrameworkunifiedStatus NotificationpersistentserviceReadUserNotificationData(Persistent_Notification_List_Type *&f_vnotificationlist); // NOLINT (runtime/references)
261 ////////////////////////////////////////////////////////////////////////////////////////////////
262 /// NotificationpersistentserviceReadNorNotificationData
263 /// Get the list of all Nor persistent notifications from a persistent memory and store it in a map.
265 /// \param [OUT] f_vpersistentnotificationlist
266 /// Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
268 /// \return EFrameworkunifiedStatus
269 /// EFrameworkunifiedStatus - success or failure status
271 ////////////////////////////////////////////////////////////////////////////////////////////////
272 EFrameworkunifiedStatus NotificationpersistentserviceReadNorNotificationData(Persistent_Notification_List_Type *&f_vnotificationlist); // NOLINT (runtime/references)
274 ////////////////////////////////////////////////////////////////////////////////////////////////
275 /// PersistAllReleaseRequests
276 /// Persist all files and folder contained in the map in persistent memory.
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
283 /// \return EFrameworkunifiedStatus
284 /// EFrameworkunifiedStatus - success or failure status
286 ////////////////////////////////////////////////////////////////////////////////////////////////
287 EFrameworkunifiedStatus PersistAllReleaseRequests(UI_32 f_uinotificationpersistentservicepersistcategoryflag);
289 ////////////////////////////////////////////////////////////////////////////////////////////////
290 /// NotificationpersistentservicePersistAllUserRequests
291 /// Persist all user files and folder contained in the map in persistent memory.
294 /// \return EFrameworkunifiedStatus
295 /// EFrameworkunifiedStatus - success or failure status
297 ////////////////////////////////////////////////////////////////////////////////////////////////
298 EFrameworkunifiedStatus NotificationpersistentservicePersistAllUserRequests();
300 ////////////////////////////////////////////////////////////////////////////////////////////////
301 /// SetReadThreadHandle
302 /// Pass the handle of the read thread to the object of file/folder persistence
304 /// \param [IN] f_hreadthread
305 /// HANDLE - Handle of read thread.
310 ////////////////////////////////////////////////////////////////////////////////////////////////
311 VOID SetReadThreadHandle(HANDLE f_hreadthread);
313 ////////////////////////////////////////////////////////////////////////////////////////////////
314 /// SetWriteThreadHandle
315 /// Pass the handle of the write thread to the object of file/folder persistence
317 /// \param [IN] f_hwritethread
318 /// HANDLE - Handle of write thread.
323 ////////////////////////////////////////////////////////////////////////////////////////////////
324 VOID SetWriteThreadHandle(HANDLE f_hwritethread);
326 ////////////////////////////////////////////////////////////////////////////////////////////////
327 /// SetNorPersistenceThreadHandle
328 /// Pass the handle of the Nor persistence write thread to the object of file/folder persistence
330 /// \param [IN] f_hwritethread
331 /// HANDLE - Handle of write thread.
334 ////////////////////////////////////////////////////////////////////////////////////////////////
335 VOID SetNorPersistenceThreadHandle(HANDLE f_hwritethread);
337 ////////////////////////////////////////////////////////////////////////////////////////////////
338 /// SetUserPersistentPath
339 /// Set user persistent path.
341 /// \param [IN] f_cusername
342 /// std::string - Name of user
347 ////////////////////////////////////////////////////////////////////////////////////////////////
348 VOID SetUserPersistentPath(std::string f_cusername);
350 ////////////////////////////////////////////////////////////////////////////////////////////
351 /// IsUserPersistence
352 /// Check if the persistence is user specific
354 /// \param [in] - f_ctag
355 /// std::string - File/folder Tag
357 /// \param [in] - f_epersisttype
358 /// ENotificationpersistentservicePersistType - persistent type
361 /// BOOL - TRUE for user specific persistence
362 /// FALSE for global persistence
363 ///////////////////////////////////////////////////////////////////////////////////////////
364 BOOL IsUserPersistence(std::string f_ctag, ENotificationpersistentservicePersistType f_epersisttype);
366 ////////////////////////////////////////////////////////////////////////////////////////////
367 /// HaveAllReleaseRequestsPersisted
368 /// Checks if all files and immediate persistent data are persisted.
373 /// TRUE if all release requests are processed else false
374 ////////////////////////////////////////////////////////////////////////////////////////////
375 BOOL HaveAllReleaseRequestsPersisted();
377 ////////////////////////////////////////////////////////////////////////////////////////////
379 /// Resets persist flag.
384 ////////////////////////////////////////////////////////////////////////////////////////////
385 VOID ResetPersistFlag();
387 ////////////////////////////////////////////////////////////////////////////////////////////////
388 /// ClearPersistenceData
389 /// Deletes the data from the persistent memory
391 /// \param [in] f_enotificationpersistentserviceclearpersistencescope
392 /// EFrameworkunifiedClearPersistence - data to be deleted from memory
394 /// \return EFrameworkunifiedStatus
395 /// EFrameworkunifiedStatus - success or failure
397 ////////////////////////////////////////////////////////////////////////////////////////////////
398 EFrameworkunifiedStatus ClearPersistenceData(const EFrameworkunifiedClearPersistence &f_enotificationpersistentserviceclearpersistencescope);
400 ////////////////////////////////////////////////////////////////////////////////////////////////
401 /// NotificationpersistentserviceSetPersistentCategory
402 /// Sets the persist type of file or folder
404 /// \param [IN] f_crequestorname
405 /// string - Application name
407 /// \param [IN] f_ctag
408 /// string - File/Folder will be persist against this tag.
410 /// \param [IN] f_epersistcategory
411 /// EFrameworkunifiedPersistCategory - persistent category
413 /// \param [IN] f_bPersist
414 /// ENotificationpersistentservicePersistType - file or folder
416 /// \return EFrameworkunifiedStatus
417 // EFrameworkunifiedStatus - success or failure status
419 ////////////////////////////////////////////////////////////////////////////////////////////////
420 EFrameworkunifiedStatus NotificationpersistentserviceSetPersistentCategory(std::string f_crequestorname,
422 EFrameworkunifiedPersistCategory f_epersistcategory,
423 ENotificationpersistentservicePersistType f_epersisttype);
425 ////////////////////////////////////////////////////////////////////////////////////////////////
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.
430 /// \param f_eshutdowntype
431 /// EFrameworkunifiedShutdownType - shutdown type - normal, quick, data reset
433 /// \param f_uinotificationpersistentservicepersistcategoryflag
434 /// UI_32 - flag representing whether to persist or reset data.
436 /// \return EFrameworkunifiedStatus
437 // EFrameworkunifiedStatus - success or failure status
439 ////////////////////////////////////////////////////////////////////////////////////////////////
440 EFrameworkunifiedStatus PersistNORData(EFrameworkunifiedShutdownType f_eshutdowntype, UI_32 f_uinotificationpersistentservicepersistcategoryflag);
442 ////////////////////////////////////////////////////////////////////////////////////////////
443 /// SetImmediateDataPersistedStatus
444 /// Set/Reset the persistence status of immediate persistence data
446 /// \param [in] - f_bstatus
448 /// TRUE - immediate persistent data are persisted
449 /// FALSE - immediate persistent data not persisted
452 ///////////////////////////////////////////////////////////////////////////////////////////
453 VOID SetImmediateDataPersistedStatus(BOOL f_bstatus);
455 ////////////////////////////////////////////////////////////////////////////////////////////
456 /// SetFilePersistedStatus
457 /// Set/Reset the persistence status of files and folders
459 /// \param [in] - f_bstatus
461 /// TRUE - all files are persisted
462 /// FALSE - all files and folders are not persisted
465 ///////////////////////////////////////////////////////////////////////////////////////////
466 VOID SetFilePersistedStatus(BOOL f_bstatus);
468 #ifdef NPP_PROFILEINFO_ENABLE
470 ////////////////////////////////////////////////////////////////////////////////////////////////
471 /// GetPersistenceProfilingData
472 /// This function is used to get the persistence info
474 /// \param [out] f_cpersistenceprofileinfo
475 /// std::string - Persistence info concated in a string
477 /// \return EFrameworkunifiedStatus
478 /// EFrameworkunifiedStatus - success or failure
480 ////////////////////////////////////////////////////////////////////////////////////////////////
481 EFrameworkunifiedStatus GetPersistenceProfilingData(std::string &f_cpersistenceprofileinfo); // NOLINT (runtime/references)
486 ////////////////////////////////////////////////////////////////////////////////////////////////
487 /// ReadImmediateNotificationData
488 /// Get the list of all immediate persistent notifications of f_epersistcategory
489 /// from a persistent memory in a vector.
491 /// \param [OUT] f_vpersistentnotificationlist
492 /// Persistent_Notification_List_Type - Retrieved list of all notifications and corresponding data
494 /// \param [IN] f_epersistcategory
495 /// const EFrameworkunifiedPersistCategory - persistent category
497 /// \return EFrameworkunifiedStatus
498 /// EFrameworkunifiedStatus - success or failure status
500 ////////////////////////////////////////////////////////////////////////////////////////////////
501 EFrameworkunifiedStatus ReadImmediateNotificationData(Persistent_Notification_List_Type *&f_vpersistentnotificationlist, // NOLINT (runtime/references)
502 const EFrameworkunifiedPersistCategory f_epersistcategory);
504 std::string m_cUserNotificationTag; ///< Tag associated with a file which is used
505 ///< for storing user related notification persistent data.
507 std::string m_cNotificationPersistFilepath; ///< Persistent file path for storing persistent data
509 std::string m_cNotificationUserMemFilepath; ///< Memory location of a file for storing persistent data of a user
511 Persist_Type m_mPersist_Type; ///< Map holds the objects of file and folder persistency.
513 CPersistentAccesser *m_poDataAccesser; ///< Object for persistent data accesser
515 HANDLE m_hNSImmediatePersistenceThread; ///< Nor persistence thread handle
517 BOOL m_bAllFilePersisted; // all files have been persisted
519 BOOL m_bImmediatedDataPersisted; // all immediate peristence data have been persisted
521 EFrameworkunifiedStatus Init();
524 ////////////////////////////////////////////////////////////////////////////////////////////
525 /// NPServiceOnCpWorkerAckCmd
526 /// Handles when the CopyWorker sends an ack back for a message received .
528 /// \param [in] f_happ
529 /// HANDLE - Handle to notificationpersistentservice_application Framework.
532 /// EFrameworkunifiedStatus - success or error
533 ////////////////////////////////////////////////////////////////////////////////////////////
534 EFrameworkunifiedStatus NPServiceOnCpWorkerAckCmd(HANDLE f_happ);
536 #endif // NOTIFICATION_PERSISTENT_SERVICE_SERVER_INCLUDE_NS_NPP_PERSISTENCE_MANAGER_H_