Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / notification_persistent_service / server / src / ns_npp_personalization_manager.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 CnotificationpersistentservicePersonalizationManager.
26 ///
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
28
29 ////////////////////////////////////////////////////////////////////////////////////////////////////
30 // Include Files
31 ////////////////////////////////////////////////////////////////////////////////////////////////////
32 #include <utility>
33 #include <string>
34 #ifdef AGL_STUB
35 #include "ns_npp_personalization_manager.h"
36 #else
37 #include "ns_npp_Personalization_manager.h"
38 #endif
39 #include "ns_npp_notificationpersistentservicelog.h"
40
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 /// CnotificationpersistentservicePersonalizationManager
43 /// Constructor of CnotificationpersistentservicePersonalizationManager class
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 CnotificationpersistentservicePersonalizationManager::CnotificationpersistentservicePersonalizationManager() {
46   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
47
48   m_uiUserId = 0;
49
50   m_cCurrentPersonality.clear();
51
52   m_pmPersonality = new(std::nothrow) Personality_Type();  // LCOV_EXCL_BR_LINE 11: except,C++ STL
53
54   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
55 }
56
57
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__, "+");
65
66   if (NULL != m_pmPersonality) {
67     m_pmPersonality->clear();
68
69     delete m_pmPersonality;
70     m_pmPersonality = NULL;
71   }
72
73   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
74 }
75 // LCOV_EXCL_STOP
76
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__, "+");
84
85   f_cpersonalityname = m_cCurrentPersonality;
86
87   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
88   return l_estatus;
89 }
90
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__, "+");
98
99   // iterator to find personality name from map of personality
100   Personality_Type::iterator l_itPersonality;
101
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);
105
106       // if personality found in map
107       if (m_pmPersonality->end() != l_itPersonality) {
108         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality found in map");
109       } else {
110         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality not found in map");
111
112         l_estatus = CreatePersonality(f_cpersonalityname);
113       }
114
115       m_cCurrentPersonality = f_cpersonalityname;
116     } else {
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
119     }
120   } else {
121     l_estatus = eFrameworkunifiedStatusInvldParam;
122   }
123
124   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
125   return l_estatus;
126 }
127
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__, "+");
135
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
138
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;
142
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));
145     }
146   } else {
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
149   }
150
151   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
152   return l_estatus;
153 }
154
155 ////////////////////////////////////////////////////////////////////////////////////////////////////
156 /// NotificationpersistentserviceIsValidPersonality
157 ///
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);
165
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;
170     } else {
171       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality not found in map");
172     }
173   } else {
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");
177     // LCOV_EXCL_STOP
178   }
179
180   return l_bReturnValue;
181 }