Re-organized sub-directory by category
[staging/basesystem.git] / service / system / system_manager / server / include / ss_sm_config.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_SystemManager
19 /// \brief    This file provides support for System Manager configuration.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #ifndef SS_SM_CONFIG_H_  // NOLINT
24 #define SS_SM_CONFIG_H_
25
26 #include <native_service/ns_config_parser_if.h>
27 #include <system_service/ss_system_types.h>
28 #include <system_service/ss_system_manager_if.h>
29 #include <system_service/ss_system_manager_if_local.h>
30 #include <system_service/ss_system_manager_protocol.h>
31 #include <system_service/ss_string_maps.h>
32 #include <list>
33 #include <map>
34 #include <string>
35 #include <vector>
36 #include "ss_sm_process_launcher_protocol.h"
37
38
39 /// All timer values are **position-dependent** in the timer calls ! These
40 /// defines are currently all used as Start and Restart Seconds parameters.
41 /// \param [in] id
42 ///         UI_32 - timer id that you want to start
43 /// \param [in] ss
44 ///         UI_32 - Start time in seconds
45 /// \param [in] sms
46 ///         UI_32 - Start time in milliseconds
47 /// \param [in] rs
48 ///         UI_32 - Repeat time in seconds
49 /// \param [in] rms
50 ///         UI_32 - Repeat time in milliseconds
51 #define SS_GROUP_LAUNCH_TIMER_CONFIG               (3)
52 #define SS_HEARTBEAT_MONITOR_TIMER_CONFIG          (10)
53 #define SS_PROCESSLAUNCHER_MONITOR_TIMER_CONFIG    (10)
54 #define SS_CLIENT_START_MONITOR_TIMER_CONFIG       (3)
55 #define SS_CLIENT_STOP_MONITOR_TIMER_CONFIG        (1)
56 #define SS_NPP_STATUS_CHECK_MONITOR_TIME_SEC       (5)
57 #define SS_LAUNCH_GROUP_TRIGGER_TIMER_CONFIG       (10)
58 // size of the internal debug dump buffer
59 #define SS_SM_DEBUG_DUMP_MAX_SIZE                   (12288u)
60 // number of _CWORD56_ command history log entries for the debug dump
61 #define SS_SM__CWORD56__CMD_HIST_SIZE                    (10u)
62 // number of timer history log entries for the debug dump
63 #define SS_SM_TIMER_CMD_HIST_SIZE                   (10u)
64 // number of message history log entries for the debug dump
65 #define SS_SM_CMD_HIST_SIZE                         (20u)
66 // number of publishing history log entries for the debug dump
67 #define SS_SM_PUB_CMD_HIST_SIZE                     (5u)
68 // number of error history log entries for the debug dump
69 #define SS_SM_ERR_HIST_SIZE                         (5u)
70
71 // When occurs repeat to abnormal rebooting, logging cause of error at first time and next time.
72 // When it occurs "ILG_RESET", Maximum number of log is 4 so that the log will be stored at the just after the startup.
73 // Need reconsideration if maximum number of abnormal logging is less than 4 using SSL.
74 #define SS_SM_ERR_LOGGING_LIMIT     (8)
75
76 // Maximum number of continuous processing of "NaviReset" by errors.
77 // It try to recover by NaviDet when it exceeds this limit. 
78 #define SS_SM_ERR_NAVI_RESET_LIMIT  (5)
79
80 typedef enum {
81   MODULE_STATE_INVALID = 0      /// Initial state of all modules
82   , MODULE_STATE_SKIPPED        /// Non-critical module has crossed max re-launch limit
83                                 ///  or hSession was null when attempted to start
84   , MODULE_STATE_LAUNCHING      /// Module launch has been requested
85   , MODULE_STATE_LAUNCHED       /// Module has been launched but a session
86                                 /// connection has NOT been established
87   , MODULE_STATE_LAUNCH_FAILED  /// Oops
88   , MODULE_STATE_CONNECTED      /// A session connection has been established
89   , MODULE_STATE_START_SENT     /// SM has sent START to the module
90   , MODULE_STATE_START_FAILED   /// FrameworkunifiedSendMsg(SS_SM_START) failed
91   , MODULE_STATE_STARTED        /// Module has replied START Complete to SM
92   , MODULE_STATE_STOP_SENT      /// SM has sent STOP to the module
93   , MODULE_STATE_STOP_FAILED    /// FrameworkunifiedSendMsg(SS_SM_STOP) failed
94   , MODULE_STATE_STOPPED        /// Module has replied STOP Complete to SM
95   , MODULE_STATE_START_PRE_SENT           //!< SM has sent Pre-boot start to the module
96   , MODULE_STATE_START_PRE_FAILED         //!< FrameworkunifiedSendMsg(SS_SM_PRE_START) failed
97   , MODULE_STATE_STARTED_PRE              //!< Module has replied Pre-boot start Complete to SM
98   , MODULE_STATE_STOP_PRE_SENT            //!< SM has sent Pre-boot stop to the module
99   , MODULE_STATE_STOP_PRE_FAILED          //!< FrameworkunifiedSendMsg(SS_SM_PRE_STOP) failed
100   , MODULE_STATE_STOPPED_PRE              //!< Module has replied Pre-boot stopComplete to SM
101   , MODULE_STATE_START_BACKGROUND_SENT    //!< SM has sent Background-boot start to the module
102   , MODULE_STATE_START_BACKGROUND_FAILED  //!< FrameworkunifiedSendMsg(SS_SM_BACKGROUND_START) failed
103   , MODULE_STATE_STARTED_BACKGROUND       //!< Module has replied Background-boot start Complete to SM
104   , MODULE_STATE_STOP_BACKGROUND_SENT     //!< SM has sent Background-boot stop to the module
105   , MODULE_STATE_STOP_BACKGROUND_FAILED   //!< FrameworkunifiedSendMsg(SS_SM_BACKGROUND_STOP) failed
106   , MODULE_STATE_STOPPED_BACKGROUND       //!< Module has replied Background-boot stop Complete to SM
107 } SMModuleState;
108 //
109 //    Module State string map type
110 typedef std::map<SMModuleState, std::string>  SMModuleStateStrMapType;
111
112 typedef  enum {
113   MODULE_DEBUG_DUMP_STATE_NOT_REQUESTED = 0
114   , MODULE_DEBUG_DUMP_STATE_REQUEST_SENT
115   , MODULE_DEBUG_DUMP_STATE_RESPONSE_RECEIVED
116 } SMModuleDebugDumpState;
117
118 typedef std::map<SMModuleDebugDumpState, std::string>  SMModuleDebugDumpStateStrMapType;
119
120 /*
121 <?xml version="1.0" encoding="UTF-8"?>
122 <Configuration>
123     <!-- System Service Launch control elements -->
124     <SystemManager>
125         <Launch>
126             <Group1>
127                 <group_name>CoreModules</group_name>
128                 <group_id>1</group_id>
129                 <Member1>
130                     <name>TRUE</name>
131                     <path>1</path>
132                     <priority>200</priority>
133                     <critical>TRUE</critical>
134                     <retry_cnt>1</retry_cnt>
135                     <arguments></arguments>
136                     <logging_mask></logging_msk>
137                     <restart>group</restart>
138                     <shudown_critical></shudown_critical>
139                     <shudown_wait_time></shudown_wait_time>
140                 </Member1>
141                 <Member2>
142                     <name>TRUE</name>
143                     <path>1</path>
144                     <priority>200</priority>
145                     <critical>TRUE</critical>
146                     <retry_cnt>1</retry_cnt>
147                     <arguments></arguments>
148                     <logging_mask></logging_msk>
149                     <restart>me</restart>
150                     <shudown_critical></shudown_critical>
151                     <shudown_wait_time></shudown_wait_time>
152                 </Member2>
153             </Group1>
154         </Launch>
155     </SystemManager>
156 </Configuration>
157 */
158
159 //******************************************************************************
160 //* CTimeSpan class                                                            *
161 //*                                                                            *
162 class CTimeSpan {
163  public:
164   CTimeSpan(): initial(0), final(0), delta(0) {}
165   CTimeSpan(UI_64 f_initial)  // NOLINT
166              : initial(f_initial), final(0), delta(0) {}
167   ~CTimeSpan() {}
168   /*
169    * Set Initial time, reset Final and Delta to zero, return time
170    */
171   UI_64 Begin();
172   /*
173    * Set Final time, calculate Delta time, return time
174    */
175   UI_64 End();
176   UI_64 GetInitial();
177   UI_64 GetFinal();
178   UI_64 GetDelta();
179   UI_64 GetTimeMilliseconds();
180
181  private:
182   UI_64   initial;
183   UI_64   final;
184   UI_64   delta;
185 };  // End of class CTimeSpan
186 //******************************************************************************
187
188
189 typedef enum {
190   NotStopped,
191   StoppedByModuleStopComplete,
192   StoppedByModuleStopFail,
193   StoppedByGroupStopTimeout,
194   StoppedByCriticalAppsTimeout,
195   StoppedByModulePreStopComplete,
196   StoppedByModulePreStopFail,
197   StoppedByModuleBackgroundStopComplete,
198   StoppedByModuleBackgroundStopFail
199 } EStopReasonType;
200
201 typedef enum {
202   NotStarted,
203   StartedByModuleStartComplete,
204   StartedByModuleStartFail,
205   StartedByModulePreStartComplete,
206   StartedByModulePreStartFail,
207   StartedByModuleBackgroundStartComplete,
208   StartedByModuleBackgroundStartFail
209 } EStartReasonType;
210
211 //******************************************************************************
212 //* CTimeEvent class                                                           *
213 //*                                                                            *
214 template <typename EEventType>
215 class CTimeEvent : public CTimeSpan {
216  public:
217   CTimeEvent() {
218       bzero(&m_eventReason, sizeof(m_eventReason));
219   }
220   ~CTimeEvent() {}
221
222   VOID            SetReason(EEventType f_eventReason)
223                   { m_eventReason = f_eventReason; }
224  private:
225   EEventType       m_eventReason;
226 };  // End of class CTimeEvent
227 //******************************************************************************
228
229 typedef enum {
230   NotRelaunched,
231   RelaunchSafe,
232   RelaunchErr
233 } ERelaunchStatusType;
234
235
236 typedef  CTimeEvent<EStartReasonType> CStartReason;
237 typedef  CTimeEvent<EStopReasonType>  CStopReason;
238 typedef CHAR TUserNameBuffer[128];  // TODO(yaomingwu): Stuff. Does Posix define a useful
239                                     // constant representing max length of user id?
240
241 class ModuleLaunchParams {
242  public:
243   // Move to private to prevent direct access
244   // SMModuleState        module_state;
245   //
246   SS_String               name;
247   SS_String               path;
248   SS_String               arguments;
249   SS_String               restart;
250   UI_32                   configuration_priority;
251   int                     cpu_assign;
252   UI_32                   previous_priority;
253   UI_32                   current_priority;
254   BOOL                    critical;
255   UI_32                   retry_cnt;
256   SS_String               logging_msk_str;
257   BOOL                    is_start_required;
258   BOOL                    shutdown_critical;
259   UI_32                   shutdown_wait_time;
260   UI_32                   fast_shutdown_wait_time;
261   SI_32                   pid;
262   HANDLE                  hsession;
263   UI_32                   relaunch_count;
264   ERelaunchStatusType     relaunch_status;
265   UI_32                   group_id;
266   TUserNameBuffer         unix_user_name;
267
268   BOOL                    m_serviceAvailability;  // Not set because it does not watch Availability for speeding up start up process.
269
270   CStartReason            m_startReason;
271   CStopReason             m_stopReason;
272
273   ModuleLaunchParams();
274   ~ModuleLaunchParams();
275   SMModuleState           GetModuleState(void);
276   BOOL                    IsModuleState(SMModuleState f_moduleState);
277   BOOL                    IsModuleConnected() const;
278   VOID                    SetModuleState(SMModuleState f_moduleState, BOOL f_bLog = TRUE);
279   std::string             ModuleStateStr(void);
280
281   SMModuleDebugDumpState  GetModuleDebugDumpState(void);
282   std::string             GetModuleDebugDumpStateStr(void);
283   VOID                    SetModuleDebugDumpState(SMModuleDebugDumpState f_moduleDebugDumpState, BOOL f_bLog = TRUE);
284   EFrameworkunifiedStatus SendMsgAndUpdateState(
285                             const UI_32 f_iCmd, const T_SS_SM_START_DataStructType* const f_startData);
286   EFrameworkunifiedStatus SendMsgAndUpdateState(T_SS_SM_STOP_DataStruct const* f_stopData);
287
288   EFrameworkunifiedStatus GetPriority(UI_32& f_Priority);  // NOLINT
289   EFrameworkunifiedStatus SetPriority(UI_32 f_Priority);
290
291   BOOL                    IsAGLUnit(void) const { return is_agl_unit; }
292   BOOL                    IsAGLResetHistoryDisable(void) const { return disable_agl_resethistory; }
293   BOOL                    IsNonAGLResetHistoryDisable(void) const { return disable_nonagl_resethistory; }
294   void                    SetAGLUnit(BOOL f_is_agl_unit) { is_agl_unit = f_is_agl_unit; }
295   void                    SetAGLResetHistoryDisable(BOOL f_disable_agl_resethistory) {
296     disable_agl_resethistory = f_disable_agl_resethistory;
297   }
298   void                    SetNonAGLResetHisoryDisable(BOOL f_disable_nonagl_resethistory) {
299     disable_nonagl_resethistory = f_disable_nonagl_resethistory;
300   }
301
302  private:
303   SMModuleState                    m_moduleState;
304   SMModuleStateStrMapType          m_ModuleStateStrMap;
305   SMModuleDebugDumpState           m_ModuleDebugDumpState;
306   SMModuleDebugDumpStateStrMapType m_ModuleDebugDumpStateStrMap;
307   BOOL                             is_agl_unit;
308   BOOL                             disable_agl_resethistory;
309   BOOL                             disable_nonagl_resethistory;
310 };
311
312 typedef std::list<ModuleLaunchParams> ModuleLaunchList;
313 typedef ModuleLaunchList::iterator ModuleLaunchListIter;
314
315 typedef struct _GroupLaunchInfo {  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
316   BOOL                launch_complete;
317   BOOL                start_complete;
318   BOOL                stop_complete;
319   SS_String           name;
320   UI_32               id;
321   UI_32               grp_launch_wait;
322   UI_32               grp_wait_for_trigger;
323   ModuleLaunchList    modules;
324 } GroupLaunchInfo;
325
326 typedef std::list<GroupLaunchInfo> GroupLaunchList;
327 typedef GroupLaunchList::iterator GroupLaunchListIter;
328
329 typedef std::map<UI_32, GroupLaunchInfo> GroupLaunchMap;
330 typedef GroupLaunchMap::iterator GroupLaunchMapIter;
331
332 typedef std::list<GroupLaunchList> GroupList;
333 typedef GroupList::iterator GroupListIter;
334
335 // Process Binary Name (key) to ModuleLaunchList iterator (ModuleLaunchParams).
336 typedef std::map<std::string, ModuleLaunchListIter>ProcessNameMap;
337 typedef ProcessNameMap::iterator ProcessNameMapIter;
338
339 // Config Parameters specific to Heart Beat Thread
340 typedef struct _HBConfigParams {
341   SI_32 MaxHeartBeatRetryCount;           /// Retry heart beat check before error report is sent to SM
342   SI_32 ApplicationHeartBeatIntervalInitial;  /// Initial Timer interval
343                                               /// between two heart beat requests & response check
344   SI_32 ApplicationHeartBeatIntervalRepeat;  /// Repeat Timer interval between two heart beat requests & response check
345 } HBConfigParameters;
346
347 typedef  struct _CDConfigParams {
348   BOOL CrashDetectorEnabled;
349 } CDConfigParameters;
350
351 typedef  struct _SLMConfigParams {  // SLM - System Low Memory
352   SI_32 SLMTimerValue;
353   SI_32 SLMMaxRetryCount;
354   SI_32 SLMThresholdValue;
355   SI_32 SLMSystemmanagerLogIntervalMs;
356 } SLMConfigParameters;
357
358 typedef struct _UserMModeConfigParams {
359   BOOL IsUserModeNotificationABOOL;
360 } UserModeConfigParameters;
361
362 typedef struct _ModuleConnectTimeConfigParams {
363   SI_32 ModuleConnectionNumTimesToCheck;
364   SI_32 ModuleConnectionTimeOutSec;
365   SI_32 ModuleStartRespTimeOutSec;
366 } ModuleConfigParams;
367
368 typedef struct _CriticalAppsMaxShutdownTime {
369   SI_32 CriticalAppsMaxShutdownTimeFastSleep;
370   SI_32 CriticalAppsMaxShutdownTimeNormalReset;
371 } CriticalAppsMaxShutdownTime;
372
373 typedef struct _ConfigurationData {
374   // Parameters specific to System Manager
375
376   // Parameters specific to Heart Beat Thread
377   HBConfigParameters HBConfig;
378
379   // Parameters specific to Launcher Thread
380
381   // Parameters specific to Crash Detector Thread
382   CDConfigParameters CDConfig;
383
384   // Parameters specific to System Low Memory
385
386   // Parameters specific to Sys Low Memory Thread
387   SLMConfigParameters SLMConfig;
388
389   // Parameters specific to User Mode Notification Data Structure
390   UserModeConfigParameters  UMConfig;
391
392   // Parameters specific to Module connection timeout with SM
393   ModuleConfigParams MCConfig;
394
395   // Parameters specific to Critical Apps Max shutdown time
396   CriticalAppsMaxShutdownTime CAMSTConfig;
397 } ConfigurationData;
398
399 typedef std::vector<UI_32> LaunchOrderedVector;
400 typedef LaunchOrderedVector::iterator LaunchOrderedIter;
401
402 class SMConfigParams {
403  public:
404   SMConfigParams();
405   virtual ~SMConfigParams();
406
407   ////////////////////////////////////////////////////////////////////////////////////////////
408   /// LoadSMConfigParameters
409   /// \brief Read System Manager configuration parameters from cfg file or
410   ///        use defaults values in case cfg file is not available
411   ///
412   /// \param [in] f_ConfigParams & - Ref to ConfigurationData that get populated.
413   /// \param [in] f_FileName       - Configuration file name.
414   ///
415   /// \return BOOL
416   ///         BOOL - TRUE or FALSE
417   ////////////////////////////////////////////////////////////////////////////////////////////
418   BOOL LoadSMConfigParameters(ConfigurationData& f_ConfigParams,  // NOLINT
419                               SS_String          f_FileName);
420
421   ////////////////////////////////////////////////////////////////////////////////////////////
422   /// GetSMConfigInformation
423   /// \brief Read config data from cfg file and populate the configuration data structure
424   ///
425   /// \param [in] f_ConfigParams & - Ref to ConfigurationData that get populated.
426   /// \param [in] f_FileName       - Configuration file name.
427   ///
428   /// \return BOOL
429   ///         BOOL - TRUE or FALSE
430   ////////////////////////////////////////////////////////////////////////////////////////////
431   BOOL GetSMConfigInformation(ConfigurationData& f_ConfigParams,  // NOLINT
432                               SS_String          f_FileName);
433
434   ////////////////////////////////////////////////////////////////////////////////////////////
435   ///  PrintConfigInfo
436   ///  \brief Print the configuration data stored in config structure
437   ///
438   /// \param [in] configata
439   ///         ConfigurationData & - Ref to structure that get populated.
440   ///
441   /// \return VOID
442   ////////////////////////////////////////////////////////////////////////////////////////////
443   VOID PrintConfigInfo(ConfigurationData const& f_ConfigParams);
444 };
445
446 class SysMgrConfiguration {
447  public:
448   ////////////////////////////////////////////////////////////////////////////////////////////
449   ///  SysMgrConfiguration
450   ///  \brief
451   ///
452   /// \return NA
453   ///
454   ////////////////////////////////////////////////////////////////////////////////////////////
455   SysMgrConfiguration();
456
457   ////////////////////////////////////////////////////////////////////////////////////////////
458   ///  ~SysMgrConfiguration
459   ///  \brief
460   ///
461   /// \return NA
462   ////////////////////////////////////////////////////////////////////////////////////////////
463   virtual ~SysMgrConfiguration();
464
465 //  ////////////////////////////////////////////////////////////////////////////////////////////
466 //  ///  LoadParameters
467 //  ///  \brief
468 //  ///
469 //  /// \param [in] groups
470 //  ///         GroupLaunchList & - Ref to GroupLaunchList that get populated.
471 //  ///
472 //  /// \return BOOL
473 //  ///         BOOL - TRUE or FALSE
474 //  ////////////////////////////////////////////////////////////////////////////////////////////
475 //  BOOL LoadParameters(GroupLaunchMap & groups_map);
476
477   ////////////////////////////////////////////////////////////////////////////////////////////
478   ///  LoadParametersCfg
479   ///  \brief
480   ///
481   /// \param [in] groups
482   ///         GroupLaunchList & - Ref to GroupLaunchList that gets populated.
483   ///         ProcessNameMap  & - Ref to ProcessNameMap  that gets populated.
484   ///         LaunchOrderedVector  & - Ref to LaunchOrderedVector  that gets populated.
485   ///
486   /// \param [in] f_launchOrderName   - launch order name.
487   ///
488   /// \return BOOL
489   ///         BOOL - TRUE or FALSE
490   ////////////////////////////////////////////////////////////////////////////////////////////
491   BOOL LoadParametersCfg(GroupLaunchMap&      groups_map,  // NOLINT
492                          ProcessNameMap&      f_processNameMap,  // NOLINT
493                          LaunchOrderedVector& f_OrderList,  // NOLINT
494                          SS_String&           f_launchOrderName,  // NOLINT
495                          SS_String&           f_launchCfgFn);  // NOLINT
496
497
498   ////////////////////////////////////////////////////////////////////////////////////////////
499   ///  PrintGroupInfo
500   ///  \brief Print method for GroupLaunchInfo only prints the group info not the module info
501   ///
502   /// \param [in] refGrpInfo
503   ///         GroupLaunchInfo & - Ref to a GroupLaunchInfo object that will be printed.
504   ///
505   /// \return VOID
506   ////////////////////////////////////////////////////////////////////////////////////////////
507   VOID PrintGroupInfo(GroupLaunchInfo& refGrpInfo);  // NOLINT
508
509   ////////////////////////////////////////////////////////////////////////////////////////////
510   ///  PrintModuleInfo
511   ///  \brief Print method for a Module's Params.
512   ///
513   /// \param [in] refMbrInfo
514   ///         ModuleLaunchParams & - Ref to ModuleLaunchParams object that will be printed.
515   ///
516   /// \return VOID
517   ////////////////////////////////////////////////////////////////////////////////////////////
518   VOID PrintModuleInfo(ModuleLaunchParams& refMbrInfo);  // NOLINT
519
520   ////////////////////////////////////////////////////////////////////////////////////////////
521   ///  PrintAllInfo
522   ///  \brief Print all the information in the GroupLaunchList.
523   ///
524   /// \param [in] refGrpList
525   ///         GroupLaunchList & - Ref to GroupLaunchList object that will be printed.
526   ///
527   /// \return VOID
528   ////////////////////////////////////////////////////////////////////////////////////////////
529   VOID PrintAllInfo(GroupLaunchMap& refGrpMap);  // NOLINT
530
531  protected:
532   // define all the configuration parameters that will be used to get data
533
534   CNSConfigReader * l_pReaderCfg;
535
536   SysMgrConfiguration(const SysMgrConfiguration&) : l_pReaderCfg(NULL) {}
537   SysMgrConfiguration & operator = (const SysMgrConfiguration &);
538
539  private:
540   BOOL ParseBoolParameter(PCSTR f_value, BOOL f_default = FALSE) const;
541 };
542
543 #endif  // SS_SM_CONFIG_H_  // NOLINT