2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_NS_NPPService
19 /// \brief This file contains implementation of CNotification class.
20 /// It define functionalities common to all types of notification.
22 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 ////////////////////////////////////////////////////////////////////////////////////////////////////
26 ////////////////////////////////////////////////////////////////////////////////////////////////////
28 #include <native_service/frameworkunified_framework_if.h>
29 #include <native_service/ns_message_center_if.h>
30 #include <native_service/ns_np_service_protocol.h>
34 #include <native_service/ns_mc_system_info.h>
35 #include "ns_npp_notificationpersistentservicelog.h"
36 #include "ns_npp_handlelist.h"
37 #include "ns_npp_notification.h"
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 /// Constructor of CNotification class
43 ////////////////////////////////////////////////////////////////////////////////////////////////////
44 CNotification::CNotification() { // LCOV_EXCL_START 8: dead code
45 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
46 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
48 m_cNotificationName = "";
50 m_ePersistentType = eFrameworkunifiedUnknown;
54 m_pmSubscribersList = NULL;
56 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
60 ////////////////////////////////////////////////////////////////////////////////////////////////////
62 /// Constructor of CNotification class
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
64 CNotification::CNotification(const std::string &f_cnotificationname,
65 const UI_32 f_uimaxmsgsize) {
66 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
68 m_cNotificationName = "";
70 m_ePersistentType = eFrameworkunifiedUnknown;
71 m_pmSubscribersList = NULL;
73 if (!f_cnotificationname.empty()) { // LCOV_EXCL_BR_LINE 200: f_cnotificationname can't be empty
74 m_cNotificationName = f_cnotificationname;
75 m_uiMaxMsgSize = f_uimaxmsgsize;
76 // m_ePersistentType = eFrameworkunifiedUnknown;
80 m_pmSubscribersList = new(std::nothrow) NotifReceiver_Type(); // LCOV_EXCL_BR_LINE 11:unexpected branch
82 // LCOV_EXCL_START 200: f_cnotificationname can't be empty
83 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
84 FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Notification String is Empty");
90 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
94 ////////////////////////////////////////////////////////////////////////////////////////////////////
96 /// Destructor of CNotification class
97 ////////////////////////////////////////////////////////////////////////////////////////////////////
98 CNotification::~CNotification() {
99 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
101 // iterator of CNotificationReceiver map
102 NotifReceiver_Iterator_Type l_itNotifReceiver;
104 CNotificationReceiver *l_pNotificationReceiver = NULL;
106 if (NULL != m_pmSubscribersList) { // LCOV_EXCL_BR_LINE 6: m_pmSubscribersList can't be NULL
107 if (!m_pmSubscribersList->empty()) {
108 for (l_itNotifReceiver = m_pmSubscribersList->begin();
109 l_itNotifReceiver != m_pmSubscribersList->end();
110 l_itNotifReceiver++) {
111 l_pNotificationReceiver = (*l_itNotifReceiver).second;
113 if (NULL != l_pNotificationReceiver) { // LCOV_EXCL_BR_LINE 6: l_pNotificationReceiver can't be NULL
114 // NOTE: Uncomment following code when implementation of the function RemoveHandleFromList
115 // is available. To find the reason why it is not implemented, see the function definition.
116 // CHandleList *l_hHandleList = CHandleList::GetHandleList();
117 // l_hHandleList->RemoveHandleFromList((*l_itNotifReceiver).first);
119 delete l_pNotificationReceiver; // LCOV_EXCL_BR_LINE 11: unexpected branch
120 l_pNotificationReceiver = NULL;
125 m_pmSubscribersList->clear();
128 delete m_pmSubscribersList; // LCOV_EXCL_BR_LINE 11: unexpected branch
129 m_pmSubscribersList = NULL;
132 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
135 ////////////////////////////////////////////////////////////////////////////////////////////////////
137 /// This function adds the name of the application to receiver list of particular notification.
138 ////////////////////////////////////////////////////////////////////////////////////////////////////
139 EFrameworkunifiedStatus CNotification::AddEventReciever(const std::string &f_csubscribername) {
140 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
141 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
143 if (!f_csubscribername.empty()) { // LCOV_EXCL_BR_LINE 6: f_csubscribername can't be empty
144 l_estatus = AddReceiverInMap(f_csubscribername);
146 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
147 l_estatus = eFrameworkunifiedStatusInvldParam; // LCOV_EXCL_LINE 6: f_csubscribername can't be empty
150 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
154 ////////////////////////////////////////////////////////////////////////////////////////////////////
156 /// This function publishes the notification to subscribed clients.
157 ////////////////////////////////////////////////////////////////////////////////////////////////////
158 EFrameworkunifiedStatus CNotification::Publish(const std::string &f_cservicename,
160 const UI_32 f_uimsgsize) {
161 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
162 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
163 return eFrameworkunifiedStatusFail;
166 ////////////////////////////////////////////////////////////////////////////////////////////////////
167 /// DeleteEventReciever
168 /// This function deletes the name of application from receivers list.
169 ////////////////////////////////////////////////////////////////////////////////////////////////////
170 EFrameworkunifiedStatus CNotification::DeleteEventReciever(const std::string &f_csubscribername) {
171 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
172 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
174 // iterator of CNotificationReceiver map
175 NotifReceiver_Iterator_Type l_iterator;
177 CNotificationReceiver *l_pNotificationReceiver = NULL;
179 if (!f_csubscribername.empty()) { // LCOV_EXCL_BR_LINE 6: double check, f_csubscribername can't be empty
180 l_iterator = m_pmSubscribersList->find(f_csubscribername);
183 if (l_iterator != m_pmSubscribersList->end()) {
184 l_pNotificationReceiver = (*l_iterator).second;
186 if (NULL != l_pNotificationReceiver) { // LCOV_EXCL_BR_LINE 6: l_pNotificationReceiver can't be NULL
187 // NOTE: Uncomment following code when implementation of the function RemoveHandleFromList
188 // is available. To find the reason why it is not implemented, see the function definition.
189 // CHandleList *l_hHandleList = CHandleList::GetHandleList();
190 // l_hHandleList->RemoveHandleFromList((*l_iterator).first);
192 delete l_pNotificationReceiver; // LCOV_EXCL_BR_LINE 11: unexpected branch
193 l_pNotificationReceiver = NULL;
196 m_pmSubscribersList->erase(l_iterator);
197 FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Subscriber successfully deleted"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
199 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Invalid Iterator");
202 // LCOV_EXCL_START 6: double check, f_csubscribername can't be empty
203 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
204 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Subscriber Name String is Empty");
205 l_estatus = eFrameworkunifiedStatusFail;
209 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
213 ////////////////////////////////////////////////////////////////////////////////////////////////////
214 /// SetNewSubscribersList
215 /// This function sets the subscribers list of notification
216 ////////////////////////////////////////////////////////////////////////////////////////////////////
217 EFrameworkunifiedStatus CNotification::SetNewSubscribersList(CNotification *f_pnotification) {
218 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
219 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
221 // iterator of CNotificationReceiver map
222 NotifReceiver_Iterator_Type l_itNotifReceiver;
224 std::string l_cSubscriberName;
226 if (NULL != f_pnotification && NULL != f_pnotification->m_pmSubscribersList) { // LCOV_EXCL_BR_LINE 6: f_pnotification and f_pnotification->m_pmSubscribersList can't be empty // NOLINT[whitespace/line_length]
227 if (!f_pnotification->m_pmSubscribersList->empty()) {
228 for (l_itNotifReceiver = f_pnotification->m_pmSubscribersList->begin();
229 l_itNotifReceiver != f_pnotification->m_pmSubscribersList->end();
230 l_itNotifReceiver++) {
231 l_cSubscriberName = (*l_itNotifReceiver).first;
232 AddReceiverInMap(l_cSubscriberName); // LCOV_EXCL_BR_LINE 11: unexpected branch
235 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Subscriber List Empty");
238 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
239 l_estatus = eFrameworkunifiedStatusNullPointer; // LCOV_EXCL_LINE 6: f_pnotification and f_pnotification->m_pmSubscribersList can't be empty // NOLINT[whitespace/line_length]
242 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
246 ////////////////////////////////////////////////////////////////////////////////////////////////////
247 /// SetEventPublisher
248 /// This function set the publisher name to current received service name
249 ////////////////////////////////////////////////////////////////////////////////////////////////////
250 EFrameworkunifiedStatus CNotification::SetEventPublisher(const std::string &f_cservicename) {
251 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
252 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
254 if (!f_cservicename.empty()) {
255 m_cServiceName = f_cservicename;
256 FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Service successfully set"); // LCOV_EXCL_BR_LINE 15: marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
258 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Service Name String is Empty");
259 l_estatus = eFrameworkunifiedStatusFail;
262 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
267 ////////////////////////////////////////////////////////////////////////////////////////////////////
268 /// ResetEventPublisher
269 /// This function resets the publisher name
270 ////////////////////////////////////////////////////////////////////////////////////////////////////
271 EFrameworkunifiedStatus CNotification::ResetEventPublisher(const std::string &f_cservicename) {
272 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
273 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
275 if (f_cservicename.empty()) { // LCOV_EXCL_BR_LINE 6: f_cservicename can't be empty
276 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
277 l_estatus = eFrameworkunifiedStatusInvldParam; // LCOV_EXCL_LINE 6: f_cservicename can't be empty
279 if (0 == m_cServiceName.compare(f_cservicename)) {
281 FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Service successfully reset"); // LCOV_EXCL_BR_LINE 15: marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
283 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Service Name Not Registered"); // LCOV_EXCL_BR_LINE 15: marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
284 l_estatus = eFrameworkunifiedStatusFail;
288 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
292 EFrameworkunifiedStatus CNotification::AddReceiverInMap(const std::string &f_csubscribername) {
293 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
294 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
296 // Message Queue Handle for passsing messages
297 HANDLE l_hMsgSenQueHandle = NULL;
299 // Pointer to class CNotificationReceiver
300 CNotificationReceiver *l_pCNotificationReceiver = NULL;
302 // Iterator for Notification Receiver map
303 NotifReceiver_Iterator_Type l_itrNotifReceiver;
305 if (!f_csubscribername.empty()) { // LCOV_EXCL_BR_LINE 6: f_csubscribername can't be empty
306 FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Message Queue Handle Set"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
308 CHandleList *l_hHandleList = CHandleList::GetHandleList();
310 l_hMsgSenQueHandle = l_hHandleList->GetSubscriberMqHandle(f_csubscribername); // LCOV_EXCL_BR_LINE 11: unexpected branch // NOLINT[whitespace/line_length]
312 // If handle not found
313 if (NULL == l_hMsgSenQueHandle) {
314 // Open a handle for sending messages to another message queue
315 l_hMsgSenQueHandle = McOpenSender(f_csubscribername.c_str());
316 l_hHandleList->AddHandleInList(f_csubscribername, l_hMsgSenQueHandle); // LCOV_EXCL_BR_LINE 11: unexpected branch // NOLINT[whitespace/line_length]
319 if (NULL != m_pmSubscribersList) { // LCOV_EXCL_BR_LINE 6: m_pmSubscribersList can't be NULL
320 l_pCNotificationReceiver = new(std::nothrow) CNotificationReceiver(); // LCOV_EXCL_BR_LINE 11: unexpected branch
322 if (NULL != l_pCNotificationReceiver) { // LCOV_EXCL_BR_LINE 5: l_pCNotificationReceiver can't be NULL
323 l_pCNotificationReceiver->m_MsgQHandle = l_hMsgSenQueHandle;
325 // Insert Subscriber name and associated message queue handle in the map
326 m_pmSubscribersList->insert(make_pair(f_csubscribername, l_pCNotificationReceiver));
328 // LCOV_EXCL_START 5: l_pCNotificationReceiver can't be NULL
329 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
330 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pCNotificationReceiver is NULL");
331 l_estatus = eFrameworkunifiedStatusNullPointer;
335 // LCOV_EXCL_START 6: m_pmSubscribersList can't be NULL
336 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
337 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "m_pmSubscribersList is NULL");
338 l_estatus = eFrameworkunifiedStatusNullPointer;
342 if (eFrameworkunifiedStatusNullPointer == l_estatus) {
343 // close the queue handle
344 // NOTE: Uncomment following code when implementation of the function RemoveHandleFromList
345 // is available. To find the reason why it is not implemented, see the function definition.
346 // CHandleList *l_hHandleList = CHandleList::GetHandleList();
347 // l_hHandleList->RemoveHandleFromList(f_csubscribername);
350 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
351 l_estatus = eFrameworkunifiedStatusInvldParam; // LCOV_EXCL_LINE 6: f_csubscribername can't be empty
354 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
358 ////////////////////////////////////////////////////////////////////////////////////////////////////
360 /// This function publishes the notification to client.
361 ////////////////////////////////////////////////////////////////////////////////////////////////////
362 EFrameworkunifiedStatus CNotification::PublishData(HANDLE f_hmsgqhandle,
363 const PVOID f_pmessage,
364 const UI_32 f_uimsgsize) {
365 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
366 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
368 if (NULL != f_hmsgqhandle) { // LCOV_EXCL_BR_LINE 6: f_hmsgqhandle can't be NULL
370 PSTR l_cNotificationName = const_cast<PSTR>(m_cNotificationName.c_str());
372 if (eFrameworkunifiedStatusOK != (l_estatus = McSendWithSysInfo(f_hmsgqhandle, AppName, NPS_NOTIFY_EV_REQ, l_cNotificationName, f_uimsgsize, f_pmessage, 0))) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT[whitespace/line_length]
373 // LCOV_EXCL_START 4: NSFW error case.
374 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
375 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "PublishData failed while McSend for Notification %s, Error Status: 0x%x",
376 l_cNotificationName, l_estatus);
380 // LCOV_EXCL_START 6: f_hmsgqhandle can't be NULL
381 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
382 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgQ Handle NULL");
383 l_estatus = eFrameworkunifiedStatusNullPointer;
387 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
391 ////////////////////////////////////////////////////////////////////////////////////////////////////
392 /// IsServiceRegistered
393 /// This function checks whether the notification is registered with any service or not.
394 ////////////////////////////////////////////////////////////////////////////////////////////////////
395 BOOL CNotification::IsServiceRegistered() {
396 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
398 if (!m_cServiceName.empty()) {
405 ////////////////////////////////////////////////////////////////////////////////////////////////////
406 /// IsSubscribersListEmpty
407 /// This function is used to check whether any service is subscribed to notification
408 ////////////////////////////////////////////////////////////////////////////////////////////////////
409 BOOL CNotification::IsSubscribersListEmpty() {
410 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
412 if (NULL != m_pmSubscribersList) { // LCOV_EXCL_BR_LINE 6: m_pmSubscribersList can't be NULL
413 if (m_pmSubscribersList->empty()) {
421 ////////////////////////////////////////////////////////////////////////////////////////////////////
422 /// GetNotificationName
423 /// This function is used to get the notification name.
424 ////////////////////////////////////////////////////////////////////////////////////////////////////
425 std::string CNotification::GetNotificationName() {
426 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
428 return m_cNotificationName;
431 ////////////////////////////////////////////////////////////////////////////////////////////////////
433 /// This function is used to get the publisher name of notification.
434 ////////////////////////////////////////////////////////////////////////////////////////////////////
435 std::string CNotification::GetPublisherName() {
436 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
438 return m_cServiceName;
441 ////////////////////////////////////////////////////////////////////////////////////////////////////
442 /// GetPersistenceType
443 /// This function is used to get the type of notification.
444 ////////////////////////////////////////////////////////////////////////////////////////////////////
445 EFrameworkunifiedNotificationType CNotification::GetNotificationType() {
446 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
448 return m_ePersistentType;
451 ////////////////////////////////////////////////////////////////////////////////////////////////////
452 /// GetMaxMessageSize
453 /// This function is used to get the max size of data of notification message.
454 ////////////////////////////////////////////////////////////////////////////////////////////////////
455 UI_32 CNotification::GetMaxMessageSize() {
456 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
458 return m_uiMaxMsgSize;
461 ////////////////////////////////////////////////////////////////////////////////////////////////
462 /// ResetMaxMessageSize
463 /// This function reset the max size of data that can be published with notification.
464 ////////////////////////////////////////////////////////////////////////////////////////////////
465 EFrameworkunifiedStatus CNotification::ResetMaxMessageSize(const UI_32 f_uilength) {
466 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
467 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
469 m_uiMaxMsgSize = f_uilength;
471 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
475 #ifdef NPP_PROFILEINFO_ENABLE
477 ////////////////////////////////////////////////////////////////////////////////////////////////
478 /// GetSubscriberList
479 /// Returns the list of subscribers subscribed to notification
480 ////////////////////////////////////////////////////////////////////////////////////////////////
481 NotifReceiver_Type *CNotification::GetSubscriberList() {
482 return m_pmSubscribersList;