2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////////////////////////////
18 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup tag_NS_NPPService
21 ////////////////////////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup tag_NS_NPPService
25 /// \brief This file contains implementation of class CRegularNotification.
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
34 #include <native_service/frameworkunified_framework_if.h>
35 #include <native_service/ns_message_center_if.h>
36 #include <native_service/ns_np_service_protocol.h>
40 #include <native_service/ns_mc_system_info.h>
41 #include "ns_npp_notificationpersistentservicelog.h"
42 #include "ns_npp_regular_notification.h"
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 /// CRegularNotification
46 /// Constructor of CRegularNotification class
47 ////////////////////////////////////////////////////////////////////////////////////////////////////
48 CRegularNotification::CRegularNotification(const std::string &f_cnotificationname,
49 const UI_32 f_uimaxmsgsize):
50 CNotification(f_cnotificationname, f_uimaxmsgsize) {
51 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
53 m_ePersistentType = eFrameworkunifiedNotificationVar;
55 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
59 ////////////////////////////////////////////////////////////////////////////////////////////////////
60 /// ~CRegularNotification
61 /// Destructor of CRegularNotification class
62 ////////////////////////////////////////////////////////////////////////////////////////////////////
63 CRegularNotification::~CRegularNotification() {
64 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
67 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
71 ////////////////////////////////////////////////////////////////////////////////////////////////////
73 /// This function adds the name of the application to receiver list of particular notification.
74 ////////////////////////////////////////////////////////////////////////////////////////////////////
75 EFrameworkunifiedStatus CRegularNotification::AddEventReciever(const std::string &f_csubscribername) {
76 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
77 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
79 if (!f_csubscribername.empty()) { // LCOV_EXCL_BR_LINE 6: double check, f_csubscribername can't be empty
80 l_estatus = AddReceiverInMap(f_csubscribername);
82 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
83 l_estatus = eFrameworkunifiedStatusInvldParam; // LCOV_EXCL_LINE 6: f_csubscribername can't be empty
86 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
91 ////////////////////////////////////////////////////////////////////////////////////////////////////
93 /// This function publishes the notification to subscribed clients.
94 ////////////////////////////////////////////////////////////////////////////////////////////////////
95 EFrameworkunifiedStatus CRegularNotification::Publish(const std::string &f_cservicename,
97 const UI_32 f_uimsgsize) {
98 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
99 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
101 // Message Queue Handle
102 HANDLE l_hMsgQHandle = NULL;
104 // Pointer to class CNotificationReceiver
105 CNotificationReceiver *l_pNotificationReceiver = NULL;
107 // Iterator for Notification Receiver map
108 NotifReceiver_Iterator_Type l_itrNotifReceiver;
110 if (m_uiMaxMsgSize >= f_uimsgsize) {
111 if (0 == m_cServiceName.compare(f_cservicename)) {
112 for (l_itrNotifReceiver = m_pmSubscribersList->begin();
113 l_itrNotifReceiver != m_pmSubscribersList->end();
114 l_itrNotifReceiver++) {
115 l_pNotificationReceiver = l_itrNotifReceiver->second;
117 if (NULL != l_pNotificationReceiver) { // LCOV_EXCL_BR_LINE 6: l_pNotificationReceiver can't be NULL
118 l_hMsgQHandle = l_pNotificationReceiver->m_MsgQHandle;
120 if (NULL != l_hMsgQHandle) { // LCOV_EXCL_BR_LINE 6: l_hMsgQHandle can't be NULL
121 if (eFrameworkunifiedStatusOK != (l_estatus = PublishData(l_hMsgQHandle, f_pmessage, f_uimsgsize))) { // LCOV_EXCL_BR_LINE 4: NSFW error case // NOLINT[whitespace/line_length]
122 // LCOV_EXCL_START 4: NSFW error case
123 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
124 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
125 "Error Publishing notification %s to %s published by %s, error status: 0x%x",
126 m_cNotificationName.c_str(), l_itrNotifReceiver->first.c_str(), f_cservicename.c_str(), l_estatus);
130 // LCOV_EXCL_START 6: l_hMsgQHandle can't be NULL
131 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
132 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "MsgQ Handle NULL");
133 l_estatus = eFrameworkunifiedStatusNullPointer;
137 // LCOV_EXCL_START 6: l_pNotificationReceiver can't be NULL
138 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
139 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "l_pNotificationReceiver is NULL");
140 l_estatus = eFrameworkunifiedStatusNullPointer;
145 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Can't publish notification %s. Registered by %s and published by %s.",
146 m_cNotificationName.c_str(), m_cServiceName.c_str(), f_cservicename.c_str()); // LCOV_EXCL_BR_LINE 15: marco defined in "native_service/ns_logger_if.h"
147 l_estatus = eFrameworkunifiedStatusInvldParam;
150 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
151 "Can't publish notification %s. Message data size (%d) is greater than maximum registered data size (%d)",
152 m_cNotificationName.c_str(), f_uimsgsize, m_uiMaxMsgSize);
153 l_estatus = eFrameworkunifiedStatusFail;
156 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");