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_Power
19 /// \brief This file supports power service session management.
21 ///////////////////////////////////////////////////////////////////////////////
22 #include "ss_power_session.h"
23 #include <system_service/ss_services.h>
24 #include <system_service/ss_templates.h>
25 #include <system_service/ss_power_service.h>
26 #include <system_service/ss_power_service_protocol.h>
27 #include <system_service/ss_power_service_local.h>
28 #include <native_service/frameworkunified_framework_if.h>
29 #include <native_service/frameworkunified_service_protocol.h>
31 #include "ss_power_powerservicelog.h"
34 PowerSessionHandler::PowerSessionHandler() {
35 // TODO(my_username) Auto-generated constructor stub
38 PowerSessionHandler::~PowerSessionHandler() { // LCOV_EXCL_START 14 Resident process, not called by NSFW
39 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
40 // TODO(my_username) Auto-generated destructor stub
42 // LCOV_EXCL_STOP 14 Resident process, not called by NSFW
44 EFrameworkunifiedStatus PowerSessionHandler::CloseSession(HANDLE h_app) {
45 EFrameworkunifiedStatus l_eStatus;
46 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
47 INTERFACEUNIFIEDLOG_RECEIVED_FROM(h_app);
49 // find the subscriber...
50 PwSessionIter iter = m_mapSessions.find(FrameworkunifiedGetMsgSrc(h_app));
52 // the iter is set to the end then the subscriber is not in the map
53 if (m_mapSessions.end() == iter) { // LCOV_EXCL_BR_LINE 11:unexpected branch
54 // LCOV_EXCL_START 11:unexpected branch
55 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
59 " Error: Subscriber '%s' was not found in the map; the Close " "Session Request is being ignored!",
60 FrameworkunifiedGetMsgSrc(h_app));
61 l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
62 } else if (NULL == iter->second.hsession) { // LCOV_EXCL_BR_LINE 11:unexpected branch
63 l_eStatus = eFrameworkunifiedStatusInvldHandle;
64 LOG_ERROR("Client's PwSessionInfo handle");
65 // LCOV_EXCL_STOP 11:unexpected branch
67 CloseSessionAck closeSessionAck;
68 closeSessionAck.sessionId = FrameworkunifiedGetSessionId(iter->second.hsession);
69 closeSessionAck.eStatus = eFrameworkunifiedStatusOK;
71 // Send Ack to subscriber
72 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedSendMsg(iter->second.hsession, PROTOCOL_CLOSE_SESSION_ACK, sizeof(CloseSessionAck), (PVOID) &closeSessionAck))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
73 // LCOV_EXCL_START 4: NSFW error case.
74 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
78 " Error: FrameworkunifiedSendMsg(%s, PROTOCOL_CLOSE_SESSION_ACK) " "errored: %d/'%s'",
79 iter->second.sz_name.c_str(), l_eStatus, GetStr(l_eStatus).c_str());
80 // LCOV_EXCL_STOP 4: NSFW error case.
82 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
83 " FrameworkunifiedSendMsg(%s, PROTOCOL_CLOSE_SESSION_ACK) successful",
84 iter->second.sz_name.c_str());
85 iter->second.frunning = FALSE;
88 // ToDo Jay 2012 November 05 1) Can't detach just basic callbacks;
89 // client could be Supervisor or System. This has been solved
90 // in another Power Service Change Set. Need to get all
91 // Change Sets merged and delivered.
92 UI_32 ss_power_basic_session_ids[] = { PROTOCOL_CLOSE_SESSION_REQ };
94 // Detach callback : Power System Session Requests
95 if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedDetachCallbacksFromDispatcher(h_app, iter->second.sz_name.c_str(), ss_power_basic_session_ids, _countof(ss_power_basic_session_ids)))) { // LCOV_EXCL_BR_LINE 4: NSFW error case. // NOLINT[whitespace/line_length]
96 // LCOV_EXCL_START 4: NSFW error case.
97 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
98 LOG_ERROR("FrameworkunifiedDetachCallbacksFromDispatcher()");
99 // LCOV_EXCL_STOP 4: NSFW error case.
101 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
102 " FrameworkunifiedDetachCallbacksFromDispatcher() successful");
105 CALL_AND_LOG_STATUS(FrameworkunifiedDestroySession(h_app, iter->second.hsession));
106 iter->second.hsession = NULL;
107 m_mapSessions.erase(iter);
110 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
114 EFrameworkunifiedStatus PowerSessionHandler::StartComplete(HANDLE h_app) { // LCOV_EXCL_START 8: can not be called
115 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
116 EFrameworkunifiedStatus l_eStatus;
117 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
118 StartCompleteAck ack;
120 if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<StartCompleteAck>(h_app, ack))) { // LCOV_EXCL_BR_LINE 4: NSFW error case.
121 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
122 LOG_ERROR("ReadMsg()");
124 // find the subscriber...
125 PwSessionIter iter = m_mapSessions.find(FrameworkunifiedGetMsgSrc(h_app));
127 // the iter is set to the end then the subscriber is not in the map
128 if (m_mapSessions.end() != iter) {
129 iter->second.sz_servicename = ack.szServiceName;
130 iter->second.frunning = TRUE;
132 if (AllClientsInGroupStarted(iter->second.ui_groupid)) {
139 "Subscriber: %s , was not found in the map, the close session is being ignored!",
140 FrameworkunifiedGetMsgSrc(h_app));
144 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
147 // LCOV_EXCL_STOP 8: can not be called
148 VOID PowerSessionHandler::Print() {
149 // find the subscriber...
150 PwSessionIter iter = m_mapSessions.begin();
151 for (; iter != m_mapSessions.end(); iter++) {
152 FRAMEWORKUNIFIEDLOG(ZONE_DEBUG_DUMP, __FUNCTION__,
153 " Power Service is session-connected to '%s'; running: %s",
154 iter->second.sz_name.data(), (iter->second.frunning ? "YES" : "NO"));
158 // LCOV_EXCL_START 8: can not be called
159 BOOL PowerSessionHandler::WakeupComplete(RequiredModuleList & wakeup_modules) {
160 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
161 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
162 BOOL rtn = TRUE; // set the return TRUE until we find a missing module
163 RequiredModuleListIter iter = wakeup_modules.begin();
164 for (; iter != wakeup_modules.end(); iter++) {
165 PwSessionIter psi = m_mapSessions.find(*iter);
166 if (m_mapSessions.end() == psi) {
167 rtn = FALSE; // Module Not Found in Power Service Session Handler
171 "Required Wakeup: %s has not connected to Power Service, Wakeup NOT COMPLETE!",
173 } else if (FALSE == psi->second.frunning) {
174 rtn = FALSE; // Module Found in Power Service Session Handler but hasn't started yet
178 "Required Wakeup: %s has connected to Power Service but is not running (FrameworkunifiedStart Response missing),"
179 " Wakeup NOT COMPLETE!",
184 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
187 // LCOV_EXCL_STOP 8: can not be called
189 BOOL PowerSessionHandler::ShutdownComplete(
190 RequiredModuleList & shutdown_modules) {
191 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
192 BOOL rtn = TRUE; // set the return TRUE until we find a missing module
193 RequiredModuleListIter iter = shutdown_modules.begin();
194 for (; iter != shutdown_modules.end(); iter++) {
195 PwSessionIter psi = m_mapSessions.find(*iter);
196 if (m_mapSessions.end() == psi) {
200 "Required Shutdown: %s is not in Power Service session list, Shutdown pending!",
202 } else if (TRUE == psi->second.frunning) {
203 rtn = FALSE; // Module Found in Power Service Session Handler but hasn't stopped yet
207 "Required Shutdown: %s is connected to Power Service but is running (Stop Response missing),"
208 " Shutdown NOT COMPLETE!",
212 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
216 EFrameworkunifiedStatus PowerSessionHandler::SendToSupervisor(UI_32 cmd, UI_32 length,
218 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
219 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
221 if (NULL == data && length > 0) { // LCOV_EXCL_BR_LINE 6: it will not be true at the other place
222 // LCOV_EXCL_START 6: it will not be true at the other place
223 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
224 LOG_ERROR("NULL == data && length > 0");
225 l_eStatus = eFrameworkunifiedStatusInvldBuf;
226 // LCOV_EXCL_STOP 6: it will not be true at the other place
228 // get first client from the map...
229 PwSessionIter iter = m_mapSessions.begin();
230 BOOL l_bFoundSupervisor = FALSE;
232 for (; iter != m_mapSessions.end() && !l_bFoundSupervisor; iter++) {
233 l_bFoundSupervisor = (epsstSUPERVISOR == iter->second.esessiontype);
234 if (l_bFoundSupervisor) {
235 l_eStatus = FrameworkunifiedSendMsg(iter->second.hsession, cmd, length, data);
236 LOG_STATUS(l_eStatus, "FrameworkunifiedSendMsg()");
239 if (!l_bFoundSupervisor) {
241 ZONE_ERR, __FUNCTION__,
242 "Error: Did not find a Supervisor session; did not " "send cmd %d !",
244 l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
248 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
252 BOOL PowerSessionHandler::AllClientsInGroupStarted(UI_32 f_ungrpid) { // LCOV_EXCL_START 8: can not be called
253 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
255 BOOL fGrpFnd = FALSE;
256 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
258 PwSessionIter iter = m_mapSessions.begin();
260 if (iter == m_mapSessions.end())
263 for (; iter != m_mapSessions.end() && fStatus; iter++) {
264 if (f_ungrpid == iter->second.ui_groupid) {
266 if (FALSE == iter->second.frunning) {
272 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- return flag: %s",
273 ((fStatus && fGrpFnd) ? "TRUE" : "FALSE"));
274 return (fStatus && fGrpFnd);
276 // LCOV_EXCL_STOP 8: can not be called