Remove unused directories and files in video_in_hal
[staging/basesystem.git] / service / native / framework_unified / client / NS_FrameworkCore / src / frameworkunified_multithreading.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 /// \ingroup  tag_NSFramework
19 /// \brief    Framework wrapper over the service directory interface APIs
20 ///
21 ///
22 ///
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include <pthread.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <sys/prctl.h>
29 #include <sys/resource.h>
30 #include <sys/syscall.h>
31
32 #include <native_service/frameworkunified_dispatcher.h>
33 #include <native_service/frameworkunified_multithreading.h>
34 #include <native_service/ns_utility.hpp>
35 #include <native_service/ns_message_center_if.h>
36 #include <native_service/frameworkunified_framework_if.h>
37 #include <native_service/ns_system_mode.h>
38 #include <native_service/ns_logger_if.h>
39 #include <native_service/frameworkunified_sm_hsmframework.h>
40 #include <native_service/frameworkunified_sm_framework_dispatch.h>
41
42 #include <iostream>
43
44 #ifdef DISPATCHER_PROFILER
45 #include <boost/bind.hpp>
46 #include "frameworkunified_msgprofiler.h"
47 #endif
48
49 #include "frameworkunified_framework_core.h"
50 #include "frameworkunified_framework_utility.h"
51 #include "frameworkunified_framework_internal.h"
52 #include "frameworkunified_sm_multithreading_internal.h"
53
54 __thread HANDLE responseWaitQ = NULL;
55
56 ////////////////////////////////////////////////////////////////////////////////////////////
57 /// IsValidWaitBarrier
58 ////////////////////////////////////////////////////////////////////////////////////////////
59 bool IsValidWaitBarrier(int wbret) {
60   return (PTHREAD_BARRIER_SERIAL_THREAD == wbret) ||
61          (0                             == wbret);
62 }
63
64 ////////////////////////////////////////////////////////////////////////////////////////////
65 /// DestroyThread
66 ////////////////////////////////////////////////////////////////////////////////////////////
67 EFrameworkunifiedStatus DestroyThread(HANDLE hApp) {
68   // terminates the dispatcher loop to destroy the thread
69   if (responseWaitQ != NULL) {
70     /**
71      * @todo
72      * The responseWaitQ is set in the FrameworkunifiedInvokeSync and is closed in the callback process (DestroyThread) of the FrameworkunifiedDestroyChildThread.
73      * Therefore, the responseWaitQ is not closed when FrameworkunifiedInvokeSync is used on the parent.
74      */
75     McClose(responseWaitQ);
76     responseWaitQ = NULL;
77   }
78   return eFrameworkunifiedStatusExit;
79 }
80
81 ////////////////////////////////////////////////////////////////////////////////////////////
82 /// setChildThreadSched
83 ////////////////////////////////////////////////////////////////////////////////////////////
84 EFrameworkunifiedStatus setChildThreadSched(EFrameworkunifiedSchedPolicy policy, SI_32 priority) {
85   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
86   struct sched_param param;
87   int get_policy, set_policy;
88   int set_priority;
89
90   if (pthread_getschedparam(pthread_self(), &get_policy, &param) != 0) {
91     // LCOV_EXCL_BR_START 15:marco defined in "native_service/ns_logger_if.h"
92     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: pthread_getschedparam errno:%d", errno);
93     // LCOV_EXCL_BR_STOP
94     return eFrameworkunifiedStatusFail;
95   }
96
97   if (policy == eFrameworkunifiedSchedPolicyInherit) {
98     set_policy = get_policy;
99   } else {
100     if (policy == eFrameworkunifiedSchedPolicyFIFO) {
101       set_policy = SCHED_FIFO;
102     } else if (policy == eFrameworkunifiedSchedPolicyRR) {
103       set_policy = SCHED_RR;
104     } else {
105       set_policy = SCHED_OTHER;
106     }
107   }
108
109   if (priority == INHERIT_PARENT_THREAD_PRIO) {
110     if (get_policy != set_policy) {
111       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __FUNCTION__, "Warning: Change policy(%d-%d) but inherit priority", get_policy, set_policy);
112
113       if (set_policy == SCHED_OTHER) {
114         set_priority = 0;
115       } else {
116         set_priority = sched_get_priority_min(set_policy);
117       }
118     } else {
119       set_priority = param.sched_priority;
120     }
121   } else {
122     set_priority = priority;
123   }
124
125   switch (set_policy) {
126     case SCHED_OTHER:
127       param.sched_priority = 0;
128       if (pthread_setschedparam(pthread_self(), SCHED_OTHER, &param) != 0) {
129         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: pthread_setschedparam errno:%d", errno);
130         eStatus = eFrameworkunifiedStatusFail;
131       } else {
132         if (setpriority(PRIO_PROCESS, static_cast<int>(syscall(__NR_gettid)), set_priority) != 0) {
133           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: setpriority errno:%d", errno);
134           eStatus = eFrameworkunifiedStatusFail;
135         }
136       }
137       break;
138
139     case SCHED_FIFO:
140     case SCHED_RR:
141       param.sched_priority = set_priority;
142       if (pthread_setschedparam(pthread_self(), set_policy, &param) != 0) {
143         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: pthread_setschedparam errno:%d", errno);
144         eStatus = eFrameworkunifiedStatusFail;
145       }
146       break;
147   }
148
149   return eStatus;
150 }
151
152 ////////////////////////////////////////////////////////////////////////////////////////////
153 /// child_thread_proc
154 ////////////////////////////////////////////////////////////////////////////////////////////
155 void *child_thread_proc(void *args) {
156   if (args == NULL) {
157     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "args is NULL");
158     return NULL;
159   }
160   PCData pcdata = *reinterpret_cast< PCData * >(args);   // Create a local copy of data
161
162   try {
163     EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
164     HANDLE hApp = NULL;
165
166     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedCreateDispatcherChild(hApp,
167                                                             pcdata.childName.c_str(),
168                                                             pcdata.parentName.c_str()))) {
169       // LCOV_EXCL_BR_START 200: If FrameworkunifiedCreateDispatcherChild return eFrameworkunifiedStatusOK, hApp would also be valid.
170       if (frameworkunifiedCheckValidAppHandle(hApp)) {
171       // LCOV_EXCL_BR_STOP
172         THApp hChildApp(hApp);
173
174         const FrameworkunifiedProtocolCallbackHandler pcbhs[] = { { SYSTEM_ON_INITIALIZATION,    pcdata.initFn },
175           { SYSTEM_ON_SHUTDOWN,          pcdata.shdnFn },
176           { SYSTEM_ON_DESTROY,           DestroyThread }
177         };  // LCOV_EXCL_BR_LINE 11:except branch
178
179         if (eFrameworkunifiedStatusOK != FrameworkunifiedAttachCallbacksToDispatcher(hChildApp,
180                                                            pcdata.parentName.c_str(),
181                                                            &pcbhs[ 0 ],
182                                                            static_cast<UI_32>(_countof(pcbhs)))) {
183           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__,
184             "Error: Attaching child callbacks to dispatcher %s", pcdata.childName.c_str());
185         }
186
187         char thread_name[16];
188         strncpy(thread_name, pcdata.childName.c_str(), sizeof(thread_name));
189         prctl(PR_SET_NAME, thread_name);
190         thread_name[15] = '\0';
191
192         setChildThreadSched(pcdata.schedPolicy, pcdata.schedPriority);
193
194         *pcdata.childStatus = eFrameworkunifiedStatusOK;
195         if (IsValidWaitBarrier(pthread_barrier_wait(pcdata.barrier))) {
196           RunChildDispatcher(hChildApp);
197         }
198       } else {
199         // LCOV_EXCL_START 200: If FrameworkunifiedCreateDispatcherChild return eFrameworkunifiedStatusOK, hApp would also be valid.
200         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
201         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hApp is NULL");
202         // LCOV_EXCL_STOP
203       }
204     } else {
205       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedCreateDispatcherChild error, status=%d", eStatus);
206
207       *pcdata.childStatus = eFrameworkunifiedStatusFail;
208       pthread_barrier_wait(pcdata.barrier);
209     }
210   } catch (const THApp::Exception &) {
211     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Error: Failed to create child %s", pcdata.childName.c_str());
212   }
213
214   return NULL;
215 }
216
217 ////////////////////////////////////////////////////////////////////////////////////////////
218 /// CreateChildThread
219 ////////////////////////////////////////////////////////////////////////////////////////////
220 HANDLE CreateChildThread(HANDLE hApp, PCSTR childName, CbFuncPtr CbInitialize, CbFuncPtr CbShutdown,
221                          const FrameworkunifiedChildThreadAttr *attr, CbFuncPtr CbCreateStateMachine) {
222   HANDLE hChildQ = NULL;
223   pthread_attr_t tAttr;
224   pthread_attr_t *pAttr = NULL;
225   SI_32 l_iThrCreate = 0;
226   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
227
228   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != childName && strlen(childName) < LIMIT_NAME_SIZE_APP &&
229       NULL != CbInitialize && NULL != CbShutdown && NULL != attr) {
230     if (attr->schedPolicy < eFrameworkunifiedSchedPolicyInherit || attr->schedPolicy >= eFrameworkunifiedSchedPolicyMAX) {
231       l_eStatus = eFrameworkunifiedStatusInvldParam;
232     } else {
233       if (EOK == pthread_attr_init(&tAttr)) {
234         if (EOK != pthread_attr_setinheritsched(&tAttr, PTHREAD_INHERIT_SCHED)) {
235           l_eStatus = eFrameworkunifiedStatusFail;
236         } else {
237           pAttr = &tAttr;
238         }
239       }
240     }
241
242     if (eFrameworkunifiedStatusOK == l_eStatus) {
243       pthread_barrier_t barrier;
244       if (EOK == pthread_barrier_init(&barrier, NULL, 2)) {
245         PCData pc(&barrier, &l_eStatus, FrameworkunifiedGetAppName(hApp), childName, CbInitialize, CbShutdown,
246                   attr->schedPolicy, attr->schedPriority, CbCreateStateMachine);
247         pthread_t childThread = 0;
248
249         if (NULL != CbCreateStateMachine) {
250           l_iThrCreate = pthread_create(&childThread, pAttr, child_hsm_thread_proc, &pc);
251         } else {
252           l_iThrCreate = pthread_create(&childThread, pAttr, child_thread_proc, &pc);
253         }
254
255         if (EOK == l_iThrCreate) {
256           if (IsValidWaitBarrier(pthread_barrier_wait(&barrier))) {
257             if (eFrameworkunifiedStatusOK == l_eStatus) {
258               hChildQ = McOpenSenderChild(childName, childThread);
259             }
260           }
261         }
262         pthread_barrier_destroy(&barrier);
263       }
264     }
265 #ifdef DISPATCHER_PROFILER
266     if (TRUE == FrameworkunifiedMsgProfiler::m_bMsgProfilerEnabled) {
267       CFrameworkunifiedFrameworkApp *pApp = static_cast<CFrameworkunifiedFrameworkApp *>(hApp);
268       if (NULL != pApp->m_pFrameworkunifiedMsgProfiler) {
269         pApp->m_pFrameworkunifiedMsgProfiler->AddChildName(childName);
270       }
271     }
272 #endif
273   }
274   return hChildQ;
275 }
276
277 ////////////////////////////////////////////////////////////////////////////////////////////
278 /// CreateChildThreadAttrInit
279 ////////////////////////////////////////////////////////////////////////////////////////////
280 EFrameworkunifiedStatus CreateChildThreadAttrInit(FrameworkunifiedChildThreadAttr *attr) {
281   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
282
283   if (attr == NULL) {
284     eStatus = eFrameworkunifiedStatusNullPointer;
285   } else {
286     memset(attr, 0, sizeof(FrameworkunifiedChildThreadAttr));
287     attr->schedPolicy = eFrameworkunifiedSchedPolicyInherit;
288     attr->schedPriority = INHERIT_PARENT_THREAD_PRIO;
289   }
290
291   return eStatus;
292 }
293
294 ////////////////////////////////////////////////////////////////////////////////////////////
295 /// CreateChildThreadAttrSetSched
296 ////////////////////////////////////////////////////////////////////////////////////////////
297 EFrameworkunifiedStatus CreateChildThreadAttrSetSched(FrameworkunifiedChildThreadAttr *attr, EFrameworkunifiedSchedPolicy policy, SI_32 priority) {
298   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
299
300   if (attr == NULL) {
301     eStatus = eFrameworkunifiedStatusNullPointer;
302   } else {
303     if (policy < eFrameworkunifiedSchedPolicyInherit || policy >= eFrameworkunifiedSchedPolicyMAX) {
304       eStatus = eFrameworkunifiedStatusInvldParam;
305     } else {
306       attr->schedPolicy = policy;
307       attr->schedPriority = priority;
308     }
309   }
310
311   return eStatus;
312 }
313
314 ////////////////////////////////////////////////////////////////////////////////////////////
315 /// FrameworkunifiedCreateChildThreadAttrInit
316 ////////////////////////////////////////////////////////////////////////////////////////////
317 EFrameworkunifiedStatus FrameworkunifiedCreateChildThreadAttrInit(FrameworkunifiedChildThreadAttr *attr) {
318   return CreateChildThreadAttrInit(attr);
319 }
320
321 ////////////////////////////////////////////////////////////////////////////////////////////
322 /// FrameworkunifiedCreateChildThreadAttrSetSched
323 ////////////////////////////////////////////////////////////////////////////////////////////
324 EFrameworkunifiedStatus FrameworkunifiedCreateChildThreadAttrSetSched(FrameworkunifiedChildThreadAttr *attr, EFrameworkunifiedSchedPolicy policy, SI_32 priority) {
325   return CreateChildThreadAttrSetSched(attr, policy, priority);
326 }
327
328 ////////////////////////////////////////////////////////////////////////////////////////////
329 /// FrameworkunifiedCreateChildThread
330 ////////////////////////////////////////////////////////////////////////////////////////////
331 HANDLE FrameworkunifiedCreateChildThread(HANDLE hApp, PCSTR childName, CbFuncPtr CbInitialize
332                             , CbFuncPtr CbShutdown) {
333   HANDLE hChildQ = NULL;
334   FrameworkunifiedChildThreadAttr attr;
335
336   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != childName && strlen(childName) < LIMIT_NAME_SIZE_APP &&
337       NULL != CbInitialize && NULL != CbShutdown) {
338     CreateChildThreadAttrInit(&attr);
339     hChildQ = CreateChildThread(hApp, childName, CbInitialize, CbShutdown, &attr, NULL);
340   }
341
342   return hChildQ;
343 }
344
345 ////////////////////////////////////////////////////////////////////////////////////////////
346 /// FrameworkunifiedCreateChildThreadWithPriority
347 ////////////////////////////////////////////////////////////////////////////////////////////
348 HANDLE FrameworkunifiedCreateChildThreadWithPriority(HANDLE hApp, PCSTR childName, CbFuncPtr CbInitialize
349                                         , CbFuncPtr CbShutdown, SI_32 schedPrio) {
350   HANDLE hChildQ = NULL;
351   FrameworkunifiedChildThreadAttr attr;
352
353   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != childName && strlen(childName) < LIMIT_NAME_SIZE_APP  &&
354       NULL != CbInitialize && NULL != CbShutdown) {
355     CreateChildThreadAttrInit(&attr);
356     CreateChildThreadAttrSetSched(&attr, eFrameworkunifiedSchedPolicyFIFO, schedPrio);
357     hChildQ = CreateChildThread(hApp, childName, CbInitialize, CbShutdown, &attr, NULL);
358   }
359
360   return hChildQ;
361 }
362
363 ////////////////////////////////////////////////////////////////////////////////////////////
364 /// FrameworkunifiedCreateChildThreadWithAttribute
365 ////////////////////////////////////////////////////////////////////////////////////////////
366 HANDLE FrameworkunifiedCreateChildThreadWithAttribute(HANDLE hApp, PCSTR childName, CbFuncPtr CbInitialize
367                                          , CbFuncPtr CbShutdown, const FrameworkunifiedChildThreadAttr *attr) {
368   HANDLE hChildQ = NULL;
369
370   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != childName  && strlen(childName) < LIMIT_NAME_SIZE_APP &&
371       NULL != CbInitialize && NULL != CbShutdown && NULL != attr) {
372     hChildQ = CreateChildThread(hApp, childName, CbInitialize, CbShutdown, attr, NULL);
373   }
374
375   return hChildQ;
376 }
377
378
379 ////////////////////////////////////////////////////////////////////////////////////////////
380 /// FrameworkunifiedDestroyChildThread
381 ////////////////////////////////////////////////////////////////////////////////////////////
382 EFrameworkunifiedStatus FrameworkunifiedDestroyChildThread(HANDLE hApp, HANDLE hChildQ) {
383   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
384
385   if (frameworkunifiedCheckValidAppHandle(hApp) && NULL != hChildQ) {
386     eStatus = FrameworkunifiedSendChild(hApp, hChildQ, PROTOCOL_THREAD_DESTROY, 0, NULL);
387
388     if (eFrameworkunifiedStatusOK != (eStatus = FrameworkunifiedJoinChild(hChildQ))) {
389       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedJoinChild Error. status: %d", eStatus);
390     }
391
392     // close the child message queue handle
393     eStatus = McClose(hChildQ);
394     hChildQ = NULL;
395   } else {
396     eStatus = eFrameworkunifiedStatusInvldParam;
397   }
398
399   return eStatus;
400 }
401
402
403 ////////////////////////////////////////////////////////////////////////////////////////////
404 /// FrameworkunifiedStartChildThread
405 ////////////////////////////////////////////////////////////////////////////////////////////
406 EFrameworkunifiedStatus FrameworkunifiedStartChildThread(HANDLE hApp, HANDLE hChildQ, UI_32 length, PCVOID data) {
407   return FrameworkunifiedSendChild(hApp, hChildQ, SYSTEM_ON_INITIALIZATION, length, data);
408 }
409
410
411 ////////////////////////////////////////////////////////////////////////////////////////////
412 /// FrameworkunifiedStopChildThread
413 ////////////////////////////////////////////////////////////////////////////////////////////
414 EFrameworkunifiedStatus FrameworkunifiedStopChildThread(HANDLE hApp, HANDLE hChildQ, UI_32 length, PCVOID data) {
415   return FrameworkunifiedSendChild(hApp, hChildQ, SYSTEM_ON_SHUTDOWN, length, data);
416 }
417
418
419 ////////////////////////////////////////////////////////////////////////////////////////////
420 /// FrameworkunifiedSendChild
421 ////////////////////////////////////////////////////////////////////////////////////////////
422 EFrameworkunifiedStatus FrameworkunifiedSendChild(HANDLE hApp, HANDLE hChildQ, UI_32 iCmd, UI_32 length, PCVOID data) {
423   if (frameworkunifiedCheckValidAppHandle(hApp)) {
424     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >(hApp);
425     return McSend(hChildQ, &pApp->cAppName[ 0 ], iCmd, length, data);
426   }
427   return eFrameworkunifiedStatusInvldHandle;
428 }
429
430
431 ////////////////////////////////////////////////////////////////////////////////////////////
432 /// FrameworkunifiedSendParent
433 ////////////////////////////////////////////////////////////////////////////////////////////
434 EFrameworkunifiedStatus FrameworkunifiedSendParent(HANDLE hChildApp, UI_32 iCmd, UI_32 length, PCVOID data) {
435   if (frameworkunifiedCheckValidAppHandle(hChildApp)) {
436     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >(hChildApp);
437     return McSend(pApp->hParentSndMsgQ, &pApp->cAppName[ 0 ], iCmd, length, data);
438   }
439   return eFrameworkunifiedStatusInvldHandle;
440 }
441
442
443
444 ////////////////////////////////////////////////////////////////////////////////////////////
445 /// FrameworkunifiedCreateDispatcherChild
446 ////////////////////////////////////////////////////////////////////////////////////////////
447 EFrameworkunifiedStatus FrameworkunifiedCreateDispatcherChild(HANDLE &hChildApp,  // NOLINT  (readability/nolint)
448                                     PCSTR childName,
449                                     PCSTR parentName) {
450   EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusOK;
451
452   if ((NULL != childName) && (NULL != parentName) && (LIMIT_NAME_SIZE_APP > strlen(parentName)) &&
453       (LIMIT_NAME_SIZE_APP > strlen(parentName))) {
454     if (eFrameworkunifiedStatusOK == (eStatus = FrameworkunifiedCreateDispatcher(childName, hChildApp, TRUE))) {
455       // LCOV_EXCL_BR_START 200: If FrameworkunifiedCreateDispatcher return eFrameworkunifiedStatusOK, hChildApp would also be valid.
456       if (frameworkunifiedCheckValidAppHandle(hChildApp)) {
457       // LCOV_EXCL_BR_STOP
458         CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >(hChildApp);
459
460         memset(pApp->cParentAppName, 0, sizeof(pApp->cParentAppName));
461         memcpy(pApp->cParentAppName, parentName, strlen(parentName));
462
463         pApp->hParentSndMsgQ = McOpenSender(parentName);
464         if (NULL == pApp->hParentSndMsgQ) {
465           FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "McOpenSender is NULL");
466           eStatus = eFrameworkunifiedStatusNullPointer;
467           return eStatus;
468         }
469         pApp->uiSessionId = THREAD_SESSION_ID;
470       } else {
471         // LCOV_EXCL_START 200: If FrameworkunifiedCreateDispatcher return eFrameworkunifiedStatusOK, hChildApp would also be valid.
472         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
473         FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "hChildApp is NULL");
474         eStatus = eFrameworkunifiedStatusNullPointer;
475         // LCOV_EXCL_STOP
476       }
477     } else {
478       FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "FrameworkunifiedCreateDispatcher error, status=%d", eStatus);
479     }
480   } else {
481     FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __FUNCTION__, "Invalid parameter received");
482     eStatus = eFrameworkunifiedStatusInvldParam;
483   }
484   return eStatus;
485 }
486
487
488 ////////////////////////////////////////////////////////////////////////////////////////////
489 /// FrameworkunifiedJoinChild
490 ////////////////////////////////////////////////////////////////////////////////////////////
491 EFrameworkunifiedStatus FrameworkunifiedJoinChild(HANDLE hChildApp) {
492   return McJoinChild(hChildApp);
493 }
494
495 ////////////////////////////////////////////////////////////////////////////////////////////
496 /// FrameworkunifiedGetChildThreadPriority
497 ////////////////////////////////////////////////////////////////////////////////////////////
498 EFrameworkunifiedStatus FrameworkunifiedGetChildThreadPriority(HANDLE hChildApp, PSI_32 threadPrio) {
499   return McGetChildThreadPriority(hChildApp, threadPrio);
500 }
501
502 EFrameworkunifiedStatus RunChildDispatcher(HANDLE hChildApp) {
503   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
504   int efd;
505   // LCOV_EXCL_BR_START 6: RunChildDispatcher is a internal function, hChildApp would checked in child_thread_proc.
506   if (frameworkunifiedCheckValidAppHandle(hChildApp)) {
507   // LCOV_EXCL_BR_STOP
508 #ifdef DISPATCHER_PROFILER
509     // Get the application handle
510     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >(hChildApp);
511     if (TRUE == FrameworkunifiedMsgProfiler::m_bMsgProfilerEnabled) {
512       pApp->m_pFrameworkunifiedMsgProfiler = new(std::nothrow) FrameworkunifiedMsgProfiler(FrameworkunifiedGetAppName(hChildApp));
513       if (NULL != pApp->m_pFrameworkunifiedMsgProfiler) {
514         FrameworkunifiedAttachChildMsgProfilerCallbacksDispatcher(hChildApp);
515       }
516     }
517 #endif
518     FrameworkunifiedGetDispatcherFD(hChildApp, &efd);
519
520     while (eFrameworkunifiedStatusExit != l_eStatus) {
521       l_eStatus = frameworkunifiedFdHandler(hChildApp, efd);
522     }
523   } else {
524     // LCOV_EXCL_START 6: RunChildDispatcher is a internal function, hChildApp would checked in child_thread_proc.
525     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
526     l_eStatus = eFrameworkunifiedStatusInvldHandle;
527     // LCOV_EXCL_STOP
528   }
529
530   return l_eStatus;
531 }