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 /// \ingroup tag_PowerService
19 /// \brief Handles Power Service Business logic
21 ///////////////////////////////////////////////////////////////////////////////
25 #include <system_service/ss_system_manager_notifications.h>
26 #include <system_service/ss_templates.h>
27 #include <system_service/ss_services.h>
28 #include <system_service/ss_sm_client_if.h>
29 #include <system_service/ss_system_manager_if.h>
30 #include <system_service/ss_system_manager_protocol.h>
31 #include <system_service/ss_power_service_protocol.h>
32 #include <system_service/ss_power_service_notifications.h>
33 #include <system_service/ss_power_service.h>
34 #include <system_service/ss_power_service_notifications_local.h>
35 #include <system_service/ss_power_service_local.h>
36 #include <native_service/frameworkunified_timer.h>
37 #include <native_service/frameworkunified_application.h>
38 #include <native_service/frameworkunified_framework_if.h>
39 #include <native_service/ns_np_service_protocol.h>
40 #include <other_service/PosixBasedOS001ClockCycleApi.h>
44 #include "ss_power_powerservicelog.h"
46 using namespace std; // NOLINT (build/namespaces)
48 static Power g_PowerSubsystem;
58 template<typename C, eFrameworkunifiedStatus (C::*M)(HANDLE)> EFrameworkunifiedStatus PowerCallback(
61 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
63 C * pObj = static_cast<C *>(&g_PowerSubsystem);
66 l_eStatus = (pObj->*M)(h_app);
72 ///////////////////////////////////////////////////////////////////////
74 /// Return global instance of Power object. Power is singleton class
76 //////////////////////////////////////////////////////////////////////
77 Power & Power::GetInstance() {
78 return g_PowerSubsystem;
81 ///////////////////////////////////////////////////////////////////////
83 /// Constructor of Power class
85 //////////////////////////////////////////////////////////////////////
87 : m__CWORD56_RepHist(SS_PWR__CWORD56__REP_HIST_SIZE),
88 m_PubCmdHist(SS_PWR_PUB_CMD_HIST_SIZE),
89 m_ErrHist(SS_PWR_ERR_HIST_SIZE),
90 m_VCmdHist(SS_PWR_V_HIST_SIZE),
91 m_PowerState(SS_PS_READY_TO_WAKEUP),
92 m_VoltageState(epsvsINVALID),
93 m_CrankState(epscsINVALID),
94 m_MaxShutdownTimeout(0) {
95 m_PPStateStrMap[SS_PS_READY_TO_WAKEUP] = "SS_PS_READY_TO_WAKEUP";
96 m_PPStateStrMap[SS_PS_WAKEUP_INITIATED] = "SS_PS_WAKEUP_INITIATED";
97 m_PPStateStrMap[SS_PS_WAKEUP_COMPLETE] = "SS_PS_WAKEUP_COMPLETE";
98 m_PPStateStrMap[SS_PS_POWER_ON_COMPLETE] = "SS_PS_POWER_ON_COMPLETE";
99 m_PPStateStrMap[SS_PS_POWER_OFF_INITIATED] = "SS_PS_POWER_OFF_INITIATED";
100 m_PPStateStrMap[SS_PS_POWER_OFF_COMPLETE] = "SS_PS_POWER_OFF_COMPLETE";
101 m_PPStateStrMap[SS_PS_SHUTDOWN_INITIATED] = "SS_PS_SHUTDOWN_INITIATED";
102 m_PPStateStrMap[SS_PS_SHUTDOWN_COMPLETE] = "SS_PS_SHUTDOWN_COMPLETE";
103 m_PPStateStrMap[SS_PS_STATE_MAX] = "SS_PS_STATE_MAX";
105 m__CWORD56_RepIter = m__CWORD56_RepHist.begin();
106 m_PubHistIter = m_PubCmdHist.begin();
107 m_ErrHistIter = m_ErrHist.begin();
108 m_VHistIter = m_VCmdHist.begin();
109 bzero(&m_WakeUpData, sizeof(m_WakeUpData));
112 ///////////////////////////////////////////////////////////////////////
114 /// Destructor of Power class
116 //////////////////////////////////////////////////////////////////////
117 Power::~Power() { // LCOV_EXCL_START 14 Resident process, not called by NSFW
118 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
120 // LCOV_EXCL_STOP 14 Resident process, not called by NSFW
122 ///////////////////////////////////////////////////////////////////////
126 //////////////////////////////////////////////////////////////////////
127 EFrameworkunifiedStatus Power::Initialize(HANDLE h_app) {
128 EFrameworkunifiedStatus l_eStatus;
129 BOOL l_SpecifiedCfgLoaded;
131 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
133 SetPowerServiceState(SS_PS_READY_TO_WAKEUP);
135 pthread_mutex_init(&pwr_hist_mutex, NULL);
137 /// Open and parse the configuration data for Power
138 const CHAR configFileName[] = "/usr/agl/conf/BS/ss/power_service/rodata/gpf_ss_ps_config.cfg";
140 PowerConfiguration config(configFileName);
141 l_SpecifiedCfgLoaded = config.LoadParameters(m_tConfigData);
142 if (FALSE == l_SpecifiedCfgLoaded) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
144 ZONE_ERR, __FUNCTION__,
145 "Reading configuration from file: %s failed. Using default parameters.",
147 config.LoadDefaultParameters(m_tConfigData);
150 config.PrintConfigInfo(m_tConfigData);
152 /// init PowerStateMachine
153 m_oStateMachine.initialize(h_app, m_tConfigData);
155 // Register all callbacks to dispatcher and notifications
156 l_eStatus = RegisterAllCallbacksAndNofitications(h_app);
157 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
158 l_eStatus, "RegisterAllCallbacksAndNofitications()");
160 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
164 ///////////////////////////////////////////////////////////////////////
165 /// RegisterAllCallbacksAndNofitications
168 //////////////////////////////////////////////////////////////////////
169 EFrameworkunifiedStatus Power::RegisterAllCallbacksAndNofitications(HANDLE h_app) {
170 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
171 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
173 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedRegisterServiceAvailabilityNotification(h_app, szNTFY_PowerAvailability))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
174 // LCOV_EXCL_START 4: NSFW error case.
175 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
177 "FrameworkunifiedRegisterServiceAvailabilityNotification( "szNTFY_PowerAvailability" )");
178 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
180 // LCOV_EXCL_STOP 4: NSFW error case.
182 l_eStatus = FrameworkunifiedPublishServiceAvailability(h_app, FALSE);
183 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
184 // LCOV_EXCL_START 4: NSFW error case.
185 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
186 LOG_ERROR("FrameworkunifiedPublishServiceAvailability()");
188 // LCOV_EXCL_STOP 4: NSFW error case.
190 SS_PWR_LOG_HIST("FrameworkunifiedPublishServiceAvailability()", m_PubCmdHist,
191 m_PubHistIter, "", l_eStatus);
194 // Attach Notification callbacks to dispatcher
195 FrameworkunifiedNotificationsList
196 ss_power_notifications[] = {
197 { szNTFY_PowerLVI1, sizeof(PowerSrvLVIStatus), eFrameworkunifiedStateVar}
198 , {szNTFY_PowerLVI2, sizeof(PowerSrvLVIStatus), eFrameworkunifiedStateVar}
199 , {szNTFY_PowerLevel, sizeof(PowerSrvLevelType), eFrameworkunifiedStateVar}
200 , {szNTFY_ShutdownPopup, sizeof(EPWR_SHUTDOWN_POPUP_TYPE), eFrameworkunifiedStateVar}
201 , {szNTFY_PowerPopup, sizeof(EPWR_POWER_POPUP_TYPE), eFrameworkunifiedStateVar}
203 // Register Notifications
204 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedNPRegisterNotifications(h_app, ss_power_notifications, _countof(ss_power_notifications)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
205 // LCOV_EXCL_START 4: NSFW error case.
206 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
207 LOG_ERROR("FrameworkunifiedNPRegisterNotifications(ss_power_notifications)");
208 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
211 // LCOV_EXCL_STOP 4: NSFW error case.
212 // Subscribe and attach call back for notification
213 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSubscribeNotificationWithCallback(h_app, NTFY_SSSystemMgrPowerOnOff, PowerCallback<Power, &Power::OnPowerOnOffNotification>))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
214 // LCOV_EXCL_START 4: NSFW error case.
215 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
216 LOG_ERROR("FrameworkunifiedSubscribeNotificationWithCallback()");
217 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
220 // LCOV_EXCL_STOP 4: NSFW error case.
222 //*************************
224 /// < Attach to the following session handles.
225 FrameworkunifiedProtocolCallbackHandler ss_power_session_req_handlers[] = {
227 { PROTOCOL_OPEN_SESSION_REQ, PowerCallback<Power,
228 &Power::OnOpenSession> }, { PROTOCOL_CLOSE_SESSION_REQ,
229 PowerCallback<Power, &Power::OnCloseSession> }, {
230 SS_POWER_STATE_CHANGE_REQ, PowerCallback<Power,
231 &Power::OnSetPowerState> }, { SS_POWER_POWER_REQUEST_MSG,
232 PowerCallback<Power, &Power::OnPowerRequestMsg> }, {
233 SS_POWER_COMM_WAKEUP,
234 PowerCallback<Power, &Power::OnSetCommWakeUp> }, {
235 SS_POWER_SHUTDOWN_REQ,
236 PowerCallback<Power, &Power::OnSetCommSleep> }, {
237 SS_POWER_SHUTDOWN_REQUEST_MSG, PowerCallback<Power,
238 &Power::OnShutdownRequestMsg> }
240 /// Wake-up / Shutdown Protocol commands for System Manager.
241 , { SS_SM_WAKEUP_MODULES_CMPL_RSPN, PowerCallback<Power,
242 &Power::OnWakeUpComplete> }, { SS_SM_SHUTDOWN_MODULES_CMPL_RSPN,
243 PowerCallback<Power, &Power::OnShutdownComplete> }
245 , { SS_POWER_PRINT_CONNECTIONS, PowerCallback<Power,
246 &Power::OnPrintConnections> }, { SS_POWER_PRINT_STACK,
247 PowerCallback<Power, &Power::OnPrintStack> }
248 /// Set Voltage & Crank states from shadow?
249 , { SS_POWER_VOLTAGE_STATE, PowerCallback<Power,
250 &Power::OnSetVoltageState> }, { SS_POWER_CRANK_STATE,
251 PowerCallback<Power, &Power::OnSetCrankState> }
252 /// Current Power Service State inquiry from Test Client
253 , { SS_POWER_CRNT_STATE_QUERY, PowerCallback<Power,
254 &Power::OnCurrentPowerStateQuery> }, {
255 SS_POWER_SYSTEM_MODE_INFO_REQ, PowerCallback<Power,
256 &Power::OnSystemModeInfoRequest> }, {
257 SS_SM_SYSTEM_MODE_INFO_RSPN, PowerCallback<Power,
258 &Power::OnSystemModeInfoResponse> }
259 /// InitComp report to SystemManager
260 , { SS_POWER_INITCOMP_REP, PowerCallback<Power,
261 &Power::OnInitCompReport> }
263 // Startup Confirmation Request ( from Power Shadow ) and
264 // Startup Confirmation Response ( from System Manager )
265 , { SS_POWER_FWD_START_CONFIRMATION_MSG_REQ, PowerCallback<Power,
266 &Power::OnSendStartupConfirmationRequest> }, {
267 SS_POWER_FWD_START_CONFIRMATION_MSG_RESP, PowerCallback<Power,
268 &Power::OnSendStartupConfirmationResponse> }
270 // User Mode Request ( from Power Shadow ) and
271 // User Mode Response ( from System Manager )
272 , { SS_SM_USER_MODE_SET_RESP, PowerCallback<Power,
273 &Power::OnUserModeResponse> }
276 // Heartbeat Request ( from Power Shadow )
277 , { SS_POWER_HEARTBEAT_REQ, PowerCallback<Power,
278 &Power::On_CWORD56_HeartBeatRequest> }, { SS_SM__CWORD56__HEARTBEAT_RSPN,
279 PowerCallback<Power, &Power::OnSM_CWORD56_HeartBeatResponse> }
281 // System Manager to Power Services
282 , { SS_SM_CPU_RESET_REQ, PowerCallback<Power,
283 &Power::OnCpuResetRequest> }, { SS_SM_REMOTE_DATA_RESET_REQ,
284 PowerCallback<Power, &Power::OnRemoteDataResetRequest> } };
287 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(h_app, FRAMEWORKUNIFIED_ANY_SOURCE, ss_power_session_req_handlers, _countof(ss_power_session_req_handlers)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
288 // LCOV_EXCL_START 4: NSFW error case.
289 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
290 LOG_ERROR("FrameworkunifiedAttachCallbacksToDispatcher( ss_power_session_req_handlers )");
291 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
294 // LCOV_EXCL_STOP 4: NSFW error case.
296 //*************************
298 // Publish szNTFY_PowerAvailable so that other services can start connecting via sessions.
300 l_eStatus = RegisterSMSessionAckCallback(
301 PowerCallback<Power, &Power::OnSystemMgrConnectionEstablished>);
302 LOG_STATUS(l_eStatus, "RegisterSMSessionAckCallback()");
304 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
308 ///////////////////////////////////////////////////////////////////////
312 //////////////////////////////////////////////////////////////////////
313 EFrameworkunifiedStatus Power::OnSetCommWakeUp(HANDLE h_app) {
314 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
315 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
316 Pwr_ServiceSetInterface l_CanStatesData;
319 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
320 // Report any errors found. *
322 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, l_CanStatesData))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
323 // LCOV_EXCL_START 4: NSFW error case.
324 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
325 LOG_ERROR("ReadMsg()");
326 // LCOV_EXCL_STOP 4: NSFW error case.
327 } else if (l_CanStatesData.data.commwake.state == epscnCANWAKEUP) {
328 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
329 "Received WakeUp from %s, Processing Ignored !!",
330 FrameworkunifiedGetMsgSrc(h_app));
333 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
337 ///////////////////////////////////////////////////////////////////////
341 //////////////////////////////////////////////////////////////////////
342 // LCOV_EXCL_START 200: can not be called from power class
343 EFrameworkunifiedStatus Power::OnSetCommSleep(HANDLE h_app) {
344 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
345 EFrameworkunifiedStatus l_eStatus;
346 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
347 Pwr_ServiceSetInterface l_CanStatesData;
350 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
351 // Report any errors found. *
353 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, l_CanStatesData))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
354 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
355 LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4: NSFW error case.
356 } else if (l_CanStatesData.data.commwake.state != epscnCANSLEEP) {
357 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
358 "Error: %s: l_CanStatesData.data.commwake.state != epscnCANSLEEP",
359 FrameworkunifiedGetMsgSrc(h_app));
360 l_eStatus = eFrameworkunifiedStatusInvldParam;
362 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Received Sleep from %s",
363 FrameworkunifiedGetMsgSrc(h_app));
365 // Send to System Manager to WakeUp Modules
366 l_eStatus = SendShutdownToSystemManager(&l_CanStatesData);
367 if (l_eStatus != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
368 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
369 LOG_ERROR("SendShutdownToSystemManager()"); // LCOV_EXCL_LINE 4: NSFW error case.
371 SetPowerServiceState(SS_PS_SHUTDOWN_INITIATED);
372 LOG_SUCCESS("SendShutdownToSystemManager()");
376 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
379 // LCOV_EXCL_STOP 200: can not be called from power class
381 ///////////////////////////////////////////////////////////////////////
382 /// SetPowerServiceState
385 //////////////////////////////////////////////////////////////////////
386 VOID Power::SetPowerServiceState(SS_PSState f_NewState) {
387 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Changing State from '%s' to '%s'",
388 m_PPStateStrMap[m_PowerState].c_str(),
389 m_PPStateStrMap[f_NewState].c_str());
391 m_PowerState = f_NewState;
394 ///////////////////////////////////////////////////////////////////////
395 /// OnPowerOnOffNotification
398 //////////////////////////////////////////////////////////////////////
399 EFrameworkunifiedStatus Power::OnPowerOnOffNotification(HANDLE h_app) {
400 EFrameworkunifiedStatus l_eStatus;
401 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
402 T_SS_SM_UserModeOnOffNotification_StructType l_userModeOnOffStruct;
403 INTERFACEUNIFIEDLOG_RECEIVED_FROM(h_app);
405 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<T_SS_SM_UserModeOnOffNotification_StructType>(h_app, l_userModeOnOffStruct))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
406 // LCOV_EXCL_START 4: NSFW error case.
407 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
408 LOG_ERROR("ReadMsg()");
409 // LCOV_EXCL_STOP 4: NSFW error case.
411 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
412 " User Mode is '%s', User Mode Change Reason is '%s'",
413 GetStr(l_userModeOnOffStruct.isUserModeOn).c_str(),
414 GetStr(l_userModeOnOffStruct.userModeChangeReason).c_str());
415 SetPowerServiceState(
416 l_userModeOnOffStruct.isUserModeOn ?
417 SS_PS_POWER_ON_COMPLETE : SS_PS_POWER_OFF_COMPLETE);
419 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
423 ///////////////////////////////////////////////////////////////////////
424 /// ProcessSystemWakeUp
425 /// On receipt of this notification send wake up notification to
426 /// System Manager to wake up (START) all modules
428 //////////////////////////////////////////////////////////////////////
429 EFrameworkunifiedStatus Power::OnSetPowerState(HANDLE h_app) {
430 EFrameworkunifiedStatus l_eStatus;
431 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
432 Pwr_ServiceSetInterface l_serviceSetIf;
435 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
436 // Report any errors found. *
438 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, l_serviceSetIf))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
439 // LCOV_EXCL_START 4: NSFW error case.
440 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
441 LOG_ERROR("ReadMsg()");
442 // LCOV_EXCL_STOP 4: NSFW error case.
444 switch (l_serviceSetIf.data.wake.powerupType) {
447 m_WakeUpData = l_serviceSetIf.data.wake;
450 ZONE_INFO, __FUNCTION__, " Received Power %s from %s, level 0x%X",
451 l_serviceSetIf.data.wake.powerupType == epswsPWRON ? "On" : "Off",
452 FrameworkunifiedGetMsgSrc(h_app), m_WakeUpData.up.level);
453 // Send to System Manager to WakeUp Modules
454 l_eStatus = SendWakeUpToSystemManager(&m_WakeUpData);
455 if (l_eStatus == eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
456 SetPowerServiceState(SS_PS_WAKEUP_INITIATED);
457 LOG_SUCCESS("SendWakeUpToSystemManager()");
459 // LCOV_EXCL_START 4: NSFW error case.
460 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
461 LOG_ERROR("SendWakeUpToSystemManager()");
462 // LCOV_EXCL_STOP 4: NSFW error case.
466 l_eStatus = eFrameworkunifiedStatusInvldParam;
467 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
468 " Error: Invalid PowerOnOff State received: 0x%X",
469 l_serviceSetIf.data.wake.powerupType);
474 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
478 ///////////////////////////////////////////////////////////////////////
480 /// Session Request Handlers
482 //////////////////////////////////////////////////////////////////////
484 EFrameworkunifiedStatus Power::OnOpenSession(HANDLE h_app) {
485 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
486 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
487 INTERFACEUNIFIEDLOG_RECEIVED_FROM(h_app);
488 l_eStatus = m_oSessionHandler.OpenSesion(h_app);
490 /// < Test Code TODO: Remove ME!!!
491 // m_oSessionHandler.Print();
493 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
497 ///////////////////////////////////////////////////////////////////////
501 //////////////////////////////////////////////////////////////////////
502 EFrameworkunifiedStatus Power::OnCloseSession(HANDLE h_app) {
503 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
504 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
505 INTERFACEUNIFIEDLOG_RECEIVED_FROM(h_app);
506 l_eStatus = m_oSessionHandler.CloseSession(h_app);
507 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
511 ///////////////////////////////////////////////////////////////////////
515 //////////////////////////////////////////////////////////////////////
516 EFrameworkunifiedStatus Power::OnWakeUpComplete(HANDLE h_app) {
517 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
518 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
522 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
523 // Report any errors found. *
525 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<wakeInfo>(h_app, l_Wake))) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
526 // LCOV_EXCL_START 4: NSFW error case.
527 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
528 LOG_ERROR("ReadMsg()");
529 // LCOV_EXCL_STOP 4: NSFW error case.
530 } else if (l_Wake.up.level == m_WakeUpData.up.level) {
531 SetPowerServiceState(SS_PS_WAKEUP_COMPLETE);
533 /// < send the state machine a wakeup event.
534 m_oStateMachine.onEvent(h_app, m_oSessionHandler,
535 PowerStateMachine::epsmeWAKEUP);
537 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
538 " Sending SS_POWER_STATE_CHANGE_RESP(%s) to PSM",
539 l_Wake.powerupType == epswsPWRON ? "User_On" : "User_Off");
541 // send Wake-up complete response to Supervisor
542 m_oSessionHandler.SendToSupervisor(SS_POWER_STATE_CHANGE_RESP,
543 sizeof(l_Wake), (PVOID) &l_Wake);
544 SS_PWR_LOG_HIST("SS_POWER_STATE_CHANGE_RESP", m__CWORD56_RepHist, m__CWORD56_RepIter,
545 "SS_PS_WAKEUP_COMPLETE", l_eStatus);
547 /// < Test Code TODO: Remove ME!!!
548 // m_oSessionHandler.Print();
550 l_eStatus = eFrameworkunifiedStatusInvldParam;
554 "Error: Power WakeUp Threshold (%d) and SM WakeUp Threshold (%d) Mismatch",
555 m_WakeUpData.up.level, l_Wake.up.level);
558 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
562 ///////////////////////////////////////////////////////////////////////
566 //////////////////////////////////////////////////////////////////////
567 EFrameworkunifiedStatus Power::OnShutdownComplete(HANDLE h_app) {
568 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
569 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
571 SetPowerServiceState(SS_PS_SHUTDOWN_COMPLETE);
573 m_oStateMachine.onEvent(h_app, m_oSessionHandler,
574 PowerStateMachine::epsmeSHUTDOWN);
576 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Sending SS_POWER_SHUTDOWN_RESP to PSM");
577 // send Shutdown complete response to Power Shadow / Supervisor
578 m_oSessionHandler.SendToSupervisor(SS_POWER_SHUTDOWN_RESP, 0, (PVOID) NULL);
580 SS_PWR_LOG_HIST("SS_POWER_SHUTDOWN_RESP", m__CWORD56_RepHist, m__CWORD56_RepIter,
581 "SS_PS_SHUTDOWN_COMPLETE", l_eStatus);
583 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
585 } // End of EFrameworkunifiedStatus Power::OnShutdownComplete(HANDLE h_app)
587 ///////////////////////////////////////////////////////////////////////
591 //////////////////////////////////////////////////////////////////////
592 EFrameworkunifiedStatus Power::OnPrintConnections(HANDLE h_app) {
593 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
594 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
595 m_oSessionHandler.Print();
596 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
600 ///////////////////////////////////////////////////////////////////////
604 //////////////////////////////////////////////////////////////////////
605 EFrameworkunifiedStatus Power::OnPrintStack(HANDLE h_app) {
606 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
607 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
608 m_oSessionHandler.Print();
609 // m_oStateMachine.Print();
610 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
614 ///////////////////////////////////////////////////////////////////////
618 //////////////////////////////////////////////////////////////////////
619 EFrameworkunifiedStatus Power::OnHysteresisTimeout(HANDLE h_app) {
620 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
621 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
622 m_oStateMachine.onEvent(h_app, m_oSessionHandler,
623 PowerStateMachine::epsmeLVI1_HYSTERESIS_TM_OUT);
624 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
627 ///////////////////////////////////////////////////////////////////////
631 //////////////////////////////////////////////////////////////////////
633 EFrameworkunifiedStatus PowerStateMachine::initialize(HANDLE h_app,
634 PowerConfigParams & refConfigParms) {
635 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
636 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
637 /// Set all hysteresis objects with the configuration data obtained from PowerService.xml
638 m_oShutdownHysteresis.set(refConfigParms.shutdown);
639 m_oLowVoltage1Hysteresis.set(refConfigParms.lvi1);
640 m_oLowVoltage2Hysteresis.set(refConfigParms.lvi2);
642 /// Copy the list of required modules.
643 m_lstWakeupModules = refConfigParms.wakeup_modules;
644 m_lstShutdownModules = refConfigParms.shutdown_modules;
645 m_lstLvi2Modules = refConfigParms.lvi2_modules;
647 m_hHysteresisTimer = FrameworkunifiedAttachTimerCallback(
648 h_app, 0, 0, PowerCallback<Power, &Power::OnHysteresisTimeout>);
649 if (NULL == m_hHysteresisTimer) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
650 // LCOV_EXCL_START 4: NSFW error case.
651 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
652 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
653 "Error: FrameworkunifiedAttachTimerCallback() returned NULL");
654 l_eStatus = eFrameworkunifiedStatusInvldHandle;
656 // LCOV_EXCL_STOP 4: NSFW error case.
658 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
662 ///////////////////////////////////////////////////////////////////////
666 //////////////////////////////////////////////////////////////////////
667 EFrameworkunifiedStatus PowerSessionHandler::OpenSesion(HANDLE h_app) {
668 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
669 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
671 // check if the subscriber is already in map
672 PwSessionIter iter = m_mapSessions.find(FrameworkunifiedGetMsgSrc(h_app));
674 // the iter is set to the end then the subscriber is not in the map
675 if (m_mapSessions.end() == iter) {
676 string subscriber(FrameworkunifiedGetMsgSrc(h_app));
677 PwSessionInfo newEntry;
678 newEntry.frunning = FALSE;
679 newEntry.hsession = FrameworkunifiedMcOpenSender(h_app, subscriber.c_str());
680 newEntry.sz_name = subscriber;
681 newEntry.sz_servicename = ""; // we will get this on the start complete.
682 newEntry.esessiontype = epsstBASIC;
683 newEntry.ui_groupid = 0;
685 if (NULL != newEntry.hsession) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
687 // Set the Session Handle for Framework so FrameworkunifiedSendResponse won't error due to a null
690 // LCOV_EXCL_BR_START 4: NSFW error case.
691 if (eFrameworkunifiedStatusOK
692 // [in] PCSTR - Name of the associated service name
693 // [in] HANDLE - Session handle
694 != (l_eStatus = FrameworkunifiedSetSessionHandle(h_app, subscriber.c_str(), newEntry.hsession))) { // NOLINT[whitespace/line_length]
696 // LCOV_EXCL_START 4: NSFW error case.
697 LOG_ERROR("FrameworkunifiedSetSessionHandle()");
698 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
699 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
701 // LCOV_EXCL_STOP 4: NSFW error case.
704 OpenSessionAck openSessionAck;
705 memset(&openSessionAck, 0, sizeof(openSessionAck));
706 strcpy(openSessionAck.cSessionName, SERVICE_POWER); // NOLINT (runtime/printf)
707 openSessionAck.eStatus = eFrameworkunifiedStatusOK;
708 openSessionAck.sessionId = 0; /// Only one session handles all the heartbeat clients
710 // Send Ack to subscriber
711 l_eStatus = FrameworkunifiedSendMsg(newEntry.hsession, PROTOCOL_OPEN_SESSION_ACK,
712 sizeof(OpenSessionAck), (PVOID) &openSessionAck);
714 snprintf(l_cBuf, sizeof(l_cBuf),
715 "FrameworkunifiedSendMsg(%s, PROTOCOL_OPEN_SESSION_ACK)", subscriber.c_str());
716 LOG_STATUS(l_eStatus, l_cBuf);
719 // If this is not a basic module then we will need to register some other protocols
720 if (0 != FrameworkunifiedGetMsgLength(h_app)) {
721 EPWR_SESSION_TYPE tOpenSessionReq;
722 if (sizeof(EPWR_SESSION_TYPE) == FrameworkunifiedGetMsgLength(h_app)) {
723 if (eFrameworkunifiedStatusOK
724 == (l_eStatus = FrameworkunifiedGetMsgDataOfSize(h_app, (PVOID) &tOpenSessionReq,
725 sizeof(EPWR_SESSION_TYPE)))) {
726 switch (tOpenSessionReq) {
728 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
729 "Subscriber : %s , open a session using type: BASIC",
731 FrameworkunifiedProtocolCallbackHandler ss_power_session_basic_handlers[] = { {
732 PROTOCOL_OPEN_SESSION_REQ, PowerCallback<Power,
733 &Power::OnOpenSession> }, { PROTOCOL_CLOSE_SESSION_REQ,
734 PowerCallback<Power, &Power::OnCloseSession> } };
736 // Attach callback : Power Session Requests
737 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(h_app, subscriber.c_str(), ss_power_session_basic_handlers, _countof(ss_power_session_basic_handlers)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
738 // LCOV_EXCL_START 4: NSFW error case.
739 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
741 "FrameworkunifiedAttachCallbacksToDispatcher(ss_power_session_basic_handlers)");
742 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
745 // LCOV_EXCL_STOP 4: NSFW error case.
747 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
748 "Subscriber '%s' opened a type 'BASIC' session",
752 case epsstSUPERVISOR: {
753 FrameworkunifiedProtocolCallbackHandler ss_power_sprv_session_handlers[] = { {
754 PROTOCOL_OPEN_SESSION_REQ, PowerCallback<Power,
755 &Power::OnOpenSession> }, { PROTOCOL_CLOSE_SESSION_REQ,
756 PowerCallback<Power, &Power::OnCloseSession> }, {
757 SS_POWER_FWD_START_CONFIRMATION_MSG_REQ, PowerCallback<Power,
758 &Power::OnSendStartupConfirmationRequest> }, {
759 SS_POWER_STATE_CHANGE_REQ, PowerCallback<Power,
760 &Power::OnSetPowerState> }, { SS_POWER_SHUTDOWN_REQ,
761 PowerCallback<Power, &Power::OnShutdownRequestMsg> }
762 , { SS_POWER_SYSTEM_MODE_INFO_REQ, PowerCallback<Power,
763 &Power::OnSystemModeInfoRequest> }, {
764 SS_POWER_PUBLISH_SHUTDOWN_CONDITION_REQ, PowerCallback<
765 Power, &Power::OnPublishShutdownPopupRequest> }, {
766 SS_POWER_PUBLISH_POWER_POPUP_REQ, PowerCallback<Power,
767 &Power::OnPublishPowerPopupRequest> }, {
768 SS_POWER_POWER_REQUEST_MSG, PowerCallback<Power,
769 &Power::OnPowerRequestMsg> } };
771 // Attach callback : Power Supervisor Session Requests
772 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(h_app, subscriber.c_str(), ss_power_sprv_session_handlers, _countof(ss_power_sprv_session_handlers)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
773 // LCOV_EXCL_START 4: NSFW error case.
774 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
776 "FrameworkunifiedAttachCallbacksToDispatcher(ss_power_sprv_session_handlers)");
777 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
780 // LCOV_EXCL_STOP 4: NSFW error case.
782 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
783 "Subscriber '%s' opened a 'SUPERVISOR' session",
785 newEntry.esessiontype = tOpenSessionReq;
787 static BOOL first_supervisor = TRUE;
788 if (first_supervisor) {
789 AttachCallbackToSystemManager( // LCOV_EXCL_BR_LINE 4: NSFW error case.
790 h_app, SS_SM_SYSTEM_MODE_INFO_RSPN,
791 PowerCallback<Power, &Power::OnSystemModeInfoResponse>);
792 first_supervisor = FALSE;
797 FrameworkunifiedProtocolCallbackHandler ss_power_system_session_handlers[] = {
798 { PROTOCOL_OPEN_SESSION_REQ, PowerCallback<Power,
799 &Power::OnOpenSession> }, { PROTOCOL_CLOSE_SESSION_REQ,
800 PowerCallback<Power, &Power::OnCloseSession> }, {
801 SS_POWER_SYSTEM_LAUNCH_COMPLETE, PowerCallback<Power,
802 &Power::OnSystemLaunchComplete> }, {
803 SS_POWER_SHUTDOWN_RESP, PowerCallback<Power,
804 &Power::OnSystemShutdownComplete> } };
806 // Attach callback : Power System Session Requests
807 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedAttachCallbacksToDispatcher(h_app, subscriber.c_str(), ss_power_system_session_handlers, _countof(ss_power_system_session_handlers)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
808 // LCOV_EXCL_START 4: NSFW error case.
809 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
811 "FrameworkunifiedAttachCallbacksToDispatcher(ss_power_session_handlers)");
812 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
815 // LCOV_EXCL_STOP 4: NSFW error case.
817 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
818 "Subscriber '%s' opened a 'SYSTEM' session",
820 newEntry.esessiontype = tOpenSessionReq;
824 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
825 "Subscriber '%s' tried to open a type 'UNKNOWN' session",
827 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
828 return eFrameworkunifiedStatusInvldParam;
836 // insert this newEntry into the map
837 m_mapSessions.insert(make_pair(subscriber, newEntry));
839 // This Subscriber is already in our map, just send and ack to keep them quote.
841 ZONE_INFO, __FUNCTION__,
842 "Subscriber : %s , is already in the map, will Just send back an ACK",
843 iter->second.sz_name.c_str());
844 if (NULL != iter->second.hsession) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
845 OpenSessionAck openSessionAck;
846 memset(&openSessionAck, 0, sizeof(openSessionAck));
847 strcpy(openSessionAck.cSessionName, SERVICE_POWER); // NOLINT (runtime/printf)
848 openSessionAck.eStatus = eFrameworkunifiedStatusOK;
849 // I can't think of a reason why we would need more that one session per subscriber.
850 openSessionAck.sessionId = 0;
852 // Send Ack to subscriber
853 l_eStatus = FrameworkunifiedSendMsg(iter->second.hsession, PROTOCOL_OPEN_SESSION_ACK,
854 sizeof(OpenSessionAck), (PVOID) &openSessionAck);
855 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
856 "FrameworkunifiedSendMsg Success to : %s , status: 0x%x",
857 iter->second.sz_name.c_str(), l_eStatus);
859 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__,
860 "What! NULL == iter->second.hsession TODO: Need to handle this!");
864 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
868 ///////////////////////////////////////////////////////////////////////
872 //////////////////////////////////////////////////////////////////////
873 EFrameworkunifiedStatus PowerSessionHandler::StopComplete(HANDLE h_app) { // LCOV_EXCL_START 8: can not be called
874 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
875 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
876 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
878 // ToDo Jay 2012 November 02 Can this be deleted ?
879 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
880 " No-op function - It's here, but it doesn't do anything");
882 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
885 // LCOV_EXCL_STOP 8: can not be called
887 ///////////////////////////////////////////////////////////////////////
888 /// ProcessVoltageNotifyRequest
891 //////////////////////////////////////////////////////////////////////
892 EFrameworkunifiedStatus Power::PublishVoltageStateChange(HANDLE h_app) {
893 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
894 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
895 PowerSrvLVIStatus l_LVIStatus;
896 PowerSrvLevelType l_PowerLevel;
898 switch (m_VoltageState) { // LCOV_EXCL_BR_LINE 6: double check
900 l_PowerLevel = epspltNORMAL;
901 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLevel, &l_PowerLevel, sizeof(PowerSrvLevelType));
902 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
904 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLevel ", epspltNORMAL)");
906 l_LVIStatus = ePwSrvLVI_Status_InActive;
907 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLVI1, &l_LVIStatus, sizeof(PowerSrvLVIStatus));
908 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
910 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLVI1 ", ePwSrvLVI_Status_InActive)");
912 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLVI2, &l_LVIStatus, sizeof(PowerSrvLVIStatus));
913 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
915 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLVI2 ", ePwSrvLVI_Status_InActive)");
919 l_PowerLevel = epspltEMERGENCY;
920 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLevel, &l_PowerLevel, sizeof(PowerSrvLevelType));
921 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
923 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLevel ", epspltEMERGENCY)");
925 l_LVIStatus = ePwSrvLVI_Status_Active;
926 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLVI1, &l_LVIStatus, sizeof(PowerSrvLVIStatus));
927 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
929 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLVI1 ", ePwSrvLVI_Status_Active)");
931 l_LVIStatus = ePwSrvLVI_Status_InActive;
932 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLVI2, &l_LVIStatus, sizeof(PowerSrvLVIStatus));
933 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
935 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLVI2 ", ePwSrvLVI_Status_InActive)");
939 l_PowerLevel = epspltEMERGENCY;
940 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLevel, &l_PowerLevel, sizeof(PowerSrvLevelType));
941 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
943 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLevel ", epspltEMERGENCY)");
945 l_LVIStatus = ePwSrvLVI_Status_InActive;
946 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLVI1, &l_LVIStatus, sizeof(PowerSrvLVIStatus));
947 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
949 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLVI1 ", ePwSrvLVI_Status_InActive)");
951 l_LVIStatus = ePwSrvLVI_Status_Active;
952 l_eStatus = FrameworkunifiedNPPublishNotification(h_app, szNTFY_PowerLVI2, &l_LVIStatus, sizeof(PowerSrvLVIStatus));
953 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
955 "FrameworkunifiedNPPublishNotification(" szNTFY_PowerLVI2 ", ePwSrvLVI_Status_Active)");
959 // LCOV_EXCL_START 6: double check
960 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
961 l_eStatus = eFrameworkunifiedStatusInvldParam;
962 LOG_ERROR(" epsvsINVALID == m_VoltageState");
964 // LCOV_EXCL_STOP 6: double check
967 // LCOV_EXCL_START 6: double check
968 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
969 l_eStatus = eFrameworkunifiedStatusInvldParam;
970 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
971 "Error: Invalid 'm_VoltageState' value detected: 0x%X/%d",
972 m_VoltageState, m_VoltageState);
974 // LCOV_EXCL_STOP 6: double check
977 SS_PWR_LOG_HIST("PublishVoltageStateChange()", m_PubCmdHist, m_PubHistIter,
980 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
983 ///////////////////////////////////////////////////////////////////////
984 /// OnSystemModeInfoResponse
986 //////////////////////////////////////////////////////////////////////
987 EFrameworkunifiedStatus Power::OnSystemModeInfoResponse(HANDLE h_app) {
988 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
989 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
990 SystemModeInfo l_SystemModeInfo;
992 std::memset(&l_SystemModeInfo, 0, sizeof(SystemModeInfo));
995 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
996 // Report any errors found. *
998 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<SystemModeInfo>(h_app, l_SystemModeInfo))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
999 // LCOV_EXCL_START 4: NSFW error case.
1000 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1001 LOG_ERROR("ReadMsg()"); // LCOV_EXCL_LINE 4: NSFW error case.
1002 // LCOV_EXCL_STOP 4: NSFW error case.
1004 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1005 "Sending SS_POWER_SYSTEM_MODE_INFO_RESP to PSM");
1006 // send Wake-up complete response to System Power Manager
1007 l_eStatus = m_oSessionHandler.SendToSupervisor(
1008 SS_POWER_SYSTEM_MODE_INFO_RESP, sizeof(SystemModeInfo),
1009 (PVOID) &l_SystemModeInfo);
1011 SS_PWR_LOG_HIST("SS_POWER_SYSTEM_MODE_INFO_RESP", m__CWORD56_RepHist,
1012 m__CWORD56_RepIter, "", l_eStatus);
1014 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
1015 l_eStatus, "m_oSessionHandler.SendToSupervisor( "
1016 "SS_POWER_SYSTEM_MODE_INFO_RESP)");
1018 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1022 ///////////////////////////////////////////////////////////////////////
1023 /// OnSystemModeInfoRequest
1025 //////////////////////////////////////////////////////////////////////
1026 EFrameworkunifiedStatus Power::OnSystemModeInfoRequest(HANDLE h_app) {
1027 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1028 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1030 if (eFrameworkunifiedStatusOK != (l_eStatus = SendSystemModeRequestToSystemManager())) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
1031 // LCOV_EXCL_START 4: NSFW error case.
1032 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1033 LOG_ERROR("SendSystemModeRequestToSystemManager()");
1034 // LCOV_EXCL_STOP 4: NSFW error case.
1036 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1040 ///////////////////////////////////////////////////////////////////////
1041 /// OnInitCompReport
1043 //////////////////////////////////////////////////////////////////////
1044 EFrameworkunifiedStatus Power::OnInitCompReport(HANDLE h_app) {
1045 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1046 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1048 if (eFrameworkunifiedStatusOK != (l_eStatus = SendInitCompReportToSystemManager())) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
1049 // LCOV_EXCL_START 4: NSFW error case.
1050 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1051 LOG_ERROR("SendInitCompReportToSystemManager()");
1052 // LCOV_EXCL_STOP 4: NSFW error case.
1055 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1059 ///////////////////////////////////////////////////////////////////////
1060 /// OnCurrentPowerStateQuery
1062 //////////////////////////////////////////////////////////////////////
1063 EFrameworkunifiedStatus Power::OnCurrentPowerStateQuery(HANDLE h_app) {
1064 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1065 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1066 SS_PSCurrentState l_CurrentState;
1067 std::memset(&l_CurrentState, 0, sizeof(SS_PSCurrentState));
1070 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
1071 // Report any errors found. *
1073 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<SS_PSCurrentState>(h_app, l_CurrentState))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1074 // LCOV_EXCL_START 4: NSFW error case.
1075 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1076 LOG_ERROR("ReadMsg()");
1077 // LCOV_EXCL_STOP 4: NSFW error case.
1078 } else if (eFrameworkunifiedStatusOK != (l_eStatus = ConstructPwrStateResponse(l_CurrentState.printRespmsg))) { // LCOV_EXCL_BR_LINE 8: dead code // NOLINT[whitespace/line_length]
1079 // LCOV_EXCL_START 8: dead code.
1080 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1081 LOG_ERROR("ConstructPwrStateResponse(l_CurrentState.printRespmsg)");
1084 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Response is %s",
1085 l_CurrentState.printRespmsg);
1086 // Send Power State to client
1088 HANDLE l_handle = FrameworkunifiedOpenService(h_app, FrameworkunifiedGetMsgSrc(h_app));
1089 if (NULL != l_handle) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
1090 l_eStatus = FrameworkunifiedSendMsg(l_handle, SS_POWER_CRNT_STATE_QUERY_RSPN,
1091 sizeof(SS_PSCurrentState),
1092 (PVOID) &l_CurrentState);
1094 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
1095 l_eStatus, "FrameworkunifiedSendMsg(SS_POWER_CRNT_STATE_QUERY_RSPN)");
1097 l_eStatus = FrameworkunifiedCloseService(h_app, l_handle);
1098 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(l_eStatus,
1099 "FrameworkunifiedCloseService()");
1101 // LCOV_EXCL_START 4: NSFW error case.
1102 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1103 l_eStatus = eFrameworkunifiedStatusNullPointer;
1104 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error. FrameworkunifiedOpenService(%s) returned NULL",
1105 FrameworkunifiedGetMsgSrc(h_app));
1106 // LCOV_EXCL_STOP 4: NSFW error case.
1110 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1114 ///////////////////////////////////////////////////////////////////////
1115 /// OnSetVoltageState
1117 //////////////////////////////////////////////////////////////////////
1118 EFrameworkunifiedStatus Power::OnSetVoltageState(HANDLE h_app) {
1119 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1120 std::string stLvl = "INVALID";
1121 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1123 Pwr_ServiceSetInterface l_VoltageState;
1125 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
1126 // Report any errors found. *
1128 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, l_VoltageState))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1129 // LCOV_EXCL_START 4: NSFW error case.
1130 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1131 LOG_ERROR("ReadMsg()");
1132 // LCOV_EXCL_STOP 4: NSFW error case.
1134 m_VoltageState = static_cast<ePowerSrvVoltageStates>(l_VoltageState.data
1136 if (eFrameworkunifiedStatusOK != (l_eStatus = PublishVoltageStateChange(h_app))) { // LCOV_EXCL_BR_LINE 4:NSFW error case.
1137 // LCOV_EXCL_START 4: NSFW error case.
1138 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1139 LOG_ERROR("PublishVoltageStateChange()");
1140 // LCOV_EXCL_STOP 4: NSFW error case.
1143 SS_PWR_LOG_HIST("OnSetVoltageState", m_PubCmdHist, m_PubHistIter,
1144 "PublishVoltageStateChange()", l_eStatus);
1146 switch (l_VoltageState.data.voltage.state) {
1147 case epsvsINVALID: {
1171 SS_PWR_LOG_HIST("OnSetVoltageState()", m_VCmdHist, m_VHistIter, stLvl,
1175 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1179 ///////////////////////////////////////////////////////////////////////
1182 //////////////////////////////////////////////////////////////////////
1183 EFrameworkunifiedStatus Power::OnSetCrankState(HANDLE h_app) {
1184 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1185 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1186 Pwr_ServiceSetInterface l_CrankState;
1189 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
1190 // Report any errors found. *
1192 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, l_CrankState))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1193 // LCOV_EXCL_START 4: NSFW error case.
1194 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1195 LOG_ERROR("ReadMsg()");
1196 // LCOV_EXCL_STOP 4: NSFW error case.
1198 m_CrankState = static_cast<ePowerSrvCrankStates>(l_CrankState.data.crank
1202 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1206 EFrameworkunifiedStatus Power::OnSystemMgrConnectionEstablished(HANDLE h_app) {
1207 EFrameworkunifiedStatus l_eStatus;
1208 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1210 l_eStatus = FrameworkunifiedPublishServiceAvailability(h_app, TRUE);
1212 SS_PWR_LOG_HIST("FrameworkunifiedPublishServiceAvailability()", m_PubCmdHist,
1213 m_PubHistIter, "", l_eStatus);
1215 LOG_STATUS(l_eStatus,
1216 "FrameworkunifiedPublishServiceAvailability(" szNTFY_PowerAvailability ",TRUE)");
1217 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1221 EFrameworkunifiedStatus Power::OnUserModeResponse(HANDLE h_app) {
1222 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1223 EFrameworkunifiedStatus l_eStatus;
1224 EPWR_USER_MODE_TYPE l_eUserModeState = epsumINVALID;
1225 Pwr_ServiceSetInterface tServiceSetIf;
1227 l_eStatus = ValidateUserModeMessage(h_app, l_eUserModeState);
1228 if (eFrameworkunifiedStatusOK != l_eStatus) {
1229 LOG_ERROR("ValidateUserModeMessage(&l_eUserModeState)");
1231 PCSTR p_sStateName = l_eUserModeState == epsumON ? "epsumON" : "epsumOFF";
1232 tServiceSetIf.data.user_mode.mode = l_eUserModeState;
1234 l_eStatus = m_oSessionHandler.SendToSupervisor(
1235 SS_POWER_USER_MODE_SET_RESP, sizeof(Pwr_ServiceSetInterface),
1236 (PVOID) &tServiceSetIf);
1238 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
1239 // LCOV_EXCL_START 4: NSFW error case.
1240 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1241 FRAMEWORKUNIFIEDLOG(
1244 "Error: m_oSessionHandler.SendToSupervisor(" " SS_POWER_USER_MODE_SET_RESP, %s) errored: %d/'%s'",
1245 p_sStateName, l_eStatus, GetStr(l_eStatus).c_str());
1248 SS_PWR_LOG_HIST("SS_POWER_USER_MODE_SET_RESP", m__CWORD56_RepHist,
1249 m__CWORD56_RepIter, p_sStateName, l_eStatus);
1250 FRAMEWORKUNIFIEDLOG(
1253 " m_oSessionHandler.SendToSupervisor(" " SS_POWER_USER_MODE_SET_RESP, %s) successful ",
1257 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1259 } // End of EFrameworkunifiedStatus Power::OnUserModeResponse( HANDLE h_app )
1261 EFrameworkunifiedStatus Power::ValidateUserModeMessage(
1262 HANDLE h_app, EPWR_USER_MODE_TYPE &l_eUserModeState) {
1263 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1264 EFrameworkunifiedStatus l_eStatus;
1265 Pwr_ServiceSetInterface tServiceSetIf;
1266 EPWR_USER_MODE_TYPE l_my_eUserModeState;
1269 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
1270 // Report any errors found. *
1272 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, tServiceSetIf))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1273 // LCOV_EXCL_START 4: NSFW error case.
1274 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1275 LOG_ERROR("ReadMsg()");
1276 // LCOV_EXCL_STOP 4: NSFW error case.
1278 l_my_eUserModeState = tServiceSetIf.data.user_mode.mode;
1279 switch (l_my_eUserModeState) {
1281 l_eStatus = eFrameworkunifiedStatusInvldParam;
1282 LOG_ERROR("l_eUserModeState == epsumINVALID");
1287 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Validated '%s'",
1288 l_my_eUserModeState == epsumON ? "epsumON" : "epsumOFF");
1289 l_eUserModeState = l_my_eUserModeState;
1290 l_eStatus = eFrameworkunifiedStatusOK;
1294 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1295 "Error: Unknown 'l_my_eUserModeState' value: 0x%x",
1296 l_my_eUserModeState);
1297 l_eStatus = eFrameworkunifiedStatusInvldParam;
1301 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1303 } // End of EFrameworkunifiedStatus Power::ValidateUserModeMessage( HANDLE h_app, EPWR_USER_MODE_TYPE &l_eUserModeState )
1305 //*****************************************************************************
1306 // Start Confirmation Protocol callback functions
1308 EFrameworkunifiedStatus Power::OnSendStartupConfirmationRequest(HANDLE h_app) {
1309 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1310 EFrameworkunifiedStatus l_eStatus;
1311 EFrameworkunifiedStatus l_responseStatus = eFrameworkunifiedStatusOK;
1312 Pwr_ServiceSetInterface tServiceSetIf;
1315 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
1316 // Report any errors found. *
1318 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<Pwr_ServiceSetInterface>(h_app, tServiceSetIf))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1319 // LCOV_EXCL_START 4: NSFW error case.
1320 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1321 LOG_ERROR("ReadMsg()");
1322 // LCOV_EXCL_STOP 4: NSFW error case.
1324 StartupConfirmationMsgStrut l_startupConfirmationMsg = tServiceSetIf.data
1325 .startupConfirmationMsg;
1326 l_eStatus = SendStartupConfirmationToSystemManager(
1327 l_startupConfirmationMsg);
1328 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
1329 l_eStatus, "SendStartupConfirmationToSystemManager()");
1332 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:interface_unified if can not be error.
1333 // LCOV_EXCL_START 200:interface_unified if can not be error.
1334 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1335 l_responseStatus = l_eStatus; // Save the current status as-is to
1336 // send in the message response to the
1338 l_eStatus = m_oSessionHandler.SendToSupervisor(
1339 SS_POWER_FWD_START_CONFIRMATION_MSG_RESP, sizeof(EFrameworkunifiedStatus),
1340 (PVOID) &l_responseStatus);
1342 SS_PWR_LOG_HIST("SS_POWER_FWD_START_CONFIRMATION_MSG_RESP", m__CWORD56_RepHist,
1343 m__CWORD56_RepIter, "", l_eStatus);
1347 "m_oSessionHandler.SendToSupervisor( " "SS_POWER_FWD_START_CONFIRMATION_MSG_RESP)");
1348 // LCOV_EXCL_STOP 200:interface_unified if can not be error.
1350 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1351 " SendStartupConfirmationToSystemManager() successful");
1354 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1356 } // End of EFrameworkunifiedStatus Power::OnSendStartupConfirmationRequest( HANDLE h_app )
1358 EFrameworkunifiedStatus Power::OnSendStartupConfirmationResponse(HANDLE h_app) {
1359 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1360 EFrameworkunifiedStatus l_eStatus;
1361 EFrameworkunifiedStatus l_responseStatus;
1364 // Check h_app ptr, msg size, msg reception, read msg if all ok. *
1365 // Report any errors found. *
1367 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<EFrameworkunifiedStatus>(h_app, l_responseStatus))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1368 // LCOV_EXCL_START 4: NSFW error case.
1369 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1370 LOG_ERROR("ReadMsg()");
1371 // LCOV_EXCL_STOP 4: NSFW error case.
1373 l_eStatus = m_oSessionHandler.SendToSupervisor(
1374 SS_POWER_FWD_START_CONFIRMATION_MSG_RESP, sizeof(EFrameworkunifiedStatus),
1375 (PVOID) &l_responseStatus);
1377 SS_PWR_LOG_HIST("SS_POWER_FWD_START_CONFIRMATION_MSG_RESP", m__CWORD56_RepHist,
1378 m__CWORD56_RepIter, "", l_eStatus);
1382 "m_oSessionHandler.SendToSupervisor(" " SS_POWER_FWD_START_CONFIRMATION_MSG_RESP)");
1385 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1387 } // End of EFrameworkunifiedStatus Power::OnSendStartupConfirmationResponse( HANDLE h_app )
1389 // End of Start Confirmation Protocol callback functions
1390 //*****************************************************************************
1392 //*****************************************************************************
1393 // Start HeartBeat Protocol callback functions
1394 // Theory of operation: Forward HB request to SM. If SM crashes, then the HB
1395 // will cease between SM and the _CWORD56_. Consequently, the _CWORD56_ will reset the
1397 EFrameworkunifiedStatus Power::On_CWORD56_HeartBeatRequest(HANDLE h_app) {
1398 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1399 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1400 EPWR_HB_REQ_MSG_STRUCT l_HbReq;
1402 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "_CWORD56_ HeartBeat Request received.");
1404 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<EPWR_HB_REQ_MSG_STRUCT>(h_app, l_HbReq))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1405 // LCOV_EXCL_START 4: NSFW error case.
1406 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1407 LOG_ERROR("ReadMsg()");
1408 // LCOV_EXCL_STOP 4: NSFW error case.
1409 } else if (eFrameworkunifiedStatusOK != (l_eStatus = Send_CWORD56_HeartBeatRequestToSystemManager(l_HbReq))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1410 // LCOV_EXCL_START 4: NSFW error case.
1411 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1412 LOG_ERROR("Send_CWORD56_HeartBeatRequestToSystemManager()");
1413 // LCOV_EXCL_STOP 4: NSFW error case.
1416 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1420 EFrameworkunifiedStatus Power::OnSM_CWORD56_HeartBeatResponse(HANDLE h_app) {
1421 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1422 EFrameworkunifiedStatus l_eStatus;
1424 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Received from SM.");
1426 l_eStatus = m_oSessionHandler.SendToSupervisor(SS_POWER_HEARTBEAT_RESP, 0,
1429 SS_PWR_LOG_HIST("SS_POWER_HEARTBEAT_RESP", m__CWORD56_RepHist, m__CWORD56_RepIter, "",
1432 LOG_STATUS(l_eStatus,
1433 "m_oSessionHandler.SendToSupervisor( SS_POWER_HEARTBEAT_RESP)");
1435 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1440 // End of Heartbeat Protocol callback functions
1441 //*****************************************************************************
1443 //*****************************************************************************
1444 // Start CPU Reset Request Protocol callback functions
1446 EFrameworkunifiedStatus Power::OnCpuResetRequest(HANDLE h_app) { // SS_SM_CPU_RESET_REQ
1447 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1448 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1449 TSystemManagerCpuResetInfo l_SmCpuResetInfo; // SS Type
1450 SS_Pwr_CpuResetMsgStruct l_PsCpuResetInfo; // SS Type translated to PSM type.
1452 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<TSystemManagerCpuResetInfo>(h_app, l_SmCpuResetInfo))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1453 // LCOV_EXCL_START 4: NSFW error case.
1454 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1455 LOG_ERROR("ReadMsg()");
1456 // LCOV_EXCL_STOP 4: NSFW error case.
1458 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "CPU Reset Type: %d",
1459 l_SmCpuResetInfo.resetReason);
1461 switch (l_SmCpuResetInfo.resetReason) {
1462 case e_SS_SM_CPU_RESET_REASON_GENERIC_ERR:
1463 case e_SS_SM_CPU_RESET_REASON_CRITICAL_ERR:
1464 l_PsCpuResetInfo.resetReason = epsCpuResetReasonGeneric;
1467 case e_SS_SM_CPU_RESET_REASON_DSP_ERR:
1468 l_PsCpuResetInfo.resetReason = epsCpuResetReasonFatalError;
1471 case e_SS_SM_CPU_RESET_REASON_USER_FORCE_RESET:
1472 l_PsCpuResetInfo.resetReason = epsCpuResetReasonUserForceReset;
1475 case e_SS_SM_CPU_RESET_REASON_NORMAL:
1476 l_PsCpuResetInfo.resetReason = epsCpuResetReasonNormalReset;
1479 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Reset reason '%d' not defined",
1480 l_SmCpuResetInfo.resetReason);
1481 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1482 return (eFrameworkunifiedStatusInvldParam);
1485 snprintf(l_PsCpuResetInfo.messageStr, PWR_RESET_MSG_STR_SIZE, "%s",
1486 l_SmCpuResetInfo.messageStr);
1488 l_eStatus = m_oSessionHandler.SendToSupervisor(SS_POWER_HARD_RESET_REQ,
1489 sizeof(l_PsCpuResetInfo),
1490 (PVOID) &l_PsCpuResetInfo);
1492 SS_PWR_LOG_HIST("SS_POWER_HARD_RESET_REQ", m__CWORD56_RepHist, m__CWORD56_RepIter, "",
1495 LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(
1496 l_eStatus, "m_oSessionHandler.SendToSupervisor( "
1497 "SS_POWER_HARD_RESET_REQ)");
1500 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1504 // End of CPU Reset Request Protocol callback functions
1505 //*****************************************************************************
1507 ///////////////////////////////////////////////////////////////////////
1511 //////////////////////////////////////////////////////////////////////
1512 void Power::SetCmdHist(std::string cmd, cmdHist &hist, cmdHistIter &it,
1513 std::string sender) {
1514 pthread_mutex_lock(&pwr_hist_mutex);
1516 UI_64 l_clkcycles = ClockCycle();
1517 /* find out how many cycles per millisecond */
1518 UI_64 l_totalmsec = l_clkcycles / 1000;
1520 it->m_time = l_totalmsec;
1522 it->m_sender = sender;
1525 if (it == hist.end()) {
1529 pthread_mutex_unlock(&pwr_hist_mutex);
1532 ///////////////////////////////////////////////////////////////////////////////
1533 /// \ingroup SSPowerDebugDump
1534 /// implement post mortem function
1539 ///////////////////////////////////////////////////////////////////////////////
1540 VOID Power::SSPowerDebugDump(HANDLE h_app) { // LCOV_EXCL_START 7:debug code
1541 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1542 char l_debugDumpData[SS_PWR_DEBUG_DUMP_MAX_SIZE];
1543 UI_16 l_byteCount = 0;
1545 memset((void*) l_debugDumpData, 0x00, sizeof(l_debugDumpData)); // NOLINT (readability/casting)
1547 l_byteCount = snprintf(l_debugDumpData, SS_PWR_DEBUG_DUMP_MAX_SIZE,
1548 ("\n <SS POWER DUMP DATA> \n"));
1550 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1551 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1552 "\n ***Error history***\n");
1554 for (i = m_ErrHist.begin(); i != m_ErrHist.end(); ++i) {
1555 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1556 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1557 "\n %s @ %llums EC:%s \n", i->m_cmd.c_str(),
1558 i->m_time, i->m_sender.c_str());
1561 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1562 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1563 "\n ***_CWORD56_ Reply history***\n");
1565 for (i = m__CWORD56_RepHist.begin(); i != m__CWORD56_RepHist.end(); ++i) {
1566 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1567 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1568 "\n %s @ %llums\n", i->m_cmd.c_str(), i->m_time);
1571 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1572 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1573 "\n ***Voltage history***\n");
1575 for (i = m_VCmdHist.begin(); i != m_VCmdHist.end(); ++i) {
1576 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1577 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1578 "\n %s @ %llums %s \n", i->m_cmd.c_str(), i->m_time,
1579 i->m_sender.c_str());
1582 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1583 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1584 "\n ***Publishshing history***\n");
1586 for (i = m_PubCmdHist.begin(); i != m_PubCmdHist.end(); ++i) {
1587 l_byteCount += snprintf(l_debugDumpData + l_byteCount,
1588 SS_PWR_DEBUG_DUMP_MAX_SIZE - l_byteCount,
1589 "\n %s @ %llums \n", i->m_cmd.c_str(), i->m_time);
1592 SSDEBUGDUMP("%s", (const char *) &l_debugDumpData);
1594 // LCOV_EXCL_STOP 7:debug code
1596 //*****************************************************************************
1597 // Start Remote Data Reset Protocol callback functions
1599 EFrameworkunifiedStatus Power::OnRemoteDataResetRequest(HANDLE h_app) { // SS_SM_REMOTE_DATA_RESET_REQ
1600 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1601 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1602 ESMDataResetType l_eSmDataResetType; // SS Type
1603 epsCpuResetReason l_ePsCpuResetReason; // SS Type translated to PSM CPU reset reason.
1604 BOOL l_bResetRequired;
1606 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<ESMDataResetType>(h_app, l_eSmDataResetType))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
1607 // LCOV_EXCL_START 4: NSFW error case.
1608 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1609 LOG_ERROR("ReadMsg()");
1610 // LCOV_EXCL_STOP 4: NSFW error case.
1612 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Remote Data Reset Type: %d",
1613 l_eSmDataResetType);
1614 l_bResetRequired = FALSE;
1615 switch (l_eSmDataResetType) {
1616 case e_SS_SM_DATA_RESET_TYPE_USER:
1617 l_ePsCpuResetReason = epsCpuResetReasonUserDataReset;
1618 l_bResetRequired = TRUE;
1621 case e_SS_SM_DATA_RESET_TYPE_FACTORY:
1622 l_ePsCpuResetReason = epsCpuResetReasonFactoryDataReset;
1623 l_bResetRequired = TRUE;
1626 case e_SS_SM_DATA_RESET_TYPE_CONFIGURATION: // No reset action required.
1627 l_bResetRequired = FALSE;
1631 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1632 "Error: Remote Reset Data type : %d not defined",
1633 l_eSmDataResetType);
1634 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1635 return (eFrameworkunifiedStatusInvldParam);
1638 if (TRUE == l_bResetRequired) {
1639 SS_Pwr_CpuResetMsgStruct l_PsCpuResetInfo = { };
1640 l_PsCpuResetInfo.resetReason = l_ePsCpuResetReason;
1641 l_eStatus = m_oSessionHandler.SendToSupervisor(SS_POWER_HARD_RESET_REQ,
1642 sizeof(l_PsCpuResetInfo),
1643 (PVOID) &l_PsCpuResetInfo);
1645 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
1646 // LCOV_EXCL_START 4: NSFW error case.
1647 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1648 FRAMEWORKUNIFIEDLOG(
1651 "Error: m_oSessionHandler.SendToSupervisor( " "SS_POWER_HARD_RESET_REQ, Reason '%d') errored:%d/'%s'",
1652 l_ePsCpuResetReason, l_eStatus, GetStr(l_eStatus).c_str());
1655 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
1656 "SS_POWER_HARD_RESET_REQ Reason '%d' sent to PSMShadow",
1657 l_ePsCpuResetReason);
1659 SS_PWR_LOG_HIST("SS_POWER_HARD_RESET_REQ", m__CWORD56_RepHist, m__CWORD56_RepIter,
1664 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1668 // End of Remote Data Reset Protocol callback functions
1669 //*****************************************************************************
1671 // EOF of /SS_PowerService/src/ss_power.cpp