Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / src / statemachine / frameworkunified_sm_hsm.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 CFrameworkunifiedHSM class definitions. CFrameworkunifiedHSM is base class for HSM Framework.
28 /// This class implements interfaces for connecting child states to parent states, connecting events
29 /// to state.
30 ///////////////////////////////////////////////////////////////////////////////////////////////////
31
32 #include <native_service/frameworkunified_sm_hsm.h>
33 #include <native_service/frameworkunified_sm_reaction.h>
34 #include <native_service/frameworkunified_sm_state.h>
35 #include <native_service/frameworkunified_sm_compositestate.h>
36 #include <native_service/frameworkunified_sm_framework_types.h>
37 #include <native_service/frameworkunified_sm_orthogonalstate.h>
38 #include <native_service/frameworkunified_framework_if.h>
39
40 #include <cstdio>
41 #include <sstream>
42 #include <string>
43
44 #include "frameworkunified_framework_internal.h"
45 #include "frameworkunified_sm_framework_core.h"
46
47 ///////////////////////////////////////////////////////////////////////////////////////////
48 /// CFrameworkunifiedHSM
49 /// Class constructor
50 ///////////////////////////////////////////////////////////////////////////////////////////
51 CFrameworkunifiedHSM::CFrameworkunifiedHSM(PVOID f_pHApp): m_uiCurrentEvent(0), m_pHApp(f_pHApp), m_pActiveState(NULL), m_pRootState(NULL),
52   m_bIsTransitioning(FALSE) {
53   // PostEventList stores the list of events posted in the state
54   m_pPostEventList =  new EventInfoList();
55 }
56
57 ///////////////////////////////////////////////////////////////////////////////////////////
58 /// CFrameworkunifiedHSM
59 /// Class constructor
60 ///////////////////////////////////////////////////////////////////////////////////////////
61 CFrameworkunifiedHSM::CFrameworkunifiedHSM(): m_uiCurrentEvent(0), m_pHApp(NULL), m_pActiveState(NULL), m_pRootState(NULL),
62   m_bIsTransitioning(FALSE) {
63   // PostEventList stores the list of events posted in the state
64   m_pPostEventList =  new EventInfoList();
65   m_pHApp = NULL;
66 }
67
68 ///////////////////////////////////////////////////////////////////////////////////////////
69 /// ~CFrameworkunifiedHSM
70 /// Class destructor
71 ///////////////////////////////////////////////////////////////////////////////////////////
72 CFrameworkunifiedHSM::~CFrameworkunifiedHSM() {
73   if (NULL != m_pPostEventList) {
74     delete m_pPostEventList;
75     m_pPostEventList = NULL;
76   }
77
78   if (m_pRootState) {
79     FrameworkunifiedClose();
80   }
81
82   // we are not deleting this pointer because memory pointed by this pointer
83   // had already been deleted in above step.
84   m_pActiveState = NULL;
85 }
86
87 ///////////////////////////////////////////////////////////////////////////////////////////
88 /// FrameworkunifiedGetActiveState
89 /// Returns the active state of the statemachine
90 ///////////////////////////////////////////////////////////////////////////////////////////
91 CFrameworkunifiedState *CFrameworkunifiedHSM::FrameworkunifiedGetActiveState() {
92   CFrameworkunifiedState *l_pCurrentState = m_pRootState;
93   CFrameworkunifiedState *l_pActiveState = NULL;
94
95   try {
96     // Iterate till the current state is leafstate or orthogonal state
97     while (l_pCurrentState != l_pActiveState) {
98       l_pActiveState = l_pCurrentState;
99       l_pCurrentState = l_pCurrentState->FrameworkunifiedGetActiveState();
100       CHKNULL(l_pCurrentState);
101     }
102
103     // Set active state
104     m_pActiveState = l_pActiveState;
105
106     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Active state is  %s "
107            , m_pActiveState->m_strStateName.c_str());
108   } catch (std::exception &e) {
109     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
110     l_pActiveState = NULL;
111   }
112
113
114   return l_pActiveState;
115 }
116
117 ///////////////////////////////////////////////////////////////////////////////////////////
118 /// FrameworkunifiedStart
119 /// This starts the state machine
120 ///////////////////////////////////////////////////////////////////////////////////////////
121 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedStart(CEventDataPtr f_pEventData) {
122   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
123
124   try {
125     CHKNULL(m_pActiveState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
126
127     m_bIsTransitioning = TRUE;
128
129     // Start the state machine execution on current state
130     m_pActiveState = m_pActiveState->FrameworkunifiedOnHSMStart(f_pEventData);  // LCOV_EXCL_BR_LINE 11:except branch
131
132     // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
133     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Active state is  %s "
134            , m_pActiveState->m_strStateName.c_str());
135     // LCOV_EXCL_BR_STOP
136     // post the event from events list
137     eStatus = ProcessEventQueue();  // LCOV_EXCL_BR_LINE 11:except branch
138
139     m_bIsTransitioning = FALSE;
140   } catch (std::exception &e) {
141     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
142     eStatus = eFrameworkunifiedStatusNullPointer;
143   }
144
145   return eStatus;
146 }
147
148 ///////////////////////////////////////////////////////////////////////////////////////////
149 /// FrameworkunifiedConnect
150 /// This connects the reaction to event and add event to child states then add child state
151 ///////////////////////////////////////////////////////////////////////////////////////////
152 EFrameworkunifiedStatus CFrameworkunifiedHSM::CFrameworkunifiedHSM::FrameworkunifiedConnect(CFrameworkunifiedState *f_pParentState, CFrameworkunifiedState *f_pChildState,
153                                         UI_32 f_uiEventId, CFrameworkunifiedReaction *f_pReaction,
154                                         BOOL f_bIsDefaultState, BOOL f_bIsDeferredEventType,
155                                         std::string f_strEventName) {
156   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
157
158   try {
159     // attach reaction to event and add it to the  child state
160     eStatus = FrameworkunifiedConnect(f_pChildState, f_uiEventId, f_pReaction, f_strEventName, f_bIsDeferredEventType);
161     if (eFrameworkunifiedStatusOK == eStatus) {
162       // add child state to parent state
163       eStatus = FrameworkunifiedConnect(f_pParentState, f_pChildState, f_bIsDefaultState);
164     }
165   } catch (std::exception &e) {
166     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
167
168     eStatus = eFrameworkunifiedStatusNullPointer;
169   }
170   return eStatus;
171 }
172 ///////////////////////////////////////////////////////////////////////////////////////////
173 /// FrameworkunifiedConnect
174 /// This add child state to parent state.
175 ///////////////////////////////////////////////////////////////////////////////////////////
176 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedConnect(CFrameworkunifiedState *f_pParentState, CFrameworkunifiedState *f_pChildState,
177                                BOOL f_bIsDefaultState) {
178   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
179   try {
180     CHKNULL(f_pParentState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
181     CHKNULL(f_pChildState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
182     // Check if the state is composite state
183     if (f_pParentState->FrameworkunifiedHasSubStates()) {
184       // Check if the child state is default state
185       if (f_bIsDefaultState) {
186         // Add child state as default state
187         (reinterpret_cast<CFrameworkunifiedCompositeState *>(f_pParentState))->FrameworkunifiedAddState(f_pChildState,
188                                                             CFrameworkunifiedCompositeState::eFrameworkunifiedDefaultState);  // LCOV_EXCL_BR_LINE 11: except branch
189       } else {
190         // Add state as regular state
191         (reinterpret_cast<CFrameworkunifiedCompositeState *>(f_pParentState))->FrameworkunifiedAddState(f_pChildState);  // LCOV_EXCL_BR_LINE 11: except branch
192       }
193
194       f_pChildState->FrameworkunifiedSetHSM(this);  // LCOV_EXCL_BR_LINE 11: except branch
195
196     } else {
197       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error %s is not a composite state",
198              f_pParentState->m_strStateName.c_str());
199     }
200   } catch (std::exception &e) {
201     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
202
203     eStatus = eFrameworkunifiedStatusNullPointer;
204   }
205
206   return eStatus;  //LCOV_EXCL_BR_LINE 11:except branch
207 }
208
209 ///////////////////////////////////////////////////////////////////////////////////////////
210 /// FrameworkunifiedConnect
211 /// This connects the reaction to event and add event to child states
212 ///////////////////////////////////////////////////////////////////////////////////////////
213 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedConnect(CFrameworkunifiedState *f_pState, UI_32 f_uiEventId, CFrameworkunifiedReaction *f_pReaction,
214                                std::string f_strEventName , BOOL f_bIsDeferredEventType) {
215   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
216   try {
217     CHKNULL(f_pState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
218     // check if the event is deferred event
219     if (f_bIsDeferredEventType) {
220       // Add event as deferred event
221       f_pState->FrameworkunifiedAddDeferredEvent(f_uiEventId, f_strEventName);  // LCOV_EXCL_BR_LINE 11: except branch
222       // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
223       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Deferred Event %d %s is "
224         "associated with Reaction and added to state %s "
225         , f_uiEventId, f_strEventName.c_str(), (f_pState->m_strStateName).c_str());
226       // LCOV_EXCL_BR_STOP
227     } else {
228       CHKNULL(f_pReaction);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
229       // Add event as regular event
230       f_pState->FrameworkunifiedAddEvent(f_uiEventId, f_pReaction, f_strEventName);  // LCOV_EXCL_BR_LINE 11: except branch
231
232       // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
233       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Event %d %s is associated with Reaction and added to state %s "
234              , f_uiEventId, f_strEventName.c_str(), (f_pState->m_strStateName).c_str());
235       // LCOV_EXCL_BR_STOP
236     }
237   } catch (std::exception &e) {
238     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
239     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed to add event %d in %s", f_uiEventId,
240            (f_pState->m_strStateName).c_str());
241
242     eStatus = eFrameworkunifiedStatusNullPointer;
243   }
244
245   return eStatus;;
246 }
247
248 ///////////////////////////////////////////////////////////////////////////////////////////
249 /// FrameworkunifiedPostEvent
250 /// This creates the default event data and sends the event to the active HSM state.
251 ///////////////////////////////////////////////////////////////////////////////////////////
252 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedPostEvent(UI_32 f_uiEventId) {
253   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;  // LCOV_EXCL_BR_LINE 11: except branch
254   try {
255     CEventDataPtr l_pEventData(new CEventData(f_uiEventId));  // LCOV_EXCL_BR_LINE 11:except branch
256     CHKNULL(l_pEventData);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
257
258     l_eStatus = FrameworkunifiedPostEvent(l_pEventData);  // LCOV_EXCL_BR_LINE 11: except branch
259   } catch (std::exception &e) {
260     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
261     l_eStatus = eFrameworkunifiedStatusNullPointer;
262   }
263   return l_eStatus;
264 }
265
266 ///////////////////////////////////////////////////////////////////////////////////////////
267 /// FrameworkunifiedPostEvent
268 /// This sends the event to the active HSM state
269 ///////////////////////////////////////////////////////////////////////////////////////////
270 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedPostEvent(CEventDataPtr f_pEventData) {
271   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
272   try {
273     CHKNULL(f_pEventData);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
274
275     if (m_bIsTransitioning) {
276       eStatus = FrameworkunifiedQueueEvent(f_pEventData);  // LCOV_EXCL_BR_LINE 11: except branch
277     } else {
278       m_bIsTransitioning = TRUE;
279
280       eStatus = ProcessEvent(f_pEventData);  // LCOV_EXCL_BR_LINE 11: except branch
281
282       m_bIsTransitioning = FALSE;
283
284       CHKNULL(m_pActiveState);
285       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Active state is  %s ", m_pActiveState->m_strStateName.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
286     }
287   } catch (std::exception &e) {
288     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
289
290     eStatus = eFrameworkunifiedStatusNullPointer;
291   }
292   return eStatus;
293 }
294
295 EFrameworkunifiedStatus CFrameworkunifiedHSM::ProcessEvent(CEventDataPtr f_pEventData) {
296   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
297   try {
298     CHKNULL(m_pActiveState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
299     CHKNULL(f_pEventData);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
300     CHKNULL(m_pActiveState->m_pEventName);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
301
302     EventNameList::iterator l_itEventName;
303     l_itEventName = m_pActiveState->m_pEventName->find(f_pEventData->m_uiEventId);
304
305     if (m_pActiveState->m_pEventName->end() != l_itEventName) {
306       // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
307       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Posting event %d %s to state  %s",
308              f_pEventData->m_uiEventId,
309              l_itEventName->second.c_str(),
310              m_pActiveState->m_strStateName.c_str());
311       // LCOV_EXCL_BR_STOP
312     }
313
314     m_uiCurrentEvent = f_pEventData->m_uiEventId;
315
316     // Send event to active state for processing
317     m_pActiveState = m_pActiveState->FrameworkunifiedOnEvent(f_pEventData);  // LCOV_EXCL_BR_LINE 11:except branch
318
319     CHKNULL(m_pActiveState);
320     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Active state is  %s ", m_pActiveState->m_strStateName.c_str());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
321
322     // post the event from events list
323     eStatus = ProcessEventQueue();  // LCOV_EXCL_BR_LINE 11:except branch
324   } catch (std::exception &e) {
325     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());  // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
326
327     eStatus = eFrameworkunifiedStatusNullPointer;
328   }
329   return eStatus;
330 }
331
332 ///////////////////////////////////////////////////////////////////////////////////////////
333 /// FrameworkunifiedClose
334 /// This stops the state machine and destroys all states and events
335 ///////////////////////////////////////////////////////////////////////////////////////////
336 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedClose(CEventDataPtr f_pEventData) {
337   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
338   try {
339     CHKNULL(m_pRootState);
340     delete m_pRootState;
341     m_pRootState = NULL;
342   } catch (std::exception &e) {
343     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
344
345     eStatus = eFrameworkunifiedStatusNullPointer;
346   }
347   return eStatus;
348 }
349
350 ///////////////////////////////////////////////////////////////////////////////////////////
351 /// FrameworkunifiedConnect
352 /// This sets the givens state as root state in the state machine
353 ///////////////////////////////////////////////////////////////////////////////////////////
354 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedConnect(CFrameworkunifiedState *f_pRootState) {
355   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
356   try {
357     CHKNULL(f_pRootState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
358
359     m_pActiveState = f_pRootState;
360     m_pRootState = f_pRootState;
361
362     m_pRootState->FrameworkunifiedSetHSM(this);  // LCOV_EXCL_BR_LINE 11:except branch
363   } catch (std::exception &e) {
364     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
365
366     eStatus = eFrameworkunifiedStatusNullPointer;
367   }
368   return eStatus;  // LCOV_EXCL_BR_LINE 11:except branch
369 }
370
371 ///////////////////////////////////////////////////////////////////////////////////////////
372 /// FrameworkunifiedPrintAllStates
373 /// This prints all states and events associated with every state on console.
374 ///////////////////////////////////////////////////////////////////////////////////////////
375 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedPrintAllStates() {
376   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
377   try {
378     CHKNULL(m_pRootState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
379     // Print the states
380     m_pRootState->FrameworkunifiedPrintStates();
381   } catch (std::exception &e) {
382     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
383
384     eStatus = eFrameworkunifiedStatusNullPointer;
385   }
386   return eStatus;  // LCOV_EXCL_BR_LINE 11:except branch
387 }
388
389 EFrameworkunifiedStatus  CFrameworkunifiedHSM::FrameworkunifiedConnectOrthogonal(CFrameworkunifiedOrthogonalState *f_pOrthogonalState,
390                                           CFrameworkunifiedCompositeState *f_pOrthogonalRegion) {
391   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
392   try {
393     CHKNULL(f_pOrthogonalState)  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
394     CHKNULL(f_pOrthogonalRegion)  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
395
396     f_pOrthogonalState->FrameworkunifiedAddOrthogonalRegion(f_pOrthogonalRegion);
397   } catch (std::exception &e) {
398     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
399     eStatus = eFrameworkunifiedStatusNullPointer;
400   }
401   return eStatus;
402 }
403
404 HANDLE CFrameworkunifiedHSM::FrameworkunifiedGetAppHandle() {
405   return m_pHApp;
406 }
407
408 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedPrintXML() {
409   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
410   try {
411     std::ostringstream l_strXMLString;
412     l_strXMLString << "<Statemachine>";
413
414     CHKNULL(m_pRootState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
415
416     // Write statemachine information in XML stream
417     m_pRootState->FrameworkunifiedPrintXML(l_strXMLString);
418     l_strXMLString << "</Statemachine>";
419
420     // Write a stream to XML file
421     if (m_pHApp) {
422       size_t l_uiLength = static_cast<size_t>(l_strXMLString.str().length());
423
424       PCHAR l_pStream = new CHAR[l_uiLength + 1];
425       if (NULL != l_pStream) {
426         std::FILE *l_pFile = NULL;
427
428         std::memset(l_pStream, 0, l_uiLength + 1);
429         std::strncpy(l_pStream, l_strXMLString.str().c_str(), l_uiLength);
430
431         std::ostringstream l_strFileName;
432
433         l_strFileName << "StatemachineXML_";
434
435         l_strFileName << FrameworkunifiedGetAppName(m_pHApp) << ".xml";
436
437         l_pFile = std::fopen(l_strFileName.str().c_str(), "wbe");
438
439         if (l_pFile) {
440           std::fwrite(l_pStream, l_uiLength, 1, l_pFile);
441           std::fclose(l_pFile);
442           FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "%s File Created"
443                  , l_strFileName.str().c_str());
444         }
445         delete[] l_pStream;
446         l_pStream = NULL;
447       } else {
448         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: StatemachineXML_%s.xml file not created", FrameworkunifiedGetAppName(m_pHApp));
449       }
450     }
451     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, l_strXMLString.str().c_str());
452   } catch (std::exception &e) {
453     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
454   }
455   return l_eStatus;
456 }
457
458 EFrameworkunifiedStatus CFrameworkunifiedHSM::FrameworkunifiedQueueEvent(CEventDataPtr f_pEventData) {
459   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
460   try {
461     CHKNULL(m_pPostEventList);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
462     CHKNULL(m_pActiveState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
463     CHKNULL(f_pEventData);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
464
465     // Push the event in the post event list(FIFO)
466     m_pPostEventList->push_back(f_pEventData);  // LCOV_EXCL_BR_LINE 11:except branch
467   } catch (std::exception &e) {
468     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
469     eStatus = eFrameworkunifiedStatusNullPointer;
470   }
471   return eStatus;  // LCOV_EXCL_BR_LINE 11:except branch
472 }
473
474 ///////////////////////////////////////////////////////////////////////////////////////////
475 /// ProcessEventQueue
476 /// This post the event from events list
477 ///////////////////////////////////////////////////////////////////////////////////////////
478 EFrameworkunifiedStatus CFrameworkunifiedHSM::ProcessEventQueue() {
479   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
480
481   try {
482     CHKNULL(m_pPostEventList);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
483
484     if (!m_pPostEventList->empty()) {
485       CEventDataPtr l_pEventData = m_pPostEventList->front();  // LCOV_EXCL_BR_LINE 11:except branch
486       CHKNULL(l_pEventData);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
487
488       CHKNULL(m_pActiveState);  // LCOV_EXCL_BR_LINE 15: marco defined in frameworkunified_sm_framework_types.h
489       // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
490       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, "Processing posted event %d in state %s",
491              l_pEventData->m_uiEventId, m_pActiveState->m_strStateName.c_str());
492       // LCOV_EXCL_BR_STOP
493       m_pPostEventList->erase(m_pPostEventList->begin());
494
495       eStatus = ProcessEvent(l_pEventData);  // LCOV_EXCL_BR_LINE 11:except branch
496     }
497   } catch (std::exception &e) {
498     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
499     eStatus = eFrameworkunifiedStatusNullPointer;
500   }
501   return eStatus;
502 }
503
504 ///////////////////////////////////////////////////////////////////////////////////////////
505 /// RemoveEventFromPostedEventQueue
506 /// This API is used to remove the all events of eventId f_uiEventId from event queue of statemachine
507 ///////////////////////////////////////////////////////////////////////////////////////////
508 EFrameworkunifiedStatus CFrameworkunifiedHSM::RemoveEventFromPostedEventQueue(const UI_32 f_uiEventId) {
509   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldID;
510   FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "+");
511
512   if (NULL != m_pPostEventList) {
513     int32_t l_siCnt = static_cast<int32_t>(m_pPostEventList->size() - 1);
514
515     for (; l_siCnt >= 0; l_siCnt--) {
516       if (NULL != m_pPostEventList->at(l_siCnt).get()) {
517         if (f_uiEventId == m_pPostEventList->at(l_siCnt).get()->m_uiEventId) {
518           m_pPostEventList->erase(m_pPostEventList->begin() + l_siCnt);
519           l_eStatus = eFrameworkunifiedStatusOK;
520         }
521       }
522     }
523   } else {
524     l_eStatus = eFrameworkunifiedStatusNullPointer;
525   }
526
527   FRAMEWORKUNIFIEDLOG_CUT(ZONE_NS_FUNC, __FUNCTION__, "-");
528   return l_eStatus;
529 }