Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / notification_persistent_service / server / src / ns_npp_notification_manager.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 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup  tag_NS_NPPService
20 /// .
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
22
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup  tag_NS_NPPService
25 /// \brief    This file contains implementation of singleton class CNotificationManager.
26 ///
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
28
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
30 // Include Files
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
32
33 #include <native_service/ns_np_service.h>
34 #include <native_service/ns_message_center_if.h>
35 #include <native_service/ns_np_service_protocol.h>
36 #include <algorithm>
37 #include <utility>
38 #include <string>
39 #include <vector>
40 #include "ns_npp_types.h"
41 #include "ns_npp_notificationpersistentservicelog.h"
42 #include "ns_npp_threads.h"
43 #include "ns_npp_notification.h"
44 #include "ns_npp_persistent_data.h"
45 #include "ns_npp_state_notification.h"
46 #include "ns_npp_regular_notification.h"
47 #include "ns_npp_notification_manager.h"
48 #include "ns_npp_state_persistence_notification.h"
49 #include "ns_npp_state_nor_persistence_notification.h"
50 #include "ns_npp_state_persistence_user_notification.h"
51
52 #ifdef NPP_PROFILEINFO_ENABLE
53 #include <sstream>
54 #endif
55
56 ////////////////////////////////////////////////////////////////////////////////////////////////////
57 /// CNotificationManager
58 /// Constructor of CNotificationManager class
59 ////////////////////////////////////////////////////////////////////////////////////////////////////
60 CNotificationManager::CNotificationManager() {
61   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
62
63   m_pmNotificationList = new(std::nothrow) Notification_Type();  // LCOV_EXCL_BR_LINE 11: unexpected branch
64
65   m_pvPersistentList = new(std::nothrow) std::vector<std::string>();  // LCOV_EXCL_BR_LINE 11: unexpected branch
66
67   m_pvUserPersistentList = new(std::nothrow) std::vector<std::string>();  // LCOV_EXCL_BR_LINE 11: unexpected branch
68
69   if (NULL == CStateNorPersistenceNotification::m_hNSImmediatePersistenceThread) {  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
70     CStateNorPersistenceNotification::m_hNSImmediatePersistenceThread =
71             McOpenSender(NS_NPP_IMMEDIATE_PERSIST_THREAD_NAME);
72   }
73
74   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
75 }
76
77 ////////////////////////////////////////////////////////////////////////////////////////////////////
78 /// ~CNotificationManager
79 /// Destructor of CNotificationManager class
80 ////////////////////////////////////////////////////////////////////////////////////////////////////
81 CNotificationManager::~CNotificationManager() {   // LCOV_EXCL_START 14: Resident process, global instance not released
82   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
83   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
84
85   // iterator to find notification from map of notifications
86   Notification_Iterator_Type l_itNotification;
87
88   CNotification *l_pNotification = NULL;
89
90   // delete the members in map of Notification
91   if (NULL != m_pmNotificationList) {
92     if (!m_pmNotificationList->empty()) {
93       for (l_itNotification = m_pmNotificationList->begin();
94            l_itNotification != m_pmNotificationList->end();
95            l_itNotification++) {
96         l_pNotification = (*l_itNotification).second;
97
98         if (NULL != l_pNotification) {
99           delete l_pNotification;
100           l_pNotification = NULL;
101         }
102       }
103
104       // clear the map
105       m_pmNotificationList->clear();
106     }
107
108     delete m_pmNotificationList;
109     m_pmNotificationList = NULL;
110   }
111
112   // delete the members in vector of persistent notification
113   if (NULL != m_pvPersistentList) {
114     if (!m_pvPersistentList->empty()) {
115       // clear the vector
116       m_pvPersistentList->clear();
117     }
118
119     delete m_pvPersistentList;
120     m_pvPersistentList = NULL;
121   }
122
123   // delete the members in vector of user persistent notification
124   if (NULL != m_pvUserPersistentList) {
125     if (!m_pvUserPersistentList->empty()) {
126       // clear the vector
127       m_pvUserPersistentList->clear();
128     }
129
130     delete m_pvUserPersistentList;
131     m_pvUserPersistentList = NULL;
132   }
133
134   if (NULL != CStateNorPersistenceNotification::m_hNSImmediatePersistenceThread) {
135     McClose(CStateNorPersistenceNotification::m_hNSImmediatePersistenceThread);
136     CStateNorPersistenceNotification::m_hNSImmediatePersistenceThread = NULL;
137   }
138
139   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
140 }
141 // LCOV_EXCL_STOP
142
143 ////////////////////////////////////////////////////////////////////////////////////////////////////
144 /// CreateNotificationObject
145 /// This function is used to get notification object from map. If doesn't exists, it create new
146 /// object as per type of notification.
147 ////////////////////////////////////////////////////////////////////////////////////////////////////
148 CNotification *CNotificationManager::CreateNotificationObject(const std::string &f_cnotificationname,
149                                                               const UI_32 f_uimsglength,
150                                                               const EFrameworkunifiedNotificationType f_enotificationtype,
151                                                               const UI_32 f_uidelay) {
152   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
153
154   // pointer of notification object
155   CNotification *l_pNotification = NULL;
156
157   // iterator to find notification from map of CNotification
158   Notification_Iterator_Type l_itNotification;
159
160   if (NULL == m_pmNotificationList || NULL == m_pvPersistentList || NULL == m_pvUserPersistentList) {  // LCOV_EXCL_START 6: double check, m_pmNotificationList, m_pvPersistentList, m_pvUserPersistentList can't be NULL  // NOLINT[whitespace/line_length]
161     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
162     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map/vector object is NULL");  // LCOV_EXCL_LINE 6: m_pmNotificationList, m_pvPersistentList, m_pvUserPersistentList can't be NULL  // NOLINT[whitespace/line_length]
163     return NULL;
164   }
165   // LCOV_EXCL_STOP
166
167   // check if notification already exists
168   l_itNotification = m_pmNotificationList->find(f_cnotificationname);
169
170   // if exists remove previous entry
171   if (m_pmNotificationList->end() != l_itNotification) {
172     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Removing previous entry of notification %s from map", f_cnotificationname.c_str());
173     m_pmNotificationList->erase(l_itNotification);
174   }
175
176   switch (f_enotificationtype) {
177     // if notification is regular notification
178     case eFrameworkunifiedNotificationVar: {
179         FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Regular Notification :: %s", f_cnotificationname.c_str());
180         l_pNotification = new(std::nothrow) CRegularNotification(f_cnotificationname,
181                                                                  f_uimsglength);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
182         break;
183       }
184
185     // if notification is state notification
186     case eFrameworkunifiedStateVar: {
187         FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "State Notification :: %s", f_cnotificationname.c_str());
188         l_pNotification = new(std::nothrow) CStateNotification(f_cnotificationname,
189                                                                f_uimsglength);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
190         break;
191       }
192
193     // if notification is persistence notification
194     case eFrameworkunifiedPersistedStateVar: {
195         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "PersistedState Notification :: %s", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
196         l_pNotification = new(std::nothrow) CStatePersistenceNotification(f_cnotificationname,
197                                                                           f_uimsglength);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
198
199         if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
200           // insert notification in persistent notification vector
201           m_pvPersistentList->push_back(f_cnotificationname);
202         } else {
203           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
204           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory not allocated");  // LCOV_EXCL_LINE 5: It's impossible to mock new() function  // NOLINT[whitespace/line_length]
205         }
206
207         break;
208       }
209
210     // if notification is user persistence notification
211     case eFrameworkunifiedPersistedStateUserVar: {
212         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "PersistedStateUser Notification :: %s", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
213         l_pNotification = new(std::nothrow) CStatePersistenceUserNotification(f_cnotificationname,
214                                                                               f_uimsglength);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
215
216         if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
217           // insert notification in user persistent notification vector
218           m_pvUserPersistentList->push_back(f_cnotificationname);
219         } else {
220           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
221           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "NULL pointer error");  // LCOV_EXCL_LINE 5: It's impossible to mock new() function  // NOLINT[whitespace/line_length]
222         }
223
224         break;
225       }
226
227     // if notification is immediate persistence notification
228     case eFrameworkunifiedImmediatePersistedStateVar: {
229         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Immediate PersistedState Notification :: %s", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
230         l_pNotification = new(std::nothrow) CStateNorPersistenceNotification(f_cnotificationname,
231                                                                              f_uimsglength,
232                                                                              f_uidelay);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
233         break;
234       }
235
236     default:
237       break;
238   }
239
240   if (NULL != l_pNotification) {
241     // insert notification in notification map
242     m_pmNotificationList->insert(make_pair(f_cnotificationname, l_pNotification));
243   } else {
244     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification object creation failed for %s.", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
245   }
246
247   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
248   return l_pNotification;
249 }
250
251 ////////////////////////////////////////////////////////////////////////////////////////////////////
252 /// SearchNotification
253 /// This function is used to search whether notification object is present in map or not.
254 /// If present it sends the reference.
255 ////////////////////////////////////////////////////////////////////////////////////////////////////
256 CNotification *CNotificationManager::SearchNotification(const std::string &f_cnotificationname) {
257   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
258
259   CNotification *l_pNotification = NULL;
260
261   // iterator to find notification from map of notifications
262   Notification_Iterator_Type l_itNotification;
263
264   if (NULL == m_pmNotificationList || f_cnotificationname.empty()) {  // LCOV_EXCL_BR_LINE 6: double check, m_pmNotificationList can't be NULL and f_cnotificationname can't be empty  // NOLINT[whitespace/line_length]
265     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
266     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map pointer is NULL");  // LCOV_EXCL_LINE 6: m_pmNotificationList can't be NULL and f_cnotificationname can't be empty  // NOLINT[whitespace/line_length]
267   } else {
268     // check if this notification's object present in map
269     l_itNotification = m_pmNotificationList->find(f_cnotificationname);
270
271     // if notification found in map
272     if (m_pmNotificationList->end() != l_itNotification) {
273       FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Notification found in map :: %s", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
274
275       // get the notification object pointer from map
276       l_pNotification = (*l_itNotification).second;
277     } else {
278       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Notification not found :: %s", f_cnotificationname.c_str());
279     }
280   }
281
282   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
283   return l_pNotification;
284 }
285
286 ////////////////////////////////////////////////////////////////////////////////////////////////////
287 /// SearchPersistenceNotification
288 /// This function is used to search for the given persistent notification in map.
289 ////////////////////////////////////////////////////////////////////////////////////////////////////
290 CStateNotification *CNotificationManager::SearchPersistenceNotification(const std::string &f_cnotificationname) {
291   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
292
293   // pointer of notification object
294   CNotification *l_pNotification = NULL;
295   CStateNotification *l_pStateNotification = NULL;
296
297   // search the notification in the map
298   l_pNotification = SearchNotification(f_cnotificationname);
299
300   if (NULL != l_pNotification) {
301     if (eFrameworkunifiedPersistedStateVar      == l_pNotification->GetNotificationType() ||
302         eFrameworkunifiedPersistedStateUserVar    == l_pNotification->GetNotificationType() ||
303         eFrameworkunifiedImmediatePersistedStateVar == l_pNotification->GetNotificationType()) {
304       l_pStateNotification = static_cast<CStateNotification *>(l_pNotification);
305     }
306   } else {
307     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "There is no persistence notification registered with name :: %s",
308            f_cnotificationname.c_str());
309   }
310
311   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
312   return l_pStateNotification;
313 }
314
315 ////////////////////////////////////////////////////////////////////////////////////////////////////
316 /// NotificationpersistentserviceServiceOnRegisterEvents
317 /// This function creates notification object depending on its type and if already created it adds
318 /// the service name to the list in the notification object.
319 ////////////////////////////////////////////////////////////////////////////////////////////////////
320 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceServiceOnRegisterEvents(const std::string &f_cservicename,
321                                                             const std::string &f_cnotificationname,
322                                                             const UI_32 f_uimsglength,
323                                                             const EFrameworkunifiedNotificationType f_enotificationtype,
324                                                             const UI_32 f_uidelay) {
325   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
326   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
327
328   CNotification *l_pNotification = NULL;
329
330   if (f_cservicename.empty() || f_cnotificationname.empty()) {
331     l_estatus = eFrameworkunifiedStatusInvldParam;
332   } else {
333     // get the notification object from map or create new object
334     l_pNotification = SearchNotification(f_cnotificationname);
335
336     // if new notification is registered
337     if (NULL == l_pNotification) {
338       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Create new notification object :: %s", f_cnotificationname.c_str());
339
340       // create the new notification object depending on type and insert in map and vector
341       l_pNotification = CreateNotificationObject(f_cnotificationname,
342                                                  f_uimsglength,
343                                                  f_enotificationtype,
344                                                  f_uidelay);
345
346       if (NULL != l_pNotification) {
347         FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Set Notification publisher %s for notification %s", f_cservicename.c_str(),
348                f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
349
350         // set publisher name
351         l_estatus = l_pNotification->SetEventPublisher(f_cservicename);
352       }
353     } else {  // if notification object already exists
354       EFrameworkunifiedNotificationType l_eNotificationType = l_pNotification->GetNotificationType();
355
356       // <<notification type is eFrameworkunifiedUnknown
357       // if some service had already subscribed to the notification before registering it.>>
358       if (eFrameworkunifiedUnknown == l_eNotificationType) {
359         // creates new notification object depending on the type and insert it in notification map
360         l_estatus = ChangeNotificationType(l_pNotification, f_cservicename, f_cnotificationname, f_uimsglength,
361                                            f_enotificationtype, f_uidelay);
362
363         // delete the old notification object
364         delete l_pNotification;  // LCOV_EXCL_BR_LINE 11: unexpected branch
365         l_pNotification = NULL;
366       } else {  // notification is already registered by some service
367         // update the notification property, if re-registered by the same publisher
368         if (f_cservicename == l_pNotification->GetPublisherName() ||    // if re-register by service
369             "" == l_pNotification->GetPublisherName()) {           // if previously unregistered by service
370           // if type is same just update the length of notification data
371           if (l_eNotificationType == f_enotificationtype) {
372             if (l_pNotification->GetMaxMessageSize() != f_uimsglength) {
373               FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
374                      "Updating max size of notification %s to %d from %d", f_cnotificationname.c_str(),
375                      f_uimsglength, l_pNotification->GetMaxMessageSize());
376               l_estatus = l_pNotification->ResetMaxMessageSize(f_uimsglength);
377             }
378
379             if ("" == l_pNotification->GetPublisherName()) {
380               FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
381                      "Updating publisher name of notification %s to %s from %s", f_cservicename.c_str(),
382                      f_cnotificationname.c_str(), l_pNotification->GetPublisherName().c_str());
383               l_pNotification->SetEventPublisher(f_cservicename);
384             }
385           } else if (eFrameworkunifiedImmediatePersistedStateVar != l_eNotificationType &&
386                      eFrameworkunifiedImmediatePersistedStateVar != f_enotificationtype) {
387             // else create new notification object depending on the type and delete the old one
388             // note: do not change immediate notification type
389             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Changing type of notfn %s from %d to %d", f_cnotificationname.c_str(),
390                    l_eNotificationType, f_enotificationtype);
391
392             std::vector<std::string>::iterator l_itNotificationName;
393
394             // remove the notification name from the persistent list of notification(if any)
395             if (eFrameworkunifiedPersistedStateVar == l_eNotificationType) {
396               l_itNotificationName = find(m_pvPersistentList->begin(), m_pvPersistentList->end(), f_cnotificationname);
397
398               if (m_pvPersistentList->end() != l_itNotificationName) {
399                 m_pvPersistentList->erase(l_itNotificationName);
400               }
401             } else if (eFrameworkunifiedPersistedStateUserVar == l_eNotificationType) {
402               l_itNotificationName = find(m_pvUserPersistentList->begin(),
403                                           m_pvUserPersistentList->end(),
404                                           f_cnotificationname);
405
406               if (m_pvUserPersistentList->end() != l_itNotificationName) {
407                 m_pvUserPersistentList->erase(l_itNotificationName);
408               }
409             } else {
410               // do nothing
411             }
412
413             // creates new notification object depending on the new type and insert it in map and delete the old one
414             l_estatus = ChangeNotificationType(l_pNotification, f_cservicename, f_cnotificationname, f_uimsglength,
415                                                f_enotificationtype, f_uidelay);
416
417             // delete the old notification object
418             delete l_pNotification;
419             l_pNotification = NULL;
420           } else {
421             // do nothing
422           }
423         } else {
424           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notfn: %s already registered by %s, skipping register request by %s",
425                  f_cnotificationname.c_str(), l_pNotification->GetPublisherName().c_str(), f_cservicename.c_str());
426
427           l_estatus = eFrameworkunifiedStatusFail;
428         }
429       }
430     }
431   }
432
433   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
434   return l_estatus;
435 }
436
437 ////////////////////////////////////////////////////////////////////////////////////////////////
438 /// ChangeNotificationType
439 /// This function creates new notification object depending on the type and replaces the old one.
440 ////////////////////////////////////////////////////////////////////////////////////////////////
441 EFrameworkunifiedStatus CNotificationManager::ChangeNotificationType(CNotification *f_pnotification,
442                                                         const std::string &f_cservicename,
443                                                         const std::string &f_cnotificationname,
444                                                         const UI_32 f_uimsglength,
445                                                         const EFrameworkunifiedNotificationType f_enotificationtype,
446                                                         const UI_32 f_uidelay) {
447   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
448   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
449
450   CNotification *l_pNewNotification = NULL;
451
452   if (NULL != f_pnotification) {  // LCOV_EXCL_BR_LINE 6: f_pnotification can't be NULL
453     FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Create New Notification :: %s", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
454
455     // create new notification object as per notification type
456     l_pNewNotification = CreateNotificationObject(f_cnotificationname, f_uimsglength, f_enotificationtype, f_uidelay);
457
458     if (NULL != l_pNewNotification) {
459       l_estatus = l_pNewNotification->SetEventPublisher(f_cservicename);
460
461       // assign subscribers list to newly created notification
462       l_pNewNotification->SetNewSubscribersList(f_pnotification);
463     } else {
464       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
465              "Error creating notification object for notification:%s",
466              f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
467       l_estatus = eFrameworkunifiedStatusNullPointer;
468     }
469   } else {
470     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
471     l_estatus = eFrameworkunifiedStatusNullPointer;  // LCOV_EXCL_LINE 6: f_pnotification can't be NULL
472   }
473
474   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
475   return l_estatus;
476 }
477
478 ////////////////////////////////////////////////////////////////////////////////////////////////////
479 /// NotificationpersistentserviceServiceOnUnRegisterEvents
480 /// This function removes the name of the service from the notification object.
481 ////////////////////////////////////////////////////////////////////////////////////////////////////
482 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceServiceOnUnRegisterEvents(const std::string &f_cservicename,
483                                                               const std::string &f_cnotificationname) {
484   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
485   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
486
487   CNotification *l_pNotification = NULL;
488   std::vector<std::string> *l_pvPersistentList = NULL;
489
490   // iterator to find notification from map of notifications
491   Notification_Iterator_Type l_itNotification;
492
493   if (f_cservicename.empty() || f_cnotificationname.empty()) {
494     l_estatus = eFrameworkunifiedStatusInvldParam;
495   } else {
496     // check if this notification's object present in map
497     l_itNotification = m_pmNotificationList->find(f_cnotificationname);
498
499     // if notification found in map
500     if (m_pmNotificationList->end() != l_itNotification) {
501       FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Notification found in map");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
502
503       // get the notification object pointer from map
504       l_pNotification = (*l_itNotification).second;
505
506       if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 6: f_pnotification can't be NULL
507         if (eFrameworkunifiedPersistedStateUserVar == l_pNotification->GetNotificationType()) {
508           l_pvPersistentList = m_pvUserPersistentList;
509         } else if (eFrameworkunifiedPersistedStateVar == l_pNotification->GetNotificationType()) {
510           l_pvPersistentList = m_pvPersistentList;
511         }
512
513         // reset the publisher name
514         l_estatus = l_pNotification->ResetEventPublisher(f_cservicename);
515
516         if (eFrameworkunifiedStatusOK == l_estatus) {
517           // if no other service is subscribed to this notification and no service is registered
518           // to this notification remove the notification object from map
519           if (!l_pNotification->IsServiceRegistered() &&
520               l_pNotification->IsSubscribersListEmpty()) {
521             FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Deleting Notification Object");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
522
523             // delete the notification
524             delete l_pNotification;  // LCOV_EXCL_BR_LINE 11: unexpected branch
525             l_pNotification = NULL;
526
527             m_pmNotificationList->erase(l_itNotification);
528
529             if (l_pvPersistentList) {
530               // find the notification in vector
531               std::vector<std::string>::iterator l_itNotificationName;
532
533               l_itNotificationName = find(l_pvPersistentList->begin(),
534                                           l_pvPersistentList->end(),
535                                           f_cnotificationname);
536
537               if (l_pvPersistentList->end() != l_itNotificationName) {
538                 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Deleting Notification name from vector");
539                 l_pvPersistentList->erase(l_itNotificationName);
540               }
541             } else {
542               FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Persistent list empty");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
543             }
544           } else {
545             FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Services still registered or subscriber list empty");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
546           }
547         } else {
548           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s is not registered by service %s",
549                  f_cnotificationname.c_str(), f_cservicename.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
550         }
551       } else {
552         // LCOV_EXCL_START 6: f_pnotification can't be NULL
553         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
554         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s not registered", f_cnotificationname.c_str());
555
556         l_estatus = eFrameworkunifiedStatusNullPointer;
557         // LCOV_EXCL_STOP
558       }
559     } else {
560       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s not found.", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
561
562       l_estatus = eFrameworkunifiedStatusFail;
563     }
564   }
565
566   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
567   return l_estatus;
568 }
569
570 ////////////////////////////////////////////////////////////////////////////////////////////////////
571 /// NotificationpersistentserviceServiceOnPublishEvent
572 /// This function stores the published data in the notification object in case of state and
573 /// persistent notification.
574 ////////////////////////////////////////////////////////////////////////////////////////////////////
575 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceServiceOnPublishEvent(const std::string &f_cservicename,
576                                                           const std::string &f_cnotificationname,
577                                                           PVOID f_pmessage,
578                                                           const UI_32 f_uimsgsize) {
579   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
580   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
581
582   CNotification *l_pNotification = NULL;
583
584   if (f_cservicename.empty() || f_cnotificationname.empty()) {  // LCOV_EXCL_BR_LINE 6: f_cservicename and f_cnotificationname can't be empty  // NOLINT[whitespace/line_length]
585     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
586     l_estatus = eFrameworkunifiedStatusInvldParam;  // LCOV_EXCL_LINE 6: f_cservicename and f_cnotificationname can't be empty
587   } else {
588     // get the notification object from map
589     l_pNotification = SearchNotification(f_cnotificationname);
590
591     if (NULL != l_pNotification) {
592       // publish the notification
593       if (eFrameworkunifiedStatusOK != (l_estatus = l_pNotification->Publish(f_cservicename,
594                                                                 f_pmessage,
595                                                                 f_uimsgsize))) {
596         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error publishing notification %s published by %s, status: %d",
597                f_cnotificationname.c_str(), f_cservicename.c_str(), l_estatus);  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
598       }
599     } else {
600       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification not registered");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
601
602       l_estatus = eFrameworkunifiedStatusNullPointer;
603     }
604   }
605
606
607   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
608   return l_estatus;
609 }
610
611 ////////////////////////////////////////////////////////////////////////////////////////////////////
612 /// NotificationpersistentserviceServiceOnSubscribeToEvent
613 /// This function adds the name of the application to subscribers list in notification object.
614 ////////////////////////////////////////////////////////////////////////////////////////////////////
615 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceServiceOnSubscribeToEvent(const std::string &f_csubscribername,
616                                                               const std::string &f_cnotificationname) {
617   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
618   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
619
620   // iterator to find notification from map of notifications
621   Notification_Iterator_Type l_itNotification;
622
623   CNotification *l_pNotification = NULL;
624
625   if (f_cnotificationname.empty() || f_csubscribername.empty()) {
626     l_estatus = eFrameworkunifiedStatusInvldParam;
627   } else if (NULL == m_pmNotificationList) {  // LCOV_EXCL_BR_LINE 6 m_pmNotificationList can't be NULL
628     // LCOV_EXCL_START 6: m_pmNotificationList can't be NULL
629     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
630     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map pointer is NULL");
631     l_estatus = eFrameworkunifiedStatusNullPointer;
632     // LCOV_EXCL_STOP
633   } else {
634     // get the notification object from map or create new object
635     l_pNotification = SearchNotification(f_cnotificationname);
636
637     if (NULL == l_pNotification) {
638       FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "CNotification object created for %s", f_cnotificationname.c_str());
639
640       l_pNotification = new(std::nothrow) CNotification(f_cnotificationname, 0);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
641
642       m_pmNotificationList->insert(make_pair(f_cnotificationname, l_pNotification));
643     }
644
645     if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 6: double check, l_pNotification can't be NULL
646       // add subscribers name in subscribers list of notification
647       l_estatus = l_pNotification->AddEventReciever(f_csubscribername);
648     } else {
649       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
650       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory not allocated for l_pNotification");  // LCOV_EXCL_LINE 6: double check, l_pNotification can't be NULL  // NOLINT[whitespace/line_length]
651     }
652   }
653
654   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
655   return l_estatus;
656 }
657
658 ////////////////////////////////////////////////////////////////////////////////////////////////////
659 /// NotificationpersistentserviceServiceOnUnSubscribeFromEvent
660 /// This function removes the name of the application from the subscribers list in notification object.
661 ////////////////////////////////////////////////////////////////////////////////////////////////////
662 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceServiceOnUnSubscribeFromEvent(const std::string &f_csubscribername,
663                                                                   const std::string &f_cnotificationname) {
664   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
665   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
666
667   CNotification *l_pNotification = NULL;
668
669   // iterator to find notification from map of notifications
670   Notification_Iterator_Type l_itNotificationType;
671
672   std::vector<std::string> *l_pvPersistentList = NULL;
673
674   if (f_cnotificationname.empty() || f_csubscribername.empty()) {
675     l_estatus = eFrameworkunifiedStatusInvldParam;
676   } else if (NULL == m_pmNotificationList) {  // LCOV_EXCL_BR_LINE 6: m_pmNotificationList can't be NULL
677     // LCOV_EXCL_START 6: m_pmNotificationList can't be NULL
678     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
679     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification list pointer is NULL");
680     l_estatus = eFrameworkunifiedStatusNullPointer;
681     // LCOV_EXCL_STOP
682   } else {
683     // check if this notification's object present in map
684     l_itNotificationType = m_pmNotificationList->find(f_cnotificationname);
685
686     // if notification found in map
687     if (m_pmNotificationList->end() != l_itNotificationType) {
688       FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Notification %s found in map", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
689
690       l_pNotification = (*l_itNotificationType).second;
691
692       if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 6: l_pNotification can't be NULL
693         if (eFrameworkunifiedPersistedStateUserVar == l_pNotification->GetNotificationType()) {
694           l_pvPersistentList = m_pvUserPersistentList;
695         } else if (eFrameworkunifiedPersistedStateVar == l_pNotification->GetNotificationType()) {
696           l_pvPersistentList = m_pvPersistentList;
697         }
698
699         // removes the subscribers name from subscribers list of notification
700         l_estatus = l_pNotification->DeleteEventReciever(f_csubscribername);
701
702         // if no other service is subscribed to this notification and no service is registered
703         // to this notification remove the notification object from map
704         if (!l_pNotification->IsServiceRegistered() &&
705             l_pNotification->IsSubscribersListEmpty()) {
706           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Deleting Notification Object from map");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
707
708           // delete notification object from map
709           delete l_pNotification;  // LCOV_EXCL_BR_LINE 11: unexpected branch
710           l_pNotification = NULL;
711
712           m_pmNotificationList->erase(l_itNotificationType);
713
714           if (l_pvPersistentList) {
715             //  find notification in vector
716             std::vector<std::string>::iterator l_itNotificationName;
717             l_itNotificationName = find(l_pvPersistentList->begin(),
718                                         l_pvPersistentList->end(),
719                                         f_cnotificationname);
720
721             if (l_pvPersistentList->end() != l_itNotificationName) {
722               FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Deleting Notification from vector");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
723               l_pvPersistentList->erase(l_itNotificationName);
724             }
725           } else {
726             FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Persistent list Empty.");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
727           }
728         }
729       } else {
730         // LCOV_EXCL_START 6: l_pNotification can't be NULL
731         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
732         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Notification %s not registered", f_cnotificationname.c_str());
733         l_estatus = eFrameworkunifiedStatusNullPointer;
734         // LCOV_EXCL_STOP
735       }
736
737     } else {
738       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Notification %s not found.", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
739       l_estatus = eFrameworkunifiedStatusFail;
740     }
741   }
742
743   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
744   return l_estatus;
745 }
746
747 ////////////////////////////////////////////////////////////////////////////////////////////////////
748 /// NPGetPersistentNotificationData
749 ///
750 ////////////////////////////////////////////////////////////////////////////////////////////////////
751 EFrameworkunifiedStatus CNotificationManager::NPGetPersistentNotificationData(const std::string &f_cnotificationname,
752                                                                  PVOID f_pnotificationdata,
753                                                                  const UI_32 f_uidatasize) {
754   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
755   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
756
757   CNotification *l_pNotification = NULL;
758   CStateNotification *l_pStateNotification = NULL;
759   const CPersistentData *l_pPersistentData = NULL;
760
761   if (f_cnotificationname.empty() || NULL == f_pnotificationdata) {  // LCOV_EXCL_BR_LINE 6: f_pnotificationdata can't be NULL and f_cnotificationname can't be empty  // NOLINT[whitespace/line_length]
762     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
763     l_estatus = eFrameworkunifiedStatusInvldParam;  // LCOV_EXCL_LINE 6: f_pnotificationdata can't be NULL and f_cnotificationname can't be empty  // NOLINT[whitespace/line_length]
764   } else {
765     l_pNotification = SearchNotification(f_cnotificationname);
766
767     if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 200: f_cnotificationname must be NTFY_NPPService_UserChange, NTFY_NPPService_UserChange must be registered in FrameworkunifiedOnEntry() by itself.  // NOLINT[whitespace/line_length]
768       const EFrameworkunifiedNotificationType l_eNotificationType = l_pNotification->GetNotificationType();
769
770       if (eFrameworkunifiedStateVar                   == l_eNotificationType ||
771           eFrameworkunifiedPersistedStateVar          == l_eNotificationType ||
772           eFrameworkunifiedPersistedStateUserVar      == l_eNotificationType ||
773           eFrameworkunifiedImmediatePersistedStateVar == l_eNotificationType) {  // LCOV_EXCL_BR_LINE 200: NTFY_NPPService_UserChange's type is eFrameworkunifiedPersistedStateVar.   // NOLINT[whitespace/line_length]
774         l_pStateNotification = static_cast<CStateNotification *>(l_pNotification);
775
776         l_pPersistentData = l_pStateNotification->GetPersistentData();
777
778         if (NULL != l_pPersistentData) {
779           if (f_uidatasize >= l_pPersistentData->m_uiMsgSize) {
780             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Sending Data Size %d", l_pPersistentData->m_uiMsgSize);
781
782             if (NULL != l_pPersistentData->m_pMessage) {
783               std::memcpy(f_pnotificationdata, l_pPersistentData->m_pMessage, l_pPersistentData->m_uiMsgSize);
784             } else {
785               FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Notification data is NULL");
786             }
787           } else {
788             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
789                    "Smaller buffer size %d is received for notification data of size %d", f_uidatasize,
790                    l_pPersistentData->m_uiMsgSize);
791           }
792         } else {
793           l_estatus = eFrameworkunifiedStatusFail;
794           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
795                  "Persistent data object is NULL for notification %s", f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
796         }
797       } else {
798         // LCOV_EXCL_START 200: NTFY_NPPService_UserChange's type is eFrameworkunifiedPersistedStateVar.
799         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
800         l_estatus = eFrameworkunifiedStatusFail;
801         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Get notification data failed, Notification %s is registered as type %d",
802                f_cnotificationname.c_str(), l_eNotificationType);
803         // LCOV_EXCL_STOP
804       }
805     } else {
806       // LCOV_EXCL_START 200: f_cnotificationname must be NTFY_NPPService_UserChange, NTFY_NPPService_UserChange must be registered in FrameworkunifiedOnEntry() by itself.  // NOLINT[whitespace/line_length]
807       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
808       l_estatus = eFrameworkunifiedStatusFail;
809       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s not found.", f_cnotificationname.c_str());
810       // LCOV_EXCL_STOP
811     }
812   }
813
814   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
815   return l_estatus;
816 }
817
818 ////////////////////////////////////////////////////////////////////////////////////////////////////
819 /// NotificationpersistentserviceServiceOnGetPersistentData
820 /// This function is used to get the persistent data stored related to notification.
821 ////////////////////////////////////////////////////////////////////////////////////////////////////
822 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceServiceOnGetPersistentData(const std::string &f_cnotificationname,
823                                                                const std::string &f_creceivername) {
824   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
825   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
826
827   CNotification *l_pNotification = NULL;
828   CStateNotification *l_pStateNotification = NULL;
829   const CPersistentData *l_pPersistentData = NULL;
830
831   if (f_cnotificationname.empty() || f_creceivername.empty()) {  // LCOV_EXCL_BR_LINE 6: f_creceivername can't be NULL and f_cnotificationname can't be empty  // NOLINT[whitespace/line_length]
832     // LCOV_EXCL_START 6: f_creceivername can't be NULL and f_cnotificationname can't be empty
833     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
834     l_estatus = eFrameworkunifiedStatusInvldParam;
835     // LCOV_EXCL_STOP
836   } else {
837     // open the receiver message queue
838     HANDLE l_hReceiverMq = McOpenSender(f_creceivername.c_str());
839
840     if (NULL == l_hReceiverMq) {  // LCOV_EXCL_BR_LINE 4: NSFW error case
841       // LCOV_EXCL_START 4: NSFW error case.
842       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
843       // catastrophic failure!
844       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Failed to open MessageQ %s ", f_creceivername.c_str());
845       l_estatus = eFrameworkunifiedStatusFail;
846       // LCOV_EXCL_STOP
847     } else {
848       // get the notification object from map or create new object
849       l_pNotification = SearchNotification(f_cnotificationname);
850
851       if (NULL != l_pNotification) {
852         l_pStateNotification = static_cast<CStateNotification *>(l_pNotification);
853
854         if (NULL != l_pStateNotification) {  // LCOV_EXCL_BR_LINE 5: fail safe for static_cast<CStateNotification *>
855           l_pPersistentData = l_pStateNotification->GetPersistentData();
856
857           if (NULL != l_pPersistentData) {
858             FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Sending Data Size %d", l_pPersistentData->m_uiMsgSize);
859
860             if (NULL == l_pPersistentData->m_pMessage) {
861               FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Sending Data is NULL");
862             }
863
864             // sent the notification data to requester
865             l_estatus = McSend(l_hReceiverMq,
866                                AppName,
867                                NPS_GET_PERS_DATA_ACK,
868                                l_pPersistentData->m_uiMsgSize,
869                                l_pPersistentData->m_pMessage);
870             FRAMEWORKUNIFIEDLOG(ZONE_PRD_INFO2, __FUNCTION__, "Persistent data found for notification %s. "
871                    "Sent NPS_GET_PERS_DATA_ACK to %s. Status: %d."
872                    , f_cnotificationname.c_str(), f_creceivername.c_str(), l_estatus);
873           } else {  // In case of failure, we send back a failure ACK
874             l_estatus = eFrameworkunifiedStatusFail;
875             FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "No persistent data found for notification %s. "
876                    , f_cnotificationname.c_str());
877           }
878         }
879       } else {
880         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s not found", f_cnotificationname.c_str());   // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
881         l_estatus = eFrameworkunifiedStatusInvldParam;
882       }
883       // Close the mq handle
884       McClose(l_hReceiverMq);
885       l_hReceiverMq = NULL;
886     }
887   }
888
889   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
890   return l_estatus;
891 }
892
893 ////////////////////////////////////////////////////////////////////////////////////////////////////
894 /// NotificationpersistentserviceGetPersistentNotificationData
895 /// This function is used to get the list of persistent notifications and data associated with it.
896 ////////////////////////////////////////////////////////////////////////////////////////////////////
897 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceGetPersistentNotificationData(std::vector<CNotificationsToPersist *>
898                                                                   *f_pvpersistnotification,
899                                                                   const EFrameworkunifiedNotificationType f_enotificationtype,
900                                                                   UI_32 f_uinotificationpersistentservicepersistcategoryflag) {
901   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
902   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
903
904   CNotification *l_pNotification = NULL;
905   CStateNotification *l_pStateNotification = NULL;
906   CStatePersistenceNotification *l_pStatePersistenceNotification = NULL;
907
908   std::string l_cNotificationName = "";
909   CNotificationsToPersist *l_pNotificationsToPersist = NULL;
910   const CPersistentData *l_pPData = NULL;
911
912   std::vector<std::string> *l_pvPersistentList = NULL;
913
914   // iterator for retrieving notifications from map of notifications
915   Notification_Iterator_Type l_itNotification;
916
917   if (eFrameworkunifiedPersistedStateUserVar == f_enotificationtype) {
918     l_pvPersistentList = m_pvUserPersistentList;
919   } else if (eFrameworkunifiedPersistedStateVar == f_enotificationtype) {  // LCOV_EXCL_BR_LINE 6: f_enotificationtype must be eFrameworkunifiedPersistedStateUserVar or eFrameworkunifiedPersistedStateVar  // NOLINT[whitespace/line_length]
920     l_pvPersistentList = m_pvPersistentList;
921   }
922
923   // copy all the notification data in map to received vector
924   if (NULL != f_pvpersistnotification && NULL != l_pvPersistentList) {  // LCOV_EXCL_BR_LINE 6: f_pvpersistnotification and l_pvPersistentList can't be null  // NOLINT[whitespace/line_length]
925     for (UI_32 l_uiCount = 0;
926          l_uiCount < l_pvPersistentList->size();
927          l_uiCount++) {
928       // get the persistent notification name from vector
929       l_cNotificationName = l_pvPersistentList->at(l_uiCount);
930
931       // search for notification in map
932       l_itNotification = m_pmNotificationList->find(l_cNotificationName);
933
934       // notification found in map
935       if (m_pmNotificationList->end() != l_itNotification) {
936         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Persistent Notification: %s", l_cNotificationName.c_str());   // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
937
938         // get notification object from map
939         l_pNotification = (*l_itNotification).second;
940
941         if (NULL != l_pNotification) {   // LCOV_EXCL_BR_LINE 6: l_pNotification can't be NULL
942           if (eFrameworkunifiedPersistedStateVar == f_enotificationtype) {
943             l_pStatePersistenceNotification = static_cast<CStatePersistenceNotification *>(l_pNotification);
944
945             // get the notification's default data
946             if ((eFrameworkunifiedUserData        == l_pStatePersistenceNotification->GetPersistentCategory() &&
947                  (f_uinotificationpersistentservicepersistcategoryflag & eFrameworkunifiedUserData)) ||
948                 (eFrameworkunifiedFactoryData       == l_pStatePersistenceNotification->GetPersistentCategory() &&
949                  (f_uinotificationpersistentservicepersistcategoryflag & eFrameworkunifiedFactoryData)) ||
950                 (eFrameworkunifiedFactoryCustomerData == l_pStatePersistenceNotification->GetPersistentCategory() &&
951                  (f_uinotificationpersistentservicepersistcategoryflag & eFrameworkunifiedFactoryCustomerData)) ||
952                 (eFrameworkunifiedDealerData        == l_pStatePersistenceNotification->GetPersistentCategory() &&
953                  (f_uinotificationpersistentservicepersistcategoryflag & eFrameworkunifiedDealerData))) {
954               l_pPData = l_pStatePersistenceNotification->GetDefaultPersistentData();
955             } else {
956               l_pStateNotification = l_pStatePersistenceNotification;
957
958               // get the published notification data
959               if (l_pStateNotification->IsPublished()) {
960                 l_pPData = l_pStateNotification->GetPersistentData();
961               } else {
962                 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Notification not published");
963               }
964             }
965           } else {
966             l_pStateNotification = static_cast<CStateNotification *>(l_pNotification);
967
968             // if not to reset userdata
969             if (0 == (f_uinotificationpersistentservicepersistcategoryflag & eFrameworkunifiedUserData)) {
970               if (l_pStateNotification->IsPublished()) {
971                 l_pPData = l_pStateNotification->GetPersistentData();
972               } else {
973                 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Notification not published");
974               }
975             }
976           }
977
978           if ((NULL != l_pStateNotification) && (NULL != l_pPData)) {
979             l_pNotificationsToPersist = CreateNotificationObjectToPersist(l_pStateNotification, l_pPData);  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
980
981             // insert the persistent data in map
982             f_pvpersistnotification->push_back(l_pNotificationsToPersist);  // LCOV_EXCL_BR_LINE 11: unexpected branch
983
984             l_pPData = NULL;
985           } else {
986             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "no data is stored in notification %s", l_cNotificationName.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
987           }
988         } else {
989           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
990           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification object is NULL for %s", l_cNotificationName.c_str());  // LCOV_EXCL_LINE 6: l_pNotification can't be NULL  // NOLINT[whitespace/line_length]
991         }
992       } else {
993         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Non Persistent Notification: %s", l_cNotificationName.c_str());
994       }
995     }
996   } else {
997     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
998     l_estatus = eFrameworkunifiedStatusNullPointer;  // LCOV_EXCL_LINE 6: f_pvpersistnotification and l_pvPersistentList can't be null  // NOLINT[whitespace/line_length]
999   }
1000
1001   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1002   return l_estatus;
1003 }
1004
1005 ////////////////////////////////////////////////////////////////////////////////////////////////////
1006 /// CreateNotificationObjectToPersist
1007 /// Creates the CNotificationsToPersist object from notification object and the persistent data.
1008 ////////////////////////////////////////////////////////////////////////////////////////////////////
1009 CNotificationsToPersist *CNotificationManager::CreateNotificationObjectToPersist(CStateNotification
1010                                                                                  *f_pStateNotification,
1011                                                                                  const CPersistentData *f_pdata) {
1012   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1013
1014   CNotificationsToPersist *l_pNotificationsToPersist = NULL;
1015   CPersistentData *l_pData = NULL;
1016
1017   if (NULL != f_pStateNotification && NULL != f_pdata) {  // LCOV_EXCL_BR_LINE 6: f_pStateNotification and f_pdata can't be NULL  // NOLINT[whitespace/line_length]
1018     if (f_pStateNotification->GetMaxMessageSize() >= f_pdata->m_uiMsgSize) {
1019       l_pNotificationsToPersist = new(std::nothrow) CNotificationsToPersist();  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
1020
1021       if (NULL != l_pNotificationsToPersist) {  // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
1022         l_pNotificationsToPersist->m_pPersistentData = new(std::nothrow) CPersistentData();  // LCOV_EXCL_BR_LINE 11: unexpected branch  // NOLINT[whitespace/line_length]
1023         l_pData = l_pNotificationsToPersist->m_pPersistentData;
1024
1025         if (NULL != l_pData) {  // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
1026           l_pNotificationsToPersist->m_cNotificationName = f_pStateNotification->GetNotificationName();
1027           l_pNotificationsToPersist->m_uiMaxMsgLength = f_pStateNotification->GetMaxMessageSize();
1028           l_pNotificationsToPersist->m_ePersistentType = f_pStateNotification->GetNotificationType();
1029
1030           if (eFrameworkunifiedPersistedStateVar == l_pNotificationsToPersist->m_ePersistentType) {
1031             l_pNotificationsToPersist->m_ePersistCategory = (static_cast<CStatePersistenceNotification *>
1032                                                              (f_pStateNotification))->GetPersistentCategory();
1033           }
1034
1035           l_pNotificationsToPersist->m_cPublisherName = f_pStateNotification->GetPublisherName();
1036
1037           l_pData->m_uiMsgSize = f_pdata->m_uiMsgSize;
1038           l_pData->m_pMessage = new(std::nothrow) CHAR[l_pNotificationsToPersist->m_uiMaxMsgLength];
1039
1040           if (NULL != l_pData->m_pMessage) {  // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
1041             std::memset(l_pData->m_pMessage, 0, l_pNotificationsToPersist->m_uiMaxMsgLength);
1042             std::memcpy(l_pData->m_pMessage, f_pdata->m_pMessage, f_pdata->m_uiMsgSize);
1043           }
1044         } else {
1045           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1046           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "memory not allocated for l_pNotificationsToPersist");  // LCOV_EXCL_LINE 5: It's impossible to mock new() function  // NOLINT[whitespace/line_length]
1047         }
1048       }
1049     } else {
1050       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1051              "Error persisting notfn, Data size of notification %s is %d greater than max registered size %d",
1052              f_pStateNotification->GetNotificationName().c_str(),
1053              f_pdata->m_uiMsgSize, f_pStateNotification->GetMaxMessageSize());
1054     }
1055   } else {
1056     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1057     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Invalid parameter received");  // LCOV_EXCL_LINE 6: f_pStateNotification and f_pdata can't be NULL  // NOLINT[whitespace/line_length]
1058   }
1059
1060   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1061   return l_pNotificationsToPersist;
1062 }
1063
1064 ////////////////////////////////////////////////////////////////////////////////////////////////////
1065 /// NotificationpersistentserviceSetPersistentNotificationData
1066 /// This function is used to create the persistent notifications object and fill the data related
1067 /// with it on system load.
1068 ////////////////////////////////////////////////////////////////////////////////////////////////////
1069 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceSetPersistentNotificationData(std::vector<CNotificationsToPersist *>
1070                                                                   *f_pvpersistnotification) {
1071   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1072   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1073
1074   CStateNotification *l_pNotification = NULL;
1075   CNotificationsToPersist *l_pNotificationsToPersist = NULL;
1076
1077   std::vector<std::string> *l_pvPersistentList = NULL;
1078
1079   Persistent_Iterator_Type l_itPersistentData;
1080
1081   // store all the notification data received in vector to map of CNotification and to vector of
1082   // persistent notification in case of persistent and user persistent notification
1083   if (NULL != f_pvpersistnotification) {  // LCOV_EXCL_BR_LINE 6: double check, f_pvpersistnotification can't be NULL
1084     for (UI_32 l_uiCount = 0;
1085          l_uiCount < f_pvpersistnotification->size();
1086          l_uiCount++) {
1087       // get the persistent data object
1088       l_pNotificationsToPersist = f_pvpersistnotification->at(l_uiCount);
1089
1090       if (NULL != l_pNotificationsToPersist) {  // LCOV_EXCL_BR_LINE 6: double check, l_pNotificationsToPersist can't be NULL  // NOLINT[whitespace/line_length]
1091         FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Persistent Type %d", l_pNotificationsToPersist->m_ePersistentType);
1092
1093         if (eFrameworkunifiedPersistedStateVar == l_pNotificationsToPersist->m_ePersistentType) {
1094           FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "PersistentState Notification");
1095
1096           l_pNotification = new(std::nothrow) CStatePersistenceNotification(
1097                       l_pNotificationsToPersist->m_cNotificationName,
1098                       l_pNotificationsToPersist->m_uiMaxMsgLength,
1099                       l_pNotificationsToPersist->m_ePersistCategory);
1100
1101           l_pvPersistentList = m_pvPersistentList;
1102         } else if (eFrameworkunifiedPersistedStateUserVar == l_pNotificationsToPersist->m_ePersistentType) {
1103           FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "PersistentStateUser Notification");
1104
1105           l_pNotification = new(std::nothrow) CStatePersistenceUserNotification(
1106                       l_pNotificationsToPersist->m_cNotificationName,
1107                       l_pNotificationsToPersist->m_uiMaxMsgLength);
1108
1109           l_pvPersistentList = m_pvUserPersistentList;
1110         } else if (eFrameworkunifiedImmediatePersistedStateVar == l_pNotificationsToPersist->m_ePersistentType) {  // LCOV_EXCL_BR_LINE 6: l_pNotificationsToPersist->m_ePersistentType must be eFrameworkunifiedPersistedStateVar, eFrameworkunifiedPersistedStateUserVar, eFrameworkunifiedImmediatePersistedStateVar // NOLINT[whitespace/line_length]
1111           FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "PersistentStateUser Notification");
1112
1113           l_pNotification = new(std::nothrow) CStateNorPersistenceNotification(
1114                       l_pNotificationsToPersist->m_cNotificationName,
1115                       l_pNotificationsToPersist->m_uiMaxMsgLength,
1116                       l_pNotificationsToPersist->m_uiDelay,
1117                       l_pNotificationsToPersist->m_ePersistCategory);
1118         }
1119
1120         if (NULL != l_pNotification) {  // LCOV_EXCL_BR_LINE 6: l_pNotification can't be NULL
1121           FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Insert persistent notification object in map");
1122
1123           l_pNotification->SetPersistentData(l_pNotificationsToPersist->m_pPersistentData->m_pMessage,
1124                                              l_pNotificationsToPersist->m_pPersistentData->m_uiMsgSize);
1125
1126           l_pNotification->SetEventPublisher(l_pNotificationsToPersist->m_cPublisherName);
1127
1128           if (NULL != m_pmNotificationList) {  // LCOV_EXCL_BR_LINE 6: double check, m_pmNotificationList can't be NULL
1129             m_pmNotificationList->insert(make_pair(l_pNotificationsToPersist->m_cNotificationName, l_pNotification));
1130
1131             if (NULL != l_pvPersistentList) {
1132               l_pvPersistentList->push_back(l_pNotificationsToPersist->m_cNotificationName);
1133               FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Inserted persistent notification object in map");
1134             }
1135             FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Inserted persistent notification object in vector");
1136           } else {
1137             // LCOV_EXCL_START 6: double check, m_pmNotificationList can't be NULL
1138             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1139             delete l_pNotification;
1140             l_pNotification = NULL;
1141             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification object not inserted in map/vector");
1142             // LCOV_EXCL_STOP
1143           }
1144         } else {
1145           // LCOV_EXCL_START 6: l_pNotification can't be NULL
1146           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1147           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "notification object is NULL");
1148
1149           l_estatus = eFrameworkunifiedStatusNullPointer;
1150           // LCOV_EXCL_STOP
1151         }
1152       } else {
1153         // LCOV_EXCL_START 6: double check, l_pNotificationsToPersist can't be NULL
1154         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1155         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pNotificationsToPersist is NULL");
1156         l_estatus = eFrameworkunifiedStatusNullPointer;
1157         // LCOV_EXCL_STOP
1158       }
1159     }
1160   } else {
1161     // LCOV_EXCL_START 6: double check, f_pvpersistnotification can't be NULL
1162     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1163     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Persistent data pointer is NULL");
1164
1165     l_estatus = eFrameworkunifiedStatusNullPointer;
1166     // LCOV_EXCL_STOP
1167   }
1168
1169   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1170   return l_estatus;
1171 }
1172
1173 ////////////////////////////////////////////////////////////////////////////////////////////////////
1174 /// RemoveUserSpecificNotificationEntry
1175 /// This function is used to remove  the user persistent notifications entry
1176 ////////////////////////////////////////////////////////////////////////////////////////////////////
1177 EFrameworkunifiedStatus CNotificationManager::RemoveUserSpecificNotificationEntry() {    // LCOV_EXCL_START 100: never be used
1178   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1179   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1180   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1181
1182   std::string l_cNotificationName;
1183
1184   std::vector<std::string>::iterator l_itNotificationName;
1185
1186   // iterator to find notification from map of notifications
1187   Notification_Iterator_Type l_itNotification;
1188
1189   CNotification *l_pNotification = NULL;
1190
1191   for (l_itNotificationName = m_pvUserPersistentList->begin() ; l_itNotificationName < m_pvUserPersistentList->end() ;
1192        l_itNotificationName++) {
1193     l_cNotificationName = *(l_itNotificationName);
1194
1195     // check if this notification's object present in map
1196     l_itNotification = m_pmNotificationList->find(l_cNotificationName);
1197
1198     if (m_pmNotificationList->end() != l_itNotification) {
1199       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Notification found in map");
1200
1201       // get the notification object pointer from map
1202       l_pNotification = (*l_itNotification).second;
1203
1204       if (NULL != l_pNotification) {
1205         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Deleting Notification Object");
1206
1207         // delete the notification
1208         delete l_pNotification;
1209         l_pNotification = NULL;
1210
1211         m_pmNotificationList->erase(l_itNotification);
1212
1213         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Deleting Notification name from vector");
1214         m_pvUserPersistentList->erase(l_itNotificationName);
1215
1216         l_itNotificationName = m_pvUserPersistentList->begin();
1217       }
1218     } else {
1219       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification not found.");
1220
1221       l_estatus = eFrameworkunifiedStatusFail;
1222     }
1223   }
1224   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1225   return l_estatus;
1226 }
1227 // LCOV_EXCL_STOP
1228
1229 EFrameworkunifiedStatus CNotificationManager::GetNotificationInfo(const std::string &f_cnotificationname,  // LCOV_EXCL_START 100: never be used  // NOLINT[whitespace/line_length]
1230                                                      CNotificationsToPersist *&f_pnotificationstopersist) {
1231   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1232   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1233   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1234
1235   CNotification *l_pNotification = NULL;
1236   CStateNotification *l_pStateNotification = NULL;
1237   const CPersistentData *l_pPData = NULL;
1238
1239   l_pNotification = SearchNotification(f_cnotificationname);
1240   l_pStateNotification = static_cast<CStateNotification *>(l_pNotification);
1241
1242   if (NULL != l_pStateNotification) {
1243     if (l_pStateNotification->IsPublished()) {
1244       l_pPData = l_pStateNotification->GetPersistentData();
1245
1246       if (NULL != l_pPData) {
1247         f_pnotificationstopersist = new(std::nothrow) CNotificationsToPersist();
1248
1249         if (NULL == f_pnotificationstopersist) {
1250           l_estatus = eFrameworkunifiedStatusNullPointer;
1251           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory allocation error for f_pnotificationstopersist");
1252         }
1253
1254         if (eFrameworkunifiedStatusOK == l_estatus) {
1255           f_pnotificationstopersist->m_pPersistentData = new(std::nothrow) CPersistentData();
1256
1257           if (NULL == f_pnotificationstopersist->m_pPersistentData) {
1258             l_estatus = eFrameworkunifiedStatusNullPointer;
1259             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory allocation error for f_pnotificationstopersist->m_pPersistentData");
1260           }
1261         }
1262
1263         if (eFrameworkunifiedStatusOK == l_estatus) {
1264           f_pnotificationstopersist->m_cNotificationName = l_pStateNotification->GetNotificationName();
1265           f_pnotificationstopersist->m_uiMaxMsgLength    = l_pStateNotification->GetMaxMessageSize();
1266           f_pnotificationstopersist->m_cPublisherName    = l_pStateNotification->GetPublisherName();
1267           f_pnotificationstopersist->m_ePersistentType   = l_pStateNotification->GetNotificationType();
1268
1269           if (eFrameworkunifiedPersistedStateVar == f_pnotificationstopersist->m_ePersistentType) {
1270             f_pnotificationstopersist->m_ePersistCategory = (static_cast<CStatePersistenceNotification *>
1271                                                              (l_pStateNotification))->GetPersistentCategory();
1272           }
1273
1274           if (eFrameworkunifiedImmediatePersistedStateVar == f_pnotificationstopersist->m_ePersistentType) {
1275             CStateNorPersistenceNotification *l_pStateNorPersistenceNotification =
1276                     static_cast<CStateNorPersistenceNotification *>(l_pStateNotification);
1277             f_pnotificationstopersist->m_uiDelay = l_pStateNorPersistenceNotification->GetPersistenceDelay();
1278             f_pnotificationstopersist->m_ePersistCategory = (static_cast<CStateNorPersistenceNotification *>
1279                                                              (l_pStateNotification))->GetPersistentCategory();
1280           }
1281
1282           f_pnotificationstopersist->m_pPersistentData->m_pMessage = new(std::nothrow)
1283           CHAR[f_pnotificationstopersist->m_uiMaxMsgLength];
1284           std::memset(f_pnotificationstopersist->m_pPersistentData->m_pMessage, 0,
1285                       f_pnotificationstopersist->m_uiMaxMsgLength);
1286           std::memcpy(f_pnotificationstopersist->m_pPersistentData->m_pMessage,
1287                       l_pPData->m_pMessage, l_pPData->m_uiMsgSize);
1288
1289           f_pnotificationstopersist->m_pPersistentData->m_uiMsgSize = l_pPData->m_uiMsgSize;
1290         }
1291       } else {
1292         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "No data is stored in notification %s", f_cnotificationname.c_str());
1293       }
1294     } else {
1295       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Notification %s not published", f_cnotificationname.c_str());
1296     }
1297   } else {
1298     l_estatus = eFrameworkunifiedStatusNullPointer;
1299   }
1300
1301   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1302   return l_estatus;
1303 }
1304 // LCOV_EXCL_STOP
1305
1306 ////////////////////////////////////////////////////////////////////////////////////////////////////
1307 /// NotificationpersistentserviceSetDefaultPersistentNotificationData
1308 /// This function is used to set the default data of persistent notification
1309 ////////////////////////////////////////////////////////////////////////////////////////////////////
1310 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceSetDefaultPersistentNotificationData(const std::string &f_cnotificationname,
1311                                                                          PVOID f_pmessage,
1312                                                                          const UI_32 f_uimsgsize) {
1313   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1314   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1315
1316   // pointer of notification object
1317   CStateNotification *l_pStateNotification = SearchPersistenceNotification(f_cnotificationname);
1318
1319   if (NULL != l_pStateNotification) {
1320     l_estatus = l_pStateNotification->SetDefaultPersistentData(f_pmessage, f_uimsgsize);
1321   } else {
1322     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Unable to set default notification data for %s, notification does not exists",
1323            f_cnotificationname.c_str());
1324   }
1325
1326   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1327   return l_estatus;
1328 }
1329
1330 ////////////////////////////////////////////////////////////////////////////////////////////////////
1331 /// NotificationpersistentserviceSetPersistentCategory
1332 /// This function is used to set the persistent type of persistent notification
1333 ////////////////////////////////////////////////////////////////////////////////////////////////////
1334 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentserviceSetPersistentCategory(const std::string &f_cnotificationname,
1335                                                           const EFrameworkunifiedPersistCategory f_epersistcategory) {
1336   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1337   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1338
1339   // pointer of notification object
1340   CStateNotification *l_pStateNotification = SearchPersistenceNotification(f_cnotificationname);
1341
1342   if (NULL != l_pStateNotification) {
1343     EFrameworkunifiedNotificationType l_eNotificationType = l_pStateNotification->GetNotificationType();
1344
1345     if (eFrameworkunifiedPersistedStateVar == l_eNotificationType) {
1346       l_estatus = (static_cast<CStatePersistenceNotification *>(l_pStateNotification))->SetPersistentCategory(
1347                     f_epersistcategory);
1348     } else if (eFrameworkunifiedImmediatePersistedStateVar == l_eNotificationType) {
1349       l_estatus = (static_cast<CStateNorPersistenceNotification *>(l_pStateNotification))->SetPersistentCategory(
1350                     f_epersistcategory);
1351     } else {
1352       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Cannot set category %d for notification %s of type %d", f_epersistcategory,
1353              f_cnotificationname.c_str(), l_eNotificationType);
1354     }
1355   } else {
1356     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1357            "Cannot set category %d for %s, Either not registered or not a persistent notification",
1358            f_epersistcategory, f_cnotificationname.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"  // NOLINT[whitespace/line_length]
1359   }
1360
1361   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1362   return l_estatus;
1363 }
1364
1365 ////////////////////////////////////////////////////////////////////////////////////////////////
1366 /// NotificationpersistentservicePublishImmediateNotification
1367 /// This function publish the immediate notification f_cnotificationname to all its subscribers.
1368 /// This API is called when service updates the immediate notification data in persistent memory
1369 /// using synchronous API.
1370 ////////////////////////////////////////////////////////////////////////////////////////////////
1371 EFrameworkunifiedStatus CNotificationManager::NotificationpersistentservicePublishImmediateNotification(const std::string &f_cservicename,
1372                                                                  const std::string &f_cnotificationname,
1373                                                                  PVOID f_pmessage,
1374                                                                  const UI_32 f_uimsgsize) {
1375   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1376   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1377
1378   if (f_cservicename.empty() || f_cnotificationname.empty()) {
1379     l_estatus = eFrameworkunifiedStatusInvldParam;
1380   } else {
1381     // get the notification object from map
1382     CStateNotification *l_pStateNotf = SearchPersistenceNotification(f_cnotificationname);
1383
1384     if (NULL != l_pStateNotf) {
1385       if (eFrameworkunifiedImmediatePersistedStateVar == l_pStateNotf->GetNotificationType()) {
1386         CStateNorPersistenceNotification *l_pImmediateNotf =
1387                 static_cast<CStateNorPersistenceNotification *>(l_pStateNotf);
1388
1389         // publish the notification
1390         if (eFrameworkunifiedStatusOK != (l_estatus = l_pImmediateNotf->PublishNotification(f_cservicename,
1391                                                                                f_pmessage,
1392                                                                                f_uimsgsize))) {
1393           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error publishing notification %s published by %s, status: %d",
1394                  f_cnotificationname.c_str(), f_cservicename.c_str(), l_estatus);
1395         }
1396       } else {
1397         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s is not registered as immediate persistence by service %s",
1398                f_cnotificationname.c_str(), f_cservicename.c_str());
1399       }
1400     } else {
1401       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification %s not registered by service %s", f_cnotificationname.c_str(),
1402              f_cservicename.c_str());
1403
1404       l_estatus = eFrameworkunifiedStatusNullPointer;
1405     }
1406   }
1407
1408   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1409   return l_estatus;
1410 }
1411
1412 #ifdef NPP_PROFILEINFO_ENABLE
1413
1414 EFrameworkunifiedStatus CNotificationManager::GetNotificationProfilingData(std::string &f_cnotificationprofileInfo) {
1415   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
1416   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1417
1418   Notification_Iterator_Type l_itNotification;
1419   NotifReceiver_Iterator_Type l_itNotifReceiver_Iterator;
1420
1421   CNotification *l_pNotification = NULL;
1422   NotifReceiver_Type *l_pSubscriberList = NULL;
1423
1424   std::stringstream ss;
1425   UI_32 l_uiSubscriberCnt = 0;
1426
1427   std::string l_cPublisher = "";
1428   std::string l_cNotification = "";
1429
1430   try {
1431     if (NULL == m_pmNotificationList) {
1432       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification List m_pmNotificationList is NULL  in notification manager");
1433       l_estatus = eFrameworkunifiedStatusFail;
1434     }
1435
1436     if (eFrameworkunifiedStatusOK == l_estatus && m_pmNotificationList->empty()) {
1437       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification List m_pmNotificationList Empty in notification manager");
1438       l_estatus = eFrameworkunifiedStatusFail;
1439     }
1440
1441     if (eFrameworkunifiedStatusOK == l_estatus) {
1442       f_cnotificationprofileInfo.append("Application Name,");
1443       f_cnotificationprofileInfo.append("Notification Name,");
1444       f_cnotificationprofileInfo.append("Type,");
1445       f_cnotificationprofileInfo.append("Length,");
1446       f_cnotificationprofileInfo.append("Subscribed By,");
1447       f_cnotificationprofileInfo.append("Subscribers Count");
1448
1449       for (l_itNotification = m_pmNotificationList->begin();
1450            l_itNotification != m_pmNotificationList->end();
1451            l_itNotification++) {
1452         l_pNotification = (*l_itNotification).second;
1453         if (NULL == l_pNotification) {
1454           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification object ptr is NULL");
1455           l_estatus = eFrameworkunifiedStatusFail;
1456         } else {
1457           l_cPublisher = l_pNotification->GetPublisherName();
1458           if (l_cPublisher.empty()) {
1459             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Publisher name empty");
1460             l_estatus = eFrameworkunifiedStatusFail;
1461           }
1462
1463           l_cNotification = l_pNotification->GetNotificationName();
1464           if (l_cNotification.empty()) {
1465             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Notification name empty");
1466             l_estatus = eFrameworkunifiedStatusFail;
1467           }
1468
1469           l_pSubscriberList = l_pNotification->GetSubscriberList();
1470           if (NULL == l_pSubscriberList) {
1471             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Subscribers List ptr is NULL");
1472             l_estatus = eFrameworkunifiedStatusFail;
1473           }
1474         }
1475
1476         if (eFrameworkunifiedStatusOK == l_estatus) {
1477           f_cnotificationprofileInfo.append("\n");
1478
1479           f_cnotificationprofileInfo.append(l_cPublisher);
1480           f_cnotificationprofileInfo.append(",");
1481
1482           f_cnotificationprofileInfo.append(l_cNotification);
1483           f_cnotificationprofileInfo.append(",");
1484
1485           switch (l_pNotification->GetNotificationType()) {
1486             case eFrameworkunifiedNotificationVar : {
1487                 f_cnotificationprofileInfo.append("Regular");
1488               }
1489               break;
1490
1491             case eFrameworkunifiedStateVar : {
1492                 f_cnotificationprofileInfo.append("State");
1493               }
1494               break;
1495
1496             case eFrameworkunifiedPersistedStateVar : {
1497                 f_cnotificationprofileInfo.append("PersistenceState");
1498               }
1499               break;
1500
1501             case eFrameworkunifiedPersistedStateUserVar : {
1502                 f_cnotificationprofileInfo.append("UserPersistenceState");
1503               }
1504               break;
1505
1506             case eFrameworkunifiedImmediatePersistedStateVar : {
1507                 f_cnotificationprofileInfo.append("ImmediatePersistenceState");
1508               }
1509               break;
1510
1511             case eFrameworkunifiedUnknown: {
1512                 f_cnotificationprofileInfo.append("Unknown");
1513               }
1514               break;
1515
1516             default:
1517               break;
1518           }
1519           f_cnotificationprofileInfo.append(",");
1520
1521           ss << l_pNotification->GetMaxMessageSize();
1522           f_cnotificationprofileInfo.append(ss.str());
1523           ss.str("");
1524           f_cnotificationprofileInfo.append(",\"");
1525
1526           l_uiSubscriberCnt = 0;
1527           for (l_itNotifReceiver_Iterator =  l_pSubscriberList->begin();
1528                l_pSubscriberList->end() != l_itNotifReceiver_Iterator;) {
1529             f_cnotificationprofileInfo.append(l_itNotifReceiver_Iterator->first);
1530             ++l_uiSubscriberCnt;
1531
1532             ++l_itNotifReceiver_Iterator;
1533
1534             if (l_pSubscriberList->end() != l_itNotifReceiver_Iterator) {
1535               f_cnotificationprofileInfo.append(",");
1536             }
1537           }
1538
1539           f_cnotificationprofileInfo.append("\",");
1540
1541           ss << l_uiSubscriberCnt;
1542           f_cnotificationprofileInfo.append(ss.str());
1543           ss.str("");
1544         }
1545
1546         l_estatus = eFrameworkunifiedStatusOK;
1547       }
1548     }
1549   } catch (std::exception &exp) {
1550     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Exception:: %s", exp.what());
1551     l_estatus = eFrameworkunifiedStatusFail;
1552   }
1553
1554   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1555   return l_estatus;
1556 }
1557
1558 #endif