common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / src / statemachine / frameworkunified_sm_historystate.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 /// \defgroup <<Group Tag>> <<Group Name>>
19 /// \ingroup  tag_NSFramework
20 /// .
21 ///////////////////////////////////////////////////////////////////////////////////////////////////
22
23 ///////////////////////////////////////////////////////////////////////////////////////////////////
24 /// \ingroup  tag_NSFramework
25 /// \brief
26 ///
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
29 /// state.
30 ///
31 ///////////////////////////////////////////////////////////////////////////////////////////////////
32
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>
37
38 #include <string>
39
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
45 }
46
47 ///////////////////////////////////////////////////////////////////////////////////////////
48 /// ~CFrameworkunifiedHistoryState
49 /// Class destructor
50 ///////////////////////////////////////////////////////////////////////////////////////////
51 CFrameworkunifiedHistoryState::~CFrameworkunifiedHistoryState() {
52   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, "CFrameworkunifiedHistoryState destructor");
53 }
54
55 CFrameworkunifiedState *CFrameworkunifiedHistoryState::FrameworkunifiedGetActiveState() {
56   return this;
57 }
58
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());
66
67   try {
68     CHKNULL(m_pLastActiveState);
69     CHKNULL(m_pEventList);
70
71     CFrameworkunifiedExternalTransition *l_pTrnTargetState = new CFrameworkunifiedExternalTransition(m_pLastActiveState);
72
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());
77
78     l_eStatus = eFrameworkunifiedStatusNullPointer;
79   }
80   return l_eStatus;
81 }
82
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;
90 }
91
92 ///////////////////////////////////////////////////////////////////////////////////////////
93 /// SetDefaultHistory
94 /// This function sets the default active state in history state
95 ///////////////////////////////////////////////////////////////////////////////////////////
96 EFrameworkunifiedStatus CFrameworkunifiedHistoryState::SetDefaultHistory() {
97   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
98
99   try {
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;
105   }
106
107   return eStatus;  // LCOV_EXCL_BR_LINE 11: except branch
108 }
109
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;
117
118   try {
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;
123     } else {
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 */
133     }
134   } catch (std::exception &e) {
135     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
136     return NULL;
137   }
138
139   return l_pActiveState;
140 }
141
142 ///////////////////////////////////////////////////////////////////////////////////////////
143 /// FrameworkunifiedOnHSMStop
144 /// This function internally calls the Exit function of the current state.
145 ///////////////////////////////////////////////////////////////////////////////////////////
146 CFrameworkunifiedState *CFrameworkunifiedHistoryState::FrameworkunifiedOnHSMStop(CEventDataPtr f_pEventData) {
147   return this;
148 }