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 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup tag_NS_NPPService
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup tag_NS_NPPService
25 /// \brief This file contains implementation of class CPersistence.
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
33 #include <other_service/strlcpy.h>
34 // #include "frameworkunified_stub.h"
37 #include <stdlib.h> // for getenv()
43 #include "ns_npp_persistence.h"
44 #include "ns_npp_registry_entry.h"
46 ////////////////////////////////////////////////////////////////////////////////////////////////////
48 /// Constructor of CPersistence class
49 ////////////////////////////////////////////////////////////////////////////////////////////////////
50 CPersistence::CPersistence():
51 m_cStoragePath(GetStoragePath()),
52 m_eCompressionType(ENOTIFICATIONPERSISTENTSERVICEDEFAULTCOMPRESSION),
53 m_hNSWriteToPersistentMem(NULL),
54 m_hNSReadFromPersistentMem(NULL),
57 m_uiNotificationpersistentservicePersistCategoryFlag(0) {
60 ////////////////////////////////////////////////////////////////////////////////////////////////////
62 /// Destructor of CPersistence class
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
64 CPersistence::~CPersistence() { // LCOV_EXCL_START 14: Resident process, global instance not released
65 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
69 ////////////////////////////////////////////////////////////////////////////////////////////////////
70 /// SetReadThreadHandle
71 /// Set read thread handle.
72 ////////////////////////////////////////////////////////////////////////////////////////////////////
73 VOID CPersistence::SetReadThreadHandle(HANDLE f_hreadthread) {
74 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
75 m_hNSReadFromPersistentMem = f_hreadthread;
76 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
79 ////////////////////////////////////////////////////////////////////////////////////////////////////
80 /// SetWriteThreadHandle
81 /// Set write thread handle.
82 ////////////////////////////////////////////////////////////////////////////////////////////////////
83 VOID CPersistence::SetWriteThreadHandle(HANDLE f_hwritethread) {
84 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
85 m_hNSWriteToPersistentMem = f_hwritethread;
86 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
89 ////////////////////////////////////////////////////////////////////////////////////////////////////
92 ////////////////////////////////////////////////////////////////////////////////////////////////////
93 std::string CPersistence::GetStoragePath() {
94 std::string l_cStoragePath(STORAGE_PATH);
96 return l_cStoragePath;
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
101 /// Register tag for persistence.
102 ////////////////////////////////////////////////////////////////////////////////////////////////////
103 EFrameworkunifiedStatus CPersistence::Register(std::string f_crequestorappname, std::string f_ctag, BOOL bisuserpersistence) {
104 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
105 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
106 if (f_ctag.empty() || f_crequestorappname.empty()) { // LCOV_EXCL_BR_LINE 6: f_ctag and f_crequestorappname can't be empty // NOLINT[whitespace/line_length]
107 // LCOV_EXCL_START 6: f_ctag and f_crequestorappname can't be empty
108 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
109 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid tag or requester.");
110 l_estatus = eFrameworkunifiedStatusFail;
113 TSourceRegistryListItr l_itRegistry = m_mPersistRegistry.find(f_crequestorappname);
114 if (l_itRegistry != m_mPersistRegistry.end()) {
115 // source available, check for file/folder availability
116 TTagRegistryListItr l_itRegistryList = (l_itRegistry->second).find(f_ctag);
117 if (l_itRegistryList != (l_itRegistry->second).end()) {
118 // found already in the registry
119 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Already exists %s , %s", f_ctag.c_str(), f_crequestorappname.c_str()); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
121 // tag not found .. so add to the registry
122 CRegistryEntry l_objRegistryEntry(f_ctag, f_crequestorappname, m_cStoragePath,
123 bisuserpersistence); // f_eRegisterType, f_cUser);
125 (l_itRegistry->second).insert(make_pair(f_ctag, l_objRegistryEntry));
126 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " %s found adding tag %s", f_crequestorappname.c_str(), f_ctag.c_str());
129 // source not found, so creating a new entry
130 CRegistryEntry l_objRegistryEntry(f_ctag, f_crequestorappname, m_cStoragePath,
131 bisuserpersistence); // f_eRegisterType, f_cUser);
133 TTagRegistryList l_mRegList;
134 l_mRegList.insert(make_pair(f_ctag, l_objRegistryEntry)); // LCOV_EXCL_BR_LINE 11:except,C++ STL
136 m_mPersistRegistry.insert(std::make_pair(f_crequestorappname, l_mRegList)); // LCOV_EXCL_BR_LINE 11:except,C++ STL // NOLINT[whitespace/line_length]
138 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "none exists %s , %s. So, added entry.", // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
139 f_ctag.c_str(), f_crequestorappname.c_str()); // LCOV_EXCL_BR_LINE 11: unexpected branch
142 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- l_estatus:0x%x", l_estatus);
147 ////////////////////////////////////////////////////////////////////////////////////////////////////
148 /// ProcessReleaseRequest
149 /// Persist file/folder that need to be persisted.
150 ////////////////////////////////////////////////////////////////////////////////////////////////////
151 EFrameworkunifiedStatus CPersistence::ProcessReleaseRequest(std::string f_crequesterappname,
153 ENotificationpersistentservicePersistType f_epersisttype,
154 std::string f_cmempath,
155 EFrameworkunifiedReleaseType enotificationpersistentservicereleasetype,
156 std::string f_cusername) {
157 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
159 if (f_cmempath.empty() || f_crequesterappname.empty() || f_ctag.empty()) { // LCOV_EXCL_BR_LINE 6:f_cmempath, f_crequesterappname and f_ctag can`t be empty // NOLINT[whitespace/line_length]
160 // LCOV_EXCL_START 6: f_cmempath, f_crequesterappname and f_ctag can`t be empty
161 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
162 FRAMEWORKUNIFIEDLOG0(ZONE_ERR, __FUNCTION__, "Invalid file path, requester or tag.");
163 l_estatus = eFrameworkunifiedStatusInvldParam;
166 // Persistence Registry map iterator
167 TSourceRegistryListItr l_itTSourceRegistryListItr = m_mPersistRegistry.find(f_crequesterappname);
169 if (l_itTSourceRegistryListItr != m_mPersistRegistry.end()) {
170 // source available, check for file if registered
171 TTagRegistryListItr l_itTRegistryList = (l_itTSourceRegistryListItr->second).find(f_ctag);
172 if (l_itTRegistryList != (l_itTSourceRegistryListItr->second).end()) {
173 if (eFrameworkunifiedNotOnRelease != enotificationpersistentservicereleasetype) {
175 l_itTRegistryList->second.SetReleasePath(f_cmempath);
177 l_itTRegistryList->second.SetPersistProperties(f_epersisttype, f_cusername); // LCOV_EXCL_BR_LINE 11:except,C++ STL // NOLINT[whitespace/line_length]
179 // file/folder found in registry
180 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
181 "%s released %s. Found in registry. queued up to persist from %s",
182 f_crequesterappname.c_str(), f_ctag.c_str(), l_itTRegistryList->second.GetReleasePath().c_str());
184 // check if persist flag is set due to shutdown or user change
185 if ((m_bPersist // It will be set to TRUE either on shutdown or userchange
186 && l_itTRegistryList->second.HasntBeenPersisted()) // File/Folder persisted or not
187 || (eFrameworkunifiedPersistInstantly == enotificationpersistentservicereleasetype)) {
189 if (((eFrameworkunifiedUserData == l_itTRegistryList->second.GetPersistentCategory()) &&
190 (eFrameworkunifiedUserData & m_uiNotificationpersistentservicePersistCategoryFlag)) ||
191 ((eFrameworkunifiedFactoryData == l_itTRegistryList->second.GetPersistentCategory()) &&
192 (eFrameworkunifiedFactoryData & m_uiNotificationpersistentservicePersistCategoryFlag)) ||
193 ((eFrameworkunifiedFactoryCustomerData == l_itTRegistryList->second.GetPersistentCategory()) &&
194 (eFrameworkunifiedFactoryCustomerData & m_uiNotificationpersistentservicePersistCategoryFlag)) ||
195 ((eFrameworkunifiedDealerData == l_itTRegistryList->second.GetPersistentCategory()) &&
196 (eFrameworkunifiedDealerData & m_uiNotificationpersistentservicePersistCategoryFlag))) {
197 // set the status of file/folder persisted as reset has been called on these data
198 l_itTRegistryList->second.SetCurrentAction(LOADTYPE_RELEASE);
199 l_itTRegistryList->second.SetBeingPersisted();
200 } else { // persist the data
201 if (eFrameworkunifiedStatusOK != (l_estatus = Persist(static_cast<CRegistryEntry &>(l_itTRegistryList->second)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
202 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
203 l_estatus = eFrameworkunifiedStatusFail; // LCOV_EXCL_LINE 4: NSFW error case.
207 // Don't persist now. Persist on shutdown.
209 } else { // not on release
210 // set the status of file/folder as released and persisted as these data need not to be persisted on shutdown
211 l_itTRegistryList->second.SetReleasePath("");
212 l_itTRegistryList->second.SetCurrentAction(LOADTYPE_RELEASE);
213 l_itTRegistryList->second.SetBeingPersisted();
216 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Warning: %s didn't register %s, not persisting",
217 f_crequesterappname.c_str(), f_ctag.c_str()); // LCOV_EXCL_BR_LINE 11: unexpected branch
218 l_estatus = eFrameworkunifiedStatusInvldParam;
221 // source not registered, cannot persist
222 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Warning: %s is not registered ignoring release of %s",
223 f_ctag.c_str(), f_crequesterappname.c_str());
224 l_estatus = eFrameworkunifiedStatusInvldParam;
230 EFrameworkunifiedStatus CPersistence::Persist(CRegistryEntry &f_objregistryentry) {
231 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
233 // Persistence Info Structure
234 NSP_CopyInfoCmd l_tCpInfo = {};
237 std::string l_cSourcePath = f_objregistryentry.GetReleasePath();
238 std::string l_cPersistPath = f_objregistryentry.GetPersistPath(); // LCOV_EXCL_BR_LINE 11:except,C++ STL
240 // Fill the persistence info structure
241 AddRequestData(l_tCpInfo,
244 f_objregistryentry.GetRequester(),
245 f_objregistryentry.GetTag(),
247 f_objregistryentry.GetPersistType());
249 // Persist only if file was released.
250 // Release means application has asked NPPService to persist file at shutdown.)
251 // Persist means actual persisting a file at persistent storage
252 if (f_objregistryentry.IsReleased()) {
253 if (ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEINPROCESS == f_objregistryentry.m_eJobState) {
254 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Another job with source: %s and tag %s is in process. "
255 "Therefore adding release request to the pending queue.",
256 f_objregistryentry.GetRequester().c_str(), f_objregistryentry.GetTag().c_str());
257 // if job corresponding to the tag is already in process, add it in pending queue
258 m_lPendingJobs.push_back(l_tCpInfo);
259 } else if (ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEIDLE == f_objregistryentry.m_eJobState) {
260 if (eFrameworkunifiedStatusOK == (SendRequestMessage(l_tCpInfo))) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
261 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Release message passed to writer thread."); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
262 f_objregistryentry.SetCurrentAction(LOADTYPE_RELEASE);
263 f_objregistryentry.m_eJobState = ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEINPROCESS;
265 // LCOV_EXCL_START 4: NSFW error case.
266 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
267 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failure in passing release message to writer thread.");
268 l_estatus = eFrameworkunifiedStatusFail;
273 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File/Folder not released yet.");
279 ////////////////////////////////////////////////////////////////////////////////////////////////////
280 /// ProcessLoadRequest
281 /// Load persisted file/folder.
282 ////////////////////////////////////////////////////////////////////////////////////////////////////
283 EFrameworkunifiedStatus CPersistence::ProcessLoadRequest(std::string f_crequesterappname,
285 ENotificationpersistentservicePersistType f_epersisttype,
286 std::string f_cretrievepath,
287 std::string f_cusername) {
288 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
290 // file/folder found in registry
291 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
292 "Load request received: Requester: %s and Tag: %s Load at: %s.",
293 f_crequesterappname.c_str(), f_ctag.c_str(), f_cretrievepath.c_str()); // LCOV_EXCL_BR_LINE 11:except,C++ STL
295 if (f_ctag.empty() || f_crequesterappname.empty() || f_cretrievepath.empty()) { // LCOV_EXCL_BR_LINE 6: both f_ctag and f_crequesterappname and f_cretrievepath can`t be empty // NOLINT[whitespace/line_length]
296 // LCOV_EXCL_START 6: both f_ctag and f_crequesterappname and f_cretrievepath can`t be empty
297 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
298 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid argument passed (RetrievePath:%s ,tag:%s, requester:%s)",
299 f_cretrievepath.c_str(), f_ctag.c_str(), f_crequesterappname.c_str());
300 l_estatus = eFrameworkunifiedStatusInvldParam;
303 // Persistence Registry Map Iterator
304 TSourceRegistryListItr l_itTRegistry = m_mPersistRegistry.find(f_crequesterappname);
306 // Persistence Info Struct
307 NSP_CopyInfoCmd l_tCopyInfo = {};
309 if (l_itTRegistry != m_mPersistRegistry.end()) {
310 // source available, check for file/folder
311 TTagRegistryListItr l_itTRegistryList = (l_itTRegistry->second).find(f_ctag);
312 if (l_itTRegistryList != (l_itTRegistry->second).end()) {
313 if ((ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATERELEASEABORTED == l_itTRegistryList->second.m_eJobState)) { // LCOV_EXCL_BR_LINE 6: m_eJobState can`t be ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATERELEASEABORTED // NOLINT[whitespace/line_length]
314 // LCOV_EXCL_START 6: m_eJobState can`t be ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATERELEASEABORTED // NOLINT[whitespace/line_length]
315 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
316 std::string l_cReleasePath(l_itTRegistryList->second.GetReleasePath());
317 // if job was aborted due to some reason like abort shutdown.
318 // Then persistent storage doesn't have updated file/folder. Just restore
319 // aborted released file.
321 if (0 == std::rename(l_cReleasePath.c_str(), f_cretrievepath.c_str())) {
322 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File loaded at requested location.");
324 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
325 "Error while processing load request when tried to move. source: %s dest: %s",
326 l_cReleasePath.c_str(), f_cretrievepath.c_str());
327 l_estatus = eFrameworkunifiedStatusFail;
329 l_itTRegistryList->second.m_eJobState = ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEIDLE;
332 std::string l_cLoadPath(l_itTRegistryList->second.GetLoadPath(f_epersisttype, f_cusername)); // LCOV_EXCL_BR_LINE 11:except,C++ STL // NOLINT[whitespace/line_length]
334 if (0 == access(l_cLoadPath.c_str(), R_OK)) {
335 // file/folder found in registry
336 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Found in registry. checking in persistence...(%s)", l_cLoadPath.c_str());
338 AddRequestData(l_tCopyInfo,
346 if (ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEINPROCESS == (l_itTRegistryList->second).m_eJobState) {
347 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Another job with source: %s and tag %s is in process. "
348 "Therefore adding load request to the pending queue.",
349 f_crequesterappname.c_str(), f_ctag.c_str());
350 m_lPendingJobs.push_back(l_tCopyInfo);
351 } else if (ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEIDLE == (l_itTRegistryList->second).m_eJobState) {
352 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Found in persistence.");
353 if (eFrameworkunifiedStatusOK == (SendRequestMessage(l_tCopyInfo))) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
354 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Load message passed to reader thread. Retrieving..");
355 // file/folder is requested for loading so reset the persisted flag.
356 l_itTRegistryList->second.ResetPersistedFlag();
357 l_itTRegistryList->second.SetCurrentAction(LOADTYPE_LOAD);
358 l_itTRegistryList->second.m_eJobState = ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEINPROCESS;
360 // LCOV_EXCL_START 4: NSFW error case.
361 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
362 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failure in passing load message to reader thread.");
363 l_estatus = eFrameworkunifiedStatusFail;
368 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "%s requested by %s. Not found in persistence memory.", // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
369 f_ctag.c_str(), f_crequesterappname.c_str()); // LCOV_EXCL_BR_LINE 11:except,C++ STL
370 l_estatus = eFrameworkunifiedStatusAccessError;
374 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Warning: %s requesting %s .. Tag not found",
375 f_crequesterappname.c_str(), f_ctag.c_str()); // LCOV_EXCL_BR_LINE 11:except,C++ STL
376 l_estatus = eFrameworkunifiedStatusFail;
380 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Warning: %s requesting %s .. Requester not found",
381 f_crequesterappname.c_str(), f_ctag.c_str());
382 l_estatus = eFrameworkunifiedStatusFail;
388 VOID CPersistence::AddRequestData(NSP_CopyInfoCmd &f_tcpinfo,
389 std::string f_sourcepath,
390 std::string f_destpath,
391 std::string f_crequesterappname,
393 ENPS_Loadtype f_eloadtype,
394 ENotificationpersistentservicePersistType f_epersisttype) {
395 #ifdef AGL_PosixBasedOS001LEGACY_USED
396 strlcpy(f_tcpinfo.m_csourcepath, f_sourcepath.c_str(), sizeof(f_tcpinfo.m_csourcepath));
397 strlcpy(f_tcpinfo.m_cdestinationpath, f_destpath.c_str(), sizeof(f_tcpinfo.m_cdestinationpath));
398 strlcpy(f_tcpinfo.m_crequesterappname, f_crequesterappname.c_str(), sizeof(f_tcpinfo.m_crequesterappname));
399 strlcpy(f_tcpinfo.m_cpersistenttag, f_ctag.c_str(), sizeof(f_tcpinfo.m_cpersistenttag));
401 f_tcpinfo.m_eloadtype = f_eloadtype;
402 f_tcpinfo.m_epersisttype = f_epersisttype;
403 // f_tcpinfo.m_eCompressionType = ENOTIFICATIONPERSISTENTSERVICECOMPRESSUSINGLIBZ;
406 EFrameworkunifiedStatus CPersistence::SendRequestMessage(NSP_CopyInfoCmd &f_tcpinfo) {
407 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
408 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
409 HANDLE l_hThreadHandle = NULL;
410 // Worker Command Protocol
411 ENSP_CopyWorkerProtocol l_eWorkerProtocol = CP_WRK_CMD_COPY;
413 if (ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE == f_tcpinfo.m_epersisttype) {
414 l_eWorkerProtocol = CP_WRK_CMD_COPY;
415 } else if (ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER == f_tcpinfo.m_epersisttype) {
416 l_eWorkerProtocol = AR_CMD_ARCHIVE;
419 if (LOADTYPE_RELEASE == f_tcpinfo.m_eloadtype) {
420 l_hThreadHandle = m_hNSWriteToPersistentMem;
421 } else if (LOADTYPE_LOAD == f_tcpinfo.m_eloadtype) {
422 l_hThreadHandle = m_hNSReadFromPersistentMem;
425 if (l_hThreadHandle) {
426 // issue a copy to the worker thread
427 if (eFrameworkunifiedStatusOK != (l_estatus = McSend(l_hThreadHandle, AppName, l_eWorkerProtocol, sizeof(NSP_CopyInfoCmd), &f_tcpinfo))) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT[whitespace/line_length]
428 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
429 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "McSend for thread failed %d", l_estatus); // LCOV_EXCL_LINE 4: NSFW error case.
433 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
437 ////////////////////////////////////////////////////////////////////////////////////////////
438 /// AckReceivedFromWorker
439 /// This is callback function for ack that file is released to persistenet memory.
440 ////////////////////////////////////////////////////////////////////////////////////////////
441 EFrameworkunifiedStatus CPersistence::AckReceivedFromWorker(PCSTR f_csource, PCSTR f_ctag, BOOL f_bcopystatus,
442 ENPS_Loadtype f_eloadtype) {
443 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
444 EFrameworkunifiedStatus retVal = eFrameworkunifiedStatusOK;
446 std::string l_cRequester(f_csource);
447 std::string l_cTag(f_ctag); // LCOV_EXCL_BR_LINE 11:except,C++ STL
449 TSourceRegistryListItr l_itTReg = m_mPersistRegistry.find(l_cRequester);
450 if (l_itTReg != m_mPersistRegistry.end()) {
451 // source available, check for file
452 TTagRegistryListItr l_itTRegList = (l_itTReg->second).find(l_cTag);
453 if (l_itTRegList != (l_itTReg->second).end()) {
454 if (LOADTYPE_RELEASE == f_eloadtype) {
455 l_itTRegList->second.SetBeingPersisted(); // LCOV_EXCL_BR_LINE 11: unexpected branch
458 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "File persisted %s / %s", f_csource, f_ctag);
460 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
461 "File not persisted %s / %s, Negative ack received from copy worker thread",
463 f_ctag); // LCOV_EXCL_BR_LINE 11:except,C++ STL
467 // Job processed. Set job state as idle
468 l_itTRegList->second.m_eJobState = ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEIDLE;
470 // check if there are any pending jobs for corresponding source and tag
471 if (!m_lPendingJobs.empty()) {
472 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Retrieving next pending job for persistence...");
473 TPendingJobsItr l_itrPendingJobs;
474 for (l_itrPendingJobs = m_lPendingJobs.begin(); l_itrPendingJobs != m_lPendingJobs.end(); ++l_itrPendingJobs) {
475 if (0 == std::strcmp((*l_itrPendingJobs).m_crequesterappname, f_csource)
476 && (0 == std::strcmp((*l_itrPendingJobs).m_cpersistenttag, f_ctag))) {
477 if (eFrameworkunifiedStatusOK == (retVal = (SendRequestMessage((*l_itrPendingJobs))))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
478 // set job state as processing
479 l_itTRegList->second.m_eJobState = ENOTIFICATIONPERSISTENTSERVICEPERSISTJObSTATEINPROCESS;
480 // set current action
481 l_itTRegList->second.SetCurrentAction((*l_itrPendingJobs).m_eloadtype);
482 // Reset persisted flag. It requires to process release request for this tag.
483 // Because, file will be persisted only once. Unless, anyone loads the file again.
484 if (LOADTYPE_LOAD == (*l_itrPendingJobs).m_eloadtype) {
485 l_itTRegList->second.ResetPersistedFlag();
488 // remove job from pending list
489 m_lPendingJobs.erase(l_itrPendingJobs);
491 // LCOV_EXCL_START 4: NSFW error case.
492 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
493 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failure in passing load/release message to the worker threads.");
494 retVal = eFrameworkunifiedStatusFail;
502 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "No pending jobs"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
506 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " ERROR %s, tag %s not found ", f_csource, f_ctag);
510 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "ERROR none exists %s , %s", f_csource, f_ctag);
513 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
517 ////////////////////////////////////////////////////////////////////////////////////////////
518 /// PersistAllReleaseRequests
519 /// Persist all files which are not persisted yet.
520 ////////////////////////////////////////////////////////////////////////////////////////////
521 EFrameworkunifiedStatus CPersistence::PersistAllReleaseRequests(UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
522 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
523 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
525 m_bPersist = TRUE; // set to true because persist of all release requests have been triggered.
526 // Trigger reason: shutdown
528 m_uiNotificationpersistentservicePersistCategoryFlag = f_uinotificationpersistentservicepersistcategoryflag;
530 TSourceRegistryListItr l_itTReg = m_mPersistRegistry.begin();
532 for (; l_itTReg != m_mPersistRegistry.end(); ++l_itTReg) {
533 TTagRegistryListItr l_itTRegList = (l_itTReg->second).begin();
534 for (; l_itTRegList != (l_itTReg->second).end(); ++l_itTRegList) {
535 if (l_itTRegList->second.HasntBeenPersisted()) {
537 if (((eFrameworkunifiedUserData == l_itTRegList->second.GetPersistentCategory()) &&
538 (eFrameworkunifiedUserData & f_uinotificationpersistentservicepersistcategoryflag)) ||
539 ((eFrameworkunifiedFactoryData == l_itTRegList->second.GetPersistentCategory()) &&
540 (eFrameworkunifiedFactoryData & f_uinotificationpersistentservicepersistcategoryflag)) ||
541 ((eFrameworkunifiedFactoryCustomerData == l_itTRegList->second.GetPersistentCategory()) &&
542 (eFrameworkunifiedFactoryCustomerData & f_uinotificationpersistentservicepersistcategoryflag)) ||
543 ((eFrameworkunifiedDealerData == l_itTRegList->second.GetPersistentCategory()) &&
544 (eFrameworkunifiedDealerData & f_uinotificationpersistentservicepersistcategoryflag))) {
545 // set the status of file/folder as released and persisted as these data need not to be persisted on shutdown
546 l_itTRegList->second.SetCurrentAction(LOADTYPE_RELEASE);
547 l_itTRegList->second.SetBeingPersisted();
548 } else { // persist the data
549 if (eFrameworkunifiedStatusOK != Persist(static_cast<CRegistryEntry &>(l_itTRegList->second))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
550 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
551 l_estatus = eFrameworkunifiedStatusFail; // LCOV_EXCL_LINE 4: NSFW error case.
558 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
562 BOOL CPersistence::HaveAllReleaseRequestsPersisted(std::string &f_ctagnotreleased) {
563 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
564 BOOL l_bRetVal = TRUE;
566 TSourceRegistryListItr l_itTReg = m_mPersistRegistry.begin();
568 f_ctagnotreleased.assign("");
570 for (; l_itTReg != m_mPersistRegistry.end(); ++l_itTReg) {
571 TTagRegistryListItr l_itTRegList = (l_itTReg->second).begin();
572 for (; l_itTRegList != (l_itTReg->second).end(); ++l_itTRegList) {
573 if (l_itTRegList->second.HasntBeenPersisted()) {
576 if (!l_itTRegList->second.IsReleased()) {
577 f_ctagnotreleased.append("\n");
578 f_ctagnotreleased.append(l_itTRegList->second.GetTag());
579 f_ctagnotreleased.append(" [");
580 f_ctagnotreleased.append(l_itTRegList->second.GetRequester());
581 f_ctagnotreleased.append("]");
587 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
591 ////////////////////////////////////////////////////////////////////////////////////////////
592 /// PersistAllUserRequests
593 /// Persist all user files which are not persisted yet.
594 ////////////////////////////////////////////////////////////////////////////////////////////
595 EFrameworkunifiedStatus CPersistence::PersistAllUserRequests() {
596 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
597 // TODO(my_username): Persist data on userchange. Uncomment following.
598 // m_bPersist = TRUE; // set to true because persist of all user release requests have been triggered.
599 // Trigger reason: user change
601 TSourceRegistryListItr l_itTReg = m_mPersistRegistry.begin();
603 for (; l_itTReg != m_mPersistRegistry.end(); ++l_itTReg) {
604 TTagRegistryListItr l_itTRegList = (l_itTReg->second).begin();
605 for (; l_itTRegList != (l_itTReg->second).end(); ++l_itTRegList) {
606 if (l_itTRegList->second.IsUserPersistence()) {
607 if (eFrameworkunifiedStatusOK != Persist(static_cast<CRegistryEntry &>(l_itTRegList->second))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
608 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
609 l_estatus = eFrameworkunifiedStatusFail; // LCOV_EXCL_LINE 4: NSFW error case.
617 BOOL CPersistence::IsUserPersistence(std::string f_ctag) {
618 BOOL l_bUserPersistence = FALSE;
620 TSourceRegistryListItr l_itTReg = m_mPersistRegistry.begin();
622 for (; l_itTReg != m_mPersistRegistry.end(); ++l_itTReg) {
623 TTagRegistryListItr l_itTRegList = (l_itTReg->second).begin();
624 for (; l_itTRegList != (l_itTReg->second).end(); ++l_itTRegList) {
625 if (l_itTRegList->second.GetTag() == f_ctag) {
626 if (l_itTRegList->second.IsUserPersistence()) {
627 l_bUserPersistence = TRUE;
634 return l_bUserPersistence;
637 ////////////////////////////////////////////////////////////////////////////////////////////
638 /// SetPersistentCategory
639 /// Sets the persist type of file/folder
640 ////////////////////////////////////////////////////////////////////////////////////////////
641 EFrameworkunifiedStatus CPersistence::SetPersistentCategory(const std::string &f_crequesterappname,
642 const std::string &f_ctag,
643 EFrameworkunifiedPersistCategory f_epersistcategory) {
644 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
645 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
647 // Persistence Registry map iterator
648 TSourceRegistryListItr l_itTSourceRegistryListItr = m_mPersistRegistry.find(f_crequesterappname);
650 if (m_mPersistRegistry.end() != l_itTSourceRegistryListItr) {
651 // source available, check for file if registered
652 TTagRegistryListItr l_itTRegistryList = (l_itTSourceRegistryListItr->second).find(f_ctag);
654 if ((l_itTSourceRegistryListItr->second).end() != l_itTRegistryList) {
655 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "AppName:: %s, Tag:: %s found in registry", f_crequesterappname.c_str(),
658 l_estatus = (l_itTRegistryList->second).SetPersistentCategory(f_epersistcategory);
660 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Warning: %s didn't register %s", f_crequesterappname.c_str(), f_ctag.c_str());
661 l_estatus = eFrameworkunifiedStatusInvldParam;
664 // source not registered, cannot persist
665 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Warning: %s is not registered", f_ctag.c_str());
666 l_estatus = eFrameworkunifiedStatusInvldParam;
669 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
673 ////////////////////////////////////////////////////////////////////////////////////////////
675 /// Resets the persist flag.
676 ////////////////////////////////////////////////////////////////////////////////////////////
677 VOID CPersistence::ResetPersistFlag() {
680 m_uiNotificationpersistentservicePersistCategoryFlag = 0;
683 #ifdef NPP_PROFILEINFO_ENABLE
685 EFrameworkunifiedStatus CPersistence::GetPersistenceProfilingData(std::string &f_cpersistenceprofileinfo) {
686 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
688 TSourceRegistryListItr l_itrTSourceRegistryListItr;
689 TTagRegistryListItr l_itrTTagRegistryListItr;
691 for (l_itrTSourceRegistryListItr = m_mPersistRegistry.begin();
692 l_itrTSourceRegistryListItr != m_mPersistRegistry.end();
693 l_itrTSourceRegistryListItr++) {
694 for (l_itrTTagRegistryListItr = (l_itrTSourceRegistryListItr->second).begin();
695 l_itrTTagRegistryListItr != (l_itrTSourceRegistryListItr->second).end();
696 l_itrTTagRegistryListItr++) {
697 f_cpersistenceprofileinfo.append("\n");
698 f_cpersistenceprofileinfo.append((*l_itrTSourceRegistryListItr).first);
699 f_cpersistenceprofileinfo.append(",");
701 f_cpersistenceprofileinfo.append(l_itrTTagRegistryListItr->first);
702 f_cpersistenceprofileinfo.append(",");
704 switch ((l_itrTTagRegistryListItr->second).GetPersistType()) {
705 case ENOTIFICATIONPERSISTENTSERVICEPERSISTFILE: {
706 f_cpersistenceprofileinfo.append("File,");
710 case ENOTIFICATIONPERSISTENTSERVICEPERSISTFOLDER: {
711 f_cpersistenceprofileinfo.append("Folder,");
716 f_cpersistenceprofileinfo.append(",");
721 if ((l_itrTTagRegistryListItr->second).IsUserPersistence()) {
722 f_cpersistenceprofileinfo.append("Yes,");
724 f_cpersistenceprofileinfo.append("No,");
727 if ((l_itrTTagRegistryListItr->second).IsReleased()) {
728 f_cpersistenceprofileinfo.append("Yes,");
730 f_cpersistenceprofileinfo.append("No,");
733 if ((l_itrTTagRegistryListItr->second).IsPersisted()) {
734 f_cpersistenceprofileinfo.append("Yes");
736 f_cpersistenceprofileinfo.append("No");