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 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup tag_NSFramework
21 ///////////////////////////////////////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup tag_NSFramework
27 /// This file has the CFrameworkunifiedHistoryState class definitions. CFrameworkunifiedHistoryState is derived from
28 /// CFrameworkunifiedState class.This class implements the additional functionality supported by HSM History
31 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 #include <native_service/frameworkunified_sm_hsm.h>
34 #include <native_service/frameworkunified_sm_historystate.h>
35 #include <native_service/frameworkunified_sm_framework_types.h>
36 #include <native_service/frameworkunified_framework_if.h>
40 ///////////////////////////////////////////////////////////////////////////////////////////
41 /// CFrameworkunifiedHistoryState
42 /// Parameterized constructor
43 ///////////////////////////////////////////////////////////////////////////////////////////
44 CFrameworkunifiedHistoryState::CFrameworkunifiedHistoryState(std::string f_pName): CFrameworkunifiedState(f_pName), m_pLastActiveState(NULL), m_uiEventId(0) { // LCOV_EXCL_BR_LINE 11:except branch
47 ///////////////////////////////////////////////////////////////////////////////////////////
48 /// ~CFrameworkunifiedHistoryState
50 ///////////////////////////////////////////////////////////////////////////////////////////
51 CFrameworkunifiedHistoryState::~CFrameworkunifiedHistoryState() {
52 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, "CFrameworkunifiedHistoryState destructor");
55 CFrameworkunifiedState *CFrameworkunifiedHistoryState::FrameworkunifiedGetActiveState() {
59 ///////////////////////////////////////////////////////////////////////////////////////////
60 /// FrameworkunifiedOnEntry
61 /// state initialization can be performed in this function.
62 ///////////////////////////////////////////////////////////////////////////////////////////
63 EFrameworkunifiedStatus CFrameworkunifiedHistoryState::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
64 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
65 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
68 CHKNULL(m_pLastActiveState);
69 CHKNULL(m_pEventList);
71 CFrameworkunifiedExternalTransition *l_pTrnTargetState = new CFrameworkunifiedExternalTransition(m_pLastActiveState);
73 m_pActiveState = l_pTrnTargetState->FrameworkunifiedReaction(this, f_pEventData);
74 CHKNULL(m_pActiveState);
75 } catch (std::exception &e) {
76 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
78 l_eStatus = eFrameworkunifiedStatusNullPointer;
83 ///////////////////////////////////////////////////////////////////////////////////////////
84 /// FrameworkunifiedOnExit
85 /// state cleanup can be performed in this function.
86 ///////////////////////////////////////////////////////////////////////////////////////////
87 EFrameworkunifiedStatus CFrameworkunifiedHistoryState::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
88 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
89 return eFrameworkunifiedStatusOK;
92 ///////////////////////////////////////////////////////////////////////////////////////////
94 /// This function sets the default active state in history state
95 ///////////////////////////////////////////////////////////////////////////////////////////
96 EFrameworkunifiedStatus CFrameworkunifiedHistoryState::SetDefaultHistory() {
97 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
100 CHKNULL(m_pParentState); // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
101 m_pLastActiveState = m_pParentState->m_pDefaultState;
102 } catch (std::exception &e) {
103 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
104 eStatus = eFrameworkunifiedStatusNullPointer;
107 return eStatus; // LCOV_EXCL_BR_LINE 11: except branch
110 ///////////////////////////////////////////////////////////////////////////////////////////
111 /// FrameworkunifiedOnHSMStart
112 /// This function internally calls the Entry function of the current state.
113 ///////////////////////////////////////////////////////////////////////////////////////////
114 CFrameworkunifiedState *CFrameworkunifiedHistoryState::FrameworkunifiedOnHSMStart(CEventDataPtr f_pEventData) {
115 CFrameworkunifiedState *l_pActiveState = this;
116 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
119 // Call Entry method of the current state. Entry method of state is called in the order of
120 // Hierarchy from Outer state to Inner state
121 if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedOnEntry(f_pEventData))) {
122 l_pActiveState = m_pActiveState;
124 // If FrameworkunifiedOnEntry failed then statemachine should report the error
125 // We can throw an exception but for now as a quick fix we are setting
126 // l_pActiveState as NULL which will stop the statemachine
127 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error:%d in state %s", eStatus,
128 l_pActiveState->m_strStateName.c_str());
129 // l_pActiveState = NULL;
130 /* Commenting it, because it was making state machine inactive. This should not be the expected behavior.
131 * Just log and take no action, if user return non-ok value.
132 * User defined error values should be handled separately */
134 } catch (std::exception &e) {
135 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
139 return l_pActiveState;
142 ///////////////////////////////////////////////////////////////////////////////////////////
143 /// FrameworkunifiedOnHSMStop
144 /// This function internally calls the Exit function of the current state.
145 ///////////////////////////////////////////////////////////////////////////////////////////
146 CFrameworkunifiedState *CFrameworkunifiedHistoryState::FrameworkunifiedOnHSMStop(CEventDataPtr f_pEventData) {