common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / systemservice / power_service / server / include / ss_power.h
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    Handles Power Service Business logic
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #ifndef POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_
23 #define POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_
24
25 #include <system_service/ss_power_service.h>
26 #include <system_service/ss_power_service_protocol.h>
27 #include <system_service/ss_string_maps.h>
28 #include <system_service/ss_templates.h>
29 #include <native_service/frameworkunified_types.h>
30 #include <map>
31 #include <vector>
32 #include <string>
33 #include <exception>
34
35 #include "ss_power_session.h"
36 #include "ss_power_config.h"
37 #include "ss_power_state_machine.h"
38 #include "ss_power_powerservicelog.h"
39
40 typedef enum _SS_PSState {
41   SS_PS_READY_TO_WAKEUP = 0x01,
42   SS_PS_WAKEUP_INITIATED,
43   SS_PS_WAKEUP_COMPLETE,
44   SS_PS_POWER_ON_COMPLETE,
45   SS_PS_POWER_OFF_INITIATED,
46   SS_PS_POWER_OFF_COMPLETE,
47   SS_PS_SHUTDOWN_INITIATED,
48   SS_PS_SHUTDOWN_COMPLETE
49   // This is not real state, used only to know total states
50   ,
51   SS_PS_STATE_MAX
52 } SS_PSState;
53
54 typedef struct {
55   std::string m_cmd;
56   UI_64 m_time;
57   std::string m_sender;
58 } Ts_cmdHist;
59
60 typedef std::vector<Ts_cmdHist> cmdHist;
61 typedef cmdHist::iterator cmdHistIter;
62
63 class Power {
64  public:
65   Power();
66   virtual ~Power();
67   EFrameworkunifiedStatus Initialize(HANDLE h_app);
68   static Power & GetInstance();
69
70   /// Session Request Handlers
71   EFrameworkunifiedStatus OnOpenSession(HANDLE h_app);
72   EFrameworkunifiedStatus OnCloseSession(HANDLE h_app);
73
74   /// Session Response\Ack Handlers
75   EFrameworkunifiedStatus OnWakeUpComplete(HANDLE h_app);
76   EFrameworkunifiedStatus OnShutdownComplete(HANDLE h_app);
77   EFrameworkunifiedStatus OnPrintConnections(HANDLE h_app);
78   EFrameworkunifiedStatus OnPrintStack(HANDLE h_app);
79
80   /// SSM Handlers
81
82   /// Supervisor Handlers
83   EFrameworkunifiedStatus OnPowerRequestMsg(HANDLE h_app);
84   EFrameworkunifiedStatus OnSetPowerState(HANDLE h_app);
85   EFrameworkunifiedStatus OnSetCommWakeUp(HANDLE h_app);
86   EFrameworkunifiedStatus OnSetCommSleep(HANDLE h_app);
87   EFrameworkunifiedStatus OnShutdownRequestMsg(HANDLE h_app);
88
89   EFrameworkunifiedStatus OnPowerOnOffNotification(HANDLE h_app);
90   EFrameworkunifiedStatus OnStartModules(HANDLE h_app);
91   EFrameworkunifiedStatus OnShutdownModules(HANDLE h_app);
92
93   EFrameworkunifiedStatus OnHysteresisTimeout(HANDLE h_app);
94
95   // System Handlers
96   EFrameworkunifiedStatus OnSystemLaunchComplete(HANDLE h_app);
97   EFrameworkunifiedStatus OnSystemShutdownComplete(HANDLE h_app);
98   EFrameworkunifiedStatus OnWakeUpTimeout(HANDLE h_app);
99   EFrameworkunifiedStatus OnShutdownTimeout(HANDLE h_app);
100
101   // Get Result query from power test client
102   EFrameworkunifiedStatus OnCurrentPowerStateQuery(HANDLE h_app);
103
104   EFrameworkunifiedStatus OnSetVoltageState(HANDLE h_app);
105   EFrameworkunifiedStatus OnSetCrankState(HANDLE h_app);
106
107   EFrameworkunifiedStatus OnSystemModeInfoRequest(HANDLE h_app);
108   EFrameworkunifiedStatus OnSystemModeInfoResponse(HANDLE h_app);
109
110   EFrameworkunifiedStatus OnInitCompReport(HANDLE h_app);
111
112   EFrameworkunifiedStatus OnSystemMgrConnectionEstablished(HANDLE h_app);
113
114   //
115   // Start Confirmation callback functions
116   //
117   EFrameworkunifiedStatus OnSendStartupConfirmationRequest(HANDLE h_app);
118   EFrameworkunifiedStatus OnSendStartupConfirmationResponse(HANDLE h_app);
119
120   //
121   // User Mode Protocol callback functions
122   //
123   EFrameworkunifiedStatus OnUserModeResponse(HANDLE h_app);
124
125   //
126   // Shutdown Condition Notification Protocol function
127   //
128   EFrameworkunifiedStatus OnPublishShutdownPopupRequest(HANDLE h_app);
129
130   //
131   // Power Popup Notification Protocol function
132   //
133   EFrameworkunifiedStatus OnPublishPowerPopupRequest(HANDLE h_app);
134
135   //
136   // HeartBeat Protocol callback functions
137   //
138   EFrameworkunifiedStatus On_CWORD56_HeartBeatRequest(HANDLE h_app);
139   EFrameworkunifiedStatus OnSM_CWORD56_HeartBeatResponse(HANDLE h_app);
140
141   //
142   // Hard Reset Protocol callback functions
143   //
144   EFrameworkunifiedStatus OnCpuResetRequest(HANDLE h_app);
145
146   //
147   // Remote Data Reset Protocol callback functions
148   //
149   EFrameworkunifiedStatus OnRemoteDataResetRequest(HANDLE h_app);
150   EFrameworkunifiedStatus OnRemoteDataResetResponse(HANDLE h_app);
151
152   cmdHist m__CWORD56_RepHist;
153   cmdHistIter m__CWORD56_RepIter;
154   cmdHist m_PubCmdHist;
155   cmdHistIter m_PubHistIter;
156   cmdHist m_ErrHist;
157   cmdHistIter m_ErrHistIter;
158   cmdHist m_VCmdHist;
159   cmdHistIter m_VHistIter;
160
161   void SSPowerDebugDump(HANDLE h_app);
162
163  private:
164 #define LOG_POWERSERVICELOG_CNT(caseid, Cnt) \
165       FRAMEWORKUNIFIEDLOG_CNT(ZONE_INFO, Cnt, 0); \
166     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " case " #caseid \
167         ": FRAMEWORKUNIFIEDLOG_CNT(ZONE_INFO, " #Cnt ", 0)");
168
169 #define LOG_POWERSERVICELOG_EVT(caseid, Evt, Data0) \
170       FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, Evt, 1, Data0); \
171     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " case " #caseid \
172         ": FRAMEWORKUNIFIEDLOG_EVT(ZONE_INFO, " #Evt ", " #Data0 ")");
173
174 #define LOG_STATUS_IF_ERRORED_PWR_SM_WITH_HIST_LOGGING(l_eStatus, pStr)          \
175     if (eFrameworkunifiedStatusOK != l_eStatus) {                  \
176         LOG_ERROR(pStr);                               \
177         SetCmdHist(pStr, m_ErrHist, m_ErrHistIter, GetStr(static_cast<EFrameworkunifiedStatus>(l_eStatus)).c_str()); \
178     }  // End of #define LOG_STATUS_IF_ERRORED(l_eStatus,pStr)
179
180 #define SS_PWR_LOG_HIST(cmd, hist, it, sender, l_eStatus) \
181     if (eFrameworkunifiedStatusOK == l_eStatus) {             \
182         SetCmdHist((static_cast< std::string> (cmd)), (static_cast<cmdHist&> (hist)), \
183                    (static_cast<cmdHistIter&> (it)), (static_cast< std::string> (sender)));      \
184     }
185   //**************************************************************************
186   // Counter Logging enums & typedefs                                        *
187   //                                                                         *
188   //  Counter Event IDs                                                      *
189   typedef enum {                                                          // *
190     CT_Startup_CanSignal = 0x0114,                                   // *
191     CT_Startup_DiagMsg = 0x0118,                                   // *
192                                                                    // *
193     CT_Shutdown_CanSignal = 0x0121,                                   // *
194     CT_Shutdown_Timeout = 0x0124,                                   // *
195     CT_Shutdown_Temperature = 0x0125,                                   // *
196     CT_Shutdown_Error = 0x0126,                                   // *
197     CT_Shutdown_Voltage = 0x0127                                    // *
198   } EPWR_COUNTER_EVENT_ID_TYPE;       // *
199   //                                                                         *
200   // End of Counter Logging enums & typedefs                                 *
201   //**************************************************************************
202
203   //**************************************************************************
204   // Event Logging enums & typedefs                                          *
205   //                                                                         *
206   //  Event ID                                                               *
207   typedef enum {                                                          // *
208     // Startup Event IDs                                                   *
209     Ei_StartUp_Cansignal = 0x0101,                           // *
210     Ei_StartUp_HK_On = 0x0102,                           // *
211     //                                0x0103 not specified              // *
212     //                                0x0104 not specified              // *
213     //                                 0x0105 System Svcs not responsible// *
214     //                                0x0106 not specified              // *
215     Ei_StartUp_ActivationLine = 0x0107,                           // *
216     Ei_StartUp_DiagMsg = 0x0108,                           // *
217     //                                                                     *
218     // Shutdown Event IDs                                                  *
219     Ei_shutdown_CANsignal = 0x0201,                           // *
220     Ei_shutdown_HkOFF = 0x0202,                           // *
221     //                                0x0203 not specified              // *
222     //                                0x0204 not specified              // *
223     Ei_shutdown_Temperature = 0x0205,                           // *
224     Ei_shutdown_NetworkError = 0x0206,                           // *
225     Ei_shutdown_Voltage = 0x0207                            // *
226   } EPWR_LOGGING_EVENT_ID_TYPE;              // *
227   //                                                                         *
228   //  Ei_StartUp_CanSignal byte0 Event Detail                                *
229   typedef enum {                                                          // *
230     epseisuedIGNITION = 0x00,                             // *
231     epseisuedHK_ON = 0x01,                             // *
232     epseisuedDOOR_MODULES = 0x02,                             // *
233     //                                    0x03 not specified              // *
234     //                                    0x04 not specified              // *
235     epseisuedPASS = 0x05,                             // *
236     epseisuedIHTM = 0x06,                             // *
237     epseisuedMPM = 0x07,                             // *
238     epseisuedSNA = 0xFF                              // *
239   } EPWR_LOGGING_EVT_DETAIL_SU_CAN_TYPE;                                  // *
240
241   //
242   // Ei_StartUp_HkOn
243   typedef enum {
244     epseisuedHK_ON_Key = 0x00
245   } EPWR_LOGGING_EVT_DETAIL_SU_KEY_TYPE;
246
247   //
248   // Ei_StartUp_ActivationLine
249   typedef enum {
250     epseisuedACV_LINE = 0x00
251   } EPWR_LOGGING_EVT_DETAIL_SU_LINE_TYPE;
252
253   //                                                                         *
254   //  Ei_StartUp_DiagMsg byte0 Event Detail                                  *
255   typedef enum {                                                          // *
256     epseisuedHU = 0x01,                                          // *
257     epseisuedCAN = 0x02,                                          // *
258   } EPWR_LOGGING_EVT_DETAIL_SU_DIAG_TYPE;                                 // *
259   //                                                                         *
260   //  Ei_ShutDown_CanSignal byte0 Event Detail                               *
261   typedef enum {                                                          // *
262     epseisdcsIGN_STATE = 0x00,                                          // *
263     epseisdcsHK_ON = 0x01                                           // *
264   } EPWR_LOGGING_EVT_DETAIL_SD_CAN_TYPE;                                  // *
265   //                                                                         *
266   //  Ei_ShutDown_Temperature byte0 Event Detail                             *
267   typedef enum {                                                          // *
268     epseisdtempECU_LOW = 0x00,                                    // *
269     epseisdtempECU_HIGH = 0x01,                                    // *
270   } EPWR_LOGGING_EVT_DETAIL_SD_TEMP_TYPE;                                 // *
271   //                                                                         *
272   //  Ei_ShutDown_NetworkError byte0 Event Detail                            *
273   typedef enum {                                                          // *
274     epseisdneHMI_CAN = 0x00,                                    // *
275     epseisdneHU_CAN = 0x01                                     // *
276   } EPWR_LOGGING_EVT_DETAIL_SD_NETWORK_ERROR_TYPE;                        // *
277   //                                                                         *
278   //  Ei_ShutDown_Voltage byte0 Event Detail                                 *
279   typedef enum {                                                          // *
280     epseisdnvoltBATTERY_CUT_OFF = 0x00,                                // *
281     epseisdnvoltLIMP_HOME = 0x01,                                // *
282     epseisdnvoltUNKNOWN = 0xFF                                 // *
283   } EPWR_LOGGING_EVT_DETAIL_SD_VOLTAGE_TYPE;                              // *
284   //                                                                         *
285   // End of Event Logging enums & typedefs                                   *
286   //**************************************************************************
287
288   PowerSessionHandler m_oSessionHandler;
289   PowerConfigParams m_tConfigData;
290   PowerStateMachine m_oStateMachine;
291   UI_32 m_aTimerIDs[15];
292   wakeInfo m_WakeUpData;   /// WakeUp data received from SPM
293   SS_PSState m_PowerState;
294   ePowerSrvVoltageStates m_VoltageState;
295   ePowerSrvCrankStates m_CrankState;
296   UI_32 m_MaxShutdownTimeout;
297   std::map<SS_PSState, std::string> m_PPStateStrMap;
298
299   // Notify Module on Voltage change detected.
300   EFrameworkunifiedStatus PublishVoltageStateChange(HANDLE h_app);
301   EFrameworkunifiedStatus ConstructPwrStateResponse(CHAR *f_MessageResponse);
302   EFrameworkunifiedStatus AddStateInformationToResponse(CHAR *f_MessageResponse);
303   EFrameworkunifiedStatus AddVoltageInformationToResponse(CHAR *f_MessageResponse);
304   EFrameworkunifiedStatus AddCrankInformationToResponse(CHAR *f_MessageResponse);
305   EFrameworkunifiedStatus RegisterAllCallbacksAndNofitications(HANDLE h_app);
306   VOID SetPowerServiceState(SS_PSState f_NewState);
307   EFrameworkunifiedStatus ValidateUserModeMessage(HANDLE h_app,
308       EPWR_USER_MODE_TYPE &l_eUserModeState);  // NOLINT (runtime/references)
309
310   pthread_mutex_t pwr_hist_mutex;
311
312   void SetCmdHist(std::string cmd,
313                   cmdHist &hist,  // NOLINT (runtime/references)
314                   cmdHistIter &it,  // NOLINT (runtime/references)
315                   std::string sender);
316 };
317
318 #endif  // POWER_SERVICE_SERVER_INCLUDE_SS_POWER_H_