common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / nsframework / notification_persistent_service / server / src / ns_npp_regular_notification.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 class CRegularNotification.
26 ///
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
28
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
30 // Include Files
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
32
33
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>
37 #include <mqueue.h>
38 #include <iostream>
39 #include <string>
40 #include <native_service/ns_mc_system_info.h>
41 #include "ns_npp_notificationpersistentservicelog.h"
42 #include "ns_npp_regular_notification.h"
43
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__, "+");
52
53   m_ePersistentType = eFrameworkunifiedNotificationVar;
54
55   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
56 }
57
58
59 ////////////////////////////////////////////////////////////////////////////////////////////////////
60 /// ~CRegularNotification
61 /// Destructor of CRegularNotification class
62 ////////////////////////////////////////////////////////////////////////////////////////////////////
63 CRegularNotification::~CRegularNotification() {
64   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
65
66
67   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
68 }
69
70
71 ////////////////////////////////////////////////////////////////////////////////////////////////////
72 /// AddEventReciever
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__, "+");
78
79   if (!f_csubscribername.empty()) {  // LCOV_EXCL_BR_LINE 6: double check, f_csubscribername can't be empty
80     l_estatus = AddReceiverInMap(f_csubscribername);
81   } else {
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
84   }
85
86   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
87   return l_estatus;
88 }
89
90
91 ////////////////////////////////////////////////////////////////////////////////////////////////////
92 /// Publish
93 /// This function publishes the notification to subscribed clients.
94 ////////////////////////////////////////////////////////////////////////////////////////////////////
95 EFrameworkunifiedStatus CRegularNotification::Publish(const std::string &f_cservicename,
96                                          PVOID f_pmessage,
97                                          const UI_32 f_uimsgsize) {
98   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
99   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
100
101   // Message Queue Handle
102   HANDLE l_hMsgQHandle = NULL;
103
104   // Pointer to class CNotificationReceiver
105   CNotificationReceiver *l_pNotificationReceiver = NULL;
106
107   // Iterator for Notification Receiver map
108   NotifReceiver_Iterator_Type l_itrNotifReceiver;
109
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;
116
117         if (NULL != l_pNotificationReceiver) {  // LCOV_EXCL_BR_LINE 6: l_pNotificationReceiver can't be NULL
118           l_hMsgQHandle = l_pNotificationReceiver->m_MsgQHandle;
119
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);
127               // LCOV_EXCL_STOP
128             }
129           } else {
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;
134             // LCOV_EXCL_STOP
135           }
136         } else {
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;
141           // LCOV_EXCL_STOP
142         }
143       }
144     } else {
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;
148     }
149   } else {
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;
154   }
155
156   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
157   return l_estatus;
158 }