Init basesystem source codes.
[staging/basesystem.git] / nsframework / framework_unified / client / NS_FrameworkCore / src / statemachine / frameworkunified_sm_localtransition.cpp
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 // Include Files
19 ///////////////////////////////////////////////////////////////////////////////////////////////////
20 #include <native_service/frameworkunified_sm_localtransition.h>
21 #include <native_service/frameworkunified_sm_state.h>
22 #include <native_service/frameworkunified_sm_framework_types.h>
23
24 ///////////////////////////////////////////////////////////////////////////////////////////
25 /// CFrameworkunifiedExternalTransition
26 /// Parameterized constructor
27 ///////////////////////////////////////////////////////////////////////////////////////////
28 CFrameworkunifiedLocalTransition::CFrameworkunifiedLocalTransition(CFrameworkunifiedState *f_pTargetState): CFrameworkunifiedTransition(f_pTargetState) {
29 }
30
31 ///////////////////////////////////////////////////////////////////////////////////////////
32 /// ~CFrameworkunifiedExternalTransition
33 /// Class destructor
34 ///////////////////////////////////////////////////////////////////////////////////////////
35 CFrameworkunifiedLocalTransition::~CFrameworkunifiedLocalTransition() {
36 }
37
38 ///////////////////////////////////////////////////////////////////////////////////////////
39 /// FrameworkunifiedReaction
40 /// The reaction for an event is implemented in this function. For local transition from inner
41 /// state to outer state exit of the inner state is invoked, but entry of outer state is not
42 /// invoked and from outer state to inner state entry of the inner state is invoked but exit of
43 /// outer state is not invoked
44 ///////////////////////////////////////////////////////////////////////////////////////////
45 CFrameworkunifiedState *CFrameworkunifiedLocalTransition::FrameworkunifiedReaction(CFrameworkunifiedState *f_pSourceState, CEventDataPtr f_pData) {
46   CFrameworkunifiedState *l_pActiveState = NULL;
47   CFrameworkunifiedState *l_pCurrentState = NULL;
48   try {
49     CHKNULL(f_pSourceState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
50     CHKNULL(m_pTargetState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
51
52     // Local transition from inner state to outer state
53     if (f_pSourceState->m_pParentState == m_pTargetState) {
54       // Source is child of target
55       l_pCurrentState = f_pSourceState->FrameworkunifiedOnHSMStop(f_pData);
56
57       if (l_pCurrentState == f_pSourceState) {
58         l_pActiveState = m_pTargetState;
59
60       } else {
61         l_pActiveState = l_pCurrentState;
62       }
63
64       /**
65        * @todo
66        * If the parent state is registered and OnEvent is performed without OrthogonalReigonList, illegal accesses occur.
67        */
68       l_pActiveState->m_pActiveState = NULL;
69
70       // Local transition from outer state to inner state
71     } else if (f_pSourceState == m_pTargetState->m_pParentState) {
72       // Source is parent to target state
73       l_pActiveState = m_pTargetState->FrameworkunifiedOnHSMStart(f_pData);
74     }
75     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "Local Transition from state %s to state %s"
76            , f_pSourceState->m_strStateName.c_str(), m_pTargetState->m_strStateName.c_str());
77   } catch (std::exception &e) {
78     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
79
80     return NULL;
81   }
82
83   return l_pActiveState;
84 }