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_SystemManager
19 /// \brief This file provides support for System Manager configuration.
21 ///////////////////////////////////////////////////////////////////////////////
23 #ifndef SS_SM_CONFIG_H_ // NOLINT
24 #define SS_SM_CONFIG_H_
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>
36 #include "ss_sm_process_launcher_protocol.h"
39 /// All timer values are **position-dependent** in the timer calls ! These
40 /// defines are currently all used as Start and Restart Seconds parameters.
42 /// UI_32 - timer id that you want to start
44 /// UI_32 - Start time in seconds
46 /// UI_32 - Start time in milliseconds
48 /// UI_32 - Repeat time in seconds
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)
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)
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)
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
109 // Module State string map type
110 typedef std::map<SMModuleState, std::string> SMModuleStateStrMapType;
113 MODULE_DEBUG_DUMP_STATE_NOT_REQUESTED = 0
114 , MODULE_DEBUG_DUMP_STATE_REQUEST_SENT
115 , MODULE_DEBUG_DUMP_STATE_RESPONSE_RECEIVED
116 } SMModuleDebugDumpState;
118 typedef std::map<SMModuleDebugDumpState, std::string> SMModuleDebugDumpStateStrMapType;
121 <?xml version="1.0" encoding="UTF-8"?>
123 <!-- System Service Launch control elements -->
127 <group_name>CoreModules</group_name>
128 <group_id>1</group_id>
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>
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>
159 //******************************************************************************
160 //* CTimeSpan class *
164 CTimeSpan(): initial(0), final(0), delta(0) {}
165 CTimeSpan(UI_64 f_initial) // NOLINT
166 : initial(f_initial), final(0), delta(0) {}
169 * Set Initial time, reset Final and Delta to zero, return time
173 * Set Final time, calculate Delta time, return time
179 UI_64 GetTimeMilliseconds();
185 }; // End of class CTimeSpan
186 //******************************************************************************
191 StoppedByModuleStopComplete,
192 StoppedByModuleStopFail,
193 StoppedByGroupStopTimeout,
194 StoppedByCriticalAppsTimeout,
195 StoppedByModulePreStopComplete,
196 StoppedByModulePreStopFail,
197 StoppedByModuleBackgroundStopComplete,
198 StoppedByModuleBackgroundStopFail
203 StartedByModuleStartComplete,
204 StartedByModuleStartFail,
205 StartedByModulePreStartComplete,
206 StartedByModulePreStartFail,
207 StartedByModuleBackgroundStartComplete,
208 StartedByModuleBackgroundStartFail
211 //******************************************************************************
212 //* CTimeEvent class *
214 template <typename EEventType>
215 class CTimeEvent : public CTimeSpan {
218 bzero(&m_eventReason, sizeof(m_eventReason));
222 VOID SetReason(EEventType f_eventReason)
223 { m_eventReason = f_eventReason; }
225 EEventType m_eventReason;
226 }; // End of class CTimeEvent
227 //******************************************************************************
233 } ERelaunchStatusType;
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?
241 class ModuleLaunchParams {
243 // Move to private to prevent direct access
244 // SMModuleState module_state;
250 UI_32 configuration_priority;
252 UI_32 previous_priority;
253 UI_32 current_priority;
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;
263 UI_32 relaunch_count;
264 ERelaunchStatusType relaunch_status;
266 TUserNameBuffer unix_user_name;
268 BOOL m_serviceAvailability; // Not set because it does not watch Availability for speeding up start up process.
270 CStartReason m_startReason;
271 CStopReason m_stopReason;
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);
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);
288 EFrameworkunifiedStatus GetPriority(UI_32& f_Priority); // NOLINT
289 EFrameworkunifiedStatus SetPriority(UI_32 f_Priority);
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;
298 void SetNonAGLResetHisoryDisable(BOOL f_disable_nonagl_resethistory) {
299 disable_nonagl_resethistory = f_disable_nonagl_resethistory;
303 SMModuleState m_moduleState;
304 SMModuleStateStrMapType m_ModuleStateStrMap;
305 SMModuleDebugDumpState m_ModuleDebugDumpState;
306 SMModuleDebugDumpStateStrMapType m_ModuleDebugDumpStateStrMap;
308 BOOL disable_agl_resethistory;
309 BOOL disable_nonagl_resethistory;
312 typedef std::list<ModuleLaunchParams> ModuleLaunchList;
313 typedef ModuleLaunchList::iterator ModuleLaunchListIter;
315 typedef struct _GroupLaunchInfo { // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h // NOLINT(whitespace/line_length)
316 BOOL launch_complete;
321 UI_32 grp_launch_wait;
322 UI_32 grp_wait_for_trigger;
323 ModuleLaunchList modules;
326 typedef std::list<GroupLaunchInfo> GroupLaunchList;
327 typedef GroupLaunchList::iterator GroupLaunchListIter;
329 typedef std::map<UI_32, GroupLaunchInfo> GroupLaunchMap;
330 typedef GroupLaunchMap::iterator GroupLaunchMapIter;
332 typedef std::list<GroupLaunchList> GroupList;
333 typedef GroupList::iterator GroupListIter;
335 // Process Binary Name (key) to ModuleLaunchList iterator (ModuleLaunchParams).
336 typedef std::map<std::string, ModuleLaunchListIter>ProcessNameMap;
337 typedef ProcessNameMap::iterator ProcessNameMapIter;
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;
347 typedef struct _CDConfigParams {
348 BOOL CrashDetectorEnabled;
349 } CDConfigParameters;
351 typedef struct _SLMConfigParams { // SLM - System Low Memory
353 SI_32 SLMMaxRetryCount;
354 SI_32 SLMThresholdValue;
355 SI_32 SLMSystemmanagerLogIntervalMs;
356 } SLMConfigParameters;
358 typedef struct _UserMModeConfigParams {
359 BOOL IsUserModeNotificationABOOL;
360 } UserModeConfigParameters;
362 typedef struct _ModuleConnectTimeConfigParams {
363 SI_32 ModuleConnectionNumTimesToCheck;
364 SI_32 ModuleConnectionTimeOutSec;
365 SI_32 ModuleStartRespTimeOutSec;
366 } ModuleConfigParams;
368 typedef struct _CriticalAppsMaxShutdownTime {
369 SI_32 CriticalAppsMaxShutdownTimeFastSleep;
370 SI_32 CriticalAppsMaxShutdownTimeNormalReset;
371 } CriticalAppsMaxShutdownTime;
373 typedef struct _ConfigurationData {
374 // Parameters specific to System Manager
376 // Parameters specific to Heart Beat Thread
377 HBConfigParameters HBConfig;
379 // Parameters specific to Launcher Thread
381 // Parameters specific to Crash Detector Thread
382 CDConfigParameters CDConfig;
384 // Parameters specific to System Low Memory
386 // Parameters specific to Sys Low Memory Thread
387 SLMConfigParameters SLMConfig;
389 // Parameters specific to User Mode Notification Data Structure
390 UserModeConfigParameters UMConfig;
392 // Parameters specific to Module connection timeout with SM
393 ModuleConfigParams MCConfig;
395 // Parameters specific to Critical Apps Max shutdown time
396 CriticalAppsMaxShutdownTime CAMSTConfig;
399 typedef std::vector<UI_32> LaunchOrderedVector;
400 typedef LaunchOrderedVector::iterator LaunchOrderedIter;
402 class SMConfigParams {
405 virtual ~SMConfigParams();
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
412 /// \param [in] f_ConfigParams & - Ref to ConfigurationData that get populated.
413 /// \param [in] f_FileName - Configuration file name.
416 /// BOOL - TRUE or FALSE
417 ////////////////////////////////////////////////////////////////////////////////////////////
418 BOOL LoadSMConfigParameters(ConfigurationData& f_ConfigParams, // NOLINT
419 SS_String f_FileName);
421 ////////////////////////////////////////////////////////////////////////////////////////////
422 /// GetSMConfigInformation
423 /// \brief Read config data from cfg file and populate the configuration data structure
425 /// \param [in] f_ConfigParams & - Ref to ConfigurationData that get populated.
426 /// \param [in] f_FileName - Configuration file name.
429 /// BOOL - TRUE or FALSE
430 ////////////////////////////////////////////////////////////////////////////////////////////
431 BOOL GetSMConfigInformation(ConfigurationData& f_ConfigParams, // NOLINT
432 SS_String f_FileName);
434 ////////////////////////////////////////////////////////////////////////////////////////////
436 /// \brief Print the configuration data stored in config structure
438 /// \param [in] configata
439 /// ConfigurationData & - Ref to structure that get populated.
442 ////////////////////////////////////////////////////////////////////////////////////////////
443 VOID PrintConfigInfo(ConfigurationData const& f_ConfigParams);
446 class SysMgrConfiguration {
448 ////////////////////////////////////////////////////////////////////////////////////////////
449 /// SysMgrConfiguration
454 ////////////////////////////////////////////////////////////////////////////////////////////
455 SysMgrConfiguration();
457 ////////////////////////////////////////////////////////////////////////////////////////////
458 /// ~SysMgrConfiguration
462 ////////////////////////////////////////////////////////////////////////////////////////////
463 virtual ~SysMgrConfiguration();
465 // ////////////////////////////////////////////////////////////////////////////////////////////
466 // /// LoadParameters
469 // /// \param [in] groups
470 // /// GroupLaunchList & - Ref to GroupLaunchList that get populated.
473 // /// BOOL - TRUE or FALSE
474 // ////////////////////////////////////////////////////////////////////////////////////////////
475 // BOOL LoadParameters(GroupLaunchMap & groups_map);
477 ////////////////////////////////////////////////////////////////////////////////////////////
478 /// LoadParametersCfg
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.
486 /// \param [in] f_launchOrderName - launch order name.
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
498 ////////////////////////////////////////////////////////////////////////////////////////////
500 /// \brief Print method for GroupLaunchInfo only prints the group info not the module info
502 /// \param [in] refGrpInfo
503 /// GroupLaunchInfo & - Ref to a GroupLaunchInfo object that will be printed.
506 ////////////////////////////////////////////////////////////////////////////////////////////
507 VOID PrintGroupInfo(GroupLaunchInfo& refGrpInfo); // NOLINT
509 ////////////////////////////////////////////////////////////////////////////////////////////
511 /// \brief Print method for a Module's Params.
513 /// \param [in] refMbrInfo
514 /// ModuleLaunchParams & - Ref to ModuleLaunchParams object that will be printed.
517 ////////////////////////////////////////////////////////////////////////////////////////////
518 VOID PrintModuleInfo(ModuleLaunchParams& refMbrInfo); // NOLINT
520 ////////////////////////////////////////////////////////////////////////////////////////////
522 /// \brief Print all the information in the GroupLaunchList.
524 /// \param [in] refGrpList
525 /// GroupLaunchList & - Ref to GroupLaunchList object that will be printed.
528 ////////////////////////////////////////////////////////////////////////////////////////////
529 VOID PrintAllInfo(GroupLaunchMap& refGrpMap); // NOLINT
532 // define all the configuration parameters that will be used to get data
534 CNSConfigReader * l_pReaderCfg;
536 SysMgrConfiguration(const SysMgrConfiguration&) : l_pReaderCfg(NULL) {}
537 SysMgrConfiguration & operator = (const SysMgrConfiguration &);
540 BOOL ParseBoolParameter(PCSTR f_value, BOOL f_default = FALSE) const;
543 #endif // SS_SM_CONFIG_H_ // NOLINT