common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / nsframework / notification_persistent_service / server / src / ns_npp_handlelist.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 tag_NS_NPPService
19 /// \ingroup  tag_NS_NPPService
20 ///
21 //////////////////////////////////////////////////////////////////////////////////////////////////
22
23 //////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup  tag_NS_NPPService
25 /// \brief    This class holds the message queue handles for notification subscribers
26 ///
27 /// This is a singleton class which holds the message queue handles for notification subscribers.
28 /// This will ensure that NS_NPPService will hold only one handle per subscriber.
29 //////////////////////////////////////////////////////////////////////////////////////////////////
30 #include <utility>
31 #include <string>
32 #include "ns_npp_handlelist.h"
33 #include "ns_npp_notificationpersistentservicelog.h"
34
35 // define static member of class CHandleList
36 CHandleList *CHandleList::m_psHandleList = NULL;
37
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 /// CHandleList
40 /// Class Constructor
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 CHandleList::CHandleList() {
43   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
44
45   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
46 }
47
48 ////////////////////////////////////////////////////////////////////////////////////////////////////
49 /// CHandleList
50 /// Class Destructor
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
52 CHandleList::~CHandleList() {   // LCOV_EXCL_START 14: Resident process, global instance not released
53   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
54   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
55
56   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
57 }
58 // LCOV_EXCL_STOP
59
60 ////////////////////////////////////////////////////////////////////////////////////////////////////
61 /// GetHandleList
62 /// This function is used to get the singleton instance of class.
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
64 CHandleList *CHandleList::GetHandleList() {
65   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
66
67   // create the instance of class
68   if (NULL == m_psHandleList) {
69     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Creating handle list.");  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
70     m_psHandleList = new(std::nothrow) CHandleList();  // LCOV_EXCL_BR_LINE 11: unexpected branch
71   }
72
73   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
74   return m_psHandleList;
75 }
76
77 ////////////////////////////////////////////////////////////////////////////////////////////////////
78 /// ReleaseHandleList
79 /// This function is used to release the instance of class.
80 ////////////////////////////////////////////////////////////////////////////////////////////////////
81 EFrameworkunifiedStatus CHandleList::ReleaseHandleList() {   // LCOV_EXCL_START 100: not used
82   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
83   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
84   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
85
86   if (NULL != m_psHandleList) {
87     delete m_psHandleList;
88     m_psHandleList = NULL;
89   } else {
90     l_estatus = eFrameworkunifiedStatusNullPointer;
91   }
92
93   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
94   return l_estatus;
95 }
96 // LCOV_EXCL_STOP
97
98 ////////////////////////////////////////////////////////////////////////////////////////////////
99 /// AddHandleInList
100 /// Add pair of subscriber name and corresponding handle in map.
101 ////////////////////////////////////////////////////////////////////////////////////////////////
102 EFrameworkunifiedStatus CHandleList::AddHandleInList(std::string f_csubscribername, HANDLE f_hmqhandle) {
103   EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
104   HandleListRetStatus_Type l_prRetValue;
105   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
106
107   l_prRetValue = m_mHandleList.insert(make_pair(f_csubscribername, f_hmqhandle));
108   if (false == l_prRetValue.second) {
109     l_estatus = eFrameworkunifiedStatusDuplicate;
110     FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Handle exists in list for %s.", f_csubscribername.c_str());
111   } else {
112     FRAMEWORKUNIFIEDLOG(ZONE_NPP_INFO, __FUNCTION__, "Handle added in list for %s.", f_csubscribername.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
113   }
114
115
116   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
117   return l_estatus;
118 }
119
120
121 ////////////////////////////////////////////////////////////////////////////////////////////////
122 /// RemoveHandleFromList
123 /// Remove handle for subscriber from the list.
124 ////////////////////////////////////////////////////////////////////////////////////////////////
125 EFrameworkunifiedStatus CHandleList::RemoveHandleFromList(std::string f_csubscribername) {   // LCOV_EXCL_START 100: not used
126   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
127   // TODO(my_username): Implementation of this function.
128   // NOTE: Right now this feature is not required. Let the NS_NPPService hold one handle for
129   //    each subscriber, even if all the notifications are unsubscribed by subscriber.
130   return eFrameworkunifiedStatusOK;
131 }
132 // LCOV_EXCL_STOP
133
134 ////////////////////////////////////////////////////////////////////////////////////////////////
135 /// GetSubscriberMqHandle
136 /// Get the message queue handle of a subscriber.
137 ////////////////////////////////////////////////////////////////////////////////////////////////
138 HANDLE CHandleList::GetSubscriberMqHandle(std::string f_csubscribername) {
139   HANDLE l_hMqHandle = NULL;
140   HandleList_Type::iterator l_itHandleList;
141   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
142
143   l_itHandleList = m_mHandleList.find(f_csubscribername);
144   if (l_itHandleList != m_mHandleList.end()) {
145     l_hMqHandle = l_itHandleList->second;
146   }
147   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
148   return l_hMqHandle;
149 }