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_NS_NPPService
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
25 ////////////////////////////////////////////////////////////////////////////////////////////////////
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
34 #include <sys/timeb.h>
35 #include <sys/types.h>
37 #include <native_service/frameworkunified_sm_leafstate.h>
38 #include <native_service/frameworkunified_multithreading.h>
39 #include <native_service/ns_np_service_protocol.h>
44 #include <native_service/ns_np_service_nor_persistence_internal.h>
45 #include "app_states.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"
59 #define NPP_VERSION_INVALID 255
60 #define NPP_VERSION_0 0
61 #define NPP_VERSION_1 1
63 #define NPP_CONNECT_DEFAULTSTATE(parent, child) \
64 FrameworkunifiedConnect(l_p## parent, l_p## child, TRUE);
66 #define NPP_CONNECT_STATE(parent, child) \
67 FrameworkunifiedConnect(l_p## parent, l_p## child);
69 #define NPP_CONNECT_DEFERREDEVENT(state, eventid, reaction) \
70 FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn## reaction, #eventid, TRUE); \
72 #define NPP_CONNECT_EVENT(state, eventid, reaction) \
73 FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn## reaction, #eventid);
75 #define NPP_CONNECTROOT(state) \
76 FrameworkunifiedConnect(l_p## state);
78 #define NPP_CONNECT_ORTHOGONAL_REGION(orthogonalstate, orthogonalregion) \
79 FrameworkunifiedConnectOrthogonal(l_p## orthogonalstate, l_p## orthogonalregion);
81 #define NPP_CREATE_STATE(class_name) \
82 C## class_name *l_p## class_name = new (std::nothrow) C## class_name(#class_name);
84 #define NPP_PRINTSTATEMACHINE() \
85 FrameworkunifiedPrintAllStates();
87 // typedef of vector of CNotificationsToPersist
88 typedef std::vector<CNotificationsToPersist *> Persistent_Notification_List_Type;
90 // iterator for CNotificationsToPersist vector
91 typedef Persistent_Notification_List_Type::iterator Persistent_Notification_List_Iterator;
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;
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
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;
112 m_pNotificationManager = NULL;
113 m_pPersonalizationManager = NULL;
114 m_pPersistenceManager = NULL;
115 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
118 ////////////////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
126 if (NULL != m_pNotificationManager) {
127 delete m_pNotificationManager;
128 m_pNotificationManager = NULL;
131 if (NULL != m_pPersonalizationManager) {
132 delete m_pPersonalizationManager;
133 m_pPersonalizationManager = NULL;
135 if (NULL != m_pPersistenceManager) {
136 delete m_pPersistenceManager;
137 m_pPersistenceManager = NULL;
140 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
144 ////////////////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
153 FrameworkunifiedProtocolEvent ns_npp_internal_protocol_handlers[] = {
154 {CP_WRK_NTFY, EVENT(evNPReleaseLoadAck)}
157 FrameworkunifiedProtocolEvent immediate_thread_protocol_handlers[] = {
158 {NOR_PERSISTENCE_ONSHUTDOWN_ACK, EVENT(evNPNorShutdownAck)},
161 UI_32 l_uiNPPVersion = NPP_VERSION_INVALID;
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();
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");
176 l_estatus = eFrameworkunifiedStatusNullPointer;
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;
206 l_estatus = CreateAndStartChildThreads(f_happ);
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);
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);
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);
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);
229 // Try to load persisted notification data
230 NotificationpersistentserviceLoadPersistentNotificationData(eFrameworkunifiedPersistedStateVar);
232 // load immediate persistence data as the respective thread is now started.
233 NotificationpersistentserviceLoadPersistentNotificationData(eFrameworkunifiedImmediatePersistedStateVar);
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");
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]
248 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
252 ////////////////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
260 if (NULL != m_pNotificationManager) {
261 delete m_pNotificationManager;
262 m_pNotificationManager = NULL;
265 if (NULL != m_pPersonalizationManager) {
266 delete m_pPersonalizationManager;
267 m_pPersonalizationManager = NULL;
270 if (NULL != m_pPersistenceManager) {
271 delete m_pPersistenceManager;
272 m_pPersistenceManager = NULL;
275 if (NULL != f_happ) {
276 EFrameworkunifiedStatus eStatus;
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);
282 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroyChildThread(f_happ, m_hNSReadThread))) {
283 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedDestroyChildThread Read Thread Failed. status=%d", eStatus);
285 m_hNSReadThread = NULL;
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);
292 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroyChildThread(f_happ, m_hNSWriteThread))) {
293 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedDestroyChildThread Write Thread Failed. status=%d", eStatus);
295 m_hNSWriteThread = NULL;
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);
302 if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedDestroyChildThread(f_happ, m_hNSImmediatePersistenceThread))) {
303 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "FrameworkunifiedDestroyChildThread ImmidatePersistence Thread Failed. status=%d", eStatus);
305 m_hNSImmediatePersistenceThread = NULL;
309 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "+");
321 std::string l_cSrcPath = "";
322 std::string l_cDestPath = "";
324 std::string l_cNSNPSPath = CPersistence::GetStoragePath();
325 std::string l_cUserDataPath = "";
327 if (CFSDirectory::DoesDirecotryExist(l_cNSNPSPath)) { // LCOV_EXCL_BR_LINE 6: l_cNSNPSPath must exist
330 struct dirent *l_pdirent = NULL;
332 l_pdir = opendir(l_cNSNPSPath.c_str());
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 '/'
340 // set the userdata folder path
341 l_cUserDataPath.assign(l_cNSNPSPath);
342 l_cUserDataPath.append(USERDATADIR);
343 l_cUserDataPath.append(ALLUSERAPPDATADIR);
345 // create the userdata directory
346 if (!CFSDirectory::DoesDirecotryExist(l_cUserDataPath)) {
347 l_estatus = CFSDirectory::CreateDirectory(l_cUserDataPath);
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);
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);
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());
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]
380 closedir(l_pdir); // close the directory
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");
390 l_estatus = SetNSNPPVersion(static_cast<UI_8>(f_uinppversion));
392 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "+");
405 // immediate notification persistent path for NPPService version 1
406 std::string l_cSrcDir = IMMEDIATE_PERSISTENCE_STORAGE_V1;
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);
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());
419 l_estatus = SetNSNPPVersion(static_cast<UI_8>(f_uinppversion));
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]
425 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
429 ///////////////////////////////////////////////////////////////////////////////////////////
431 /// Get the version of NSNPP from version.txt
432 ///////////////////////////////////////////////////////////////////////////////////////////
433 UI_32 CNSNPP::GetNSNPPVersion() {
434 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
436 UI_32 l_uiVersion = NPP_VERSION_INVALID;
437 CHAR l_cVerStr[3] = {};
438 FILE *l_pFile = NULL;
440 std::string l_cVersion = CPersistence::GetStoragePath();
441 if (l_cVersion[l_cVersion.length() - 1] != '/') { // LCOV_EXCL_BR_LINE 6: must has '/'
444 l_cVersion.append(VERSION_TXT);
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
453 l_uiVersion = static_cast<UI_32>(strtol(l_cVerStr, NULL, 10));
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;
466 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to open file: %s, errno=%d", l_cVersion.c_str(), errno);
467 l_uiVersion = NPP_VERSION_0;
470 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
473 ///////////////////////////////////////////////////////////////////////////////////////////
475 /// Syncfs is carried out.
479 /// \return EFrameworkunifiedStatus
480 /// EFrameworkunifiedStatus - Returns status of operation
482 ///////////////////////////////////////////////////////////////////////////////////////////
483 EFrameworkunifiedStatus CNSNPP::Syncfs() {
486 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
487 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
489 std::string l_cPath = CPersistence::GetStoragePath();
492 dfd = open(l_cPath.c_str(), O_RDONLY | O_DIRECTORY);
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]
501 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to open file: %s serrno=%d", l_cPath.c_str(), errno);
502 l_estatus = eFrameworkunifiedStatusNullPointer;
505 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
508 ///////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
516 FILE *l_pFile = NULL;
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 '/'
523 if (!CFSDirectory::DoesDirecotryExist(l_cVersion)) {
524 CFSDirectory::CreateDirectory(l_cVersion);
527 l_cVersion.append(VERSION_TXT);
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);
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;
543 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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__, "+");
555 // ========Create states
556 NPP_CREATE_STATE(sNotificationpersistentserviceNPPRoot)
557 NPP_CREATE_STATE(sNotificationpersistentserviceNPPStart)
558 NPP_CREATE_STATE(sNotificationpersistentserviceNPPError)
560 CREATE_ORTHOGONALREGION(sNotificationpersistentservicePersistence)
561 CREATE_ORTHOGONALREGION(sNotificationpersistentserviceShutdown)
562 CREATE_ORTHOGONALREGION(sNotificationpersistentserviceNotification)
564 NPP_CREATE_STATE(sNotificationpersistentservicePersistenceReady)
565 NPP_CREATE_STATE(sNotificationpersistentservicePersistenceError)
567 NPP_CREATE_STATE(sNotificationpersistentserviceNotificationReady)
568 NPP_CREATE_STATE(sNotificationpersistentserviceNotificationError)
570 NPP_CREATE_STATE(sNotificationpersistentserviceShutdownIdle)
571 NPP_CREATE_STATE(sNotificationpersistentserviceShutdownDataSave)
573 // ========Connect states
574 NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentserviceNPPRoot, sNotificationpersistentserviceNPPStart)
575 NPP_CONNECT_STATE(sNotificationpersistentserviceNPPRoot, sNotificationpersistentserviceNPPStart)
576 NPP_CONNECT_STATE(sNotificationpersistentserviceNPPRoot, sNotificationpersistentserviceNPPError)
578 NPP_CONNECT_ORTHOGONAL_REGION(sNotificationpersistentserviceNPPStart, sNotificationpersistentservicePersistence)
579 NPP_CONNECT_ORTHOGONAL_REGION(sNotificationpersistentserviceNPPStart, sNotificationpersistentserviceShutdown)
580 NPP_CONNECT_ORTHOGONAL_REGION(sNotificationpersistentserviceNPPStart, sNotificationpersistentserviceNotification)
582 NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentservicePersistence, sNotificationpersistentservicePersistenceReady)
583 NPP_CONNECT_STATE(sNotificationpersistentservicePersistence, sNotificationpersistentservicePersistenceError)
585 NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentserviceShutdown, sNotificationpersistentserviceShutdownIdle)
586 NPP_CONNECT_STATE(sNotificationpersistentserviceShutdown, sNotificationpersistentserviceShutdownDataSave)
588 NPP_CONNECT_DEFAULTSTATE(sNotificationpersistentserviceNotification, sNotificationpersistentserviceNotificationReady)
589 NPP_CONNECT_STATE(sNotificationpersistentserviceNotification, sNotificationpersistentserviceNotificationError)
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)
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)
616 CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPShutdown)
617 CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnShutdownTimeout)
618 CREATE_INTERNALTRANSITION(NotificationpersistentserviceCheckAllReleaseRequestsProcessed)
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)
634 #ifdef NPP_PROFILEINFO_ENABLE
636 CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPProfileNotifications)
637 CREATE_INTERNALTRANSITION(NotificationpersistentserviceOnNPProfilePersistence)
639 NPP_CONNECT_EVENT(sNotificationpersistentserviceNotificationReady, evNPProfileNotification, NotificationpersistentserviceOnNPProfileNotifications)
640 NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evNPProfilePersistence, NotificationpersistentserviceOnNPProfilePersistence)
644 // ========Connect events
645 NPP_CONNECT_EVENT(sNotificationpersistentserviceNPPRoot, evNPClearPersistedData, NotificationpersistentserviceOnNPClearPersistedData)
647 NPP_CONNECT_EVENT(sNotificationpersistentserviceNPPStart, evError, sNotificationpersistentserviceNPPError)
648 NPP_CONNECT_EVENT(sNotificationpersistentserviceNPPError, evReady, sNotificationpersistentserviceNPPStart)
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)
665 NPP_CONNECT_EVENT(sNotificationpersistentservicePersistenceReady, evUserChange, NotificationpersistentserviceOnUserChange)
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)
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)
688 NPP_CONNECTROOT(sNotificationpersistentserviceNPPRoot)
690 NPP_PRINTSTATEMACHINE() // NOLINT (whitespace/empty_if_body)
692 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
696 ////////////////////////////////////////////////////////////////////////////////////////////////////
697 /// NotificationpersistentservicePersistAll
699 ////////////////////////////////////////////////////////////////////////////////////////////////////
700 EFrameworkunifiedStatus CNSNPP::NotificationpersistentservicePersistAll(EFrameworkunifiedShutdownType f_eshutdowntype, UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
701 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
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);
708 // send request to immediate persistence thread to stop all the immediate notification timer
709 m_pPersistenceManager->PersistNORData(f_eshutdowntype, f_uinotificationpersistentservicepersistcategoryflag);
712 if (eFrameworkunifiedNormalShutdown == f_eshutdowntype) {
713 f_uinotificationpersistentservicepersistcategoryflag = 0x0;
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.");
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.");
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);
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);
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
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);
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.");
775 ////////////////////////////////////////////////////////////////////////////////////////////////////
776 /// DeletePersistedDataFolder
777 ////////////////////////////////////////////////////////////////////////////////////////////////////
778 EFrameworkunifiedStatus CNSNPP::DeletePersistedDataFolder(UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
779 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
780 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
782 struct timeb timebuf;
786 theTime = gmtime(&timebuf.time); // NOLINT (runtime/threadsafe_fn)
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);
793 std::string l_cBasePath = CPersistence::GetStoragePath();
794 std::string l_cSrcPath = "";
795 std::string l_cDestPath = "";
797 if (eFrameworkunifiedUserData == (eFrameworkunifiedUserData & f_uinotificationpersistentservicepersistcategoryflag)) {
798 l_cSrcPath.assign(l_cBasePath);
799 l_cSrcPath.append(USERDATA);
801 if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
802 l_cDestPath.assign(l_cSrcPath);
803 l_cDestPath.append(l_cDateTime);
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",
818 if (eFrameworkunifiedFactoryData == (eFrameworkunifiedFactoryData & f_uinotificationpersistentservicepersistcategoryflag)) {
819 l_cSrcPath.assign(l_cBasePath);
820 l_cSrcPath.append(FACTORYDATA);
822 if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
823 l_cDestPath.assign(l_cSrcPath);
824 l_cDestPath.append(l_cDateTime);
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",
839 if (eFrameworkunifiedFactoryCustomerData == (eFrameworkunifiedFactoryCustomerData & f_uinotificationpersistentservicepersistcategoryflag)) {
840 l_cSrcPath.assign(l_cBasePath);
841 l_cSrcPath.append(FACTORYCUSTOMERDATA);
843 if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
844 l_cDestPath.assign(l_cSrcPath);
845 l_cDestPath.append(l_cDateTime);
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",
860 if (eFrameworkunifiedDealerData == (eFrameworkunifiedDealerData & f_uinotificationpersistentservicepersistcategoryflag)) {
861 l_cSrcPath.assign(l_cBasePath);
862 l_cSrcPath.append(DEALERDATA);
864 if (CFSDirectory::DoesDirecotryExist(l_cSrcPath)) {
865 l_cDestPath.assign(l_cSrcPath);
866 l_cDestPath.append(l_cDateTime);
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",
882 if (NULL != l_cDateTime) { // LCOV_EXCL_BR_LINE 6: l_cDateTime can't be NULL
883 delete[] l_cDateTime;
887 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
901 // pointer of Notification Manager
902 CNotificationManager *l_pNotificationManager = NULL;
904 // pointer of Persistence Manager
905 CPersistenceManager *l_pCNotificationpersistentservicePersistenceManager = NULL;
907 Persistent_Notification_List_Type *l_vPersistentNotificationList = NULL;
909 // get the instance of notification manager
910 l_pNotificationManager = m_pNotificationManager;
912 // get the instance of persistence manager
913 l_pCNotificationpersistentservicePersistenceManager = m_pPersistenceManager;
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();
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,
923 f_uinotificationpersistentservicepersistcategoryflag);
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;
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);
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);
947 // delete the locally created vector
948 if (!l_vPersistentNotificationList->empty()) {
949 for (UI_32 l_uiCount = 0;
950 l_uiCount < l_vPersistentNotificationList->size();
952 if (NULL != l_vPersistentNotificationList->at(l_uiCount)) { // LCOV_EXCL_BR_LINE 6: can't be NULL
953 delete l_vPersistentNotificationList->at(l_uiCount);
958 l_vPersistentNotificationList->clear();
961 delete l_vPersistentNotificationList;
962 l_vPersistentNotificationList = NULL;
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;
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;
979 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
992 // pointer of Notification Manager
993 CNotificationManager *l_pNotificationManager = NULL;
995 // pointer of Persistence Manager
996 CPersistenceManager *l_pNotificationpersistentservicePersistenceManager = NULL;
998 // iterator of CNotificationToPersist vector
999 Persistent_Notification_List_Type *l_vPersistentNotificationList = NULL;
1001 // get the instance of notification manager
1002 l_pNotificationManager = m_pNotificationManager;
1004 // get the instance of persistent manager
1005 l_pNotificationpersistentservicePersistenceManager = m_pPersistenceManager;
1007 // create new vector for persistent notifications
1008 l_vPersistentNotificationList = new(std::nothrow) Persistent_Notification_List_Type();
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);
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);
1027 if (0 < l_vPersistentNotificationList->size()) {
1028 // send the notification list to notification manager
1029 l_estatus = l_pNotificationManager->NotificationpersistentserviceSetPersistentNotificationData(l_vPersistentNotificationList);
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;
1039 if (!l_vPersistentNotificationList->empty()) {
1040 for (UI_32 l_uiCount = 0;
1041 l_uiCount < l_vPersistentNotificationList->size();
1043 if (NULL != l_vPersistentNotificationList->at(l_uiCount)) { // LCOV_EXCL_BR_LINE 6: can't be NULL
1044 delete l_vPersistentNotificationList->at(l_uiCount);
1049 l_vPersistentNotificationList->clear();
1052 delete l_vPersistentNotificationList;
1053 l_vPersistentNotificationList = NULL;
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;
1062 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1066 ////////////////////////////////////////////////////////////////////////////////////////////////////
1067 /// CreateAndStartChildThreads
1069 ////////////////////////////////////////////////////////////////////////////////////////////////////
1070 EFrameworkunifiedStatus CNSNPP::CreateAndStartChildThreads(HANDLE f_happ) {
1071 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
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
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);
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);
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]
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");
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);
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);
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]
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");
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);
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);
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]
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");