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 tag_NS_NPPService
19 /// \ingroup tag_NS_NPPService
21 //////////////////////////////////////////////////////////////////////////////////////////////////
23 //////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup tag_NS_NPPService
25 /// \brief This class holds the message queue handles for notification subscribers
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 //////////////////////////////////////////////////////////////////////////////////////////////////
32 #include "ns_npp_handlelist.h"
33 #include "ns_npp_notificationpersistentservicelog.h"
35 // define static member of class CHandleList
36 CHandleList *CHandleList::m_psHandleList = NULL;
38 ////////////////////////////////////////////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 CHandleList::CHandleList() {
43 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
45 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
48 ////////////////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
56 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
60 ////////////////////////////////////////////////////////////////////////////////////////////////////
62 /// This function is used to get the singleton instance of class.
63 ////////////////////////////////////////////////////////////////////////////////////////////////////
64 CHandleList *CHandleList::GetHandleList() {
65 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
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
73 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
74 return m_psHandleList;
77 ////////////////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
86 if (NULL != m_psHandleList) {
87 delete m_psHandleList;
88 m_psHandleList = NULL;
90 l_estatus = eFrameworkunifiedStatusNullPointer;
93 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
98 ////////////////////////////////////////////////////////////////////////////////////////////////
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__, "+");
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());
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"
116 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
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;
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__, "+");
143 l_itHandleList = m_mHandleList.find(f_csubscribername);
144 if (l_itHandleList != m_mHandleList.end()) {
145 l_hMqHandle = l_itHandleList->second;
147 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");