common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / power_service / server / src / ss_pwr_test_client_handlers.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 /// \ingroup  tag_PowerService
19 /// \brief    This file supports the power service test client.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "ss_power.h"
24 #include <system_service/ss_power_service_local.h>
25 #include <native_service/frameworkunified_application.h>
26 #include <native_service/frameworkunified_framework_if.h>
27 #include <other_service/itoa.h>
28 #include <map>
29 #include <string>
30 #include "ss_power_powerservicelog.h"
31
32 using namespace std;  // NOLINT (build/namespaces)
33
34 #define SS_CRANK_STATE_STRING_LENGTH      5
35 #define SS_VOLTAGE_STATE_STRING_LENGTH      5
36 #define SS_MODULE_STATE_STRING_LENGTH      5
37 #define SS_HEX_BASE_VALUE            16
38
39 const CHAR ReeadyToWakeUpDescription[] = "_READY_TO_WAKEUP:";
40 const CHAR WakeUpInitiatedDescription[] = "_WAKEUP_INITIATED:";
41 const CHAR WakeUpCompletedDescription[] = "_WAKEUP_COMPLETED:";
42 const CHAR PowerOnCompletedDescription[] = "_POWER_ON_COMPLETED:";
43 const CHAR PowerOffInitiatedDescription[] = "_POWER_OFF_INITIATED:";
44 const CHAR PowerOffCompletedDescription[] = "_POWER_OFF_COMPLETED:";
45 const CHAR ShutdownInitiatedDescription[] = "_SHUTDOWN_INITIATED:";
46 const CHAR ShutdownCompletedDescription[] = "_SHUTDOWN_COMPLETED:";
47
48 const CHAR CrankInvalidDescription[] = "_INVALID:";
49 const CHAR CrankEntryDescription[] = "_ENTRY:";
50 const CHAR CrankExitDescription[] = "_EXIT:";
51
52 const CHAR VoltageInvalidDescription[] = "_INVALID:";
53 const CHAR VoltageNormalDescription[] = "_NORMAL:";
54 const CHAR VoltageLVI1Description[] = "_LVI1:";
55 const CHAR VoltageLVI2Description[] = "_LVI2:";
56
57 ///////////////////////////////////////////////////////////////////////
58 /// AddCrankInformationToResponse
59 ///
60 //////////////////////////////////////////////////////////////////////
61 EFrameworkunifiedStatus Power::AddCrankInformationToResponse(CHAR *f_MessageResponse) {
62   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
63   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
64   CHAR l_Buffer[SS_CRANK_STATE_STRING_LENGTH] = { 0 };
65   UI_32 l_Index = 0;
66
67   std::map<ePowerSrvCrankStates, std::string> CrankMap;
68   CrankMap[epscsINVALID] = CrankInvalidDescription;
69   CrankMap[epscsENTRY] = CrankEntryDescription;
70   CrankMap[epscsEXIT] = CrankExitDescription;
71
72   // confirm that CrankState value would fit in buffer array
73   if (m_CrankState < 0xFFFF) {  // LCOV_EXCL_BR_LINE 8: dead code
74     itoa(m_CrankState, l_Buffer, SS_HEX_BASE_VALUE);
75     while (l_Buffer[l_Index]) {
76       l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
77       l_Index++;
78     }
79   }
80
81   if (MaxRespMsg > (strlen(f_MessageResponse) + strlen(CrankMap[m_CrankState].c_str()) + strlen(l_Buffer))) {  // LCOV_EXCL_BR_LINE 8: dead code  // NOLINT[whitespace/line_length]
82     strcat(f_MessageResponse, l_Buffer);  // NOLINT (runtime/printf)
83     strcat(f_MessageResponse, CrankMap[m_CrankState].c_str());  // NOLINT (runtime/printf)
84   } else {
85     FRAMEWORKUNIFIEDLOG(
86         ZONE_ERR,
87         __FUNCTION__,
88         "Buffer Overrun Condition : Failed to add Crank State description to response");
89     l_eStatus = eFrameworkunifiedStatusFail;
90   }
91
92   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
93   return l_eStatus;
94 }
95 ///////////////////////////////////////////////////////////////////////
96 /// AddVoltageInformationToResponse
97 ///
98 //////////////////////////////////////////////////////////////////////
99 EFrameworkunifiedStatus Power::AddVoltageInformationToResponse(CHAR *f_MessageResponse) {
100   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
101   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
102   CHAR l_Buffer[SS_VOLTAGE_STATE_STRING_LENGTH] = { 0 };
103   UI_32 l_Index = 0;
104
105   std::map<ePowerSrvVoltageStates, std::string> VoltageMap;
106   VoltageMap[epsvsINVALID] = VoltageInvalidDescription;
107   VoltageMap[epsvsNORMAL] = VoltageNormalDescription;
108   VoltageMap[epsvsLVI1] = VoltageLVI1Description;
109   VoltageMap[epsvsLVI2] = VoltageLVI2Description;
110
111   // confirm that VoltageState value would fit in buffer array
112   if (m_VoltageState < 0xFFFF) {  // LCOV_EXCL_BR_LINE 8: dead code
113     itoa(m_VoltageState, l_Buffer, SS_HEX_BASE_VALUE);
114     while (l_Buffer[l_Index]) {
115       l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
116       l_Index++;
117     }
118   }
119
120   if (MaxRespMsg > (strlen(f_MessageResponse) + strlen(VoltageMap[m_VoltageState].c_str()) + strlen(l_Buffer))) {  // LCOV_EXCL_BR_LINE 8: dead code  // NOLINT[whitespace/line_length]
121     strcat(f_MessageResponse, l_Buffer);  // NOLINT (runtime/printf)
122     strcat(f_MessageResponse, VoltageMap[m_VoltageState].c_str());  // NOLINT (runtime/printf)
123   } else {
124     FRAMEWORKUNIFIEDLOG(
125         ZONE_ERR,
126         __FUNCTION__,
127         "Buffer Overrun Condition : Failed to add Voltage State description to response");
128     l_eStatus = eFrameworkunifiedStatusFail;
129   }
130
131   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
132   return l_eStatus;
133 }
134 ///////////////////////////////////////////////////////////////////////
135 /// AddStateInformationToResponse
136 ///
137 ///
138 //////////////////////////////////////////////////////////////////////
139 EFrameworkunifiedStatus Power::AddStateInformationToResponse(CHAR *f_MessageResponse) {
140   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
141   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
142   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
143   CHAR l_Buffer[SS_MODULE_STATE_STRING_LENGTH] = { 0 };
144   UI_32 l_Index = 0;
145
146   std::map<SS_PSState, std::string> StateMap;   // State Map
147   StateMap[SS_PS_READY_TO_WAKEUP] = ReeadyToWakeUpDescription;
148   StateMap[SS_PS_WAKEUP_INITIATED] = WakeUpInitiatedDescription;
149   StateMap[SS_PS_WAKEUP_COMPLETE] = WakeUpCompletedDescription;
150   StateMap[SS_PS_POWER_ON_COMPLETE] = PowerOnCompletedDescription;
151   StateMap[SS_PS_POWER_OFF_INITIATED] = PowerOffInitiatedDescription;
152   StateMap[SS_PS_POWER_OFF_COMPLETE] = PowerOffCompletedDescription;
153   StateMap[SS_PS_SHUTDOWN_INITIATED] = ShutdownInitiatedDescription;
154   StateMap[SS_PS_SHUTDOWN_COMPLETE] = ShutdownCompletedDescription;
155
156   // confirm that PowerState value would fit in buffer array
157   if (m_PowerState < 0xFFFF) {  // LCOV_EXCL_BR_LINE 8: dead code
158     itoa(m_PowerState, l_Buffer, SS_HEX_BASE_VALUE);
159     while (l_Buffer[l_Index]) {
160       l_Buffer[l_Index] = toupper(l_Buffer[l_Index]);
161       l_Index++;
162     }
163   }
164
165   if (MaxRespMsg > (strlen(f_MessageResponse) + strlen(StateMap[m_PowerState].c_str()) + strlen(l_Buffer))) {  // LCOV_EXCL_BR_LINE 8: dead code  // NOLINT[whitespace/line_length]
166     strcat(f_MessageResponse, l_Buffer);  // NOLINT (runtime/printf)
167     strcat(f_MessageResponse, StateMap[m_PowerState].c_str());  // NOLINT (runtime/printf)
168   } else {
169     FRAMEWORKUNIFIEDLOG(
170         ZONE_ERR,
171         __FUNCTION__,
172         "Buffer Overrun Condition : Failed to add Module State description to response");
173     l_eStatus = eFrameworkunifiedStatusFail;
174   }
175
176   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
177   return l_eStatus;
178 }
179
180 ///////////////////////////////////////////////////////////////////////
181 /// ConstructPwrStateResponse
182 ///
183 ///
184 //////////////////////////////////////////////////////////////////////
185 EFrameworkunifiedStatus Power::ConstructPwrStateResponse(CHAR *f_MessageResponse) {
186   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
187   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "+");
188
189   if (f_MessageResponse == NULL) {  // LCOV_EXCL_BR_LINE 8: dead code
190     FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
191     return eFrameworkunifiedStatusFail;
192   }
193
194   if (eFrameworkunifiedStatusOK == (l_eStatus = AddStateInformationToResponse(f_MessageResponse))) {  // LCOV_EXCL_BR_LINE 8: dead code  // NOLINT[whitespace/line_length]
195     if (eFrameworkunifiedStatusOK == (l_eStatus = AddVoltageInformationToResponse(f_MessageResponse))) {  // LCOV_EXCL_BR_LINE 8: dead code  // NOLINT[whitespace/line_length]
196       if (eFrameworkunifiedStatusOK == (l_eStatus = AddCrankInformationToResponse(f_MessageResponse))) {  // LCOV_EXCL_BR_LINE 8: dead code  // NOLINT[whitespace/line_length]
197         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Response Constructed");
198       }
199     }
200   }
201
202   FRAMEWORKUNIFIEDLOG0(ZONE_FUNC, __FUNCTION__, "-");
203   return l_eStatus;
204 }