Init basesystem source codes.
[staging/basesystem.git] / nsframework / notification_persistent_service / server / src / ns_npp.cpp
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_NS_NPPService
19 /// \brief
20 ///
21 ///
22 ///
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24
25 ////////////////////////////////////////////////////////////////////////////////////////////////////
26 // Include Files
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
28 #include <time.h>
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <stdlib.h>
32 #include <dirent.h>
33 #include <sys/stat.h>
34 #include <sys/timeb.h>
35 #include <sys/types.h>
36
37 #include <native_service/frameworkunified_sm_leafstate.h>
38 #include <native_service/frameworkunified_multithreading.h>
39 #include <native_service/ns_np_service_protocol.h>
40
41 #include <string>
42 #include <vector>
43
44 #include <native_service/ns_np_service_nor_persistence_internal.h>
45 #include "app_states.h"
46 #include "ns_npp.h"
47 #include "ns_npp_types.h"
48 #include "ns_npp_notificationpersistentservicelog.h"
49 #include "ns_npp_threads.h"
50 #include "ns_npp_copy_worker.h"
51 #include "ns_npp_fs_directory.h"
52 #include "ns_npp_persist_folder.h"
53 #include "ns_npp_persistent_data.h"
54 #include "ns_npp_persistence_manager.h"
55 #include "ns_npp_notification_manager.h"
56 #include "ns_npp_personalization_manager.h"
57 #include "ns_npp_nor_persistence_worker_thread.h"
58
59 #define NPP_VERSION_INVALID     255
60 #define NPP_VERSION_0           0
61 #define NPP_VERSION_1           1
62
63 #define NPP_CONNECT_DEFAULTSTATE(parent, child) \
64     FrameworkunifiedConnect(l_p## parent, l_p## child, TRUE);
65
66 #define NPP_CONNECT_STATE(parent, child) \
67     FrameworkunifiedConnect(l_p## parent, l_p## child);
68
69 #define NPP_CONNECT_DEFERREDEVENT(state, eventid, reaction) \
70     FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn## reaction, #eventid, TRUE); \
71
72 #define NPP_CONNECT_EVENT(state, eventid, reaction) \
73     FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn## reaction, #eventid);
74
75 #define NPP_CONNECTROOT(state) \
76     FrameworkunifiedConnect(l_p## state);
77
78 #define NPP_CONNECT_ORTHOGONAL_REGION(orthogonalstate, orthogonalregion) \
79     FrameworkunifiedConnectOrthogonal(l_p## orthogonalstate, l_p## orthogonalregion);
80
81 #define NPP_CREATE_STATE(class_name) \
82     C## class_name *l_p## class_name = new (std::nothrow) C## class_name(#class_name);
83
84 #define NPP_PRINTSTATEMACHINE() \
85     FrameworkunifiedPrintAllStates();
86
87 // typedef of vector of CNotificationsToPersist
88 typedef std::vector<CNotificationsToPersist *> Persistent_Notification_List_Type;
89
90 // iterator for CNotificationsToPersist vector
91 typedef Persistent_Notification_List_Type::iterator Persistent_Notification_List_Iterator;
92
93 // initialize static variables
94 SI_32 CNSNPP::m_siWriteThreadPrio = NS_NPP_WRITE_THREAD_PRIO;
95 SI_32 CNSNPP::m_siReadThreadPrio = NS_NPP_READ_THREAD_PRIO;
96 SI_32 CNSNPP::m_siImmediatePersistenceThreadPrio = NS_NPP_IMMEDIATE_PERSIST_THREAD_PRIO;
97 UI_16 CNSNPP::m_siCRCCheckCount = 0;
98
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 /// CNSNPP
101 /// Class Constructor
102 ////////////////////////////////////////////////////////////////////////////////////////////////////
103 CNSNPP::CNSNPP(PVOID f_happ) : CFrameworkunifiedHSM(f_happ),
104   m_cReadThreadName(NS_NPP_READ_THREAD_NAME),
105   m_cWriteThreadName(NS_NPP_WRITE_THREAD_NAME),
106   m_cImmediatePersistenceThreadName(NS_NPP_IMMEDIATE_PERSIST_THREAD_NAME) {
107   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
108   m_hNSReadThread = NULL;
109   m_hNSWriteThread = NULL;
110   m_hNSImmediatePersistenceThread = NULL;
111
112   m_pNotificationManager = NULL;
113   m_pPersonalizationManager = NULL;
114   m_pPersistenceManager = NULL;
115   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
116 }
117
118 ////////////////////////////////////////////////////////////////////////////////////////////////////
119 /// CNSNPP
120 /// Class Destructor
121 ////////////////////////////////////////////////////////////////////////////////////////////////////
122 CNSNPP::~CNSNPP() {  // LCOV_EXCL_START 200: cannot test code
123   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
124   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
125
126   if (NULL != m_pNotificationManager) {
127     delete m_pNotificationManager;
128     m_pNotificationManager = NULL;
129   }
130
131   if (NULL != m_pPersonalizationManager) {
132     delete m_pPersonalizationManager;
133     m_pPersonalizationManager = NULL;
134   }
135   if (NULL != m_pPersistenceManager) {
136     delete m_pPersistenceManager;
137     m_pPersistenceManager = NULL;
138   }
139
140   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
141 }
142 // LCOV_EXCL_STOP
143
144 ////////////////////////////////////////////////////////////////////////////////////////////////////
145 /// Init
146 /// This function is used to allocate dynamic memory for member variables of this class after
147 /// creation of object.
148 ////////////////////////////////////////////////////////////////////////////////////////////////////
149 EFrameworkunifiedStatus CNSNPP::Init(HANDLE f_happ) {
150   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
151   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
152
153   FrameworkunifiedProtocolEvent ns_npp_internal_protocol_handlers[] = {
154     {CP_WRK_NTFY, EVENT(evNPReleaseLoadAck)}
155   };
156
157   FrameworkunifiedProtocolEvent immediate_thread_protocol_handlers[] = {
158     {NOR_PERSISTENCE_ONSHUTDOWN_ACK, EVENT(evNPNorShutdownAck)},
159   };
160
161   UI_32 l_uiNPPVersion = NPP_VERSION_INVALID;
162
163   // initialize Notification Manager
164   m_pNotificationManager = new(std::nothrow) CNotificationManager();
165   // initialize Personalization Manager
166   m_pPersonalizationManager =  new(std::nothrow) CnotificationpersistentservicePersonalizationManager();
167   // initialize Persistence Manager
168   m_pPersistenceManager = new(std::nothrow) CPersistenceManager();
169
170   if ((NULL == f_happ) || (NULL == m_pNotificationManager) || (NULL == m_pPersonalizationManager) || (NULL == m_pPersistenceManager)) {  // LCOV_EXCL_BR_LINE 5: f_happ, m_pNotificationManager, m_pPersonalizationManager, m_pPersistenceManager can't be NULL  // NOLINT[whitespace/line_length]
171     // LCOV_EXCL_START 5: f_happ, m_pNotificationManager, m_pPersonalizationManager, m_pPersistenceManager can't be NULL
172     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
173     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
174            "f_happ or m_pNotificationManager or m_pPersonalizationManager or  m_pPersistenceManager is NULL");
175
176     l_estatus = eFrameworkunifiedStatusNullPointer;
177     // LCOV_EXCL_STOP
178   } else {
179     if ((eFrameworkunifiedStatusOK != FrameworkunifiedAttachCallbackToDispatcher(  // LCOV_EXCL_BR_LINE 4: NSFW error case
180              f_happ, m_cReadThreadName.c_str(),
181              CP_WRK_ACK_CMD_COMPLETE,
182              NPServiceOnCpWorkerAckCmd))
183         || (eFrameworkunifiedStatusOK != FrameworkunifiedAttachCallbackToDispatcher(
184                 f_happ, m_cWriteThreadName.c_str(),
185                 CP_WRK_ACK_CMD_COMPLETE,
186                 NPServiceOnCpWorkerAckCmd))
187         || (eFrameworkunifiedStatusOK != FrameworkunifiedAttachHSMEventsToDispatcher(
188                 f_happ, m_cWriteThreadName.c_str(),
189                 ns_npp_internal_protocol_handlers,
190                 static_cast<UI_32>(_countof(ns_npp_internal_protocol_handlers))))
191         || (eFrameworkunifiedStatusOK != FrameworkunifiedAttachHSMEventsToDispatcher(
192                 f_happ, m_cReadThreadName.c_str(),
193                 ns_npp_internal_protocol_handlers,
194                 static_cast<UI_32>(_countof(ns_npp_internal_protocol_handlers))))
195         || (eFrameworkunifiedStatusOK != FrameworkunifiedAttachHSMEventsToDispatcher(
196                 f_happ, m_cImmediatePersistenceThreadName.c_str(),
197                 immediate_thread_protocol_handlers,
198                 static_cast<UI_32>(_countof(immediate_thread_protocol_handlers))))) {
199       // LCOV_EXCL_START 4: NSFW error case.
200       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
201       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
202              "Attaching callbacks and events failed for protocols CP_WRK_ACK_CMD_COMPLETE, CP_WRK_NTFY");
203       l_estatus = eFrameworkunifiedStatusFail;
204       // LCOV_EXCL_STOP
205     } else {
206       l_estatus = CreateAndStartChildThreads(f_happ);
207
208       if (eFrameworkunifiedStatusOK == l_estatus) {  // LCOV_EXCL_BR_LINE 4: NSFW error case
209         if (NPP_VERSION_INVALID != (l_uiNPPVersion = GetNSNPPVersion())) {  // LCOV_EXCL_BR_LINE 6: l_uiNPPVersion can't be NPP_VERSION_INVALID  // NOLINT[whitespace/line_length]
210           if (NPP_VERSION_0 == l_uiNPPVersion) {
211             l_estatus = SwitchToFileStructureVersion1(l_uiNPPVersion + 1);
212
213             l_estatus = SwitchToFileStructureVersion2(l_uiNPPVersion + 2);
214           } else if (NPP_VERSION_1 == l_uiNPPVersion) {  // LCOV_EXCL_BR_LINE 200: cannot test code in init sequence
215             // LCOV_EXCL_START 200: cannot test code in init sequence
216             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
217             l_estatus = SwitchToFileStructureVersion2(l_uiNPPVersion + 1);
218
219             // send the message to write worker thread to delete the persistent
220             /// which was requested for deletion during previous shutdown
221             l_estatus = FrameworkunifiedSendChild(f_happ, m_hNSWriteThread, CMD_DELETE_OLD_DATA, 0, NULL);
222             // LCOV_EXCL_STOP
223           } else {
224             // send the message to write worker thread to delete the persistent
225             /// which was requested for deletion during previous shutdown
226             l_estatus = FrameworkunifiedSendChild(f_happ, m_hNSWriteThread, CMD_DELETE_OLD_DATA, 0, NULL);
227           }
228
229           // Try to load persisted notification data
230           NotificationpersistentserviceLoadPersistentNotificationData(eFrameworkunifiedPersistedStateVar);
231
232           // load immediate persistence data as the respective thread is now started.
233           NotificationpersistentserviceLoadPersistentNotificationData(eFrameworkunifiedImmediatePersistedStateVar);
234         } else {
235           // LCOV_EXCL_START 6: l_uiNPPVersion can't be NPP_VERSION_INVALID
236           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
237           l_estatus = eFrameworkunifiedStatusFail;
238           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid version of NPPService");
239           // LCOV_EXCL_STOP
240         }
241       } else {
242         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
243         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error in creating child threads of NPPService");  // LCOV_EXCL_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
244       }
245     }
246   }
247
248   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
249   return l_estatus;
250 }
251
252 ////////////////////////////////////////////////////////////////////////////////////////////////////
253 /// DeInit
254 /// This function is used to deinitialize the NPP object
255 ////////////////////////////////////////////////////////////////////////////////////////////////////
256 VOID CNSNPP::DeInit(HANDLE f_happ) {  // LCOV_EXCL_START 200: cannot test code
257   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
258   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
259
260   if (NULL != m_pNotificationManager) {
261     delete m_pNotificationManager;
262     m_pNotificationManager = NULL;
263   }
264
265   if (NULL != m_pPersonalizationManager) {
266     delete m_pPersonalizationManager;
267     m_pPersonalizationManager = NULL;
268   }
269
270   if (NULL != m_pPersistenceManager) {
271     delete m_pPersistenceManager;
272     m_pPersistenceManager = NULL;
273   }
274
275   if (NULL != f_happ) {
276     EFrameworkunifiedStatus eStatus;
277
278     if (NULL != m_hNSReadThread) {
279       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedStopChildThread(f_happ, m_hNSReadThread, 0, NULL))) {
280         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedStopChildThread Read Thread Failed. status=%d", eStatus);
281       }
282       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroyChildThread(f_happ, m_hNSReadThread))) {
283         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedDestroyChildThread Read Thread Failed. status=%d", eStatus);
284       }
285       m_hNSReadThread = NULL;
286     }
287
288     if (NULL != m_hNSWriteThread) {
289       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedStopChildThread(f_happ, m_hNSWriteThread, 0, NULL))) {
290         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedStopChildThread Write Thread Failed. status=%d", eStatus);
291       }
292       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroyChildThread(f_happ, m_hNSWriteThread))) {
293         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedDestroyChildThread Write Thread Failed. status=%d", eStatus);
294       }
295       m_hNSWriteThread = NULL;
296     }
297
298     if (NULL != m_hNSImmediatePersistenceThread) {
299       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedStopChildThread(f_happ, m_hNSImmediatePersistenceThread, 0, NULL))) {
300         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedStopChildThread ImmidatePersistence Thread Failed. status=%d", eStatus);
301       }
302       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroyChildThread(f_happ, m_hNSImmediatePersistenceThread))) {
303         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedDestroyChildThread ImmidatePersistence Thread Failed. status=%d", eStatus);
304       }
305       m_hNSImmediatePersistenceThread = NULL;
306     }
307   }
308
309   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
310 }
311 // LCOV_EXCL_STOP
312
313 ////////////////////////////////////////////////////////////////////////////////////////////////
314 /// SwitchToFileStructureVersion1
315 /// Copy all the user data from old persistent path to new persistent path i.e. UserData folder
316 ////////////////////////////////////////////////////////////////////////////////////////////////
317 EFrameworkunifiedStatus CNSNPP::SwitchToFileStructureVersion1(const UI_32 f_uinppversion) {
318   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
319   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
320
321   std::string l_cSrcPath = "";
322   std::string l_cDestPath = "";
323
324   std::string l_cNSNPSPath = CPersistence::GetStoragePath();
325   std::string l_cUserDataPath = "";
326
327   if (CFSDirectory::DoesDirecotryExist(l_cNSNPSPath)) {  // LCOV_EXCL_BR_LINE 6: l_cNSNPSPath must exist
328     DIR *l_pdir = NULL;
329
330     struct dirent *l_pdirent = NULL;
331
332     l_pdir = opendir(l_cNSNPSPath.c_str());
333
334     if (NULL != l_pdir) {  // LCOV_EXCL_BR_LINE 4: NSFW error case
335       if (l_cNSNPSPath[l_cNSNPSPath.length() - 1] != '/') {  // LCOV_EXCL_BR_LINE 6: l_cNSNPSPath must has '/'
336         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
337         l_cNSNPSPath.append("/");  // LCOV_EXCL_LINE 6: l_cNSNPSPath must has '/'
338       }
339
340       // set the userdata folder path
341       l_cUserDataPath.assign(l_cNSNPSPath);
342       l_cUserDataPath.append(USERDATADIR);
343       l_cUserDataPath.append(ALLUSERAPPDATADIR);
344
345       // create the userdata directory
346       if (!CFSDirectory::DoesDirecotryExist(l_cUserDataPath)) {
347         l_estatus = CFSDirectory::CreateDirectory(l_cUserDataPath);
348       }
349
350       // if directory successfully created or is already present on target
351       if (eFrameworkunifiedStatusOK == l_estatus) {  // LCOV_EXCL_BR_LINE 6: l_estatus must be eFrameworkunifiedStatusOK
352         while (NULL != (l_pdirent = readdir(l_pdir))) {
353           if (0 != std::strcmp(l_pdirent->d_name, ".") &&
354               0 != std::strcmp(l_pdirent->d_name, "..") &&
355               0 != std::strcmp(l_pdirent->d_name, AppName) &&
356               0 != std::strcmp(l_pdirent->d_name, USERDATA)) {
357             l_cSrcPath.assign(l_cNSNPSPath.c_str());
358             l_cSrcPath.append(l_pdirent->d_name);
359
360             if (CFSDirectory::IsDirectory(l_cSrcPath)) {  // LCOV_EXCL_BR_LINE 6: cannot test in init sequence
361               l_cDestPath.assign(l_cUserDataPath);
362               l_cDestPath.append(l_pdirent->d_name);
363
364               // move the old app user data to the UserData fodler
365               if (0 != rename(l_cSrcPath.c_str(), l_cDestPath.c_str())) {  // LCOV_EXCL_BR_LINE 6: rename must return ok  // NOLINT[whitespace/line_length]
366                 // LCOV_EXCL_START 6: rename must return ok
367                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
368                 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error renaming folder %s to %s",
369                        l_cSrcPath.c_str(), l_cDestPath.c_str());
370                 // LCOV_EXCL_STOP
371               }
372             }
373           }
374         }
375       } else {
376         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
377         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to create directory:: %s", l_cDestPath.c_str());  // LCOV_EXCL_LINE 6: l_estatus must be eFrameworkunifiedStatusOK  // NOLINT[whitespace/line_length]
378       }
379
380       closedir(l_pdir);  // close the directory
381     } else {
382       // LCOV_EXCL_START 4: NSFW error case
383       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
384       l_estatus = eFrameworkunifiedStatusNullPointer;
385       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pdir is NULL");
386       // LCOV_EXCL_STOP
387     }
388   }
389
390   l_estatus = SetNSNPPVersion(static_cast<UI_8>(f_uinppversion));
391
392   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
393   return l_estatus;
394 }
395
396 ////////////////////////////////////////////////////////////////////////////////////////////////
397 /// SwitchToFileStructureVersion2
398 /// Move immediate notification data files from IMMEDIATE_PERSISTENCE_STORAGE_V1 to
399 /// IMMEDIATE_PERSISTENCE_STORAGE_V2/AllUserAppData/UserData
400 //// ////////////////////////////////////////////////////////////////////////////////////////////
401 EFrameworkunifiedStatus CNSNPP::SwitchToFileStructureVersion2(const UI_32 f_uinppversion) {
402   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
403   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
404
405   // immediate notification persistent path for NPPService version 1
406   std::string l_cSrcDir = IMMEDIATE_PERSISTENCE_STORAGE_V1;
407
408   // immediate notification persistent path for NPPService version 2
409   std::string l_cDestDir = IMMEDIATE_PERSISTENCE_STORAGE_V2;
410   l_cDestDir.append(USERDATADIR);
411   l_cDestDir.append(ALLUSERAPPDATADIR);
412   l_cDestDir.append(IMMEDIATEDATADIR);
413
414   if (eFrameworkunifiedStatusOK == (l_estatus = SynchronousMovePersistentData(l_cSrcDir.c_str(), l_cDestDir.c_str()))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
415     if (!CFSDirectory::RemoveDirectory(l_cSrcDir)) {  // LCOV_EXCL_BR_LINE 6: cannot test in init sequence
416       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Error deleting old immediate pers. dir %s", l_cSrcDir.c_str());
417     }
418
419     l_estatus = SetNSNPPVersion(static_cast<UI_8>(f_uinppversion));
420   } else {
421     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
422     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "SynchronousMovePersistentData faiure, status=%d", l_estatus);  // LCOV_EXCL_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
423   }
424
425   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
426   return l_estatus;
427 }
428
429 ///////////////////////////////////////////////////////////////////////////////////////////
430 /// GetNSNPPVersion
431 /// Get the version of NSNPP from version.txt
432 ///////////////////////////////////////////////////////////////////////////////////////////
433 UI_32 CNSNPP::GetNSNPPVersion() {
434   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
435
436   UI_32 l_uiVersion = NPP_VERSION_INVALID;
437   CHAR l_cVerStr[3] = {};
438   FILE *l_pFile = NULL;
439
440   std::string l_cVersion = CPersistence::GetStoragePath();
441   if (l_cVersion[l_cVersion.length() - 1] != '/') {  // LCOV_EXCL_BR_LINE 6: must has '/'
442     l_cVersion += "/";
443   }
444   l_cVersion.append(VERSION_TXT);
445
446   if (NULL != (l_pFile = fopen(l_cVersion.c_str(), "r"))) {
447     // read the version from file
448     if (NULL == fgets(l_cVerStr, 2, l_pFile)) {  // LCOV_EXCL_BR_LINE 6: can't return NULL
449       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
450       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "File empty: %s", l_cVersion.c_str());  // LCOV_EXCL_LINE 6: can't return NULL
451     } else {
452       errno = EOK;
453       l_uiVersion = static_cast<UI_32>(strtol(l_cVerStr, NULL, 10));
454
455       if (EOK != errno) {  // LCOV_EXCL_BR_LINE 6: errno always is EOK
456         // LCOV_EXCL_START 6: errno always is EOK
457         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
458         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error converting string %s to hex, errno=%d", l_cVerStr, errno);
459         l_uiVersion = NPP_VERSION_0;
460         // LCOV_EXCL_STOP
461       }
462     }
463
464     fclose(l_pFile);
465   } else {
466     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to open file: %s, errno=%d", l_cVersion.c_str(), errno);
467     l_uiVersion = NPP_VERSION_0;
468   }
469
470   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
471   return l_uiVersion;
472 }
473 ///////////////////////////////////////////////////////////////////////////////////////////
474 /// Syncfs
475 /// Syncfs is carried out.
476 ///
477 /// \param
478 ///
479 /// \return EFrameworkunifiedStatus
480 ///         EFrameworkunifiedStatus - Returns status of operation
481 ///
482 ///////////////////////////////////////////////////////////////////////////////////////////
483 EFrameworkunifiedStatus  CNSNPP::Syncfs() {
484   int dfd;
485
486   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
487   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
488
489   std::string l_cPath = CPersistence::GetStoragePath();
490
491   // create the file
492   dfd = open(l_cPath.c_str(), O_RDONLY | O_DIRECTORY);
493   if (-1 != dfd) {
494     // syncfs()
495     if (syncfs(dfd) < 0) {  // LCOV_EXCL_BR_LINE 5: syncfs's error case.
496       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
497       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to syncfs: %s errno=%d", l_cPath.c_str(), errno);  // LCOV_EXCL_LINE 5: syncfs's error case.  // NOLINT[whitespace/line_length]
498     }
499     close(dfd);
500   } else {
501     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to open file: %s serrno=%d", l_cPath.c_str(), errno);
502     l_estatus = eFrameworkunifiedStatusNullPointer;
503   }
504
505   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
506   return l_estatus;
507 }
508 ///////////////////////////////////////////////////////////////////////////////////////////
509 /// SetNSNPPVersion
510 /// Set the version of NSNPP in version.txt
511 ///////////////////////////////////////////////////////////////////////////////////////////
512 EFrameworkunifiedStatus CNSNPP::SetNSNPPVersion(UI_8 f_uiversion) {
513   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
514   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
515
516   FILE *l_pFile = NULL;
517
518   std::string l_cVersion = CPersistence::GetStoragePath();
519   if (l_cVersion[l_cVersion.length() - 1] != '/') {  // LCOV_EXCL_BR_LINE 6: must has '/'
520     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
521     l_cVersion += "/";  // LCOV_EXCL_LINE 6: must has '/'
522   }
523   if (!CFSDirectory::DoesDirecotryExist(l_cVersion)) {
524     CFSDirectory::CreateDirectory(l_cVersion);
525   }
526
527   l_cVersion.append(VERSION_TXT);
528
529   // create the file and write
530   l_pFile = fopen(l_cVersion.c_str(), "w");
531   if (NULL != l_pFile) {  // LCOV_EXCL_BR_LINE 6: l_pFile can't be NULL
532     // write the version to file
533     fprintf(l_pFile, "%d", f_uiversion);
534     fclose(l_pFile);
535   } else {
536     // LCOV_EXCL_START 6: l_pFile can't be NULL
537     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
538     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to open file: %s", l_cVersion.c_str());
539     l_estatus = eFrameworkunifiedStatusNullPointer;
540     // LCOV_EXCL_STOP
541   }
542
543   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
544   return l_estatus;
545 }
546
547 ////////////////////////////////////////////////////////////////////////////////////////////////////
548 /// FrameworkunifiedCreate
549 /// In this function, states and events of StateMachine are created and connected.
550 ////////////////////////////////////////////////////////////////////////////////////////////////////
551 EFrameworkunifiedStatus CNSNPP::FrameworkunifiedCreate(PVOID f_peventdata) {
552   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
553   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
554
555   // ========Create states
556   NPP_CREATE_STATE(sNotificationpersistentserviceNPPRoot)
557   NPP_CREATE_STATE(sNotificationpersistentserviceNPPStart)
558   NPP_CREATE_STATE(sNotificationpersistentserviceNPPError)
559
560   CREATE_ORTHOGONALREGION(sNotificationpersistentservicePersistence)
561   CREATE_ORTHOGONALREGION(sNotificationpersistentserviceShutdown)
562   CREATE_ORTHOGONALREGION(sNotificationpersistentserviceNotification)
563
564   NPP_CREATE_STATE(sNotificationpersistentservicePersistenceReady)
565   NPP_CREATE_STATE(sNotificationpersistentservicePersistenceError)
566
567   NPP_CREATE_STATE(sNotificationpersistentserviceNotificationReady)
568   NPP_CREATE_STATE(sNotificationpersistentserviceNotificationError)
569
570   NPP_CREATE_STATE(sNotificationpersistentserviceShutdownIdle)
571   NPP_CREATE_STATE(sNotificationpersistentserviceShutdownDataSave)
572
573   // ========Connect states
574   NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentserviceNPPRoot, sNotificationpersistentserviceNPPStart)
575   NPP_CONNECT_STATE(sNotificationpersistentserviceNPPRoot, sNotificationpersistentserviceNPPStart)
576   NPP_CONNECT_STATE(sNotificationpersistentserviceNPPRoot, sNotificationpersistentserviceNPPError)
577
578   NPP_CONNECT_ORTHOGONAL_REGION(sNotificationpersistentserviceNPPStart, sNotificationpersistentservicePersistence)
579   NPP_CONNECT_ORTHOGONAL_REGION(sNotificationpersistentserviceNPPStart, sNotificationpersistentserviceShutdown)
580   NPP_CONNECT_ORTHOGONAL_REGION(sNotificationpersistentserviceNPPStart, sNotificationpersistentserviceNotification)
581
582   NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentservicePersistence, sNotificationpersistentservicePersistenceReady)
583   NPP_CONNECT_STATE(sNotificationpersistentservicePersistence, sNotificationpersistentservicePersistenceError)
584
585   NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentserviceShutdown, sNotificationpersistentserviceShutdownIdle)
586   NPP_CONNECT_STATE(sNotificationpersistentserviceShutdown, sNotificationpersistentserviceShutdownDataSave)
587
588   NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentserviceNotification, sNotificationpersistentserviceNotificationReady)
589   NPP_CONNECT_STATE(sNotificationpersistentserviceNotification, sNotificationpersistentserviceNotificationError)
590
591   // ========Create external transitions
592   CREATE_EXTERNALTRANSITION(sNotificationpersistentserviceNPPStart)
593   CREATE_EXTERNALTRANSITION(sNotificationpersistentserviceNPPError)
594   CREATE_EXTERNALTRANSITION(sNotificationpersistentservicePersistenceReady)
595   CREATE_EXTERNALTRANSITION(sNotificationpersistentservicePersistenceError)
596   CREATE_EXTERNALTRANSITION(sNotificationpersistentserviceShutdownIdle)
597   CREATE_EXTERNALTRANSITION(sNotificationpersistentserviceShutdownDataSave)
598   CREATE_EXTERNALTRANSITION(sNotificationpersistentserviceNotificationReady)
599   CREATE_EXTERNALTRANSITION(sNotificationpersistentserviceNotificationError)
600
601   // ========Create internal transitions
602   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPReadPersistedData)
603   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPReleaseFileAck)
604   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnUserChange)
605   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPNorDataSaveAck)
606   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnRegisterPersistentFile)
607   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnReleasePersistentFile)
608   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnLoadPersistentFile)
609   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnRegisterPersistentFolder)
610   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnLoadPersistentFolder)
611   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnReleasePersistentFolder)
612   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPSetFilePersistentType)
613   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPSetFolderPersistentType)
614   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPPersistentSync)
615
616   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPShutdown)
617   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnShutdownTimeout)
618   CREATE_INTERNALTRANSITION(NotificationpersistentserviceCheckAllReleaseRequestsProcessed)
619
620   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPPublishNotification)
621   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPRegisterNotifications)
622   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPSubscribeToNotification)
623   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPSubscribeToNotifications)
624   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPUnRegisterNotifications)
625   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPUnSubscribeFromNotification)
626   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPUnSubscribeFromNotifications)
627   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPGetReadyStatus)
628   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPRegisterImmediateNotifications)
629   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPClearPersistedData)
630   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPSetDefaultPersistentData)
631   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPSetNotfnPersistentType)
632   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPPublishImmediateNotification)
633
634 #ifdef NPP_PROFILEINFO_ENABLE
635
636   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPProfileNotifications)
637   CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPProfilePersistence)
638
639   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPProfileNotification, NotificationpersistentserviceOnNPProfileNotifications)
640   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPProfilePersistence, NotificationpersistentserviceOnNPProfilePersistence)
641
642 #endif
643
644   // ========Connect events
645   NPP_CONNECT_EVENT(sNotificationpersistentserviceNPPRoot, evNPClearPersistedData, NotificationpersistentserviceOnNPClearPersistedData)
646
647   NPP_CONNECT_EVENT(sNotificationpersistentserviceNPPStart, evError, sNotificationpersistentserviceNPPError)
648   NPP_CONNECT_EVENT(sNotificationpersistentserviceNPPError, evReady, sNotificationpersistentserviceNPPStart)
649
650   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evError, sNotificationpersistentservicePersistenceError)
651   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceError, evReady, sNotificationpersistentservicePersistenceReady)
652   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPReadPersistedData, NotificationpersistentserviceOnNPReadPersistedData)
653   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPReleaseLoadAck, NotificationpersistentserviceOnNPReleaseFileAck)
654   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPRegisterPersistentFile, NotificationpersistentserviceOnRegisterPersistentFile)
655   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPReleasePersistentFile, NotificationpersistentserviceOnReleasePersistentFile)
656   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPLoadPersistentFile, NotificationpersistentserviceOnLoadPersistentFile)
657   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPRegisterPersistentFolder, NotificationpersistentserviceOnRegisterPersistentFolder)
658   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPLoadPersistentFolder, NotificationpersistentserviceOnLoadPersistentFolder)
659   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPReleasePersistentFolder, NotificationpersistentserviceOnReleasePersistentFolder)
660   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPGetReadyStatus, NotificationpersistentserviceOnNPGetReadyStatus)
661   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPSetFilePersistentType, NotificationpersistentserviceOnNPSetFilePersistentType)
662   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPSetFolderPersistentType, NotificationpersistentserviceOnNPSetFolderPersistentType)
663   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPPersistentSync, NotificationpersistentserviceOnNPPersistentSync)
664
665   NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evUserChange, NotificationpersistentserviceOnUserChange)
666
667   NPP_CONNECT_EVENT(sNotificationpersistentserviceShutdownIdle, evShutdown, NotificationpersistentserviceOnNPShutdown)
668   NPP_CONNECT_EVENT(sNotificationpersistentserviceShutdownIdle, evNPShutdownDataSave, sNotificationpersistentserviceShutdownDataSave)
669   NPP_CONNECT_EVENT(sNotificationpersistentserviceShutdownDataSave, evIdle, sNotificationpersistentserviceShutdownIdle)
670   NPP_CONNECT_EVENT(sNotificationpersistentserviceShutdownDataSave, evShutdownTimeout, NotificationpersistentserviceOnShutdownTimeout)
671   NPP_CONNECT_EVENT(sNotificationpersistentserviceShutdownDataSave, evCheckAllFilesPersisted, NotificationpersistentserviceCheckAllReleaseRequestsProcessed)
672   NPP_CONNECT_EVENT(sNotificationpersistentserviceShutdownDataSave, evNPNorShutdownAck, NotificationpersistentserviceOnNPNorDataSaveAck)
673
674   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evError, sNotificationpersistentserviceNotificationError)
675   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationError, evReady, sNotificationpersistentserviceNotificationReady)
676   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPPublishNotification, NotificationpersistentserviceOnNPPublishNotification)
677   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPRegisterNotifications, NotificationpersistentserviceOnNPRegisterNotifications)
678   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPSubscribeToNotification, NotificationpersistentserviceOnNPSubscribeToNotification)
679   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPSubscribeToNotifications, NotificationpersistentserviceOnNPSubscribeToNotifications)
680   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPUnRegisterNotifications, NotificationpersistentserviceOnNPUnRegisterNotifications)
681   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPUnSubscribeFromNotification, NotificationpersistentserviceOnNPUnSubscribeFromNotification)
682   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPUnSubscribeFromNotifications, NotificationpersistentserviceOnNPUnSubscribeFromNotifications)
683   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPRegisterImmediateNotifications, NotificationpersistentserviceOnNPRegisterImmediateNotifications)
684   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPSetDefaultPersistentData, NotificationpersistentserviceOnNPSetDefaultPersistentData)
685   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPSetNotfnPersistentType, NotificationpersistentserviceOnNPSetNotfnPersistentType)
686   NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPPublishImmediateNotification, NotificationpersistentserviceOnNPPublishImmediateNotification)
687
688   NPP_CONNECTROOT(sNotificationpersistentserviceNPPRoot)
689
690   NPP_PRINTSTATEMACHINE() // NOLINT (whitespace/empty_if_body)
691
692   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
693   return l_estatus;
694 }
695
696 ////////////////////////////////////////////////////////////////////////////////////////////////////
697 /// NotificationpersistentservicePersistAll
698 ///
699 ////////////////////////////////////////////////////////////////////////////////////////////////////
700 EFrameworkunifiedStatus CNSNPP::NotificationpersistentservicePersistAll(EFrameworkunifiedShutdownType f_eshutdowntype, UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
701   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
702
703   if (eFrameworkunifiedQuickShutdown == f_eshutdowntype) {
704     if (NULL != m_pPersistenceManager) {   // LCOV_EXCL_BR_LINE 6: m_pPersistenceManager can't be NULL
705       // set all file persisted status as TRUE
706       m_pPersistenceManager->SetFilePersistedStatus(TRUE);
707
708       // send request to immediate persistence thread to stop all the immediate notification timer
709       m_pPersistenceManager->PersistNORData(f_eshutdowntype, f_uinotificationpersistentservicepersistcategoryflag);
710     }
711   } else {
712     if (eFrameworkunifiedNormalShutdown == f_eshutdowntype) {
713       f_uinotificationpersistentservicepersistcategoryflag = 0x0;
714     }
715
716     // save global notification data of persisted state notification
717     if (eFrameworkunifiedStatusOK != NotificationpersistentserviceSaveNotificationPersistentData(eFrameworkunifiedPersistedStateVar, f_uinotificationpersistentservicepersistcategoryflag)) {  // LCOV_EXCL_BR_LINE 6: NotificationpersistentserviceSaveNotificationPersistentData will always return ok  // NOLINT[whitespace/line_length]
718       // LCOV_EXCL_START 6: NotificationpersistentserviceSaveNotificationPersistentData will always return ok
719       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
720       l_estatus = eFrameworkunifiedStatusFail;
721       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error while saving notification persistent data.");
722       // LCOV_EXCL_STOP
723     }
724
725     // save user notification data for the current user
726     if (eFrameworkunifiedStatusOK != NotificationpersistentserviceSaveNotificationPersistentData(eFrameworkunifiedPersistedStateUserVar, f_uinotificationpersistentservicepersistcategoryflag)) {  // LCOV_EXCL_BR_LINE 6: NotificationpersistentserviceSaveNotificationPersistentData will always return ok  // NOLINT[whitespace/line_length]
727       // LCOV_EXCL_START 6: NotificationpersistentserviceSaveNotificationPersistentData will always return ok
728       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
729       l_estatus = eFrameworkunifiedStatusFail;
730       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error while saving user notification persistent data.");
731       // LCOV_EXCL_STOP
732     }
733
734     // NOR data is saved immediately,
735     // but during shutdown it can be possible that because of delay in consecutive save to NOR
736     // the latest data may not get persisted. So if we get shutdown we will need to persist the data immediately.
737     if (NULL != m_pPersistenceManager) {  // LCOV_EXCL_BR_LINE 6: m_pPersistenceManager can't be NULL
738       m_pPersistenceManager->PersistNORData(f_eshutdowntype, f_uinotificationpersistentservicepersistcategoryflag);
739     }
740
741     // delete all persistent files and folders for all applications
742     if ((eFrameworkunifiedUserData | eFrameworkunifiedFactoryData | eFrameworkunifiedFactoryCustomerData | eFrameworkunifiedDealerData) == f_uinotificationpersistentservicepersistcategoryflag) {
743       if (NULL != m_pPersistenceManager) {  // LCOV_EXCL_BR_LINE 6: m_pPersistenceManager can't be NULL
744         m_pPersistenceManager->SetFilePersistedStatus(TRUE);
745       } else {
746         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
747         l_estatus = eFrameworkunifiedStatusNullPointer;  // LCOV_EXCL_LINE 6: m_pPersistenceManager can't be NULL
748       }
749     } else {
750       // writes the temporary global and user files to permanent memory
751       if (m_pPersistenceManager) {  // LCOV_EXCL_BR_LINE 6: m_pPersistenceManager can't be NULL
752         if (eFrameworkunifiedStatusOK == m_pPersistenceManager->PersistAllReleaseRequests(f_uinotificationpersistentservicepersistcategoryflag)) {  // LCOV_EXCL_BR_LINE 6: PersistAllReleaseRequests will always return ok  // NOLINT[whitespace/line_length]
753           // this is needed to check in case when there are no file to persist
754           if (TRUE == m_pPersistenceManager->HaveAllReleaseRequestsPersisted()) {  // LCOV_EXCL_BR_LINE 6: HaveAllReleaseRequestsPersisted will always return ok  // NOLINT[whitespace/line_length]
755             // LCOV_EXCL_START 6: HaveAllReleaseRequestsPersisted will always return ok
756             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
757             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "All file release requests processed");
758             m_pPersistenceManager->SetFilePersistedStatus(TRUE);
759             // LCOV_EXCL_STOP
760           }
761         } else {
762           // LCOV_EXCL_START 6: PersistAllReleaseRequests will always return ok
763           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
764           l_estatus = eFrameworkunifiedStatusFail;
765           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error while persisting temporary files.");
766           // LCOV_EXCL_STOP
767         }
768       }
769     }
770   }
771
772   return l_estatus;
773 }
774
775 ////////////////////////////////////////////////////////////////////////////////////////////////////
776 /// DeletePersistedDataFolder
777 ////////////////////////////////////////////////////////////////////////////////////////////////////
778 EFrameworkunifiedStatus CNSNPP::DeletePersistedDataFolder(UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
779   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
780   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
781
782   struct timeb timebuf;
783   struct tm   *theTime;
784
785   ftime(&timebuf);
786   theTime = gmtime(&timebuf.time); // NOLINT (runtime/threadsafe_fn)
787
788   // get the current date and time to append to the folder name
789   PCHAR l_cDateTime = new CHAR[MAX_STRING_SIZE_TAG];
790   snprintf(l_cDateTime, MAX_STRING_SIZE_TAG, "_%02d%02d%02d_%02d%02d%02d", theTime->tm_mon + 1, theTime->tm_mday,
791            theTime->tm_year + 1900, theTime->tm_hour, theTime->tm_min, theTime->tm_sec);
792
793   std::string l_cBasePath = CPersistence::GetStoragePath();
794   std::string l_cSrcPath = "";
795   std::string l_cDestPath = "";
796
797   if (eFrameworkunifiedUserData == (eFrameworkunifiedUserData & f_uinotificationpersistentservicepersistcategoryflag)) {
798     l_cSrcPath.assign(l_cBasePath);
799     l_cSrcPath.append(USERDATA);
800
801     if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
802       l_cDestPath.assign(l_cSrcPath);
803       l_cDestPath.append(l_cDateTime);
804
805       // instead of deleting the data, rename the persistence folder before shutdown
806       if (0 != rename(l_cSrcPath.c_str(), l_cDestPath.c_str())) {  // LCOV_EXCL_BR_LINE 6: rename must return ok
807         // LCOV_EXCL_START 6: rename must return ok
808         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
809         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
810                "Error renaming folder %s to %s, errno = %d",
811                l_cSrcPath.c_str(),
812                l_cDestPath.c_str(),
813                errno);
814         // LCOV_EXCL_STOP
815       }
816     }
817   }
818   if (eFrameworkunifiedFactoryData == (eFrameworkunifiedFactoryData & f_uinotificationpersistentservicepersistcategoryflag)) {
819     l_cSrcPath.assign(l_cBasePath);
820     l_cSrcPath.append(FACTORYDATA);
821
822     if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
823       l_cDestPath.assign(l_cSrcPath);
824       l_cDestPath.append(l_cDateTime);
825
826       // instead of deleting the data, rename the persistence folder before shutdown
827       if (0 != rename(l_cSrcPath.c_str(), l_cDestPath.c_str())) {  // LCOV_EXCL_BR_LINE 6: rename must return ok
828         // LCOV_EXCL_START 6: rename must return ok
829         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
830         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
831                "Error renaming folder %s to %s, errno = %d",
832                l_cSrcPath.c_str(),
833                l_cDestPath.c_str(),
834                errno);
835         // LCOV_EXCL_STOP
836       }
837     }
838   }
839   if (eFrameworkunifiedFactoryCustomerData == (eFrameworkunifiedFactoryCustomerData & f_uinotificationpersistentservicepersistcategoryflag)) {
840     l_cSrcPath.assign(l_cBasePath);
841     l_cSrcPath.append(FACTORYCUSTOMERDATA);
842
843     if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
844       l_cDestPath.assign(l_cSrcPath);
845       l_cDestPath.append(l_cDateTime);
846
847       // instead of deleting the data, rename the persistence folder before shutdown
848       if (0 != rename(l_cSrcPath.c_str(), l_cDestPath.c_str())) {  // LCOV_EXCL_BR_LINE 6: rename must return ok
849         // LCOV_EXCL_START 6: rename must return ok
850         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
851         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
852                "Error renaming folder %s to %s, errno = %d",
853                l_cSrcPath.c_str(),
854                l_cDestPath.c_str(),
855                errno);
856         // LCOV_EXCL_STOP
857       }
858     }
859   }
860   if (eFrameworkunifiedDealerData == (eFrameworkunifiedDealerData & f_uinotificationpersistentservicepersistcategoryflag)) {
861     l_cSrcPath.assign(l_cBasePath);
862     l_cSrcPath.append(DEALERDATA);
863
864     if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
865       l_cDestPath.assign(l_cSrcPath);
866       l_cDestPath.append(l_cDateTime);
867
868       // instead of deleting the data, rename the persistence folder before shutdown
869       if (0 != rename(l_cSrcPath.c_str(), l_cDestPath.c_str())) {  // LCOV_EXCL_BR_LINE 6: rename must return ok
870         // LCOV_EXCL_START 6: rename must return ok
871         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
872         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
873                "Error renaming folder %s to %s, errno = %d",
874                l_cSrcPath.c_str(),
875                l_cDestPath.c_str(),
876                errno);
877         // LCOV_EXCL_STOP
878       }
879     }
880   }
881
882   if (NULL != l_cDateTime) {  // LCOV_EXCL_BR_LINE 6: l_cDateTime can't be NULL
883     delete[] l_cDateTime;
884     l_cDateTime = NULL;
885   }
886
887   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
888   return l_estatus;
889 }
890
891 ////////////////////////////////////////////////////////////////////////////////////////////////////
892 /// NotificationpersistentserviceSaveNotificationPersistentData
893 /// In this function, all the data related to persistent notification is retrieved from
894 /// notification manager and stored in persistent file by persistent manager.
895 ////////////////////////////////////////////////////////////////////////////////////////////////////
896 EFrameworkunifiedStatus CNSNPP::NotificationpersistentserviceSaveNotificationPersistentData(EFrameworkunifiedNotificationType f_epersistenttype,
897                                                      UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
898   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
899   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
900
901   // pointer of Notification Manager
902   CNotificationManager *l_pNotificationManager = NULL;
903
904   // pointer of Persistence Manager
905   CPersistenceManager *l_pCNotificationpersistentservicePersistenceManager = NULL;
906
907   Persistent_Notification_List_Type *l_vPersistentNotificationList = NULL;
908
909   // get the instance of notification manager
910   l_pNotificationManager = m_pNotificationManager;
911
912   // get the instance of persistence manager
913   l_pCNotificationpersistentservicePersistenceManager = m_pPersistenceManager;
914
915   if (NULL != l_pNotificationManager && NULL != l_pCNotificationpersistentservicePersistenceManager) {  // LCOV_EXCL_BR_LINE 6: l_pNotificationManager and l_pCNotificationpersistentservicePersistenceManager can't be NULL  // NOLINT[whitespace/line_length]
916     // create new vector to retrieve persistent notification data
917     l_vPersistentNotificationList = new(std::nothrow) Persistent_Notification_List_Type();
918
919     if (NULL != l_vPersistentNotificationList) {  // LCOV_EXCL_BR_LINE 5: l_vPersistentNotificationList can't be NULL
920       // get all the persistent notification data in vector from notification manager
921       l_pNotificationManager->NotificationpersistentserviceGetPersistentNotificationData(l_vPersistentNotificationList,
922                                                                f_epersistenttype,
923                                                                f_uinotificationpersistentservicepersistcategoryflag);
924     } else {
925       // LCOV_EXCL_START 5: l_vPersistentNotificationList can't be NULL
926       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
927       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_vPersistentNotificationList is NULL");
928       l_estatus = eFrameworkunifiedStatusNullPointer;
929       // LCOV_EXCL_STOP
930     }
931
932     if (NULL != l_vPersistentNotificationList) {  // LCOV_EXCL_BR_LINE 5: l_vPersistentNotificationList can't be NULL
933       if (eFrameworkunifiedPersistedStateVar == f_epersistenttype) {
934         // save persistent notification data from vector to file
935         l_estatus = l_pCNotificationpersistentservicePersistenceManager->NotificationpersistentserviceSaveNotificationData(l_vPersistentNotificationList);
936       } else if (eFrameworkunifiedPersistedStateUserVar == f_epersistenttype) {  // LCOV_EXCL_BR_LINE 200: f_epersistenttype must be eFrameworkunifiedPersistedStateVar or eFrameworkunifiedPersistedStateUserVar  // NOLINT[whitespace/line_length]
937         l_estatus = l_pCNotificationpersistentservicePersistenceManager->NotificationpersistentserviceSaveUserNotificationData(l_vPersistentNotificationList);
938       } else {
939         // LCOV_EXCL_START 200: f_epersistenttype must be eFrameworkunifiedPersistedStateVar or eFrameworkunifiedPersistedStateUserVar
940         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
941         l_estatus = eFrameworkunifiedStatusFail;
942         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Save data for %d PersistentVarType not supported", f_epersistenttype);
943         // LCOV_EXCL_STOP
944       }
945
946
947       // delete the locally created vector
948       if (!l_vPersistentNotificationList->empty()) {
949         for (UI_32 l_uiCount = 0;
950              l_uiCount < l_vPersistentNotificationList->size();
951              l_uiCount++) {
952           if (NULL != l_vPersistentNotificationList->at(l_uiCount)) {  // LCOV_EXCL_BR_LINE 6: can't be NULL
953             delete l_vPersistentNotificationList->at(l_uiCount);
954           }
955         }
956
957         // clear the vector
958         l_vPersistentNotificationList->clear();
959       }
960
961       delete l_vPersistentNotificationList;
962       l_vPersistentNotificationList = NULL;
963     } else {
964       // LCOV_EXCL_START 5: l_vPersistentNotificationList can't be NULL
965       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
966       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_vPersistentNotificationList is NULL");
967       l_estatus = eFrameworkunifiedStatusNullPointer;
968       // LCOV_EXCL_STOP
969     }
970   } else {
971     // LCOV_EXCL_START 6: l_pNotificationManager and l_pCNotificationpersistentservicePersistenceManager can't be NULL
972     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
973     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pNotificationManager is NULL");
974     l_estatus = eFrameworkunifiedStatusNullPointer;
975     // LCOV_EXCL_STOP
976   }
977
978
979   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
980   return l_estatus;
981 }
982
983 ////////////////////////////////////////////////////////////////////////////////////////////////////
984 /// NotificationpersistentserviceOnLoadPersistentData
985 /// In this transition, persistent file is loaded by persistent manager and
986 /// persistent notifications and its data is stored by notification manager.
987 ////////////////////////////////////////////////////////////////////////////////////////////////////
988 EFrameworkunifiedStatus CNSNPP::NotificationpersistentserviceLoadPersistentNotificationData(EFrameworkunifiedNotificationType f_epersistenttype) {
989   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
990   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
991
992   // pointer of Notification Manager
993   CNotificationManager *l_pNotificationManager = NULL;
994
995   // pointer of Persistence Manager
996   CPersistenceManager *l_pNotificationpersistentservicePersistenceManager = NULL;
997
998   // iterator of CNotificationToPersist vector
999   Persistent_Notification_List_Type *l_vPersistentNotificationList = NULL;
1000
1001   // get the instance of notification manager
1002   l_pNotificationManager = m_pNotificationManager;
1003
1004   // get the instance of persistent manager
1005   l_pNotificationpersistentservicePersistenceManager = m_pPersistenceManager;
1006
1007   // create new vector for persistent notifications
1008   l_vPersistentNotificationList = new(std::nothrow) Persistent_Notification_List_Type();
1009
1010   if (NULL != l_vPersistentNotificationList) {  // LCOV_EXCL_BR_LINE 5: l_vPersistentNotificationList can't be NULL
1011     if (NULL != l_pNotificationManager && NULL != l_pNotificationpersistentservicePersistenceManager) {  // LCOV_EXCL_BR_LINE 6: l_pNotificationManager and l_pNotificationpersistentservicePersistenceManager can't be NULL  // NOLINT[whitespace/line_length]
1012       if (eFrameworkunifiedPersistedStateVar == f_epersistenttype) {
1013         // read persistent notification data from file and store in vector
1014         l_estatus = l_pNotificationpersistentservicePersistenceManager->NotificationpersistentserviceReadNotificationData(l_vPersistentNotificationList);
1015       } else if (eFrameworkunifiedPersistedStateUserVar == f_epersistenttype) {
1016         l_estatus = l_pNotificationpersistentservicePersistenceManager->NotificationpersistentserviceReadUserNotificationData(l_vPersistentNotificationList);
1017       } else if (eFrameworkunifiedImmediatePersistedStateVar == f_epersistenttype) {   // LCOV_EXCL_BR_LINE 200: f_epersistenttype must be eFrameworkunifiedPersistedStateVar or eFrameworkunifiedPersistedStateUserVar or eFrameworkunifiedImmediatePersistedStateVar  // NOLINT[whitespace/line_length]
1018         l_estatus = l_pNotificationpersistentservicePersistenceManager->NotificationpersistentserviceReadNorNotificationData(l_vPersistentNotificationList);
1019       } else {
1020         // LCOV_EXCL_START 200: f_epersistenttype must be eFrameworkunifiedPersistedStateVar or eFrameworkunifiedPersistedStateUserVar or eFrameworkunifiedImmediatePersistedStateVar  // NOLINT[whitespace/line_length]
1021         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1022         l_estatus = eFrameworkunifiedStatusFail;
1023         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Read data for %d PersistentVarType not supported", f_epersistenttype);
1024         // LCOV_EXCL_STOP
1025       }
1026
1027       if (0 < l_vPersistentNotificationList->size()) {
1028         // send the notification list to notification manager
1029         l_estatus = l_pNotificationManager->NotificationpersistentserviceSetPersistentNotificationData(l_vPersistentNotificationList);
1030       }
1031     } else {
1032       // LCOV_EXCL_START 6: l_pNotificationManager and l_pNotificationpersistentservicePersistenceManager can't be NULL
1033       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1034       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pNotificationManager or l_pNotificationpersistentservicePersistenceManager is NULL");
1035       l_estatus = eFrameworkunifiedStatusNullPointer;
1036       // LCOV_EXCL_STOP
1037     }
1038
1039     if (!l_vPersistentNotificationList->empty()) {
1040       for (UI_32 l_uiCount = 0;
1041            l_uiCount < l_vPersistentNotificationList->size();
1042            l_uiCount++) {
1043         if (NULL != l_vPersistentNotificationList->at(l_uiCount)) {  // LCOV_EXCL_BR_LINE 6: can't be NULL
1044           delete l_vPersistentNotificationList->at(l_uiCount);
1045         }
1046       }
1047
1048       // clear the vector
1049       l_vPersistentNotificationList->clear();
1050     }
1051
1052     delete l_vPersistentNotificationList;
1053     l_vPersistentNotificationList = NULL;
1054   } else {
1055     // LCOV_EXCL_START 5: l_vPersistentNotificationList can't be NULL
1056     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1057     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory allocation error for l_vPersistentNotificationList");
1058     l_estatus = eFrameworkunifiedStatusNullPointer;
1059     // LCOV_EXCL_STOP
1060   }
1061
1062   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1063   return l_estatus;
1064 }
1065
1066 ////////////////////////////////////////////////////////////////////////////////////////////////////
1067 /// CreateAndStartChildThreads
1068 ///
1069 ////////////////////////////////////////////////////////////////////////////////////////////////////
1070 EFrameworkunifiedStatus CNSNPP::CreateAndStartChildThreads(HANDLE f_happ) {
1071   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1072
1073   if (NULL == f_happ) {  // LCOV_EXCL_BR_LINE 6: f_happ can't be NULL
1074     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1075     l_estatus = eFrameworkunifiedStatusNullPointer;  // LCOV_EXCL_LINE 6: f_happ can't be NULL
1076   }
1077
1078   if (eFrameworkunifiedStatusOK == l_estatus) {  // LCOV_EXCL_BR_LINE 6: l_estatus is eFrameworkunifiedStatusOK
1079     // create reader thread
1080     if (NULL != (m_hNSReadThread = FrameworkunifiedCreateChildThreadWithPriority(f_happ, m_cReadThreadName.c_str(), NSPCopyWorkerOnStart, NSPCopyWorkerOnStop, CNSNPP::m_siReadThreadPrio))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1081       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1082              "Thread %s created, Prio=%d",
1083              m_cReadThreadName.c_str(),
1084              CNSNPP::m_siReadThreadPrio);
1085
1086       // start the reader thread
1087       if (eFrameworkunifiedStatusOK == (l_estatus = FrameworkunifiedStartChildThread(f_happ, m_hNSReadThread, 0, NULL))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1088         m_pPersistenceManager->SetReadThreadHandle(m_hNSReadThread);
1089       } else {
1090         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1091         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Fail to Start Read Worker thread. Status:0x%x", l_estatus);  // LCOV_EXCL_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1092       }
1093     } else {
1094       // LCOV_EXCL_START 4: NSFW error case
1095       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1096       l_estatus = eFrameworkunifiedStatusNullPointer;
1097       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error creating NPP Read Worker thread");
1098       // LCOV_EXCL_STOP
1099     }
1100   }
1101
1102   if (eFrameworkunifiedStatusOK == l_estatus) {  // LCOV_EXCL_BR_LINE 6: l_estatus is eFrameworkunifiedStatusOK
1103     // create writer thread
1104     if (NULL != (m_hNSWriteThread = FrameworkunifiedCreateChildThreadWithPriority(f_happ, m_cWriteThreadName.c_str(), NSPCopyWorkerOnStart, NSPCopyWorkerOnStop, CNSNPP::m_siWriteThreadPrio))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1105       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1106              "Thread %s created, Prio=%d",
1107              m_cWriteThreadName.c_str(),
1108              CNSNPP::m_siWriteThreadPrio);
1109
1110       // start the writer thread
1111       if (eFrameworkunifiedStatusOK == (l_estatus = FrameworkunifiedStartChildThread(f_happ, m_hNSWriteThread, 0, NULL))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1112         m_pPersistenceManager->SetWriteThreadHandle(m_hNSWriteThread);
1113       } else {
1114         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1115         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Fail to Start Write Worker thread. Status:0x%x", l_estatus);  // LCOV_EXCL_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1116       }
1117     } else {
1118       // LCOV_EXCL_START 4: NSFW error case
1119       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1120       l_estatus = eFrameworkunifiedStatusNullPointer;
1121       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error creating NPP Write Worker thread");
1122       // LCOV_EXCL_STOP
1123     }
1124   }
1125
1126   if (eFrameworkunifiedStatusOK == l_estatus) {  // LCOV_EXCL_BR_LINE 6: l_estatus is eFrameworkunifiedStatusOK
1127     // create immediate Persistence thread
1128       if (NULL != (m_hNSImmediatePersistenceThread = FrameworkunifiedCreateChildThreadWithPriority(f_happ, m_cImmediatePersistenceThreadName.c_str(), NSPNorPersistenceWorkerOnStart, NSPNorPersistenceWorkerOnStop, CNSNPP::m_siImmediatePersistenceThreadPrio))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1129       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Thread %s created, Prio=%d", m_cImmediatePersistenceThreadName.c_str(),
1130              CNSNPP::m_siImmediatePersistenceThreadPrio);
1131
1132       // start the immediate Persistence thread
1133       if (eFrameworkunifiedStatusOK == (l_estatus = FrameworkunifiedStartChildThread(f_happ, m_hNSImmediatePersistenceThread, 0, NULL))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1134         m_pPersistenceManager->SetNorPersistenceThreadHandle(m_hNSImmediatePersistenceThread);
1135       } else {
1136         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1137         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Fail to Start immediate persistence thread. Status:0x%x", l_estatus);  // LCOV_EXCL_LINE 4: NSFW error case  // NOLINT[whitespace/line_length]
1138       }
1139     } else {
1140       // LCOV_EXCL_START 4: NSFW error case
1141       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1142       l_estatus = eFrameworkunifiedStatusNullPointer;
1143       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error creating NPP immediate persistence Worker thread");
1144       // LCOV_EXCL_STOP
1145     }
1146   }
1147
1148   return l_estatus;
1149 }