Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / nsframework / framework_unified / client / NS_FrameworkCore / include / frameworkunified_framework_core.h
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    Application framework's core structures and data types.
20 ///
21 ///
22 ///
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_CORE_H_
26 #define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_CORE_H_
27
28 #include <pthread.h>
29 #include <errno.h>
30
31 #include <other_service/strlcpy.h>
32 #include <native_service/frameworkunified_framework_types.h>
33 #include <native_service/ns_logger_if.h>
34
35 #include <iostream>
36 #include <string>
37 #include <map>
38 #include <queue>
39 #include <cstdio>
40 #include <vector>
41 #include <utility>
42
43 static const UI_32 THREAD_SESSION_ID  = 0;
44
45 typedef HANDLE SessionHandle;
46 typedef int SessionId;  // < service protocol command
47 typedef int ServiceProtocolCommand;  // < service protocol command
48 typedef int Fd;  // < FD associated with callback
49 typedef std::string Notification;   // < notification name
50 typedef std::string ServiceName;    // < service name
51 typedef std::string ThreadName;
52 typedef std::string DataKey;
53 typedef std::string InvokerName;
54 typedef int Socket;
55 typedef std::string ConnectKey;
56 typedef PVOID Data;
57
58 typedef std::map<Notification, CallbackFunctionPtr> NotificationTable;
59
60
61 typedef std::map<ServiceProtocolCommand, CallbackFunctionPtr> ServiceProtocolTable;
62 typedef std::map<SessionId, ServiceProtocolTable> SessionTable;
63 typedef std::map<ServiceName, SessionTable> Services;
64 typedef std::map<HANDLE, ServiceName> ServiceSendMsgHandle;
65 typedef std::map<Fd, CallbackFunctionPtr> FdTable;
66
67 typedef int EventId;
68 typedef std::map<ServiceProtocolCommand, EventId> ServiceEventProtocolTable;
69 typedef std::map<SessionId, ServiceEventProtocolTable> EventSessionTable;
70 typedef std::map<ServiceName, EventSessionTable> EventServices;
71 typedef std::map<Notification, EventId> NotificationEventTable;
72 typedef std::map<SessionId, SessionHandle> SessionHandleTable;
73 typedef std::map<ServiceName, SessionHandleTable> ServiceSessionTable;
74 typedef std::map<InvokerName, HANDLE> InvokeResponseQTable;
75 typedef std::map<Socket, ConnectKey> AcceptMonitorTable;
76 typedef std::map<Socket, ConnectKey> ConnectMonitorTable;
77
78 typedef std::pair<NotificationTable::iterator, bool> NotificationTableRetStatus;
79 typedef std::map<DataKey, Data> AppData;
80
81 // private event data structure
82 typedef struct _EventData {
83   PVOID pData;                 ///  <message data
84   UI_32 uiLength;                  ///  <message length
85 } EventData;
86
87 // framework message queue info
88 typedef struct _MsgQInfo {
89   CHAR cSrcName[MAX_NAME_SIZE_APP];  ///  <source message queue name
90   CHAR cMsgQName[MAX_NAME_SIZE_APP];  ///  <name of the handle to the msgq
91   UI_32 checkCode;
92   pthread_t self;
93   HANDLE hMsgQ;                  ///  <handle to message queue
94   UI_32  sessionId;                  ///  <Used only when it is a session handle
95 } MsgQInfo;
96
97 #define MSGQ_CHECK_CODE (0xACCE55ED)
98
99 static inline BOOL frameworkunifiedCheckValidMsgQ(HANDLE hService) {
100   static __thread int detect_once = 0;
101   if (NULL != hService) {
102     MsgQInfo *pMsgQ = reinterpret_cast<MsgQInfo *>(hService);
103     /**
104      * @todo
105      *  If an application handle is specified in place of a session handle,
106      *  the element is accessed illegally without type checking,
107      *  and a DeathTest occurs because the thread_self check is violated.
108      */
109     if (pMsgQ->self != pthread_self() && detect_once == 0) {
110       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __func__, "Invalid thread context detect(hService/hSession):%#lx:%#lx", pMsgQ->self,
111              pthread_self());
112       detect_once = 1;
113     }
114     if (pMsgQ->checkCode == MSGQ_CHECK_CODE) {
115       return TRUE;
116     }
117   }
118   return FALSE;
119 }
120
121 /* data structure for public state events and data associated with it */
122 // map of state events and data associated with it
123 typedef std::map<UI_32, EventData *> PublicStateEventTable;
124
125 /* data structure for private state events and data associated with it */
126 // list of session id's of service and event data(private) associated with it
127 typedef std::map<UI_32, EventData *> SessionEventData;
128
129 // map of service name and list of its session id's and associated event data
130 typedef std::map<ServiceName, SessionEventData> ServiceSessionEventData;
131
132 // map of private events and the data published on the all sessions of all services subscribed to it
133 typedef std::map<UI_32, ServiceSessionEventData> PrivateStateEventTable;
134
135
136 // list of session id's for each service registering with event
137 typedef std::vector<UI_32> SessionIdList;
138 typedef std::vector<UI_32> EventIdList;
139
140 // map of service name and and list of its session id
141 typedef std::map<ServiceName, SessionIdList> ServiceSessionIdListTable;
142 // map of events and its subscribers
143 typedef std::map<UI_32, ServiceSessionIdListTable> EventTable;
144
145 // structure to hold the session handle and list of event ids for that session
146 typedef struct _SessionEventInfo {
147   HANDLE    m_hSession;  // Msg queue handle for the specific session
148   EventIdList m_vEvents;  // List of event ids corresponding to the session
149 } SessionEventInfo, *PSessionEventInfo;
150
151 // map to hold the session id and structure of session event info
152 typedef std::map<SessionId, SessionEventInfo *> SessionToEventInfo;
153
154 // map of service name with session id and session handle
155 typedef std::map<ServiceName, SessionToEventInfo > ServiceSessionHandleTable;
156
157 // Defer'ed queue
158 // When a pop is issued this data will be copied to the internal CFrameworkunifiedFrameworkApp struct
159 // which will call the FrameworkunifiedDispatchProcess that will process the message as if
160 // it was received off the message queue!
161 class DeferedMsgInfo {
162   void copy_me(const DeferedMsgInfo &defer) {
163     if (this != &defer) {
164       uiProtocolCmd = defer.uiProtocolCmd;
165       strlcpy(cMsgSrcName, defer.cMsgSrcName, sizeof(cMsgSrcName));
166       std::memcpy(uiMsgRcvBuffer, defer.uiMsgRcvBuffer, MAX_MSGQ_BUFFER);
167     }
168   }
169
170  public:
171   UI_32  uiProtocolCmd;                   ///  <protocol req/ack received
172   CHAR   cMsgSrcName[MAX_NAME_SIZE_APP];  ///  <name of client/server(application) message queue
173   UI_8   uiMsgRcvBuffer[MAX_MSGQ_BUFFER];  ///  <receive buffer for message queue
174
175   DeferedMsgInfo() : uiProtocolCmd(0) {
176     std::memset(uiMsgRcvBuffer, 0, MAX_MSGQ_BUFFER);
177     std::memset(cMsgSrcName, '\0', MAX_NAME_SIZE_APP);
178   }
179
180   DeferedMsgInfo(const DeferedMsgInfo &defer) {
181     copy_me(defer);  //  LCOV_EXCL_BR_LINE 11:except branch
182   }
183
184   DeferedMsgInfo(UI_32 cmd, PCSTR name, UI_8 buf[MAX_MSGQ_BUFFER]) {
185     DeferedMsgInfo defer;
186
187     defer.uiProtocolCmd = cmd;
188     strlcpy(defer.cMsgSrcName, name, sizeof(defer.cMsgSrcName));
189     std::memcpy(defer.uiMsgRcvBuffer, buf, MAX_MSGQ_BUFFER);
190
191     copy_me(defer);
192   }
193
194   DeferedMsgInfo &operator = (const DeferedMsgInfo &defer) {
195     copy_me(defer);
196
197     return *this;
198   }
199 };
200
201 typedef struct _ServiceNotificationInfo {
202   CHAR   sNotificationName[MAX_SYS_INFO_SIZE];
203   UI_32  uiEventId;
204 } ServiceNotificationInfo;
205
206 typedef std::vector<ServiceNotificationInfo> NotificationList;
207 typedef std::queue<DeferedMsgInfo>  DeferedMessageQueue;
208
209 typedef struct _LostSessionInfo {
210   std::string sServiceName;
211   SessionId   iSessionId;
212 } LostSessionInfo;
213
214 typedef std::queue<LostSessionInfo> LostSessionQueue;
215
216 #ifdef DISPATCHER_PROFILER
217 class FrameworkunifiedMsgProfiler;
218 #endif
219
220 class ResponseData {
221   std::vector<UI_8> rawBuffer;
222
223  public:
224   void set(PVOID src, UI_32 size) {
225     rawBuffer.resize(size);
226     std::memcpy(&rawBuffer[0], src, size);
227   }
228
229   UI_8 *data(void) {
230     return rawBuffer.empty() ? NULL : &rawBuffer[0];
231   }
232
233   void clear(void) {
234     std::vector<UI_8>().swap(rawBuffer);
235   }
236
237   UI_32 size(void) {
238     return static_cast<UI_32>(rawBuffer.size());
239   }
240 };
241
242
243 // framework container
244 typedef struct _CFrameworkunifiedFrameworkApp {
245   CHAR cAppName[MAX_NAME_SIZE_APP];   ///  <application(client/service) name
246   UI_32 checkCode;            ///  <check code
247   pthread_t self;
248
249   // message receive information
250   HANDLE hAppRcvMsgQ;                     ///  <handle to apps receive message queue
251   HANDLE hAppSndMsgQ;           ///  <handle to apps send message queue
252   UI_32  uiMsgLength;                     ///  <length of data in message queue
253   UI_32  uiProtocolCmd;                   ///  <protocol req/ack received
254   UI_32  uiSessionId;
255   CHAR   cSystemInfo[MAX_SYS_INFO_SIZE];
256   CHAR   cMsgSrcName[MAX_NAME_SIZE_APP];  ///  <name of client/server(application) message queue
257   UI_8   uiMsgRcvBuffer[MAX_MSGQ_BUFFER];  ///  <receive buffer for message queue
258   int    efd;               ///  <FD for multiple wait generated by the epoll_create()
259   int    defer_evfd;            ///  <FD for receiving Defer events to Dispatcher
260
261   Services services;                   ///  <services <map>
262   ServiceSendMsgHandle servicesHandle;  ///  <serviceHandle <map>
263   NotificationTable notifications;     ///  <notification <map>
264   FdTable fds;                         ///  <fdTable <map>
265
266   InvokeResponseQTable invokeResQTable;
267
268   AcceptMonitorTable acceptMonitorTable;
269   ConnectMonitorTable connectMonitorTable;
270   LostSessionQueue lostSessionQueue;
271   CallbackFunctionPtr lostSessionHandler;
272
273   EventServices eventservices;
274   NotificationEventTable notificationevents;
275
276   AppData appdata;
277
278   // Defer'ed Message Queue
279   DeferedMessageQueue deferedMsgQueue;  ///  <defer'ed message <queue>
280   BOOL fPopDeferedMsg;
281
282   HANDLE hNPSndMsgQ;  ///  <send msgq handle to NPService
283
284   // application & framework errors
285   EFrameworkunifiedStatus eLastFrameworkError;  ///  <Framework internal errors
286   EFrameworkunifiedStatus eLastAppError;       ///  <application(client/server/child thread) reported errors
287
288   /////////////////////////////////////////
289   void *FrameworkData;
290   HANDLE hParentSndMsgQ;
291   CHAR cParentAppName[MAX_NAME_SIZE_APP];   ///  <application(client/service) name
292   /////////////////////////////////////////
293
294   HANDLE hConfigFileHandle;
295
296   class CFrameworkunifiedHSMFramework *m_pFrameworkunifiedStateMachine;
297
298   ServiceSessionTable sessiontable;
299   NotificationList servicenotificationlist;
300   CHAR   sServiceAvailabilityNotification[MAX_SYS_INFO_SIZE];
301   BOOL bIsAvailable;
302
303   ServiceSessionHandleTable servicesessionhandletable;
304
305   void *pRsrcMgr;
306
307   // framework state information
308   // TODO(framework_unified): consider this for future
309
310   // Current user
311   HANDLE hUser;
312
313   // table holding list of all the events of service and its subscribers
314   EventTable eventtable;
315
316   // table holding list of all the public events of service and the event data corresponding to it
317   PublicStateEventTable publicstateeventtable;
318
319   // table holding list of all the private events of service and
320   // the event data corresponding to each of the subscribed session of its subscribers
321   PrivateStateEventTable privatestateeventtable;
322
323   ResponseData responsedata;
324
325   UI_64 total_occupy_time;
326   UI_64 total_run_count;
327   UI_32 max_occupy_time;
328
329   SI_32 siMonitorSock;
330
331   BOOL fDeferredSyncResponse;
332
333 #ifdef DISPATCHER_PROFILER
334   // Profiler object. This is required per dispatcher
335   FrameworkunifiedMsgProfiler *m_pFrameworkunifiedMsgProfiler;
336 #endif
337 } CFrameworkunifiedFrameworkApp;
338
339 // Structure containing the synchronization data
340 struct SFrameworkunifiedSyncDataPacket {
341   PVOID   m_pNotificationData;  // Data published with the notification
342   UI_32   m_uiDataSize;    // Size of the data published with the notification
343   time_t  m_tTimeStamp;    // Time when the notification was recently published
344 };
345
346 struct PCData {
347   PCData(pthread_barrier_t *bar, EFrameworkunifiedStatus *status, PCSTR parent, PCSTR child, CbFuncPtr init, CbFuncPtr shdn,
348          EFrameworkunifiedSchedPolicy policy, SI_32 priority, CbFuncPtr CreateHSM = NULL)
349     : barrier(bar),
350       childStatus(status),
351       parentName(parent),
352       childName(child),
353       initFn(init),
354       shdnFn(shdn),
355       schedPolicy(policy),
356       schedPriority(priority),
357       CbCreateStateMachine(CreateHSM) {  // LCOV_EXCL_BR_LINE 11:except branch
358   }
359
360   pthread_barrier_t *barrier;
361   EFrameworkunifiedStatus *childStatus;
362   const ServiceName parentName;
363   const ServiceName childName;
364   CbFuncPtr initFn;
365   CbFuncPtr shdnFn;
366   EFrameworkunifiedSchedPolicy schedPolicy;
367   SI_32 schedPriority;
368   CbFuncPtr CbCreateStateMachine;
369 };
370
371 #define APP_CHECK_CODE (0xAC1D5EED)
372
373 static inline BOOL frameworkunifiedCheckValidAppHandle(HANDLE hApp) {
374   static __thread int detect_once = 0;
375   if (NULL != hApp) {
376     CFrameworkunifiedFrameworkApp *pApp = reinterpret_cast< CFrameworkunifiedFrameworkApp * >(hApp);
377     /**
378      * @todo
379      *  eFrameworkunifiedStatusOK is returned even if a appHandle created in another thread is passed,
380      *  and the specifications and operations differ.
381      * @todo
382      *  If an application handle is specified in place of a session handle,
383      *  the element is accessed illegally without type checking,
384      *  and a DeathTest occurs because the thread_self check is violated.
385      * @todo
386      *  If you specify an app handle for a child thread,
387      *  the NULL's return value is not terminated abnormally at the intended point (frameworkunifiedCheckValidAppHandle).
388      */
389     if (pApp->self != pthread_self() && detect_once == 0) {
390       FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __func__, "Invalid thread context detect(hApp):%#lx:%#lx", pApp->self, pthread_self());
391       detect_once = 1;
392     }
393     if (pApp->checkCode == APP_CHECK_CODE) {
394       return TRUE;
395     }
396   }
397   return FALSE;
398 }
399
400 ////////////////////////////////////////////////////////////////////////////////////////////
401 ///   NPSubscribeToNotification
402 /// API to send message to Notification Service to add to subscription list for
403 /// that notification
404 ///
405 /// \param [in] hApp
406 ///         HANDLE - Handle to the Framework
407 /// \param [in] pNotification
408 ///         PCSTR - Name of Notification
409 ///
410 /// \return status
411 ///         EFrameworkunifiedStatus - success or error
412 ////////////////////////////////////////////////////////////////////////////////////////////
413 EFrameworkunifiedStatus FrameworkunifiedNPSubscribeToNotification(HANDLE hApp, PCSTR pNotification);
414
415
416 ////////////////////////////////////////////////////////////////////////////////////////////
417 /// FrameworkunifiedNPSubscribeToNotifications
418 /// API to send message to Notification Service to add multiple subscriptions list for
419 /// that notification
420 ///
421 /// \param [in] hApp
422 ///         HANDLE - Handle to the Framework
423 /// \param [in] pList
424 ///         FrameworkunifiedNotificationCallbackHandler - Name of Notification
425 /// \param [in] uiListLength
426 ///         UI_32 - number of notification that your subscribing too.
427 ///
428 /// \return status
429 ///         EFrameworkunifiedStatus - success or error
430 ////////////////////////////////////////////////////////////////////////////////////////////
431 EFrameworkunifiedStatus FrameworkunifiedNPSubscribeToNotifications(HANDLE hApp, const  FrameworkunifiedNotificationCallbackHandler *pList, UI_32 uiListLength);
432
433 ////////////////////////////////////////////////////////////////////////////////////////////
434 ///   NPUnsubscribeFromNotification
435 /// API to send message to Notification Service to remove from subscription list for
436 /// that notification
437 ///
438 /// \param [in] hApp
439 ///         HANDLE - Handle to the Framework
440 /// \param [in] pNotification
441 ///         PCSTR - Name of Notification
442 ///
443 /// \return status
444 ///         EFrameworkunifiedStatus - success or error
445 ////////////////////////////////////////////////////////////////////////////////////////////
446 EFrameworkunifiedStatus FrameworkunifiedNPUnsubscribeFromNotification(HANDLE hApp, PCSTR pNotification);
447
448 ////////////////////////////////////////////////////////////////////////////////////////////
449 ///   FrameworkunifiedNPUnsubscribeFromNotifications
450 /// API to send message to Notification Service to remove multiple notification from subscription list for
451 /// that notification
452 ///
453 /// \param [in] hApp
454 ///         HANDLE - Handle to the Framework
455 /// \param [in] pList
456 ///         FrameworkunifiedNotificationCallbackHandler - notifications list
457 ///
458 /// \return status
459 ///         EFrameworkunifiedStatus - success or error
460 ////////////////////////////////////////////////////////////////////////////////////////////
461 EFrameworkunifiedStatus FrameworkunifiedNPUnsubscribeFromNotifications(HANDLE hApp, const  FrameworkunifiedNotificationCallbackHandler *pList,
462                                              UI_32 uiListLength);
463
464
465 ////////////////////////////////////////////////////////////////////////////////////////////
466 /// FrameworkunifiedNPHSMSubscribeToNotificationsEvents
467 /// API to send message to Notification Service to add multiple subscriptions list for
468 /// that notification
469 ///
470 /// \param [in] hApp
471 ///         HANDLE - Handle to the Framework
472 /// \param [in] pList
473 ///         FrameworkunifiedNotificationEvent - list of notification events
474 /// \param [in] uiListLength
475 ///         UI_32 - number of notification that your subscribing too.
476 ///
477 /// \return status
478 ///         EFrameworkunifiedStatus - success or error
479 ////////////////////////////////////////////////////////////////////////////////////////////
480 EFrameworkunifiedStatus FrameworkunifiedNPHSMSubscribeToNotificationsEvents(HANDLE hApp, const  FrameworkunifiedNotificationEvent *pList,
481                                                   UI_32 uiListLength);
482
483 ////////////////////////////////////////////////////////////////////////////////////////////
484 ///   FrameworkunifiedNPHSMSubscribeToNotificationEvent
485 /// API to send message to Notification Service to add to subscription list for
486 /// that notification
487 ///
488 /// \param [in] hApp
489 ///         HANDLE - Handle to the Framework
490 /// \param [in] pNotification
491 ///         PCSTR - Name of Notification
492 ///
493 /// \return status
494 ///         EFrameworkunifiedStatus - success or error
495 ////////////////////////////////////////////////////////////////////////////////////////////
496 EFrameworkunifiedStatus FrameworkunifiedNPHSMSubscribeToNotificationEvent(HANDLE hApp, PCSTR pNotification);
497
498 ////////////////////////////////////////////////////////////////////////////////////////////
499 /// FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent
500 /// API to send message to Notification Service to remove from subscription list for
501 /// that notification
502 ///
503 /// \param [in] hApp
504 ///         HANDLE - Handle to the Framework
505 /// \param [in] pNotification
506 ///         PCSTR - Name of Notification
507 ///
508 /// \return status
509 ///         EFrameworkunifiedStatus - success or error
510 ////////////////////////////////////////////////////////////////////////////////////////////
511 EFrameworkunifiedStatus FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent(HANDLE hApp, PCSTR pNotification);
512
513 ////////////////////////////////////////////////////////////////////////////////////////////
514 /// FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents
515 /// API to send message to Notification Service to remove multiple subscriptions list for
516 /// that notification
517 ///
518 /// \param [in] hApp
519 ///         HANDLE - Handle to the Framework
520 /// \param [in] pList
521 ///         FrameworkunifiedNotificationEvent - list of notification events
522 /// \param [in] uiListLength
523 ///         UI_32 - number of notification that your subscribing too.
524 ///
525 /// \return status
526 ///         EFrameworkunifiedStatus - success or error
527 ////////////////////////////////////////////////////////////////////////////////////////////
528 EFrameworkunifiedStatus FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents(HANDLE hApp, const  FrameworkunifiedNotificationEvent *pList,
529                                                      UI_32 uiListLength);
530
531 ////////////////////////////////////////////////////////////////////////////////////////////
532 /// CreateDispatcher
533 ///
534 /// \param [in] cAppName
535 ///         PCSTR - Application name
536 ///
537 /// \return status
538 ///         EFrameworkunifiedStatus - success or error
539 ////////////////////////////////////////////////////////////////////////////////////////////
540 EFrameworkunifiedStatus FrameworkunifiedProcessServiceProtocol(HANDLE hApp);
541
542 EFrameworkunifiedStatus frameworkunifiedAddConnectMonitor(HANDLE hApp, PCSTR serverName, PCSTR clientName);
543 EFrameworkunifiedStatus frameworkunifiedDelConnectMonitorPre(int efd, PCSTR serverName, PCSTR clientName);
544 EFrameworkunifiedStatus frameworkunifiedDelConnectMonitor(HANDLE hApp, PCSTR serverName, PCSTR clientName);
545
546 ////////////////////////////////////////////////////////////////////////////////////////////
547 /// CreateDispatcher
548 ///
549 /// \param [in] cAppName
550 ///         PCSTR - Application name
551 /// \param [out] hApp
552 ///         HANDLE& - Reference of application handle
553 /// \param [in] bIsChildThread
554 ///         BOOL - child thread
555 ///
556 /// \return status
557 ///         EFrameworkunifiedStatus - eFrameworkunifiedStatusOK if success
558 ///            eFrameworkunifiedStatusFail if invalid app name
559 ///            eFrameworkunifiedStatusNullPointer if unable to open message Q handle
560 ///            or possible errors from call FrameworkunifiedAttachSystemCallbacksDispatcher/
561 ///                           FrameworkunifiedAttachLoggerCallbacksDispatcher/
562 ///                           FrameworkunifiedAttachVersionCallbacksDispatcher
563 ///
564 ////////////////////////////////////////////////////////////////////////////////////////////
565 EFrameworkunifiedStatus CreateDispatcher(PCSTR cAppName, HANDLE &hApp, BOOL bIsChildThread = FALSE);  // NOLINT (readability/nolint)
566
567 ////////////////////////////////////////////////////////////////////////////////////////////
568 /// RunDispatcher
569 ///
570 /// \param [in] hApp
571 ///         HANDLE - Handle to the Framework
572 ///
573 /// \return status
574 ///         EFrameworkunifiedStatus - success or error
575 ////////////////////////////////////////////////////////////////////////////////////////////
576 EFrameworkunifiedStatus RunDispatcher(HANDLE hApp);
577
578 ////////////////////////////////////////////////////////////////////////////////////////////
579 /// RunChildDispatcher
580 /// Dispatcher for child thread. Only difference with \ref RunDispatcher is, child dispatcher
581 /// exits when non eFrameworkunifiedStatusOK value by callback function is returned.
582 /// Whereas, \ref RunDispatcher is not supposed to exit.
583 ///
584 /// \param [in] hApp
585 ///         HANDLE - Handle to the Framework
586 ///
587 /// \return status
588 ///         EFrameworkunifiedStatus - success or error
589 ////////////////////////////////////////////////////////////////////////////////////////////
590 EFrameworkunifiedStatus RunChildDispatcher(HANDLE hChildApp);
591
592 ////////////////////////////////////////////////////////////////////////////////////////////
593 /// IsValidWaitBarrier
594 ///
595 /// \param [in] wbret
596 ///         int - barrier
597 ///
598 /// \return bool
599 ///         valid or invalid
600 ////////////////////////////////////////////////////////////////////////////////////////////
601 bool IsValidWaitBarrier(int wbret);
602
603 ////////////////////////////////////////////////////////////////////////////////////////////
604 /// setChildThreadSched
605 ///
606 /// \param [in] policy
607 ///         EFrameworkunifiedSchedPolicy - scheduling policy
608 /// \param [in] priority
609 ///         SI_32 - scheduling priority
610 ///
611 /// \return status
612 ///         EFrameworkunifiedStatus - success or error
613 ////////////////////////////////////////////////////////////////////////////////////////////
614 EFrameworkunifiedStatus setChildThreadSched(EFrameworkunifiedSchedPolicy policy, SI_32 priority);
615
616 ////////////////////////////////////////////////////////////////////////////////////////////
617 /// CreateChildThread
618 ///
619 /// \param [in] hApp
620 ///         HANDLE - Handle to the Framework
621 /// \param [in] childName
622 ///     PCSTR - Name of child thread to be created
623 /// \param [in] CbInitialize
624 ///     CbFuncPtr - Initialize function.
625 /// \param [in] CbShutdown
626 ///     CbFuncPtr - Shutdown function.
627 /// \param [in] attr
628 ///     const FrameworkunifiedChildThreadAttr * - child thread attribute
629 /// \param [in] CbCreateStateMachine
630 ///     CbFuncPtr - Function pointer to create state machine, in case of SM child thread, else NULL
631 ///
632 /// \return HANDLE
633 ///         Non-null value if thread is created else NULL
634 ////////////////////////////////////////////////////////////////////////////////////////////
635 HANDLE CreateChildThread(HANDLE hApp, PCSTR childName, CbFuncPtr CbInitialize, CbFuncPtr CbShutdown,
636                          const FrameworkunifiedChildThreadAttr *attr, CbFuncPtr CbCreateStateMachine);
637
638 ////////////////////////////////////////////////////////////////////////////////////////////
639 /// Child thread attribute initialize
640 ///
641 /// \param [out] attr
642 ///         FrameworkunifiedChildThreadAttr - Child thread attribute
643 ///
644 /// \return status
645 ///         EFrameworkunifiedStatus - success or error
646 ////////////////////////////////////////////////////////////////////////////////////////////
647 EFrameworkunifiedStatus CreateChildThreadAttrInit(FrameworkunifiedChildThreadAttr *attr);
648
649 ////////////////////////////////////////////////////////////////////////////////////////////
650 /// Child thread attribute set schedule policy & priority
651 ///
652 /// \param [out] attr
653 ///         FrameworkunifiedChildThreadAttr - Child thread attribute
654 /// \param [int] policy
655 ///         EFrameworkunifiedSchedPolicy - Child thread scheduling policy
656 /// \param [in] priority
657 ///         SI_32 - Child thread scheduling priority
658 ///
659 /// \return status
660 ///         EFrameworkunifiedStatus - success or error
661 ////////////////////////////////////////////////////////////////////////////////////////////
662 EFrameworkunifiedStatus CreateChildThreadAttrSetSched(FrameworkunifiedChildThreadAttr *attr, EFrameworkunifiedSchedPolicy policy, SI_32 priority);
663
664 ////////////////////////////////////////////////////////////////////////////////////////////
665 /// DestroyThread
666 //  Sends eFrameworkunifiedStatusExit status to exits the dispatcher loop to terminate the thread.
667 ///
668 /// \param [in] hApp
669 ///         HANDLE - Handle to the Framework
670 ///
671 /// \return status
672 ///         EFrameworkunifiedStatus - success or error
673 ////////////////////////////////////////////////////////////////////////////////////////////
674 EFrameworkunifiedStatus DestroyThread(HANDLE hApp);
675
676 #endif  // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_CORE_H_