Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / src / statemachine / frameworkunified_sm_hsmframework.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 CFrameworkunifiedHSMParentFramework class definitions. CFrameworkunifiedHSMParentFramework is derived from
28 /// CFrameworkunifiedHSM class. It defines the states required for NS statemachine framework, it creates the NS
29 /// statemachine and implements the reaction associated with the events
30 ///
31 ///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////////////////////////////
34 // Include Files
35 ///////////////////////////////////////////////////////////////////////////////////////////////////
36 #include <native_service/frameworkunified_sm_hsmframework.h>
37 #include <native_service/frameworkunified_framework_if.h>
38 #include <native_service/frameworkunified_framework_types.h>
39 #include <native_service/ns_np_service_protocol.h>
40 #include <native_service/ns_np_service_notification.h>
41 #include <native_service/frameworkunified_sm_framework_dispatch.h>
42 #include <native_service/ns_plogger_if.h>
43
44 #include <map>
45 #include <string>
46
47 #include "frameworkunified_framework_core.h"
48 #include "frameworkunified_framework_internal.h"
49 #include "frameworkunified_framework_utility.h"
50 #include "frameworkunified_sm_framework_core.h"
51
52 extern EFrameworkunifiedStatus FrameworkunifiedHSMOnLoadData(HANDLE hApp) __attribute__((weak));
53 extern EFrameworkunifiedStatus FrameworkunifiedHSMOnStopInsFrameworkunifiedRun(HANDLE hApp) __attribute__((weak));
54
55 CFrameworkunifiedHSMFramework::CFrameworkunifiedHSMFramework(): CFrameworkunifiedHSM() {
56 }
57 CFrameworkunifiedHSMFramework::CFrameworkunifiedHSMFramework(PVOID f_pHApp): CFrameworkunifiedHSM(f_pHApp) {
58 }
59 CFrameworkunifiedHSMParentFramework::CFrameworkunifiedHSMParentFramework(): CFrameworkunifiedHSMFramework() {
60   try {
61     m_pFrameworkunifiedStateList = new std::map<UI_32, CFrameworkunifiedState *>();
62   } catch (std::exception &e) {
63     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
64   }
65 }
66 ///////////////////////////////////////////////////////////////////////////////////////////
67 /// CFrameworkunifiedHSMParentFramework
68 /// default constructor
69 ///////////////////////////////////////////////////////////////////////////////////////////
70 CFrameworkunifiedHSMParentFramework::CFrameworkunifiedHSMParentFramework(PVOID f_pHApp): CFrameworkunifiedHSMFramework(f_pHApp) {
71   try {
72     m_pFrameworkunifiedStateList = new std::map<UI_32, CFrameworkunifiedState *>();
73   } catch (std::exception &e) {
74     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
75   }
76 }
77 ///////////////////////////////////////////////////////////////////////////////////////////
78 /// ~CFrameworkunifiedHSMParentFramework
79 /// Class destructor
80 ///////////////////////////////////////////////////////////////////////////////////////////
81 CFrameworkunifiedHSMParentFramework::~CFrameworkunifiedHSMParentFramework() {
82   // TODO(framework_unifeid) Auto-generated destructor stub
83 }
84
85 ///////////////////////////////////////////////////////////////////////////////////////////
86 /// FrameworkunifiedCreate
87 /// Statemachine states and events created and connected in this interface.
88 ///////////////////////////////////////////////////////////////////////////////////////////
89 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::FrameworkunifiedCreate(PVOID f_pEventData) {
90   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
91   HSMConfigOptions *l_tHSMConfig = NULL;
92   try {
93     if (f_pEventData) {
94       l_tHSMConfig  = reinterpret_cast<HSMConfigOptions *>(f_pEventData);
95     }
96
97     // Create states
98     CREATE_STATE(sFrameworkunifiedRoot)
99     CREATE_STATE(sFrameworkunifiedApp)
100     CREATE_STATE(sFrameworkunifiedInitialization)
101     CREATE_STATE(sFrameworkunifiedLoadData)
102     CREATE_STATE(sFrameworkunifiedRun)
103     CREATE_STATE(sFrameworkunifiedLoadSessions)
104     CREATE_STATE(sFrameworkunifiedReady)
105     CREATE_STATE(sFrameworkunifiedStop)
106     CREATE_STATE(sFrameworkunifiedStopping)
107     CREATE_STATE(sFrameworkunifiedPre)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
108     CREATE_STATE(sFrameworkunifiedBackground)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
109
110     // connect states as per the statemachine
111     CONNECT_DEFAULTSTATE(sFrameworkunifiedRoot, sFrameworkunifiedApp)
112     CONNECT_STATE(sFrameworkunifiedRoot, sFrameworkunifiedStop)
113
114     CONNECT_DEFAULTSTATE(sFrameworkunifiedApp, sFrameworkunifiedInitialization)
115     CONNECT_STATE(sFrameworkunifiedApp, sFrameworkunifiedRun)
116
117     CONNECT_DEFAULTSTATE(sFrameworkunifiedInitialization, sFrameworkunifiedLoadData)
118     CONNECT_STATE(sFrameworkunifiedInitialization, sFrameworkunifiedPre)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
119     CONNECT_STATE(sFrameworkunifiedInitialization, sFrameworkunifiedBackground)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
120
121     CONNECT_DEFAULTSTATE(sFrameworkunifiedRun, sFrameworkunifiedLoadSessions)
122     CONNECT_STATE(sFrameworkunifiedRun, sFrameworkunifiedReady)
123
124     CONNECT_DEFAULTSTATE(sFrameworkunifiedStop, sFrameworkunifiedStopping)
125
126     // Create External Transition
127     CREATE_EXTERNALTRANSITION(sFrameworkunifiedApp)
128     CREATE_EXTERNALTRANSITION(sFrameworkunifiedStop)
129
130     CREATE_EXTERNALTRANSITION(sFrameworkunifiedLoadSessions)
131     CREATE_EXTERNALTRANSITION(sFrameworkunifiedReady)
132
133     CREATE_EXTERNALTRANSITION(sFrameworkunifiedPre)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
134     CREATE_EXTERNALTRANSITION(sFrameworkunifiedBackground)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
135
136     // CREATE_ACTION(aFrameworkunifiedOnStart)
137
138     // this is a patch, this code will be fixed once we change the macro for CONNECT_ACTION
139     CFrameworkunifiedExternalTransition *l_pTrnsFrameworkunifiedRunevFrameworkunifiedStart = new CFrameworkunifiedExternalTransition(l_psFrameworkunifiedRun);
140
141     // CONNECT_ACTION(sFrameworkunifiedRunevFrameworkunifiedStart,aFrameworkunifiedOnStart)
142
143     // Connecting events to sFrameworkunifiedInitialization state
144     CONNECT_EVENT(sFrameworkunifiedInitialization, evFrameworkunifiedStart, sFrameworkunifiedRunevFrameworkunifiedStart)
145     CONNECT_EVENT(sFrameworkunifiedInitialization, evFrameworkunifiedPreStart, sFrameworkunifiedPre)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
146     CONNECT_EVENT(sFrameworkunifiedInitialization, evFrameworkunifiedBackgroundStart, sFrameworkunifiedBackground)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
147
148     // Create Local transitions
149     CREATE_LOCALTRANSITION(sFrameworkunifiedInitialization);
150     CREATE_LOCALTRANSITION(sFrameworkunifiedStop);
151
152     // Connect events to state
153
154     // Connecting events to sFrameworkunifiedLoadData state
155     CONNECT_DEFERREDEVENT(sFrameworkunifiedLoadData, evFrameworkunifiedStart)
156     CONNECT_DEFERREDEVENT(sFrameworkunifiedLoadData, evFrameworkunifiedUserChange)
157     CONNECT_LOCAL_EVENT(sFrameworkunifiedLoadData, evFrameworkunifiedLoadComplete, sFrameworkunifiedInitialization)
158
159     // Connecting events to App state
160     CONNECT_EVENT(sFrameworkunifiedApp, evFrameworkunifiedStop, sFrameworkunifiedStop)
161     CONNECT_LOCAL_EVENT(sFrameworkunifiedStopping, evFrameworkunifiedStopComplete, sFrameworkunifiedStop)
162     CONNECT_DEFERREDEVENT(sFrameworkunifiedStopping, evFrameworkunifiedStart)
163
164     // Connecting events to Connecting state
165     CONNECT_EVENT(sFrameworkunifiedLoadSessions, evFrameworkunifiedReady, sFrameworkunifiedReady)
166     // CONNECT_EVENT(sFrameworkunifiedReady,evFrameworkunifiedLoadSessions,sFrameworkunifiedRun)
167     CONNECT_EVENT(sFrameworkunifiedReady, evFrameworkunifiedLoadSessions, sFrameworkunifiedLoadSessions)
168
169     // Connecting events to Stop state
170     CONNECT_EVENT(sFrameworkunifiedStop, evFrameworkunifiedInit, sFrameworkunifiedApp)
171
172     // Create internal transitions
173     CREATE_INTERNALTRANSITION(OnEventStartInStopState)
174     CONNECT_EVENT(sFrameworkunifiedStop, evFrameworkunifiedStart, OnEventStartInStopState)
175
176     CREATE_INTERNALTRANSITION(OnEventStopInStoppingState)
177     CONNECT_EVENT(sFrameworkunifiedStopping, evFrameworkunifiedStop, OnEventStopInStoppingState)
178
179     // Connecting events to sFrameworkunifiedRun state
180     CONNECT_EVENT(sFrameworkunifiedRun, evFrameworkunifiedPreStop, sFrameworkunifiedPre)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
181     CONNECT_EVENT(sFrameworkunifiedRun, evFrameworkunifiedBackgroundStop, sFrameworkunifiedBackground)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
182
183     // Connecting events to sFrameworkunifiedBackground state
184     CONNECT_EVENT(sFrameworkunifiedBackground, evFrameworkunifiedPreStop, sFrameworkunifiedPre)  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
185
186     if (NULL != l_tHSMConfig) {
187       if (eUserchangeIgnore != l_tHSMConfig->eUserChange) {
188         if (eUserchangeReInit == l_tHSMConfig->eUserChange) {
189           // Create Internal Transition
190           CREATE_INTERNALTRANSITION(OnEventUserChangeInInitializationState)
191           CONNECT_EVENT(sFrameworkunifiedInitialization, evFrameworkunifiedUserChange, OnEventUserChangeInInitializationState)
192
193           // Create Internal Transition
194           CREATE_INTERNALTRANSITION(OnEventUserChangeInRunState)
195           CONNECT_EVENT(sFrameworkunifiedRun, evFrameworkunifiedUserChange, OnEventUserChangeInRunState)
196
197           CREATE_ACTION(aFrameworkunifiedOnStop)
198
199           // this is a patch, this code will be fixed once we change the macro for CONNECT_ACTION
200           CFrameworkunifiedExternalTransition *l_pTrnsFrameworkunifiedAppevFrameworkunifiedInit = new CFrameworkunifiedExternalTransition(l_psFrameworkunifiedApp);
201
202           CONNECT_ACTION(sFrameworkunifiedAppevFrameworkunifiedInit, aFrameworkunifiedOnStop)
203
204           CONNECT_EVENT(sFrameworkunifiedApp, evFrameworkunifiedInit, sFrameworkunifiedAppevFrameworkunifiedInit)
205
206         } else if (eUserchangeRetPrevState == l_tHSMConfig->eUserChange) {
207           CREATE_STATE(sFrameworkunifiedUserChange)
208
209           CONNECT_STATE(sFrameworkunifiedRoot, sFrameworkunifiedUserChange)
210
211           CREATE_EXTERNALTRANSITION(sFrameworkunifiedUserChange)
212
213           CONNECT_EVENT(sFrameworkunifiedApp, evFrameworkunifiedUserChange, sFrameworkunifiedUserChange)
214           CONNECT_EVENT(sFrameworkunifiedUserChange, evFrameworkunifiedStop, sFrameworkunifiedStop)
215
216           CONNECT_DEFERREDEVENT(sFrameworkunifiedUserChange, evFrameworkunifiedStart)
217           CONNECT_DEFERREDEVENT(sFrameworkunifiedUserChange, evFrameworkunifiedUserChange)
218
219           // add shallow history state in state sFrameworkunifiedApp
220           ADD_SHALLOWHISTORYSTATE(sFrameworkunifiedApp)
221
222           // create transition to shallow history state in state sFrameworkunifiedApp
223           CREATE_SHALLOWHISTORYTRANSITION(sFrameworkunifiedApp)
224
225           // Connecting events to UserChange State
226           CONNECT_SHALLOWHISTORYEVENT(sFrameworkunifiedUserChange, evFrameworkunifiedUserChangeComplete, sFrameworkunifiedApp)
227         } else {
228           FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Incorrect  Userchange config option %d", l_tHSMConfig->eUserChange);
229         }
230       }
231     }
232
233     // Connecting FrameworkRoot to statemachine
234     CONNECTROOT(sFrameworkunifiedRoot)
235
236     // Creating the application specific statemachine
237     CHKNULL(m_pHApp);
238     FrameworkunifiedCreateStateMachineInternal(m_pHApp);
239
240     // Print statemachine xml
241     PRINT_HSM();
242   } catch (std::exception &e) {
243     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
244
245     eStatus = eFrameworkunifiedStatusNullPointer;
246   }
247
248   return eStatus;
249 }
250
251 ///////////////////////////////////////////////////////////////////////////////////////////
252 /// FrameworkunifiedFrameworkConnect
253 /// This adds the given state as a sub state of sReady state of the Framework
254 ///////////////////////////////////////////////////////////////////////////////////////////
255 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::FrameworkunifiedFrameworkConnect(CFrameworkunifiedState *f_pAppState, BOOL f_bIsDefaultState) {
256   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
257   try {
258     CHKNULL(m_pFrameworkunifiedStateList);
259     CHKNULL(f_pAppState);
260
261     if (m_pFrameworkunifiedStateList->find(esFrameworkunifiedReady) == m_pFrameworkunifiedStateList->end()) {
262       throw CNullPointerException();
263     }
264     CFrameworkunifiedState *l_pReady = reinterpret_cast<CFrameworkunifiedCompositeState *>(m_pFrameworkunifiedStateList->find(esFrameworkunifiedReady)->second);
265     CHKNULL(l_pReady);
266
267     eStatus = FrameworkunifiedConnect(l_pReady, f_pAppState, f_bIsDefaultState);
268   } catch (std::exception &e) {
269     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
270
271     eStatus = eFrameworkunifiedStatusNullPointer;
272   }
273
274   return eStatus;
275 }
276
277 ///////////////////////////////////////////////////////////////////////////////////////////
278 /// FrameworkunifiedFrameworkConnect
279 /// This connects the reaction to event and add event to states
280 ///////////////////////////////////////////////////////////////////////////////////////////
281 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::FrameworkunifiedFrameworkConnect(FRAMEWORKUNIFIED_HSM_STATES f_eFrameworkunifiedState, UI_32 f_uiEventId,
282                                                        CFrameworkunifiedReaction *f_pReaction, std::string f_strEventName,
283                                                        BOOL f_bIsDeferredEvent) {
284   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
285   try {
286     CHKNULL(m_pFrameworkunifiedStateList);
287
288     if (m_pFrameworkunifiedStateList->find(f_eFrameworkunifiedState) == m_pFrameworkunifiedStateList->end()) {
289       throw CNullPointerException();
290     }
291     CFrameworkunifiedState *l_pFrameworkunifiedState = reinterpret_cast<CFrameworkunifiedCompositeState *>(m_pFrameworkunifiedStateList->find(f_eFrameworkunifiedState)->second);
292
293     CHKNULL(l_pFrameworkunifiedState);
294
295     eStatus = FrameworkunifiedConnect(l_pFrameworkunifiedState, f_uiEventId, f_pReaction, f_strEventName, f_bIsDeferredEvent);
296   } catch (std::exception &e) {
297     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
298
299     eStatus = eFrameworkunifiedStatusNullPointer;
300   }
301   return eStatus;
302 }
303
304 ///////////////////////////////////////////////////////////////////////////////////////////
305 /// CsFrameworkunifiedRoot
306 /// Parameterized constructor
307 ///////////////////////////////////////////////////////////////////////////////////////////
308 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRoot::CsFrameworkunifiedRoot(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {
309 }
310
311 ///////////////////////////////////////////////////////////////////////////////////////////
312 /// ~CsFrameworkunifiedRoot
313 /// class destructor
314 ///////////////////////////////////////////////////////////////////////////////////////////
315 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRoot::~CsFrameworkunifiedRoot() {
316 }
317
318 ///////////////////////////////////////////////////////////////////////////////////////////
319 /// FrameworkunifiedOnEntry
320 /// Initializes the application and registers the service availability notification
321 ///////////////////////////////////////////////////////////////////////////////////////////
322 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRoot::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
323   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
324   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
325
326   HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
327   CHKNULL(l_pHApp);
328
329   FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnInitialization +");
330   if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedOnInitializationInternal(l_pHApp))) {
331     FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to Initialize application:0x%x ", eStatus);
332   }
333   FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnInitialization -");
334
335   // Publish service unavailability
336   if (FrameworkunifiedIsAutoPublishServiceAvailableEnabled()) {
337     if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedPublishServiceAvailability(l_pHApp, FALSE))) {
338       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to set service availability notification:0x%x ", eStatus);
339     } else {
340       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Service unavailable published");
341     }
342   }
343
344   return eStatus;
345 }
346
347 ///////////////////////////////////////////////////////////////////////////////////////////
348 /// FrameworkunifiedOnExit
349 /// state cleanup can be performed in this function.
350 ///////////////////////////////////////////////////////////////////////////////////////////
351 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRoot::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
352   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
353   return eFrameworkunifiedStatusOK;
354 }
355
356 ///////////////////////////////////////////////////////////////////////////////////////////
357 /// CsFrameworkunifiedApp
358 /// Parameterized constructor
359 ///////////////////////////////////////////////////////////////////////////////////////////
360 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedApp::CsFrameworkunifiedApp(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {
361 }
362
363 ///////////////////////////////////////////////////////////////////////////////////////////
364 /// ~CsFrameworkunifiedRoot
365 /// class destructor
366 ///////////////////////////////////////////////////////////////////////////////////////////
367 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedApp::~CsFrameworkunifiedApp() {
368 }
369
370 ///////////////////////////////////////////////////////////////////////////////////////////
371 /// FrameworkunifiedOnEntry
372 /// Initializes the application and registers the service availability notification
373 ///////////////////////////////////////////////////////////////////////////////////////////
374 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedApp::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
375   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
376   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
377   return eStatus;
378 }
379
380 ///////////////////////////////////////////////////////////////////////////////////////////
381 /// FrameworkunifiedOnExit
382 /// state cleanup can be performed in this function.
383 ///////////////////////////////////////////////////////////////////////////////////////////
384 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedApp::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
385   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
386   try {
387     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
388   } catch (std::exception &e) {
389     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
390     eStatus = eFrameworkunifiedStatusNullPointer;
391   }
392
393   return eStatus;
394 }
395
396 ///////////////////////////////////////////////////////////////////////////////////////////
397 /// CsFrameworkunifiedUserChange
398 /// Parameterized constructor
399 ///////////////////////////////////////////////////////////////////////////////////////////
400 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedUserChange::CsFrameworkunifiedUserChange(std::string f_pName): CFrameworkunifiedLeafState(f_pName) {
401 }
402
403 ///////////////////////////////////////////////////////////////////////////////////////////
404 /// ~CsFrameworkunifiedRoot
405 /// class destructor
406 ///////////////////////////////////////////////////////////////////////////////////////////
407 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedUserChange::~CsFrameworkunifiedUserChange() {
408 }
409
410 ///////////////////////////////////////////////////////////////////////////////////////////
411 /// FrameworkunifiedOnEntry
412 /// Initializes the application and registers the service availability notification
413 ///////////////////////////////////////////////////////////////////////////////////////////
414 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedUserChange::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
415   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
416   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
417
418   if (!FrameworkunifiedIsReactionAvailable(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedLoadUserData))) {
419     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, " Reaction not available for evFrameworkunifiedUserChangeComplete");
420     FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, " No reaction for loading user specific data ");
421
422     FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedUserChangeComplete));
423   } else {
424     FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedLoadUserData));
425   }
426
427   return eStatus;
428 }
429
430 ///////////////////////////////////////////////////////////////////////////////////////////
431 /// FrameworkunifiedOnExit
432 /// state cleanup can be performed in this function.
433 ///////////////////////////////////////////////////////////////////////////////////////////
434 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedUserChange::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
435   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
436   return eFrameworkunifiedStatusOK;
437 }
438
439
440 ///////////////////////////////////////////////////////////////////////////////////////////
441 /// CsFrameworkunifiedInitialization
442 /// Parameterized constructor
443 ///////////////////////////////////////////////////////////////////////////////////////////
444 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedInitialization::CsFrameworkunifiedInitialization(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {
445 }
446
447 ///////////////////////////////////////////////////////////////////////////////////////////
448 /// ~CsFrameworkunifiedInitialization
449 /// class destructor
450 ///////////////////////////////////////////////////////////////////////////////////////////
451 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedInitialization::~CsFrameworkunifiedInitialization() {
452 }
453
454 ///////////////////////////////////////////////////////////////////////////////////////////
455 /// FrameworkunifiedOnEntry
456 /// state initialization can be performed in this function.
457 ///////////////////////////////////////////////////////////////////////////////////////////
458 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedInitialization::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
459   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
460   try {
461     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
462   } catch (std::exception &e) {
463     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
464
465     eStatus = eFrameworkunifiedStatusNullPointer;
466   }
467
468   return eStatus;
469 }
470
471 ///////////////////////////////////////////////////////////////////////////////////////////
472 /// FrameworkunifiedOnExit
473 /// state cleanup can be performed in this function.
474 ///////////////////////////////////////////////////////////////////////////////////////////
475 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedInitialization::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
476   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
477   return eFrameworkunifiedStatusOK;
478 }
479
480 CFrameworkunifiedState *CFrameworkunifiedHSMParentFramework::COnEventUserChangeInInitializationState::FrameworkunifiedReaction(CFrameworkunifiedState *f_pSourceState,
481                                                                                         CEventDataPtr f_pEventData) {
482   try {
483     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "In Reaction OnEventUserChangeInInitializationState");
484     CHKNULL(f_pSourceState);
485
486     // post the event to move to sFrameworkunifiedApp state
487     f_pSourceState->FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedInit));
488   } catch (std::exception &e) {
489     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
490     return NULL;
491   }
492
493   return f_pSourceState;
494 }
495
496 ///////////////////////////////////////////////////////////////////////////////////////////
497 /// CsFrameworkunifiedLoadData
498 /// Parameterized constructor
499 ///////////////////////////////////////////////////////////////////////////////////////////
500 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadData::CsFrameworkunifiedLoadData(std::string f_pName): CFrameworkunifiedLeafState(f_pName) {
501 }
502
503 ///////////////////////////////////////////////////////////////////////////////////////////
504 /// CsFrameworkunifiedLoadData
505 /// Parameterized constructor
506 ///////////////////////////////////////////////////////////////////////////////////////////
507 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadData::~CsFrameworkunifiedLoadData() {
508 }
509
510 ///////////////////////////////////////////////////////////////////////////////////////////
511 /// FrameworkunifiedOnEntry
512 /// state initialization can be performed in this function.
513 ///////////////////////////////////////////////////////////////////////////////////////////
514 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadData::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
515   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
516   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
517   try {
518     HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
519     CHKNULL(l_pHApp);
520
521     CHKNULL(FrameworkunifiedGetStateMachine(l_pHApp));
522
523     UI_32 l_uiCurrentEventId = FrameworkunifiedGetStateMachine(l_pHApp)->m_uiCurrentEvent;
524     if (!(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedUserChangeComplete) == l_uiCurrentEventId)) {
525       if (FrameworkunifiedHSMOnLoadData) {
526         if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedHSMOnLoadData(l_pHApp))) {
527           FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to load application data:0x%X ", eStatus);
528         }
529       } else {
530         FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning: FrameworkunifiedHSMOnLoadData not defined by the application");
531       }
532
533       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedSubscribeNotificationWithHSMEvent(l_pHApp,
534                                                                           NTFY_NPPService_UserChange,
535                                                                           FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedUserChange)))) {
536         FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "FrameworkunifiedSubscribeNotificationWithHSMEvent "
537           "NTFY_NPPService_UserChange Failed Status:0x%x ", eStatus);
538         return eStatus;
539       }
540       // Attach callback : Event to start the StateMachine
541       if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedAttachHSMEventToDispatcher(l_pHApp,
542                                                                    FRAMEWORKUNIFIED_ANY_SOURCE,
543                                                                    NPS_GET_PERS_FILE_ACK,
544                                                                    FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedLoadFileAck)))) {
545         FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__,
546                "FrameworkunifiedAttachCallbackToDispatcher NPS_GET_PERS_FILE_ACK (FRAMEWORKUNIFIED_ANY_SOURCE) Failed Status:0x%x ", eStatus);
547         return eStatus;
548       }
549       if (!FrameworkunifiedIsReactionAvailable(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedLoadFileAck))) {
550         FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, " Reaction not available for evFrameworkunifiedLoadFileAck");
551
552         FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedLoadComplete));
553       }
554     } else {
555       FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedLoadComplete));
556     }
557   } catch (std::exception &e) {
558     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
559
560     eStatus = eFrameworkunifiedStatusNullPointer;
561   }
562
563   return eStatus;
564 }
565
566 ///////////////////////////////////////////////////////////////////////////////////////////
567 /// FrameworkunifiedOnExit
568 /// state cleanup can be performed in this function.
569 ///////////////////////////////////////////////////////////////////////////////////////////
570 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadData::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
571   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
572   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
573   try {
574     HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
575     CHKNULL(l_pHApp);
576
577     CFrameworkunifiedHSM *l_pHSM = FrameworkunifiedGetStateMachine(l_pHApp);
578     CHKNULL(l_pHSM);
579
580     UI_32 l_uiCurrentEventId = l_pHSM->m_uiCurrentEvent;
581
582     if (FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStop) == l_uiCurrentEventId) {
583       l_pHSM->RemoveEventFromPostedEventQueue(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStart));
584     }
585   } catch (std::exception &e) {
586     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
587
588     eStatus = eFrameworkunifiedStatusNullPointer;
589   }
590   return eStatus;
591 }
592
593 ///////////////////////////////////////////////////////////////////////////////////////////
594 /// CsFrameworkunifiedPre
595 /// Parameterized constructor
596 ///////////////////////////////////////////////////////////////////////////////////////////
597 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedPre::CsFrameworkunifiedPre(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {  // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)  // NOLINT(whitespace/line_length)
598 }
599
600 ///////////////////////////////////////////////////////////////////////////////////////////
601 /// ~CsFrameworkunifiedPre
602 /// class destructor
603 ///////////////////////////////////////////////////////////////////////////////////////////
604 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedPre::~CsFrameworkunifiedPre() {
605 }
606
607 ///////////////////////////////////////////////////////////////////////////////////////////
608 /// FrameworkunifiedOnEntry
609 /// state initialization can be performed in this function.
610 ///////////////////////////////////////////////////////////////////////////////////////////
611 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedPre::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
612   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
613   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
614
615   HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
616   CHKNULL(l_pHApp);  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
617   CHKNULL(f_pEventData);  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
618
619   // Only evFrameworkunifiedPreStart or evFrameworkunifiedPreStop events occur when functions are executed.
620   if (f_pEventData->m_uiEventId == FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedPreStart)) {
621     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnPreStartInternal +");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
622     eStatus = FrameworkunifiedOnPreStartInternal(l_pHApp);
623     if (eFrameworkunifiedStatusOK != eStatus) {
624       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to pre start application:0x%x ", eStatus);
625     }
626     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnPreStartInternal -");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
627   } else {
628     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnPreStopInternal +");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
629     eStatus = FrameworkunifiedOnPreStopInternal(l_pHApp);
630     if (eFrameworkunifiedStatusOK != eStatus) {
631       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to pre stop application:0x%x ", eStatus);
632     }
633     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnPreStopInternal -");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
634   }
635
636   return eStatus;
637 }
638
639 ///////////////////////////////////////////////////////////////////////////////////////////
640 /// FrameworkunifiedOnExit
641 /// state cleanup can be performed in this function.
642 ///////////////////////////////////////////////////////////////////////////////////////////
643 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedPre::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
644   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
645   return eFrameworkunifiedStatusOK;
646 }
647
648 ///////////////////////////////////////////////////////////////////////////////////////////
649 /// CsFrameworkunifiedBackground
650 /// Parameterized constructor
651 ///////////////////////////////////////////////////////////////////////////////////////////
652 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedBackground::CsFrameworkunifiedBackground(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {  // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)  // NOLINT(whitespace/line_length)
653 }
654
655 ///////////////////////////////////////////////////////////////////////////////////////////
656 /// ~CsFrameworkunifiedBackground
657 /// class destructor
658 ///////////////////////////////////////////////////////////////////////////////////////////
659 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedBackground::~CsFrameworkunifiedBackground() {
660 }
661
662 ///////////////////////////////////////////////////////////////////////////////////////////
663 /// FrameworkunifiedOnEntry
664 /// state initialization can be performed in this function.
665 ///////////////////////////////////////////////////////////////////////////////////////////
666 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedBackground::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
667   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
668   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
669
670   HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
671   CHKNULL(l_pHApp);  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
672   CHKNULL(f_pEventData);  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions
673
674   // Only evFrameworkunifiedBackgroundStart or evFrameworkunifiedBackgroundStop events occur when functions are executed.
675   if (f_pEventData->m_uiEventId == FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedBackgroundStart)) {
676     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnBackgroundStartInternal +");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
677     eStatus = FrameworkunifiedOnBackgroundStartInternal(l_pHApp);
678     if (eFrameworkunifiedStatusOK != eStatus) {
679       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to background start application:0x%x ", eStatus);
680     }
681     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnBackgroundStartInternal -");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
682   } else {
683     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnBackgroundStopInternal +");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
684     eStatus = FrameworkunifiedOnBackgroundStopInternal(l_pHApp);
685     if (eFrameworkunifiedStatusOK != eStatus) {
686       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to background stop application:0x%x ", eStatus);
687     }
688     FRAMEWORKUNIFIEDLOG_PERFORMANCE_DEBUG("FrameworkunifiedOnBackgroundStopInternal -");  // LCOV_EXCL_BR_LINE 15:Excluded due to inlined functions  // NOLINT(whitespace/line_length)
689   }
690
691   return eStatus;
692 }
693
694 ///////////////////////////////////////////////////////////////////////////////////////////
695 /// FrameworkunifiedOnExit
696 /// state cleanup can be performed in this function.
697 ///////////////////////////////////////////////////////////////////////////////////////////
698 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedBackground::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
699   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
700   return eFrameworkunifiedStatusOK;
701 }
702
703 ///////////////////////////////////////////////////////////////////////////////////////////
704 /// CsFrameworkunifiedRun
705 /// Parameterized constructor
706 ///////////////////////////////////////////////////////////////////////////////////////////
707 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRun::CsFrameworkunifiedRun(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {
708 }
709
710 ///////////////////////////////////////////////////////////////////////////////////////////
711 /// ~CsFrameworkunifiedRun
712 /// class destructor
713 ///////////////////////////////////////////////////////////////////////////////////////////
714 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRun::~CsFrameworkunifiedRun() {
715 }
716
717 ///////////////////////////////////////////////////////////////////////////////////////////
718 /// FrameworkunifiedOnEntry
719 /// Subscribes for the service availability notification and calls FrameworkunifiedOnStart
720 ///////////////////////////////////////////////////////////////////////////////////////////
721 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRun::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
722   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
723   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
724
725   try {
726     HANDLE hApp = FrameworkunifiedGetAppHandle();
727
728     if (frameworkunifiedCheckValidAppHandle(hApp)) {
729       FrameworkunifiedOnStartInternal(hApp);
730
731       CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
732
733       for (UI_32 l_uiCount = 0; l_uiCount < pApp->servicenotificationlist.size(); l_uiCount++) {
734         ServiceNotificationInfo objNotification = pApp->servicenotificationlist.at(l_uiCount);
735
736         if (eFrameworkunifiedStatusOK != (l_eStatus =  FrameworkunifiedSubscribeNotificationWithHSMEvent
737                                           (hApp, objNotification.sNotificationName, objNotification.uiEventId))) {
738           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "failed to subscribe notification %s"
739                  , objNotification.sNotificationName);
740         } else {
741           FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "successfully subscribe notification %s"
742                  , objNotification.sNotificationName);
743         }
744       }
745     } else {
746       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__, "Application handle is NULL");
747     }
748   } catch (std::exception &e) {
749     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
750
751     l_eStatus = eFrameworkunifiedStatusNullPointer;
752   }
753
754   return l_eStatus;
755 }
756
757 ///////////////////////////////////////////////////////////////////////////////////////////
758 /// FrameworkunifiedOnExit
759 /// state cleanup can be performed in this function.
760 ///////////////////////////////////////////////////////////////////////////////////////////
761 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedRun::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
762   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
763   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
764
765   try {
766     HANDLE hApp = FrameworkunifiedGetAppHandle();
767     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
768
769     if (frameworkunifiedCheckValidAppHandle(hApp)) {
770       // Let application also handle exit of sFrameworkunifiedRun state
771       if (FrameworkunifiedHSMOnStopInsFrameworkunifiedRun) {
772         if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedHSMOnStopInsFrameworkunifiedRun(hApp))) {
773           FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning: FrameworkunifiedHSMOnStopInsFrameworkunifiedRun returned: 0x%X ", l_eStatus);
774         }
775       } else {
776         FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning: FrameworkunifiedHSMOnStopInsFrameworkunifiedRun not defined by the application");
777       }
778
779       for (UI_32 l_uiCount = 0; l_uiCount < pApp->servicenotificationlist.size(); l_uiCount++) {
780         ServiceNotificationInfo objNotification = pApp->servicenotificationlist.at(l_uiCount);
781
782         if (eFrameworkunifiedStatusOK != (l_eStatus =  FrameworkunifiedUnsubscribeNotificationWithHSMEvent(hApp,
783                                                                                  objNotification.sNotificationName))) {
784           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "failed to unsubscribe notification %s",
785                  objNotification.sNotificationName);
786         } else {
787           FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "successfully unsubscribed from notification %s",
788                  objNotification.sNotificationName);
789         }
790       }
791     } else {
792       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __PRETTY_FUNCTION__, "Application handle is NULL");
793     }
794   } catch (std::exception &e) {
795     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
796
797     l_eStatus = eFrameworkunifiedStatusNullPointer;
798   }
799   return l_eStatus;
800 }
801
802 CFrameworkunifiedState *CFrameworkunifiedHSMParentFramework::COnEventUserChangeInRunState::FrameworkunifiedReaction(CFrameworkunifiedState *f_pSourceState,
803                                                                              CEventDataPtr f_pEventData) {
804   try {
805     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "In Reaction OnEventUserChangeInRunState");
806     CHKNULL(f_pSourceState);
807
808     // post the event to move to sFrameworkunifiedApp state
809     f_pSourceState->FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedInit));
810
811     CHKNULL(f_pSourceState);
812
813     // post the event to move to sFrameworkunifiedRun state
814     f_pSourceState->FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStart));
815   } catch (std::exception &e) {
816     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
817     return NULL;
818   }
819   return f_pSourceState;
820 }
821
822 ///////////////////////////////////////////////////////////////////////////////////////////
823 /// CsFrameworkunifiedLoadSessions
824 /// Parameterized constructor
825 ///////////////////////////////////////////////////////////////////////////////////////////
826 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadSessions::CsFrameworkunifiedLoadSessions(std::string f_pName): CFrameworkunifiedLeafState(f_pName) {
827 }
828
829 ///////////////////////////////////////////////////////////////////////////////////////////
830 /// ~CsFrameworkunifiedLoadSessions
831 /// class destructor
832 ///////////////////////////////////////////////////////////////////////////////////////////
833 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadSessions::~CsFrameworkunifiedLoadSessions() {
834 }
835
836 ///////////////////////////////////////////////////////////////////////////////////////////
837 /// FrameworkunifiedOnEntry
838 /// state initialization can be performed in this function.
839 ///////////////////////////////////////////////////////////////////////////////////////////
840 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadSessions::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
841   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
842   try {
843     FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
844
845     HANDLE hApp = FrameworkunifiedGetAppHandle();
846     CHKNULL(hApp);
847
848     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast<CFrameworkunifiedFrameworkApp *>(hApp);
849
850     if (!pApp->servicenotificationlist.size()) {
851       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, " No Mandatory services set ");
852
853       FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedReady));
854     } else {
855       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_DEV_INFO, __FUNCTION__, " Wait for service availability of mandatory services ");
856     }
857   } catch (std::exception &e) {
858     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
859
860     l_eStatus = eFrameworkunifiedStatusNullPointer;
861   }
862
863   return l_eStatus;
864 }
865
866 ///////////////////////////////////////////////////////////////////////////////////////////
867 /// FrameworkunifiedOnExit
868 /// state cleanup can be performed in this function.
869 ///////////////////////////////////////////////////////////////////////////////////////////
870 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedLoadSessions::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
871   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
872   return eFrameworkunifiedStatusOK;
873 }
874
875 ///////////////////////////////////////////////////////////////////////////////////////////
876 /// CsFrameworkunifiedReady
877 /// Parameterized constructor
878 ///////////////////////////////////////////////////////////////////////////////////////////
879 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedReady::CsFrameworkunifiedReady(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {
880 }
881
882 ///////////////////////////////////////////////////////////////////////////////////////////
883 /// ~CsFrameworkunifiedReady
884 /// class destructor
885 ///////////////////////////////////////////////////////////////////////////////////////////
886 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedReady::~CsFrameworkunifiedReady() {
887 }
888
889 ///////////////////////////////////////////////////////////////////////////////////////////
890 /// FrameworkunifiedOnEntry
891 /// state initialization can be performed in this function.
892 ///////////////////////////////////////////////////////////////////////////////////////////
893 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedReady::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
894   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
895   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
896   try {
897     HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
898     CHKNULL(l_pHApp);
899     if (FrameworkunifiedIsAutoPublishServiceAvailableEnabled()) {  // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
900       // Publish Service available this can also be published from FrameworkunifiedOnStart callback
901       if (eFrameworkunifiedStatusOK != (FrameworkunifiedPublishServiceAvailability(l_pHApp, TRUE))) {
902         FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "warning:Failed to Publish service availability notification:0x%x ",
903           l_eStatus);
904       } else {
905         FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Service available published");
906       }
907     } else {
908       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Auto Service available published feature disabled");
909     }
910   } catch (std::exception &e) {
911     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
912
913     l_eStatus = eFrameworkunifiedStatusNullPointer;
914   }
915   return l_eStatus;
916 }
917
918 ///////////////////////////////////////////////////////////////////////////////////////////
919 /// FrameworkunifiedOnExit
920 /// state cleanup can be performed in this function.
921 ///////////////////////////////////////////////////////////////////////////////////////////
922 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedReady::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
923   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
924   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
925   try {
926     ServiceSessionTable::iterator session_iterator;
927     SessionHandleTable::iterator session_handle_iterator;
928
929     HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
930     CHKNULL(l_pHApp);
931
932     if (FrameworkunifiedIsAutoPublishServiceAvailableEnabled()) {  // LCOV_EXCL_BR_LINE 11:Excluded due to gcov constraints (others)
933       // Publish Service available this can also be published from FrameworkunifiedOnStart callback
934       if (eFrameworkunifiedStatusOK != (FrameworkunifiedPublishServiceAvailability(l_pHApp, FALSE))) {
935         FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning:Failed to set service availability notification:0x%x ", l_eStatus);
936       } else {
937         FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Service unavailable published");
938       }
939     } else {
940       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Auto Service available published feature disabled");
941     }
942   } catch (std::exception &e) {
943     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
944
945     l_eStatus = eFrameworkunifiedStatusNullPointer;
946   }
947   return l_eStatus;
948 }
949
950 ///////////////////////////////////////////////////////////////////////////////////////////
951 /// CsFrameworkunifiedStop
952 /// Parameterized constructor
953 ///////////////////////////////////////////////////////////////////////////////////////////
954 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStop::CsFrameworkunifiedStop(std::string f_pName): CFrameworkunifiedCompositeState(f_pName) {
955 }
956
957 ///////////////////////////////////////////////////////////////////////////////////////////
958 /// ~CsFrameworkunifiedStop
959 /// class destructor
960 ///////////////////////////////////////////////////////////////////////////////////////////
961 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStop::~CsFrameworkunifiedStop() {
962 }
963
964 ///////////////////////////////////////////////////////////////////////////////////////////
965 /// FrameworkunifiedOnEntry
966 /// state initialization can be performed in this function.
967 ///////////////////////////////////////////////////////////////////////////////////////////
968 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStop::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
969   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
970   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
971   try {
972     HANDLE l_pHApp = FrameworkunifiedGetAppHandle();
973     CHKNULL(l_pHApp);
974
975     // every application need to implement this function
976     // all the resource deallocation like file release,etc should be done in this callback
977     l_eStatus = FrameworkunifiedOnStopInternal(l_pHApp);
978     if (eFrameworkunifiedStatusOK != l_eStatus) {
979       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "WARNING: FrameworkunifiedOnStop returned %d", l_eStatus);
980       // We just need to print the error.
981       // Returning this status to state machine is not required.
982       // Currently, If not OK is sent to state machine while FrameworkunifiedOnEntry, then state machine becomes dead.
983       l_eStatus = eFrameworkunifiedStatusOK;  // Therefore assign ok.
984     }
985   } catch (std::exception &e) {
986     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
987     l_eStatus = eFrameworkunifiedStatusNullPointer;
988   }
989   return l_eStatus;
990 }
991
992 ///////////////////////////////////////////////////////////////////////////////////////////
993 /// FrameworkunifiedOnExit
994 /// state cleanup can be performed in this function.
995 ///////////////////////////////////////////////////////////////////////////////////////////
996 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStop::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
997   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
998   return eFrameworkunifiedStatusOK;
999 }
1000
1001 ///////////////////////////////////////////////////////////////////////////////////////////
1002 /// CsFrameworkunifiedStopping
1003 /// Parameterized constructor
1004 ///////////////////////////////////////////////////////////////////////////////////////////
1005 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStopping::CsFrameworkunifiedStopping(std::string f_pName): CFrameworkunifiedLeafState(f_pName) {
1006 }
1007
1008 ///////////////////////////////////////////////////////////////////////////////////////////
1009 /// ~CsFrameworkunifiedStopping
1010 /// class destructor
1011 ///////////////////////////////////////////////////////////////////////////////////////////
1012 CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStopping::~CsFrameworkunifiedStopping() {
1013 }
1014
1015 ///////////////////////////////////////////////////////////////////////////////////////////
1016 /// FrameworkunifiedOnEntry
1017 /// state initialization can be performed in this function.
1018 ///////////////////////////////////////////////////////////////////////////////////////////
1019 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStopping::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
1020   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1021   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
1022   try {
1023     if (FrameworkunifiedIsWaitInStoppingStateEnabled()) {
1024       FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Event evFrameworkunifiedStopComplete not posted. User has to post it.");
1025     } else {
1026       FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Reaction not available for evFrameworkunifiedStopAck");
1027       FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, "Posting event evFrameworkunifiedStopComplete");
1028       FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStopComplete));
1029     }
1030   } catch (std::exception &e) {
1031     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1032     l_eStatus = eFrameworkunifiedStatusNullPointer;
1033   }
1034   return l_eStatus;
1035 }
1036
1037 ///////////////////////////////////////////////////////////////////////////////////////////
1038 /// FrameworkunifiedOnExit
1039 /// state cleanup can be performed in this function.
1040 ///////////////////////////////////////////////////////////////////////////////////////////
1041 EFrameworkunifiedStatus CFrameworkunifiedHSMParentFramework::CsFrameworkunifiedStopping::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
1042   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
1043   return eFrameworkunifiedStatusOK;
1044 }
1045
1046 CFrameworkunifiedState *CFrameworkunifiedHSMParentFramework::COnEventStopInStoppingState::FrameworkunifiedReaction(CFrameworkunifiedState *f_pSourceState,
1047                                                                             CEventDataPtr f_pEventData) {
1048   try {
1049     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "In Reaction OnEventStopInStoppingState");
1050     CHKNULL(f_pSourceState);
1051
1052     (VOID)f_pSourceState->FrameworkunifiedRemoveEventFromDeferredEventList(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStart));
1053   } catch (std::exception &e) {
1054     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1055     return NULL;
1056   }
1057   return f_pSourceState;
1058 }
1059
1060 CFrameworkunifiedState *CFrameworkunifiedHSMParentFramework::COnEventStartInStopState::FrameworkunifiedReaction(CFrameworkunifiedState *f_pSourceState,
1061                                                                          CEventDataPtr f_pEventData) {
1062   try {
1063     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "In Reaction OnEventStartInStopState");
1064     CHKNULL(f_pSourceState);
1065
1066     // post the event to move to sFrameworkunifiedApp state
1067     f_pSourceState->FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedInit));
1068
1069     CHKNULL(f_pSourceState);
1070
1071     // post the event to transit to sFrameworkunifiedRun state
1072     f_pSourceState->FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedStart));
1073   } catch (std::exception &e) {
1074     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1075     return NULL;
1076   }
1077   return f_pSourceState;
1078 }
1079
1080 VOID CFrameworkunifiedHSMParentFramework::CaFrameworkunifiedOnStop::FrameworkunifiedAction(CFrameworkunifiedState *f_pSourceState, CFrameworkunifiedState *f_pTargetState,
1081                                                     CEventDataPtr f_pData) {
1082   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, "In Action %s", m_strName.c_str());
1083
1084   HANDLE l_pHApp = f_pSourceState->FrameworkunifiedGetAppHandle();
1085   if (NULL != l_pHApp) {
1086     FrameworkunifiedOnStopInternal(l_pHApp);
1087   } else {
1088     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Application handle is NULL in Action %s", m_strName.c_str());
1089   }
1090 }
1091
1092 CFrameworkunifiedHSMChildFramework::CFrameworkunifiedHSMChildFramework(): CFrameworkunifiedHSMFramework() {
1093 }
1094
1095
1096 CFrameworkunifiedHSMChildFramework::CFrameworkunifiedHSMChildFramework(PVOID f_pHApp): CFrameworkunifiedHSMFramework(f_pHApp) {
1097   try {
1098     m_pFrameworkunifiedStateList = new std::map<UI_32, CFrameworkunifiedState *>();
1099   } catch (std::exception &e) {
1100     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1101   }
1102 }
1103
1104 CFrameworkunifiedHSMChildFramework::~CFrameworkunifiedHSMChildFramework() {
1105 }
1106
1107 ///////////////////////////////////////////////////////////////////////////////////////////
1108 /// FrameworkunifiedCreate
1109 /// Statemachine states and events created and connected in this interface.
1110 ///////////////////////////////////////////////////////////////////////////////////////////
1111 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::FrameworkunifiedCreate(PVOID f_pEventData) {
1112   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1113   try {
1114     // Create states
1115     CREATE_STATE(sFrameworkunifiedThreadRoot)
1116     CREATE_STATE(sFrameworkunifiedThreadIdle)
1117     CREATE_STATE(sFrameworkunifiedThreadStart)
1118     CREATE_STATE(sFrameworkunifiedThreadReady)
1119     CREATE_STATE(sFrameworkunifiedThreadStop)
1120
1121     // connect states as per the statemachine
1122     CONNECT_DEFAULTSTATE(sFrameworkunifiedThreadRoot, sFrameworkunifiedThreadIdle)
1123     CONNECT_STATE(sFrameworkunifiedThreadRoot, sFrameworkunifiedThreadStart)
1124     CONNECT_STATE(sFrameworkunifiedThreadRoot, sFrameworkunifiedThreadStop)
1125     CONNECT_STATE(sFrameworkunifiedThreadRoot, sFrameworkunifiedThreadReady)
1126
1127     // Create External Transition
1128     CREATE_EXTERNALTRANSITION(sFrameworkunifiedThreadIdle)
1129     CREATE_EXTERNALTRANSITION(sFrameworkunifiedThreadStart)
1130     CREATE_EXTERNALTRANSITION(sFrameworkunifiedThreadReady)
1131     CREATE_EXTERNALTRANSITION(sFrameworkunifiedThreadStop)
1132
1133     // Connect events to state
1134     CONNECT_EVENT(sFrameworkunifiedThreadIdle, evFrameworkunifiedStart, sFrameworkunifiedThreadStart)
1135     CONNECT_EVENT(sFrameworkunifiedThreadStart, evFrameworkunifiedReady, sFrameworkunifiedThreadReady)
1136     CONNECT_EVENT(sFrameworkunifiedThreadStart, evFrameworkunifiedError, sFrameworkunifiedThreadIdle)
1137     CONNECT_EVENT(sFrameworkunifiedThreadReady, evFrameworkunifiedStop, sFrameworkunifiedThreadStop)
1138     CONNECT_EVENT(sFrameworkunifiedThreadStop, evFrameworkunifiedStart, sFrameworkunifiedThreadStart)
1139
1140     // Create Internal Transition
1141     CREATE_INTERNALTRANSITION(OnDestroyThread)
1142     CONNECT_EVENT(sFrameworkunifiedThreadRoot, evFrameworkunifiedDestroy, OnDestroyThread)
1143
1144     // Connecting AppRoot to statemachine
1145     CONNECTROOT(sFrameworkunifiedThreadRoot)
1146   } catch (std::exception &e) {
1147     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1148
1149     eStatus = eFrameworkunifiedStatusNullPointer;
1150   }
1151   return eStatus;
1152 }
1153
1154 ///////////////////////////////////////////////////////////////////////////////////////////
1155 /// COnDestroyThread::FrameworkunifiedReaction
1156 /// This reaction is executed when request for terminating the thread is received.
1157 ///////////////////////////////////////////////////////////////////////////////////////////
1158 CFrameworkunifiedState *CFrameworkunifiedHSMChildFramework::COnDestroyThread::FrameworkunifiedReaction(CFrameworkunifiedState *f_pSourceState,
1159                                                                 CEventDataPtr f_pEventData) {
1160   // return the NULL to exit the dispatcher loop of thread
1161   return NULL;
1162 }
1163
1164 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::FrameworkunifiedFrameworkConnect(CFrameworkunifiedState *f_pAppState, BOOL f_bIsDefaultState) {
1165   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1166   try {
1167     CHKNULL(m_pFrameworkunifiedStateList);
1168     CHKNULL(f_pAppState);
1169
1170     if (m_pFrameworkunifiedStateList->find(esFrameworkunifiedThreadReady) == m_pFrameworkunifiedStateList->end()) {
1171       throw CNullPointerException();
1172     }
1173     CFrameworkunifiedState *l_pReady = reinterpret_cast<CFrameworkunifiedCompositeState *>(m_pFrameworkunifiedStateList->find(esFrameworkunifiedThreadReady)->second);
1174     CHKNULL(l_pReady);
1175
1176     eStatus = FrameworkunifiedConnect(l_pReady, f_pAppState, f_bIsDefaultState);
1177   } catch (std::exception &e) {
1178     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1179
1180     eStatus = eFrameworkunifiedStatusNullPointer;
1181   }
1182   return eStatus;
1183 }
1184
1185 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::FrameworkunifiedFrameworkConnect(FRAMEWORKUNIFIED_HSM_STATES f_eFrameworkunifiedState, UI_32 f_uiEventId,
1186                                                       CFrameworkunifiedReaction *f_pReaction,
1187                                                       std::string f_strEventName, BOOL f_bIsDeferredEvent) {
1188   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1189   try {
1190     CHKNULL(m_pFrameworkunifiedStateList);
1191
1192     if (m_pFrameworkunifiedStateList->find(f_eFrameworkunifiedState) == m_pFrameworkunifiedStateList->end()) {
1193       throw CNullPointerException();
1194     }
1195     CFrameworkunifiedState *l_pFrameworkunifiedState = reinterpret_cast<CFrameworkunifiedCompositeState *>(m_pFrameworkunifiedStateList->find(f_eFrameworkunifiedState)->second);
1196
1197     CHKNULL(l_pFrameworkunifiedState);
1198
1199     eStatus = FrameworkunifiedConnect(l_pFrameworkunifiedState, f_uiEventId, f_pReaction, f_strEventName, f_bIsDeferredEvent);
1200   } catch (std::exception &e) {
1201     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1202
1203     eStatus = eFrameworkunifiedStatusNullPointer;
1204   }
1205   return eStatus;
1206 }
1207
1208 ///////////////////////////////////////////////////////////////////////////////////////////
1209 /// CFrameworkunifiedThreadRoot
1210 /// Parameterized constructor
1211 ///////////////////////////////////////////////////////////////////////////////////////////
1212 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadRoot::CsFrameworkunifiedThreadRoot(std::string f_pName)
1213   : CFrameworkunifiedCompositeState(f_pName) {
1214 }
1215
1216 ///////////////////////////////////////////////////////////////////////////////////////////
1217 /// ~CsFrameworkunifiedThreadRoot
1218 /// class destructor
1219 ///////////////////////////////////////////////////////////////////////////////////////////
1220 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadRoot::~CsFrameworkunifiedThreadRoot() {
1221 }
1222
1223 ///////////////////////////////////////////////////////////////////////////////////////////
1224 /// FrameworkunifiedOnEntry
1225 /// publishes the service availability notification
1226 ///////////////////////////////////////////////////////////////////////////////////////////
1227 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadRoot::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
1228   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1229   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
1230   return eStatus;
1231 }
1232
1233 ///////////////////////////////////////////////////////////////////////////////////////////
1234 /// FrameworkunifiedOnExit
1235 /// state cleanup can be performed in this function.
1236 ///////////////////////////////////////////////////////////////////////////////////////////
1237 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadRoot::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
1238   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
1239   return eFrameworkunifiedStatusOK;
1240 }
1241
1242 ///////////////////////////////////////////////////////////////////////////////////////////
1243 /// CFrameworkunifiedThreadIdle
1244 /// Parameterized constructor
1245 ///////////////////////////////////////////////////////////////////////////////////////////
1246 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadIdle::CsFrameworkunifiedThreadIdle(std::string f_pName)
1247   : CFrameworkunifiedCompositeState(f_pName) {
1248 }
1249
1250 ///////////////////////////////////////////////////////////////////////////////////////////
1251 /// ~CsFrameworkunifiedThreadIdle
1252 /// class destructor
1253 ///////////////////////////////////////////////////////////////////////////////////////////
1254 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadIdle::~CsFrameworkunifiedThreadIdle() {
1255 }
1256
1257 ///////////////////////////////////////////////////////////////////////////////////////////
1258 /// FrameworkunifiedOnEntry
1259 /// publishes the service availability notification
1260 ///////////////////////////////////////////////////////////////////////////////////////////
1261 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadIdle::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
1262   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1263   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
1264   return eStatus;
1265 }
1266
1267 ///////////////////////////////////////////////////////////////////////////////////////////
1268 /// FrameworkunifiedOnExit
1269 /// state cleanup can be performed in this function.
1270 ///////////////////////////////////////////////////////////////////////////////////////////
1271 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadIdle::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
1272   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
1273   return eFrameworkunifiedStatusOK;
1274 }
1275
1276 ///////////////////////////////////////////////////////////////////////////////////////////
1277 /// CFrameworkunifiedThreadStart
1278 /// Parameterized constructor
1279 ///////////////////////////////////////////////////////////////////////////////////////////
1280 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStart::CsFrameworkunifiedThreadStart(std::string f_pName)
1281   : CFrameworkunifiedCompositeState(f_pName) {
1282 }
1283
1284 ///////////////////////////////////////////////////////////////////////////////////////////
1285 /// ~CsFrameworkunifiedThreadStart
1286 /// class destructor
1287 ///////////////////////////////////////////////////////////////////////////////////////////
1288 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStart::~CsFrameworkunifiedThreadStart() {
1289 }
1290
1291 ///////////////////////////////////////////////////////////////////////////////////////////
1292 /// FrameworkunifiedOnEntry
1293 /// publishes the service availability notification
1294 ///////////////////////////////////////////////////////////////////////////////////////////
1295 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStart::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
1296   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1297
1298   try {
1299     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
1300
1301     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >
1302                              (FrameworkunifiedGetAppHandle());
1303     CHKNULL(reinterpret_cast<CFrameworkunifiedHSMChildFramework *>(pApp->m_pFrameworkunifiedStateMachine));
1304     CHKNULL((reinterpret_cast<CFrameworkunifiedHSMChildFramework *>(pApp->m_pFrameworkunifiedStateMachine))->m_fpStartThread);
1305     if (eFrameworkunifiedStatusOK ==
1306         (reinterpret_cast<CFrameworkunifiedHSMChildFramework *>(pApp->m_pFrameworkunifiedStateMachine))->m_fpStartThread(pApp)) {
1307       FrameworkunifiedPostEvent(FRAMEWORKUNIFIED_EVENT(evFrameworkunifiedReady));
1308     } else {
1309       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, " Thread start Failed: %s", m_strStateName.c_str());
1310     }
1311   } catch (std::exception &e) {
1312     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1313
1314     eStatus = eFrameworkunifiedStatusNullPointer;
1315   }
1316
1317   return eStatus;
1318 }
1319
1320 ///////////////////////////////////////////////////////////////////////////////////////////
1321 /// FrameworkunifiedOnExit
1322 /// state cleanup can be performed in this function.
1323 ///////////////////////////////////////////////////////////////////////////////////////////
1324 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStart::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
1325   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
1326   return eFrameworkunifiedStatusOK;
1327 }
1328
1329 ///////////////////////////////////////////////////////////////////////////////////////////
1330 /// CFrameworkunifiedThreadReady
1331 /// Parameterized constructor
1332 ///////////////////////////////////////////////////////////////////////////////////////////
1333 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadReady::CsFrameworkunifiedThreadReady(std::string f_pName)
1334   : CFrameworkunifiedCompositeState(f_pName) {
1335 }
1336
1337 ///////////////////////////////////////////////////////////////////////////////////////////
1338 /// ~CsFrameworkunifiedThreadReady
1339 /// class destructor
1340 ///////////////////////////////////////////////////////////////////////////////////////////
1341 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadReady::~CsFrameworkunifiedThreadReady() {
1342 }
1343
1344 ///////////////////////////////////////////////////////////////////////////////////////////
1345 /// FrameworkunifiedOnEntry
1346 /// publishes the service availability notification
1347 ///////////////////////////////////////////////////////////////////////////////////////////
1348 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadReady::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
1349   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1350   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
1351   return eStatus;
1352 }
1353
1354 ///////////////////////////////////////////////////////////////////////////////////////////
1355 /// FrameworkunifiedOnExit
1356 /// state cleanup can be performed in this function.
1357 ///////////////////////////////////////////////////////////////////////////////////////////
1358 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadReady::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
1359   FRAMEWORKUNIFIEDLOG(ZONE_NS_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
1360   return eFrameworkunifiedStatusOK;
1361 }
1362
1363 ///////////////////////////////////////////////////////////////////////////////////////////
1364 /// CFrameworkunifiedThreadStop
1365 /// Parameterized constructor
1366 ///////////////////////////////////////////////////////////////////////////////////////////
1367 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStop::CsFrameworkunifiedThreadStop(std::string f_pName)
1368   : CFrameworkunifiedLeafState(f_pName) {
1369 }
1370
1371 ///////////////////////////////////////////////////////////////////////////////////////////
1372 /// ~CsFrameworkunifiedThreadStop
1373 /// class destructor
1374 ///////////////////////////////////////////////////////////////////////////////////////////
1375 CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStop::~CsFrameworkunifiedThreadStop() {
1376 }
1377
1378 ///////////////////////////////////////////////////////////////////////////////////////////
1379 /// FrameworkunifiedOnEntry
1380 /// publishes the service availability notification
1381 ///////////////////////////////////////////////////////////////////////////////////////////
1382 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStop::FrameworkunifiedOnEntry(CEventDataPtr f_pEventData) {
1383   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
1384   try {
1385     FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Entering state %s ", m_strStateName.c_str());
1386
1387     HANDLE hApp = FrameworkunifiedGetAppHandle();
1388     CHKNULL(hApp);
1389     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >
1390                              (hApp);
1391     CHKNULL(reinterpret_cast<CFrameworkunifiedHSMChildFramework *>(pApp->m_pFrameworkunifiedStateMachine));
1392     CHKNULL((reinterpret_cast<CFrameworkunifiedHSMChildFramework *>(pApp->m_pFrameworkunifiedStateMachine))->m_fpStopThread);
1393
1394     eStatus = (reinterpret_cast<CFrameworkunifiedHSMChildFramework *>(pApp->m_pFrameworkunifiedStateMachine))->m_fpStopThread(pApp);
1395
1396     if (eFrameworkunifiedStatusOK != eStatus) {
1397       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "WARNING: Thread stop function returned %d", eStatus);
1398       // We just need to print the error.
1399       // Returning this status to state machine is not required.
1400       // Currently, If not OK is sent to state machine while FrameworkunifiedOnEntry, then state machine becomes dead.
1401       eStatus = eFrameworkunifiedStatusOK;  // Therefore assign ok.
1402     }
1403   } catch (std::exception &e) {
1404     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Exception %s", e.what());
1405
1406     eStatus = eFrameworkunifiedStatusNullPointer;
1407   }
1408
1409   return eStatus;
1410 }
1411
1412 ///////////////////////////////////////////////////////////////////////////////////////////
1413 /// FrameworkunifiedOnExit
1414 /// state cleanup can be performed in this function.
1415 ///////////////////////////////////////////////////////////////////////////////////////////
1416 EFrameworkunifiedStatus CFrameworkunifiedHSMChildFramework::CsFrameworkunifiedThreadStop::FrameworkunifiedOnExit(CEventDataPtr f_pEventData) {
1417   FRAMEWORKUNIFIEDLOG(ZONE_NS_SM_USR_INFO, __FUNCTION__, " Leaving state %s ", m_strStateName.c_str());
1418   return eFrameworkunifiedStatusOK;
1419 }