summaryrefslogtreecommitdiffstats
path: root/nsframework/notification_persistent_service/server/src/ns_npp_personalization_manager.cpp
blob: 43714653f8754437602483ccf2b394fbc68741a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \defgroup <<Group Tag>> <<Group Name>>
/// \ingroup  tag_NS_NPPService
/// .
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_NS_NPPService
/// \brief    This file contains implementation of class CnotificationpersistentservicePersonalizationManager.
///
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Files
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <utility>
#include <string>
#ifdef AGL_STUB
#include "ns_npp_personalization_manager.h"
#else
#include "ns_npp_Personalization_manager.h"
#endif
#include "ns_npp_notificationpersistentservicelog.h"

////////////////////////////////////////////////////////////////////////////////////////////////////
/// CnotificationpersistentservicePersonalizationManager
/// Constructor of CnotificationpersistentservicePersonalizationManager class
////////////////////////////////////////////////////////////////////////////////////////////////////
CnotificationpersistentservicePersonalizationManager::CnotificationpersistentservicePersonalizationManager() {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  m_uiUserId = 0;

  m_cCurrentPersonality.clear();

  m_pmPersonality = new(std::nothrow) Personality_Type();  // LCOV_EXCL_BR_LINE 11: except,C++ STL

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}


////////////////////////////////////////////////////////////////////////////////////////////////////
/// ~CnotificationpersistentservicePersonalizationManager
/// Destructor of CnotificationpersistentservicePersonalizationManager class
////////////////////////////////////////////////////////////////////////////////////////////////////
CnotificationpersistentservicePersonalizationManager::~CnotificationpersistentservicePersonalizationManager() {   // LCOV_EXCL_START 14: Resident process, global instance not released  // NOLINT[whitespace/line_length]
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  if (NULL != m_pmPersonality) {
    m_pmPersonality->clear();

    delete m_pmPersonality;
    m_pmPersonality = NULL;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
}
// LCOV_EXCL_STOP

////////////////////////////////////////////////////////////////////////////////////////////////////
/// NotificationpersistentserviceGetPersonality
/// This function is used to get the current personality.
////////////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CnotificationpersistentservicePersonalizationManager::NotificationpersistentserviceGetPersonality(std::string &f_cpersonalityname) {
  EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  f_cpersonalityname = m_cCurrentPersonality;

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_estatus;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// NotificationpersistentserviceSetPersonality
/// This function is used to set the new personality.
////////////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CnotificationpersistentservicePersonalizationManager::NotificationpersistentserviceSetPersonality(const std::string f_cpersonalityname) {
  EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  // iterator to find personality name from map of personality
  Personality_Type::iterator l_itPersonality;

  if (!f_cpersonalityname.empty()) {
    if (NULL != m_pmPersonality) {  // LCOV_EXCL_BR_LINE 6: double check, m_pmPersonality can't be NULL
      l_itPersonality = m_pmPersonality->find(f_cpersonalityname);

      // if personality found in map
      if (m_pmPersonality->end() != l_itPersonality) {
        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality found in map");
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality not found in map");

        l_estatus = CreatePersonality(f_cpersonalityname);
      }

      m_cCurrentPersonality = f_cpersonalityname;
    } else {
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map object is NULL");  // LCOV_EXCL_LINE 6: m_pmPersonality can't be NULL
    }
  } else {
    l_estatus = eFrameworkunifiedStatusInvldParam;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_estatus;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// CreatePersonality
/// This function is used to create new Personality.
////////////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CnotificationpersistentservicePersonalizationManager::CreatePersonality(const std::string &f_cpersonalityname) {
  EFrameworkunifiedStatus l_estatus = eFrameworkunifiedStatusOK;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  if (NULL != m_pmPersonality) {  // LCOV_EXCL_BR_LINE 6: m_pmPersonality can't be NULL
    CNotificationpersistentservicePersonality *l_pPersonality = new(std::nothrow) CNotificationpersistentservicePersonality();  // LCOV_EXCL_BR_LINE 11: unexpected branch

    if (NULL != l_pPersonality) {  // LCOV_EXCL_BR_LINE 5: It's impossible to mock new() function
      l_pPersonality->m_uiUserId = ++m_uiUserId;
      l_pPersonality->m_cUserName = f_cpersonalityname;

      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]
      m_pmPersonality->insert(make_pair(f_cpersonalityname, l_pPersonality));
    }
  } else {
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map object is NULL");  // LCOV_EXCL_LINE 6: m_pmPersonality can't be NULL
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return l_estatus;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
/// NotificationpersistentserviceIsValidPersonality
///
////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CnotificationpersistentservicePersonalizationManager::NotificationpersistentserviceIsValidPersonality(const std::string f_cpersonalityname) {
  BOOL l_bReturnValue = FALSE;
  // iterator to find personality name from map of personality
  Personality_Type::iterator l_itPersonality;
  if (NULL != m_pmPersonality) {  // LCOV_EXCL_BR_LINE 6: m_pmPersonality can't be NULL
    l_itPersonality = m_pmPersonality->find(f_cpersonalityname);

    // if personality found in map
    if (m_pmPersonality->end() != l_itPersonality) {
      FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality found in map");
      l_bReturnValue = TRUE;
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Personality not found in map");
    }
  } else {
    // LCOV_EXCL_START 6: m_pmPersonality can't be NULL
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "map object is NULL");
    // LCOV_EXCL_STOP
  }

  return l_bReturnValue;
}