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 CFrameworkunifiedState class implementation. CFrameworkunifiedState is base class for all types of
28 /// state classes.This class implements the basic functionality required for HSM state.
29 /// It provides the standard interfaces for entering, exiting and reacting in a state.
31 ///////////////////////////////////////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////////////////////////
36 #include <native_service/frameworkunified_sm_state.h>
37 #include <native_service/frameworkunified_sm_reaction.h>
38 #include <native_service/frameworkunified_sm_framework_types.h>
39 #include <native_service/frameworkunified_sm_hsm.h>
43 #include "frameworkunified_sm_framework_core.h"
44 #include "frameworkunified_framework_internal.h"
46 ///////////////////////////////////////////////////////////////////////////////////////////
47 /// CFrameworkunifiedState
48 /// Parameterized constructor
49 ///////////////////////////////////////////////////////////////////////////////////////////
50 CFrameworkunifiedState::CFrameworkunifiedState(std::string f_pName): m_strStateName(f_pName) {
52 // EventList stores the list of events associated with the state
53 m_pEventList = new EventReactionList(); // LCOV_EXCL_BR_LINE 11:except branch
55 // Deferred eventlist stores the list of deferred events associated
57 m_pDeferredEventList = new DeferredEventList(); // LCOV_EXCL_BR_LINE 11:except branch
59 // Deferred PostEventList stores the list of posted deferred events posted
61 m_pDeferredPostEventList = new EventInfoList(); // LCOV_EXCL_BR_LINE 11:except branch
63 // EventName map stores the Name of event against event id, The event name is
64 // only used for debugging so this can be disbaled in case of release build
65 m_pEventName = new EventNameList(); // LCOV_EXCL_BR_LINE 11:except branch
67 m_pDefaultState = NULL;
68 m_pActiveState = NULL;
69 m_pParentState = NULL;
70 m_pStateMachine = NULL;
72 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "%s state created ", f_pName.c_str()); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
73 } catch (std::exception &e) {
74 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
75 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed in %s state ", f_pName.c_str());
79 ///////////////////////////////////////////////////////////////////////////////////////////
80 /// ~CFrameworkunifiedState
82 ///////////////////////////////////////////////////////////////////////////////////////////
83 CFrameworkunifiedState::~CFrameworkunifiedState() {
84 EventReactionIterator l_objEventIterator;
85 EventReactionIterator l_objDeferredEventIterator;
88 // Delete the event list
89 CHKNULL(m_pEventList);
90 for (l_objEventIterator = m_pEventList->begin();
91 l_objEventIterator != m_pEventList->end();
92 l_objEventIterator++) {
93 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, " deleting the event %d in state %s",
94 (*l_objEventIterator).first , m_strStateName.c_str());
96 if (NULL != (*l_objEventIterator).second) {
97 (*l_objEventIterator).second->m_ucRefCount--;
99 if (0 == ((*l_objEventIterator).second->m_ucRefCount)) {
100 delete(*l_objEventIterator).second;
101 (*l_objEventIterator).second = NULL;
106 // Delete the eventlist
107 m_pEventList->clear();
111 // Delete the deferred eventlist
112 CHKNULL(m_pDeferredEventList);
113 m_pDeferredEventList->clear();
114 delete m_pDeferredEventList;
115 m_pDeferredEventList = NULL;
117 // delete deferred Post event list
118 CHKNULL(m_pDeferredPostEventList);
119 m_pDeferredPostEventList->clear();
120 delete m_pDeferredPostEventList;
121 m_pDeferredPostEventList = NULL;
123 // delete event name list
124 CHKNULL(m_pEventName);
125 m_pEventName->clear();
128 } catch (std::exception &e) {
129 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
132 ///////////////////////////////////////////////////////////////////////////////////////////
133 /// FrameworkunifiedAddEvent
134 /// Associates the event id with the reaction in the state. When the event is posted to the
135 /// state the associated reaction is executed. This also adds the event name to the map
136 /// which is used for debugging.
137 ///////////////////////////////////////////////////////////////////////////////////////////
138 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedAddEvent(UI_32 f_uiEventId, CFrameworkunifiedReaction *f_pReaction, std::string f_strEventName) {
139 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
142 // LCOV_EXCL_BR_START 15:marco defined in frameworkunified_sm_framework_types.h
143 CHKNULL(m_pEventName);
144 CHKNULL(m_pEventList);
145 CHKNULL(f_pReaction);
147 // associate the eventname with event id (debugging only)
148 m_pEventName->insert(std::pair<UI_32, std::string>(f_uiEventId, f_strEventName));
150 f_pReaction->m_ucRefCount++;
152 // associate the reaction with event id
153 m_pEventList->insert(std::pair<UI_32, CFrameworkunifiedReaction *>(f_uiEventId, f_pReaction));
155 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
156 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "Reaction associated with the event %d %s in the state %s "
157 , f_uiEventId, (m_pEventName->find(f_uiEventId)->second).c_str(), m_strStateName.c_str());
159 } catch (std::exception &e) {
160 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
161 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed to add event %d %s in state %s",
162 f_uiEventId , (m_pEventName->find(f_uiEventId)->second).c_str(), m_strStateName.c_str());
163 eStatus = eFrameworkunifiedStatusNullPointer;
169 ///////////////////////////////////////////////////////////////////////////////////////////
170 /// FrameworkunifiedOnEvent
171 /// This function processes the event. If the reaction for event is available in the current
172 /// state within eventlist and deferred eventlist then it is consumed in the current state
173 /// otherwise forwarded to the parent state. Event forwarding is done recursively till either
174 /// event is consumed or the root state has encountered. This also process the events posted
175 /// in the reactions recursively till all posted events are cleared.
176 ///////////////////////////////////////////////////////////////////////////////////////////
177 CFrameworkunifiedState *CFrameworkunifiedState::FrameworkunifiedOnEvent(CEventDataPtr f_pEventData) {
178 CFrameworkunifiedState *l_pCurrentState = this;
179 CFrameworkunifiedReaction *l_pEventReaction = NULL;
182 // LCOV_EXCL_BR_START 15:marco defined in frameworkunified_sm_framework_types.h
183 CHKNULL(m_pEventList);
184 CHKNULL(m_pDeferredEventList);
186 // Find the reaction object for given event id
190 * Unauthorized accesses will occur if NULL is specified for the event data.
192 if (m_pEventList->end() != m_pEventList->find(f_pEventData->m_uiEventId)) {
193 l_pEventReaction = reinterpret_cast<CFrameworkunifiedReaction *>((m_pEventList->find(f_pEventData->m_uiEventId))->second);
196 if (l_pEventReaction) {
197 // execute the reaction associated with the event
198 l_pCurrentState = l_pEventReaction->FrameworkunifiedReaction(this, f_pEventData); // LCOV_EXCL_BR_LINE 11:except branch
200 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
201 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, "Reaction completed for event %d %s in state %s "
202 , f_pEventData->m_uiEventId, (m_pEventName->find(f_pEventData->m_uiEventId)->second).c_str(),
203 m_strStateName.c_str());
205 } else if (IsEventDeferred(f_pEventData->m_uiEventId)) {
206 // If given event is deferred event then handle defer event
207 CHKNULL(m_pDeferredPostEventList);
209 m_pDeferredPostEventList->push_back(f_pEventData);
211 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "deferred event %d %s posted to state %s ",
212 f_pEventData->m_uiEventId,
213 (m_pEventName->find(f_pEventData->m_uiEventId)->second).c_str(),
214 m_strStateName.c_str());
217 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
218 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, "Reaction not available or event %d not found in state %s"
219 , f_pEventData->m_uiEventId, m_strStateName.c_str());
221 // check if the current state has parent state
222 if (m_pParentState) {
223 // No reaction available fot given event in the current state
224 // then forward event to parent state
225 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
226 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "Forwarding an event %d to %s"
227 , f_pEventData->m_uiEventId, m_pParentState->m_strStateName.c_str());
229 l_pCurrentState = m_pParentState->FrameworkunifiedOnEvent(f_pEventData); // LCOV_EXCL_BR_LINE 11:except branch
232 // No parent is available then reached root state,
233 // No reaction available in the statemachine then discard the event
234 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
235 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "Discarding an event %d ", f_pEventData->m_uiEventId);
239 CHKNULL(l_pCurrentState);
241 // This is a recursive function that recurse in parent states till the event is
242 // consumed or discarded So Setting the current state as the active state of the
243 // returned state, as the return state is parent state
244 if (l_pCurrentState->m_pActiveState) {
245 l_pCurrentState = l_pCurrentState->m_pActiveState;
248 // do nothing in leaf state, as current state is active state
251 } catch (std::exception &e) {
252 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
255 return l_pCurrentState;
258 //////////////////////////////////////////////////////////////////////////////////////////////////
259 /// FrameworkunifiedAddDeferredEvent
260 /// When the event is posted to the state the event is deferred and stored in the state.
261 /// In case of implicit recall of the deferred events, events are processed before exiting the state.
262 /// The deferred events can also be recalled explicitly in the state.
263 /// This also adds the event name to the map which is used for debugging.
264 //////////////////////////////////////////////////////////////////////////////////////////////////
265 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedAddDeferredEvent(UI_32 f_uiEventId, std::string f_strEventName) {
266 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
269 // LCOV_EXCL_BR_START 15:marco defined in frameworkunified_sm_framework_types.h
270 CHKNULL(m_pEventName);
272 CHKNULL(m_pDeferredEventList);
274 // associate the deferred eventname with event id (debugging only)
275 m_pEventName->insert(std::pair<UI_32, std::string>(f_uiEventId, f_strEventName));
277 // associate the reaction with deferred event id
278 m_pDeferredEventList->push_back(f_uiEventId); // LCOV_EXCL_BR_LINE 11:except branch
279 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
280 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "Added deferred event %d %s in the state %s "
281 , f_uiEventId, (m_pEventName->find(f_uiEventId)->second).c_str(), m_strStateName.c_str());
283 } catch (std::exception &e) {
284 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
285 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed to add event %d %s in state %s",
286 f_uiEventId, (m_pEventName->find(f_uiEventId)->second).c_str(), m_strStateName.c_str());
288 eStatus = eFrameworkunifiedStatusNullPointer;
294 ///////////////////////////////////////////////////////////////////////////////////////////
295 /// FrameworkunifiedPostEvent
296 /// This function creates new eventdata object and add the to event queue of the state.
297 /// The events are posted in the reaction which are executed in the state.
298 /// The event queue is processed once the execution of the reaction is completed.
299 ///////////////////////////////////////////////////////////////////////////////////////////
300 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedPostEvent(UI_32 f_uiEventId) {
301 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
303 CHKNULL(m_pStateMachine); // LCOV_EXCL_BR_LINE 15:marco defined in frameworkunified_sm_framework_types.h
305 CEventDataPtr l_pEventData(new CEventData(f_uiEventId)); // LCOV_EXCL_BR_LINE 11:except branch
307 l_eStatus = m_pStateMachine->FrameworkunifiedPostEvent(l_pEventData); // LCOV_EXCL_BR_LINE 11:except branch // LCOV_EXCL_BR_LINE 11:except branch
308 } catch (std::exception &e) {
309 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
310 l_eStatus = eFrameworkunifiedStatusNullPointer;
316 ///////////////////////////////////////////////////////////////////////////////////////////
317 /// FrameworkunifiedPostEvent
318 /// This function adds the event queue of the state. The events are posted in the reaction
319 /// which are executed in the state. The event queue is processed once the execution of the
320 /// reaction is completed.
321 ///////////////////////////////////////////////////////////////////////////////////////////
322 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedPostEvent(CEventDataPtr f_pEventData) {
323 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
326 CHKNULL(m_pStateMachine);
327 CHKNULL(f_pEventData);
329 l_eStatus = m_pStateMachine->FrameworkunifiedPostEvent(f_pEventData);
330 } catch (std::exception &e) {
331 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
332 l_eStatus = eFrameworkunifiedStatusNullPointer;
338 ///////////////////////////////////////////////////////////////////////////////////////////
339 /// FrameworkunifiedOnHSMStart
340 /// This function is called recursively till the leaf state is reached. This internally
341 /// calls the Entry function of the current state.
342 ///////////////////////////////////////////////////////////////////////////////////////////
343 CFrameworkunifiedState *CFrameworkunifiedState::FrameworkunifiedOnHSMStart(CEventDataPtr f_pEventData) {
344 CFrameworkunifiedState *l_pActiveState = this;
345 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
348 // Call Entry method of the current state. Entry method of state is called in the order of
349 // Hierarchy from Outer state to Inner state
350 if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedOnEntry(f_pEventData))) {
351 // If current state has sub states then enter into active state for state entry
352 // active state is same as the default state. In this case the FrameworkunifiedOnStart is called
353 // recursively and recursion breaks when the current state is leafstate that does not have
354 // any active/default state.
355 if (m_pActiveState) {
356 l_pActiveState = m_pActiveState->FrameworkunifiedOnHSMStart(f_pEventData); // LCOV_EXCL_BR_LINE 11:except branch
358 l_pActiveState = this;
361 // set current state as the active state of its parent state to maintain the Hierarchy
362 if (m_pParentState) {
363 m_pParentState->m_pActiveState = this;
366 // If FrameworkunifiedOnEntry failed then statemachine should report the error
367 // We can throw an exception but for now as a quick fix we are setting
368 // l_pActiveState as NULL which will stop the statemachine
369 // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
370 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error:%d in FrameworkunifiedOnEntry of state %s", eStatus,
371 l_pActiveState->m_strStateName.c_str());
373 // l_pActiveState = NULL;
374 /* Commenting it, because it was making state machine inactive. This should not be the expected behavior.
375 * Just log and take no action, if user return non-ok value.
376 * User defined error values should be handled separately */
378 } catch (std::exception &e) {
379 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
383 return l_pActiveState;
386 ///////////////////////////////////////////////////////////////////////////////////////////
387 /// FrameworkunifiedOnHSMStop
388 /// This function is called recursively till the required parent state is reached. This
389 /// internally calls the Exit function of the current state.
390 ///////////////////////////////////////////////////////////////////////////////////////////
391 CFrameworkunifiedState *CFrameworkunifiedState::FrameworkunifiedOnHSMStop(CEventDataPtr f_pEventData) {
392 CFrameworkunifiedState *l_pActiveState = this;
394 // if active state is composite state, update the shallow and deep history state(if exists)
395 UpdateHistory(); // LCOV_EXCL_BR_LINE 11:except branch
397 // if current state has active state then recursively call the FrameworkunifiedOnHSMStop till current
398 // state has no active state i.e. current state is leaf state
399 if (m_pActiveState) {
400 m_pActiveState->FrameworkunifiedOnHSMStop(f_pEventData);
403 m_pActiveState = m_pDefaultState;
405 // Post deferred events to statemachine event queue
406 CHKNULL(m_pDeferredPostEventList); // LCOV_EXCL_BR_LINE 15:marco defined in frameworkunified_sm_framework_types.h
408 // recall deferred events till the vector is empty
409 while (!m_pDeferredPostEventList->empty()) {
410 // get the first event list object
411 CEventDataPtr l_pEventData = m_pDeferredPostEventList->front();
413 CHKNULL(l_pEventData);
414 CHKNULL(m_pEventName);
416 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "Recalling event %d %s in state %s"
417 , l_pEventData->m_uiEventId,
418 (m_pEventName->find(l_pEventData->m_uiEventId)->second).c_str(), m_strStateName.c_str());
420 m_pDeferredPostEventList->erase(m_pDeferredPostEventList->begin());
422 // recall the event stored in the eventinfo object
423 FrameworkunifiedPostEvent(l_pEventData);
426 FrameworkunifiedOnExit(f_pEventData);
427 } catch (std::exception &e) {
428 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
432 return l_pActiveState;
435 ///////////////////////////////////////////////////////////////////////////////////////////
437 /// This checks if the given event is marked as deferred in the state.
438 ///////////////////////////////////////////////////////////////////////////////////////////
439 BOOL CFrameworkunifiedState::IsEventDeferred(UI_32 f_uiEventId) {
440 BOOL bStatus = FALSE;
442 CHKNULL(m_pDeferredEventList); // LCOV_EXCL_BR_LINE 15:marco defined in frameworkunified_sm_framework_types.h
443 for (UI_32 l_uiCount = 0; l_uiCount < m_pDeferredEventList->size(); l_uiCount++) {
444 if (f_uiEventId == m_pDeferredEventList->at(l_uiCount)) {
449 } catch (std::exception &e) {
450 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
453 return bStatus; // LCOV_EXCL_BR_LINE 15:marco defined in frameworkunified_sm_framework_types.h
456 ///////////////////////////////////////////////////////////////////////////////////////////
457 /// FrameworkunifiedRemoveEventFromDeferredEventList
458 /// This function removes the event from the posted deferred queue list of the state.
459 ///////////////////////////////////////////////////////////////////////////////////////////
460 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedRemoveEventFromDeferredEventList(UI_32 f_uiEventId) {
461 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldID;
462 FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "+");
465 CHKNULL(m_pDeferredPostEventList);
466 int32_t l_siCnt = static_cast<int32_t>(m_pDeferredPostEventList->size() - 1);
468 for (; l_siCnt >= 0; l_siCnt--) {
469 if (NULL != m_pDeferredPostEventList->at(l_siCnt).get()) {
470 if (f_uiEventId == m_pDeferredPostEventList->at(l_siCnt).get()->m_uiEventId) {
471 m_pDeferredPostEventList->erase(m_pDeferredPostEventList->begin() + l_siCnt);
472 l_eStatus = eFrameworkunifiedStatusOK;
476 } catch (std::exception &e) {
477 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
478 l_eStatus = eFrameworkunifiedStatusNullPointer;
480 FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "-");
484 ///////////////////////////////////////////////////////////////////////////////////////////
485 /// FrameworkunifiedRecallEvent
486 /// This indicates if the state has sub states. It returns TRUE only in the CompositeState
487 /// where this function is overridden
488 ///////////////////////////////////////////////////////////////////////////////////////////
489 BOOL CFrameworkunifiedState::FrameworkunifiedHasSubStates() {
493 ///////////////////////////////////////////////////////////////////////////////////////////
494 /// FrameworkunifiedPrintStates
495 /// This logs the state name and events associated with the state
496 ///////////////////////////////////////////////////////////////////////////////////////////
497 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedPrintStates() {
498 EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
499 EventReactionIterator l_objEventIterator;
501 CHKNULL(m_pEventList);
502 CHKNULL(m_pDeferredEventList);
503 CHKNULL(m_pEventName);
505 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "%s:%s",
506 (m_pParentState->m_strStateName).c_str(), m_strStateName.c_str());
509 for (l_objEventIterator = m_pEventList->begin();
510 l_objEventIterator != m_pEventList->end(); l_objEventIterator++) {
511 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "event %d %s", ((*l_objEventIterator).first),
512 (m_pEventName->find((*l_objEventIterator).first)->second).c_str());
515 // print deferred events
516 for (UI_32 l_uiCount = 0; l_uiCount < m_pDeferredEventList->size(); l_uiCount++) {
517 FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "deferred event %d %s", m_pDeferredEventList->at(l_uiCount),
518 (m_pEventName->find(m_pDeferredEventList->at(l_uiCount))->second).c_str());
520 } catch (std::exception &e) {
521 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
522 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed to print in state %s", m_strStateName.c_str());
523 eStatus = eFrameworkunifiedStatusNullPointer;
529 BOOL CFrameworkunifiedState::FrameworkunifiedHasOrthogoanlRegions() {
533 BOOL CFrameworkunifiedState::FrameworkunifiedIsReactionAvailable(UI_32 f_uiEventId) {
534 BOOL IsReactionAvailable = FALSE;
535 CFrameworkunifiedReaction *l_pEventReaction = NULL;
538 // LCOV_EXCL_BR_START 15:marco defined in frameworkunified_sm_framework_types.h
539 CHKNULL(m_pEventList);
540 CHKNULL(m_pDeferredEventList);
542 if (m_pEventList->end() != m_pEventList->find(f_uiEventId)) {
543 // Find the reaction object for given event id
544 l_pEventReaction = reinterpret_cast<CFrameworkunifiedReaction *>((m_pEventList->find(f_uiEventId))->second);
547 if (l_pEventReaction) {
548 IsReactionAvailable = TRUE;
550 if (IsEventDeferred(f_uiEventId)) {
551 IsReactionAvailable = TRUE;
554 } catch (std::exception &e) {
555 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
558 return IsReactionAvailable; // LCOV_EXCL_BR_LINE 11:except branch
561 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedSetHSM(CFrameworkunifiedHSM *f_pStatemachine) {
562 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
565 CHKNULL(f_pStatemachine); // LCOV_EXCL_BR_LINE 15:marco defined in frameworkunified_sm_framework_types.h
566 m_pStateMachine = f_pStatemachine;
567 } catch (std::exception &e) {
568 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
569 l_eStatus = eFrameworkunifiedStatusNullPointer;
571 return l_eStatus; // LCOV_EXCL_BR_LINE 11:except branch
574 HANDLE CFrameworkunifiedState:: FrameworkunifiedGetAppHandle() {
575 HANDLE l_pHApp = NULL;
577 CHKNULL(m_pStateMachine); // LCOV_EXCL_BR_LINE 15:marco defined in frameworkunified_sm_framework_types.h
578 l_pHApp = m_pStateMachine->FrameworkunifiedGetAppHandle(); // LCOV_EXCL_BR_LINE 11:except branch
579 } catch (std::exception &e) {
580 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
582 return l_pHApp; // LCOV_EXCL_BR_LINE 11:except branch
585 EFrameworkunifiedStatus CFrameworkunifiedState::FrameworkunifiedPrintXML(std::ostringstream &f_strXMLString) {
586 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
587 EventReactionIterator l_objEventIterator;
589 CHKNULL(m_pEventList);
590 CHKNULL(m_pDeferredEventList);
591 CHKNULL(m_pEventName);
593 f_strXMLString << "<" << m_strStateName.c_str() << ">";
595 f_strXMLString << "<EventList>";
597 for (l_objEventIterator = m_pEventList->begin();
598 l_objEventIterator != m_pEventList->end(); l_objEventIterator++) {
599 std::string l_strEventName =
600 (m_pEventName->find((*l_objEventIterator).first)->second);
602 UI_32 l_uiEventId = (*l_objEventIterator).first;
604 f_strXMLString << "<Event " << "Id = " << "\"" << l_uiEventId << "\">";
606 f_strXMLString << "<Name>" << l_strEventName.c_str() << "</Name>";
608 f_strXMLString << "</Event>";
610 f_strXMLString << "</EventList>";
612 // print deferred events
613 f_strXMLString << "<DeferredEventList>";
614 for (UI_32 l_uiCount = 0; l_uiCount < m_pDeferredEventList->size(); l_uiCount++) {
615 UI_32 l_uiEventId = m_pDeferredEventList->at(l_uiCount);
617 std::string l_strEventName = (m_pEventName->find(l_uiEventId)->second);
619 f_strXMLString << "<Event " << "Id = " << "\"" << l_uiEventId << "\">";
621 f_strXMLString << "<Name>" << l_strEventName.c_str() << "</Name>";
623 f_strXMLString << "</Event>";
626 f_strXMLString << "</DeferredEventList>";
627 f_strXMLString << "</" << m_strStateName.c_str() << ">";
628 } catch (std::exception &e) {
629 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
630 FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed to print in state %s", m_strStateName.c_str());
631 l_eStatus = eFrameworkunifiedStatusNullPointer;