common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / power_service / server / src / ss_power_config.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 power service configuration.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <string>
23 #include "ss_power_config.h"
24
25 // define all the configuration parmeters that will be used to get data
26 const char * PowerConfiguration::kPowerLogicPlugin = "PowerLogicPlugin.dll";
27 const char * PowerConfiguration::kLVI1Timeout = "LVI1.Timeouts_Timeout";
28 const char * PowerConfiguration::kLVI1HysteresisTimeout =
29     "LVI1.Hysteresis_Timeout";
30 const char * PowerConfiguration::kLVI1HysteresisEnabled =
31     "LVI1.Hysteresis_Enabled";
32 const char * PowerConfiguration::kLVI1HysteresisTries = "LVI1.Hysteresis_Tries";
33 const char * PowerConfiguration::kLVI2Timeout = "LVI2.Timeouts_Timeout";
34 const char * PowerConfiguration::kLVI2HysteresisTimeout =
35     "LVI2.Hysteresis_Timeout";
36 const char * PowerConfiguration::kLVI2HysteresisEnabled =
37     "LVI2.Hysteresis_Enabled";
38 const char * PowerConfiguration::kLVI2HysteresisTries = "LVI2.Hysteresis_Tries";
39 const char * PowerConfiguration::kShutdownTimeout = "Shutdown.Timeouts_Timeout";
40 const char * PowerConfiguration::kShutdownHysteresisTimeout =
41     "Shutdown.Hysteresis_Timeout";
42 const char * PowerConfiguration::kShutdownHysteresisEnabled =
43     "Shutdown.Hysteresis_Enabled";
44 const char * PowerConfiguration::kShutdownHysteresisTries =
45     "Shutdown.Hysteresis_Tries";
46 /// < defines the names in the cfg file that are used to get required modules names
47 const char * PowerConfiguration::kRequiredWakeupModules =
48     "Wakeup.RequiredModules.";  /// < once all the modules have been wakened up send wake-up complete
49 const char * PowerConfiguration::kRequiredShutdownModules =
50     "Shutdown.RequiredModules.";  /// < once all the modules have been shutdown send shutdown complete
51 const char * PowerConfiguration::kRequiredLvi2Modules =
52     "LVI2.RequiredModules.";  /// < once all the modules have been wakened up send wake-up complete
53
54 PowerConfiguration::PowerConfiguration(std::string f_configfilename)
55     : m_ConfigFileName(f_configfilename) {
56 }
57
58 PowerConfiguration::~PowerConfiguration() {
59 }
60
61 BOOL PowerConfiguration::LoadParameters(PowerConfigParams & params) {
62   EFrameworkunifiedStatus l_eStatus;
63   BOOL l_rtnCode = FALSE;
64
65   CNSConfigReader *l_pReaderCfg = new CNSConfigReader();
66   if (NULL == l_pReaderCfg) {  // LCOV_EXCL_BR_LINE 5:new error case
67     // LCOV_EXCL_START 5:new error case
68     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
69     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
70            " Error. new CNSConfigReader() returned NULL pointer.");
71     // LCOV_EXCL_STOP 5:new error case
72   } else {
73     if (eFrameworkunifiedStatusOK != (l_eStatus = l_pReaderCfg->Parse(m_ConfigFileName))) {
74       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
75              " Error. l_pReaderCfg->Open(%s) returned NULL pointer.",
76              m_ConfigFileName.c_str());
77     } else if (eFrameworkunifiedStatusOK
78         != (l_eStatus = l_pReaderCfg->GetInt(kShutdownTimeout,
79                                              params.shutdown.timeout))) {
80       LOG_STATUS_IF_ERRORED(l_eStatus, "l_pReaderCfg->GetInt(ShutdownTimeout)");
81     } else if (eFrameworkunifiedStatusOK
82         != (l_eStatus = l_pReaderCfg->GetInt(kLVI1Timeout, params.lvi1.timeout))) {
83       LOG_STATUS_IF_ERRORED(l_eStatus, "l_pReaderCfg->GetInt(LVI1Timeout)");
84     } else if (eFrameworkunifiedStatusOK
85         != (l_eStatus = l_pReaderCfg->GetInt(kLVI2Timeout, params.lvi2.timeout))) {
86       LOG_STATUS_IF_ERRORED(l_eStatus, "l_pReaderCfg->GetInt(LVI2Timeout)");
87     } else if (eFrameworkunifiedStatusOK
88         != (l_eStatus = l_pReaderCfg->GetInt(kShutdownHysteresisTimeout,
89                                              params.shutdown.hysteresis.timeout))) {
90       LOG_STATUS_IF_ERRORED(l_eStatus,
91                             "l_pReaderCfg->GetInt(ShutdownHysteresisTimeout)");
92     } else if (eFrameworkunifiedStatusOK
93         != (l_eStatus = l_pReaderCfg->GetInt(kLVI1HysteresisTimeout,
94                                              params.lvi1.hysteresis.timeout))) {
95       LOG_STATUS_IF_ERRORED(l_eStatus,
96                             "l_pReaderCfg->GetInt(LVI1HysteresisTimeout)");
97     } else if (eFrameworkunifiedStatusOK
98         != (l_eStatus = l_pReaderCfg->GetInt(kLVI2HysteresisTimeout,
99                                              params.lvi2.hysteresis.timeout))) {
100       LOG_STATUS_IF_ERRORED(l_eStatus,
101                             "l_pReaderCfg->GetInt(LVI2HysteresisTimeout)");
102     } else if (eFrameworkunifiedStatusOK
103         != (l_eStatus = l_pReaderCfg->GetInt(kShutdownHysteresisTries,
104                                              params.shutdown.hysteresis.tries))) {
105       LOG_STATUS_IF_ERRORED(l_eStatus,
106                             "l_pReaderCfg->GetInt(ShutdownHysteresisTries)");
107     } else if (eFrameworkunifiedStatusOK
108         != (l_eStatus = l_pReaderCfg->GetInt(kLVI1HysteresisTries,
109                                              params.lvi1.hysteresis.tries))) {
110       LOG_STATUS_IF_ERRORED(l_eStatus,
111                             "l_pReaderCfg->GetInt(LVI1HysteresisTries)");
112     } else if (eFrameworkunifiedStatusOK
113         != (l_eStatus = l_pReaderCfg->GetInt(kLVI2HysteresisTries,
114                                              params.lvi2.hysteresis.tries))) {
115       LOG_STATUS_IF_ERRORED(l_eStatus,
116                             "l_pReaderCfg->GetInt(LVI2HysteresisTries)");
117     } else if (eFrameworkunifiedStatusOK
118         != (l_eStatus = l_pReaderCfg->GetBool(
119             kShutdownHysteresisEnabled, params.shutdown.hysteresis.enabled))) {
120       LOG_STATUS_IF_ERRORED(l_eStatus,
121                             "l_pReaderCfg->GetInt(ShutdownHysteresisEnabled)");
122     } else if (eFrameworkunifiedStatusOK
123         != (l_eStatus = l_pReaderCfg->GetBool(kLVI1HysteresisEnabled,
124                                               params.lvi1.hysteresis.enabled))) {
125       LOG_STATUS_IF_ERRORED(l_eStatus,
126                             "l_pReaderCfg->GetInt(LVI1HysteresisEnabled)");
127     } else if (eFrameworkunifiedStatusOK
128         != (l_eStatus = l_pReaderCfg->GetBool(kLVI2HysteresisEnabled,
129                                               params.lvi2.hysteresis.enabled))) {
130       LOG_STATUS_IF_ERRORED(l_eStatus,
131                             "l_pReaderCfg->GetInt(LVI2HysteresisEnabled)");
132     } else if (eFrameworkunifiedStatusOK
133         != (l_eStatus = l_pReaderCfg->GetString(kPowerLogicPlugin,
134                                                 params.power_logic_plugin))) {
135       LOG_STATUS_IF_ERRORED(l_eStatus, "l_pReaderCfg->GetInt(PowerLogicPlugin)");
136     } else {
137       l_rtnCode = TRUE;
138     }
139
140     delete l_pReaderCfg;
141   }
142
143   return (l_rtnCode);
144 }
145
146 void PowerConfiguration::LoadDefaultParameters(PowerConfigParams & params) {
147   params.power_logic_plugin = "ss_powerlogic.dll";
148   params.shutdown.timeout = 600;  // thats 5mins
149   params.shutdown.hysteresis.enabled = FALSE;  // There should be hysteresis for Shutdown
150   params.shutdown.hysteresis.timeout = 0;  // Don't Care since disabled.
151   params.shutdown.hysteresis.tries = 0;  // Don't Care since disabled.
152   params.lvi1.timeout = 2;  // thats 2secs
153   params.lvi1.hysteresis.enabled = TRUE;  // Enable LVI1 hysteresis
154   params.lvi1.hysteresis.tries = 2;  // check twice before switching to LVI1
155   params.lvi1.hysteresis.timeout = 500;  // thats 500 msecs
156   params.lvi2.timeout = 2;  // thats 2secs
157   params.lvi2.hysteresis.enabled = TRUE;  // Enable LVI2 hysteresis
158   params.lvi2.hysteresis.tries = 2;  // check twice before switching to LVI2
159   params.lvi2.hysteresis.timeout = 100;  // thats 100 msecs
160 }
161
162 void PowerConfiguration::PrintConfigInfo(PowerConfigParams & f_params) {
163   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "shutdown.timeout: %d",
164          f_params.shutdown.timeout);
165   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi1.timeout:  %d", f_params.lvi1.timeout);
166   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi2.timeout: %d", f_params.lvi2.timeout);
167   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "shutdown.hysteresis.timeout: %d",
168          f_params.shutdown.hysteresis.timeout);
169   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi1.hysteresis.timeout: %d",
170          f_params.lvi1.hysteresis.timeout);
171   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi2.hysteresis.timeout: %d",
172          f_params.lvi2.hysteresis.timeout);
173   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "shutdown.hysteresis.tries: %d",
174          f_params.shutdown.hysteresis.tries);
175   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi1.hysteresis.tries: %d",
176          f_params.lvi1.hysteresis.tries);
177   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi1.hysteresis.tries: %d",
178          f_params.lvi1.hysteresis.tries);
179   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "shutdown.hysteresis.enabled: %d",
180          f_params.shutdown.hysteresis.enabled);
181   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi1.hysteresis.enabled: %d",
182          f_params.lvi1.hysteresis.enabled);
183   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "lvi2.hysteresis.enabled: %d",
184          f_params.lvi2.hysteresis.enabled);
185   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "power_logic_plugin: %s",
186          f_params.power_logic_plugin.c_str());
187   return;
188 }