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 CnotificationpersistentservicePersonalizationManager.
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
35 #include "ns_npp_personalization_manager.h"
37 #include "ns_npp_Personalization_manager.h"
39 #include "ns_npp_notificationpersistentservicelog.h"
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 /// CnotificationpersistentservicePersonalizationManager
43 /// Constructor of CnotificationpersistentservicePersonalizationManager class
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 CnotificationpersistentservicePersonalizationManager::CnotificationpersistentservicePersonalizationManager() {
46 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
50 m_cCurrentPersonality.clear();
52 m_pmPersonality = new(std::nothrow) Personality_Type(); // LCOV_EXCL_BR_LINE 11: except,C++ STL
54 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
58 ////////////////////////////////////////////////////////////////////////////////////////////////////
59 /// ~CnotificationpersistentservicePersonalizationManager
60 /// Destructor of CnotificationpersistentservicePersonalizationManager class
61 ////////////////////////////////////////////////////////////////////////////////////////////////////
62 CnotificationpersistentservicePersonalizationManager::~CnotificationpersistentservicePersonalizationManager() { // LCOV_EXCL_START 14: Resident process, global instance not released // NOLINT[whitespace/line_length]
63 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
64 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
66 if (NULL != m_pmPersonality) {
67 m_pmPersonality->clear();
69 delete m_pmPersonality;
70 m_pmPersonality = NULL;
73 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
77 ////////////////////////////////////////////////////////////////////////////////////////////////////
78 /// NotificationpersistentserviceGetPersonality
79 /// This function is used to get the current personality.
80 ////////////////////////////////////////////////////////////////////////////////////////////////////
81 EFrameworkunifiedStatus CnotificationpersistentservicePersonalizationManager::NotificationpersistentserviceGetPersonality(std::string &f_cpersonalityname) {
82 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
83 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
85 f_cpersonalityname = m_cCurrentPersonality;
87 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
91 ////////////////////////////////////////////////////////////////////////////////////////////////////
92 /// NotificationpersistentserviceSetPersonality
93 /// This function is used to set the new personality.
94 ////////////////////////////////////////////////////////////////////////////////////////////////////
95 EFrameworkunifiedStatus CnotificationpersistentservicePersonalizationManager::NotificationpersistentserviceSetPersonality(const std::string f_cpersonalityname) {
96 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
97 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
99 // iterator to find personality name from map of personality
100 Personality_Type::iterator l_itPersonality;
102 if (!f_cpersonalityname.empty()) {
103 if (NULL != m_pmPersonality) { // LCOV_EXCL_BR_LINE 6: double check, m_pmPersonality can't be NULL
104 l_itPersonality = m_pmPersonality->find(f_cpersonalityname);
106 // if personality found in map
107 if (m_pmPersonality->end() != l_itPersonality) {
108 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality found in map");
110 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality not found in map");
112 l_estatus = CreatePersonality(f_cpersonalityname);
115 m_cCurrentPersonality = f_cpersonalityname;
117 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
118 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map object is NULL"); // LCOV_EXCL_LINE 6: m_pmPersonality can't be NULL
121 l_estatus = eFrameworkunifiedStatusInvldParam;
124 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
128 ////////////////////////////////////////////////////////////////////////////////////////////////////
129 /// CreatePersonality
130 /// This function is used to create new Personality.
131 ////////////////////////////////////////////////////////////////////////////////////////////////////
132 EFrameworkunifiedStatus CnotificationpersistentservicePersonalizationManager::CreatePersonality(const std::string &f_cpersonalityname) {
133 EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
134 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
136 if (NULL != m_pmPersonality) { // LCOV_EXCL_BR_LINE 6: m_pmPersonality can't be NULL
137 CNotificationpersistentservicePersonality *l_pPersonality = new(std::nothrow) CNotificationpersistentservicePersonality(); // LCOV_EXCL_BR_LINE 11: unexpected branch
139 if (NULL != l_pPersonality) { // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
140 l_pPersonality->m_uiUserId = ++m_uiUserId;
141 l_pPersonality->m_cUserName = f_cpersonalityname;
143 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Inserting new personality in map"); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h" // NOLINT[whitespace/line_length]
144 m_pmPersonality->insert(make_pair(f_cpersonalityname, l_pPersonality));
147 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
148 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map object is NULL"); // LCOV_EXCL_LINE 6: m_pmPersonality can't be NULL
151 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
155 ////////////////////////////////////////////////////////////////////////////////////////////////////
156 /// NotificationpersistentserviceIsValidPersonality
158 ////////////////////////////////////////////////////////////////////////////////////////////////////
159 BOOL CnotificationpersistentservicePersonalizationManager::NotificationpersistentserviceIsValidPersonality(const std::string f_cpersonalityname) {
160 BOOL l_bReturnValue = FALSE;
161 // iterator to find personality name from map of personality
162 Personality_Type::iterator l_itPersonality;
163 if (NULL != m_pmPersonality) { // LCOV_EXCL_BR_LINE 6: m_pmPersonality can't be NULL
164 l_itPersonality = m_pmPersonality->find(f_cpersonalityname);
166 // if personality found in map
167 if (m_pmPersonality->end() != l_itPersonality) {
168 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality found in map");
169 l_bReturnValue = TRUE;
171 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality not found in map");
174 // LCOV_EXCL_START 6: m_pmPersonality can't be NULL
175 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
176 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map object is NULL");
180 return l_bReturnValue;