From 17cf21bcf8a2e29d2cbcf0a313474d2a4ee44f5d Mon Sep 17 00:00:00 2001 From: Tadao Tanikawa Date: Fri, 20 Nov 2020 23:36:23 +0900 Subject: Re-organized sub-directory by category Since all the sub-directories were placed in the first level, created sub-directories, "hal", "module", and "service" for classification and relocated each component. Signed-off-by: Tadao Tanikawa Change-Id: Ifdf743ac0d1893bd8e445455cf0d2c199a011d5c --- .../include/frameworkunified_framework_core.h | 676 +++++++++++++++++++++ .../frameworkunified_framework_error_internal.hpp | 43 ++ .../include/frameworkunified_framework_internal.h | 675 ++++++++++++++++++++ .../include/frameworkunified_framework_utility.h | 41 ++ .../include/frameworkunified_msgprofiler.h | 148 +++++ .../statemachine/frameworkunified_sm_finalstate.h | 97 +++ .../frameworkunified_sm_framework_core.h | 89 +++ .../frameworkunified_sm_multithreading_internal.h | 30 + 8 files changed, 1799 insertions(+) create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_core.h create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_error_internal.hpp create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_internal.h create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_utility.h create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_msgprofiler.h create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_finalstate.h create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_framework_core.h create mode 100755 service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_multithreading_internal.h (limited to 'service/native/framework_unified/client/NS_FrameworkCore/include') diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_core.h b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_core.h new file mode 100755 index 0000000..cb8bcee --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_core.h @@ -0,0 +1,676 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSFramework +/// \brief Application framework's core structures and data types. +/// +/// +/// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_CORE_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_CORE_H_ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static const UI_32 THREAD_SESSION_ID = 0; + +typedef HANDLE SessionHandle; +typedef int SessionId; // < service protocol command +typedef int ServiceProtocolCommand; // < service protocol command +typedef int Fd; // < FD associated with callback +typedef std::string Notification; // < notification name +typedef std::string ServiceName; // < service name +typedef std::string ThreadName; +typedef std::string DataKey; +typedef std::string InvokerName; +typedef int Socket; +typedef std::string ConnectKey; +typedef PVOID Data; + +typedef std::map NotificationTable; + + +typedef std::map ServiceProtocolTable; +typedef std::map SessionTable; +typedef std::map Services; +typedef std::map ServiceSendMsgHandle; +typedef std::map FdTable; + +typedef int EventId; +typedef std::map ServiceEventProtocolTable; +typedef std::map EventSessionTable; +typedef std::map EventServices; +typedef std::map NotificationEventTable; +typedef std::map SessionHandleTable; +typedef std::map ServiceSessionTable; +typedef std::map InvokeResponseQTable; +typedef std::map AcceptMonitorTable; +typedef std::map ConnectMonitorTable; + +typedef std::pair NotificationTableRetStatus; +typedef std::map AppData; + +// private event data structure +typedef struct _EventData { + PVOID pData; /// (hService); + /** + * @todo + * If an application handle is specified in place of a session handle, + * the element is accessed illegally without type checking, + * and a DeathTest occurs because the thread_self check is violated. + */ + if (pMsgQ->self != pthread_self() && detect_once == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __func__, "Invalid thread context detect(hService/hSession):%#lx:%#lx", pMsgQ->self, + pthread_self()); + detect_once = 1; + } + if (pMsgQ->checkCode == MSGQ_CHECK_CODE) { + return TRUE; + } + } + return FALSE; +} + +/* data structure for public state events and data associated with it */ +// map of state events and data associated with it +typedef std::map PublicStateEventTable; + +/* data structure for private state events and data associated with it */ +// list of session id's of service and event data(private) associated with it +typedef std::map SessionEventData; + +// map of service name and list of its session id's and associated event data +typedef std::map ServiceSessionEventData; + +// map of private events and the data published on the all sessions of all services subscribed to it +typedef std::map PrivateStateEventTable; + + +// list of session id's for each service registering with event +typedef std::vector SessionIdList; +typedef std::vector EventIdList; + +// map of service name and and list of its session id +typedef std::map ServiceSessionIdListTable; +// map of events and its subscribers +typedef std::map EventTable; + +// structure to hold the session handle and list of event ids for that session +typedef struct _SessionEventInfo { + HANDLE m_hSession; // Msg queue handle for the specific session + EventIdList m_vEvents; // List of event ids corresponding to the session +} SessionEventInfo, *PSessionEventInfo; + +// map to hold the session id and structure of session event info +typedef std::map SessionToEventInfo; + +// map of service name with session id and session handle +typedef std::map ServiceSessionHandleTable; + +// Defer'ed queue +// When a pop is issued this data will be copied to the internal CFrameworkunifiedFrameworkApp struct +// which will call the FrameworkunifiedDispatchProcess that will process the message as if +// it was received off the message queue! +class DeferedMsgInfo { + void copy_me(const DeferedMsgInfo &defer) { + if (this != &defer) { + uiProtocolCmd = defer.uiProtocolCmd; + strlcpy(cMsgSrcName, defer.cMsgSrcName, sizeof(cMsgSrcName)); + std::memcpy(uiMsgRcvBuffer, defer.uiMsgRcvBuffer, MAX_MSGQ_BUFFER); + } + } + + public: + UI_32 uiProtocolCmd; /// NotificationList; +typedef std::queue DeferedMessageQueue; + +typedef struct _LostSessionInfo { + std::string sServiceName; + SessionId iSessionId; +} LostSessionInfo; + +typedef std::queue LostSessionQueue; + +#ifdef DISPATCHER_PROFILER +class FrameworkunifiedMsgProfiler; +#endif + +class ResponseData { + std::vector rawBuffer; + + public: + void set(PVOID src, UI_32 size) { + rawBuffer.resize(size); + std::memcpy(&rawBuffer[0], src, size); + } + + UI_8 *data(void) { + return rawBuffer.empty() ? NULL : &rawBuffer[0]; + } + + void clear(void) { + std::vector().swap(rawBuffer); + } + + UI_32 size(void) { + return static_cast(rawBuffer.size()); + } +}; + + +// framework container +typedef struct _CFrameworkunifiedFrameworkApp { + CHAR cAppName[MAX_NAME_SIZE_APP]; /// + ServiceSendMsgHandle servicesHandle; /// + NotificationTable notifications; /// + FdTable fds; /// + + InvokeResponseQTable invokeResQTable; + + AcceptMonitorTable acceptMonitorTable; + ConnectMonitorTable connectMonitorTable; + LostSessionQueue lostSessionQueue; + CallbackFunctionPtr lostSessionHandler; + + EventServices eventservices; + NotificationEventTable notificationevents; + + AppData appdata; + + // Defer'ed Message Queue + DeferedMessageQueue deferedMsgQueue; /// + BOOL fPopDeferedMsg; + + HANDLE hNPSndMsgQ; /// (hApp); + /** + * @todo + * eFrameworkunifiedStatusOK is returned even if a appHandle created in another thread is passed, + * and the specifications and operations differ. + * @todo + * If an application handle is specified in place of a session handle, + * the element is accessed illegally without type checking, + * and a DeathTest occurs because the thread_self check is violated. + * @todo + * If you specify an app handle for a child thread, + * the NULL's return value is not terminated abnormally at the intended point (frameworkunifiedCheckValidAppHandle). + */ + if (pApp->self != pthread_self() && detect_once == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_NS_WAR, __func__, "Invalid thread context detect(hApp):%#lx:%#lx", pApp->self, pthread_self()); + detect_once = 1; + } + if (pApp->checkCode == APP_CHECK_CODE) { + return TRUE; + } + } + return FALSE; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +/// NPSubscribeToNotification +/// API to send message to Notification Service to add to subscription list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pNotification +/// PCSTR - Name of Notification +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPSubscribeToNotification(HANDLE hApp, PCSTR pNotification); + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedNPSubscribeToNotifications +/// API to send message to Notification Service to add multiple subscriptions list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pList +/// FrameworkunifiedNotificationCallbackHandler - Name of Notification +/// \param [in] uiListLength +/// UI_32 - number of notification that your subscribing too. +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPSubscribeToNotifications(HANDLE hApp, const FrameworkunifiedNotificationCallbackHandler *pList, UI_32 uiListLength); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// NPUnsubscribeFromNotification +/// API to send message to Notification Service to remove from subscription list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pNotification +/// PCSTR - Name of Notification +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPUnsubscribeFromNotification(HANDLE hApp, PCSTR pNotification); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedNPUnsubscribeFromNotifications +/// API to send message to Notification Service to remove multiple notification from subscription list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pList +/// FrameworkunifiedNotificationCallbackHandler - notifications list +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPUnsubscribeFromNotifications(HANDLE hApp, const FrameworkunifiedNotificationCallbackHandler *pList, + UI_32 uiListLength); + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedNPHSMSubscribeToNotificationsEvents +/// API to send message to Notification Service to add multiple subscriptions list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pList +/// FrameworkunifiedNotificationEvent - list of notification events +/// \param [in] uiListLength +/// UI_32 - number of notification that your subscribing too. +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPHSMSubscribeToNotificationsEvents(HANDLE hApp, const FrameworkunifiedNotificationEvent *pList, + UI_32 uiListLength); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedNPHSMSubscribeToNotificationEvent +/// API to send message to Notification Service to add to subscription list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pNotification +/// PCSTR - Name of Notification +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPHSMSubscribeToNotificationEvent(HANDLE hApp, PCSTR pNotification); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent +/// API to send message to Notification Service to remove from subscription list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pNotification +/// PCSTR - Name of Notification +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPHSMUnsubscribeFromNotificationEvent(HANDLE hApp, PCSTR pNotification); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents +/// API to send message to Notification Service to remove multiple subscriptions list for +/// that notification +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] pList +/// FrameworkunifiedNotificationEvent - list of notification events +/// \param [in] uiListLength +/// UI_32 - number of notification that your subscribing too. +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedNPHSMUnsubscribeFromNotificationEvents(HANDLE hApp, const FrameworkunifiedNotificationEvent *pList, + UI_32 uiListLength); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// CreateDispatcher +/// +/// \param [in] cAppName +/// PCSTR - Application name +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedProcessServiceProtocol(HANDLE hApp); + +EFrameworkunifiedStatus frameworkunifiedAddConnectMonitor(HANDLE hApp, PCSTR serverName, PCSTR clientName); +EFrameworkunifiedStatus frameworkunifiedDelConnectMonitorPre(int efd, PCSTR serverName, PCSTR clientName); +EFrameworkunifiedStatus frameworkunifiedDelConnectMonitor(HANDLE hApp, PCSTR serverName, PCSTR clientName); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// CreateDispatcher +/// +/// \param [in] cAppName +/// PCSTR - Application name +/// \param [out] hApp +/// HANDLE& - Reference of application handle +/// \param [in] bIsChildThread +/// BOOL - child thread +/// +/// \return status +/// EFrameworkunifiedStatus - eFrameworkunifiedStatusOK if success +/// eFrameworkunifiedStatusFail if invalid app name +/// eFrameworkunifiedStatusNullPointer if unable to open message Q handle +/// or possible errors from call FrameworkunifiedAttachSystemCallbacksDispatcher/ +/// FrameworkunifiedAttachLoggerCallbacksDispatcher/ +/// FrameworkunifiedAttachVersionCallbacksDispatcher +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CreateDispatcher(PCSTR cAppName, HANDLE &hApp, BOOL bIsChildThread = FALSE); // NOLINT (readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////////////// +/// RunDispatcher +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus RunDispatcher(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// RunChildDispatcher +/// Dispatcher for child thread. Only difference with \ref RunDispatcher is, child dispatcher +/// exits when non eFrameworkunifiedStatusOK value by callback function is returned. +/// Whereas, \ref RunDispatcher is not supposed to exit. +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus RunChildDispatcher(HANDLE hChildApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// IsValidWaitBarrier +/// +/// \param [in] wbret +/// int - barrier +/// +/// \return bool +/// valid or invalid +//////////////////////////////////////////////////////////////////////////////////////////// +bool IsValidWaitBarrier(int wbret); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// setChildThreadSched +/// +/// \param [in] policy +/// EFrameworkunifiedSchedPolicy - scheduling policy +/// \param [in] priority +/// SI_32 - scheduling priority +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus setChildThreadSched(EFrameworkunifiedSchedPolicy policy, SI_32 priority); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// CreateChildThread +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// \param [in] childName +/// PCSTR - Name of child thread to be created +/// \param [in] CbInitialize +/// CbFuncPtr - Initialize function. +/// \param [in] CbShutdown +/// CbFuncPtr - Shutdown function. +/// \param [in] attr +/// const FrameworkunifiedChildThreadAttr * - child thread attribute +/// \param [in] CbCreateStateMachine +/// CbFuncPtr - Function pointer to create state machine, in case of SM child thread, else NULL +/// +/// \return HANDLE +/// Non-null value if thread is created else NULL +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE CreateChildThread(HANDLE hApp, PCSTR childName, CbFuncPtr CbInitialize, CbFuncPtr CbShutdown, + const FrameworkunifiedChildThreadAttr *attr, CbFuncPtr CbCreateStateMachine); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// Child thread attribute initialize +/// +/// \param [out] attr +/// FrameworkunifiedChildThreadAttr - Child thread attribute +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CreateChildThreadAttrInit(FrameworkunifiedChildThreadAttr *attr); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// Child thread attribute set schedule policy & priority +/// +/// \param [out] attr +/// FrameworkunifiedChildThreadAttr - Child thread attribute +/// \param [int] policy +/// EFrameworkunifiedSchedPolicy - Child thread scheduling policy +/// \param [in] priority +/// SI_32 - Child thread scheduling priority +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CreateChildThreadAttrSetSched(FrameworkunifiedChildThreadAttr *attr, EFrameworkunifiedSchedPolicy policy, SI_32 priority); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// DestroyThread +// Sends eFrameworkunifiedStatusExit status to exits the dispatcher loop to terminate the thread. +/// +/// \param [in] hApp +/// HANDLE - Handle to the Framework +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus DestroyThread(HANDLE hApp); + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_CORE_H_ diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_error_internal.hpp b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_error_internal.hpp new file mode 100755 index 0000000..8599fb2 --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_error_internal.hpp @@ -0,0 +1,43 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSFramework +/// \brief This file provides framework's API which are used by system services. +/////////////////////////////////////////////////////////////////////////////// +//@{ + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_ERROR_INTERNAL_HPP_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_ERROR_INTERNAL_HPP_ + +#include +#include + +namespace frameworkunified { +namespace framework { +namespace error { + +class CSystemError : public std::runtime_error { + public: + explicit CSystemError(EFrameworkunifiedSystemError error, PCSTR errorMsg); + const EFrameworkunifiedSystemError m_eSystemError; +}; +} +} +} + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_ERROR_INTERNAL_HPP_ +//@} diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_internal.h b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_internal.h new file mode 100755 index 0000000..4d38828 --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_internal.h @@ -0,0 +1,675 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSFramework +/// \brief Internal functions of the application framework. +/// +/// +/// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_INTERNAL_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_INTERNAL_H_ + +#include +#include +#include "frameworkunified_framework_core.h" +#define PASA_APPCONFIG_FILES "PASA_APPCONFIG_FILES" + +#define FRAMEWORKUNIFIEDLOG_CUT(zone, funcname, print_fmt, args...) + +////////////////////////////////////////////////// +// dispatcher internal functions +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedAttachSystemCallbacksDispatcher +/// All system defined callbacks will be attached to the dispatcher +/// +/// \param [in] hApp +/// HANDLE - Handle to the application framework. +/// +/// \return eStatus +/// EFrameworkunifiedStatus - success or error +/// +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedAttachSystemCallbacksDispatcher(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedSendSystemErrMessage +/// This API is used to send application's critical error message to system manager. +/// +/// \param [in] hApp +/// HANDLE - Handle to the application framework. +/// \param [in] eSystemError +/// EFrameworkunifiedSystemError - System error type +/// +/// \return EFrameworkunifiedStatus - success or error +/// +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedSendSystemErrMessage(HANDLE hApp, EFrameworkunifiedSystemError eSystemError); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedCreateDispatcher +/// Creates and initializes an applications/threads dispatcher. +/// +/// \param [in] cAppname +/// PCSTR - Application/ thread name +/// \param [out] hApp +/// HANDLE& - Reference of application handle +/// \param [in] bIsChildThread +/// BOOL - child thread +/// +/// \return status +/// EFrameworkunifiedStatus - eFrameworkunifiedStatusOK if Success +/// possible errors from call CreateDispatcher +/// +/// \see FrameworkunifiedDispatchBlock, +/// FrameworkunifiedDispatchProcess, FrameworkunifiedCloseDispatcher, +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedCreateDispatcher(PCSTR cAppName, HANDLE &hApp, BOOL bIsChildThread); // NOLINT (readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedCreateHSMDispatcher +/// Creates and initializes an applications/threads hsm dispatcher. +/// +/// \param [in] cAppname +/// PCSTR - Application/ thread name +/// \param [out] hApp +/// HANDLE& - Reference of application handle +/// \param [in] bIsThread +/// BOOL - child thread +/// \param [in] f_pFrameworkunifiedHSM +/// CFrameworkunifiedHSMFramework* - statemachine instances +/// +/// \return status +/// EFrameworkunifiedStatus - eFrameworkunifiedStatusOK if Success +/// possible errors from call CreateDispatcher +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedCreateHSMDispatcher(PCSTR cAppName, + HANDLE &hApp, // NOLINT (readability/nolint) + BOOL bIsThread, + CFrameworkunifiedHSMFramework *f_pFrameworkunifiedHSM = NULL); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedDispatchBlock +/// Blocked until the dipatcher receives a notification of a service request or ack. +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// EFrameworkunifiedStatus -Success or error +/// +/// \see FrameworkunifiedCreateDispatcher, +/// FrameworkunifiedDispatchProcess, FrameworkunifiedCloseDispatcher, +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedDispatchBlock(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// frameworkunifiedFdHandler +/// FD POLLIN blocked & process. +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// \param [in] efd +/// int - epoll FD +/// +/// \return status +/// EFrameworkunifiedStatus -Success or error +/// +/// \see FrameworkunifiedCreateDispatcher, FrameworkunifiedDispatchProcess, FrameworkunifiedDispatchBlock, +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus frameworkunifiedFdHandler(HANDLE hApp , int efd); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedDispatchProcess +/// Processes the Service/system request or notification. +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// EFrameworkunifiedStatus -Success or error +/// +/// \see FrameworkunifiedCreateDispatcher, FrameworkunifiedDispatchBlock +/// FrameworkunifiedCloseDispatcher, +/// +/// \details +/// \code +/// Pseudo code: +/// IF message_source != Notification Service +/// FIND source_name +/// IF source_name available +/// FIND protocol_cmd +/// IF protocol_cmd available +/// execute callback +/// ELSE +/// ignore +/// END +/// ELSE +/// ignore +/// END +/// ELSE // notification +/// FIND notification_callback +/// IF available +/// execute callback +/// END +/// \endcode +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedDispatchProcess(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedCloseDispatcher +/// Closing the dispatcher +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// EFrameworkunifiedStatus -Success or error +/// +/// \see FrameworkunifiedCreateDispatcher, FrameworkunifiedDispatchBlock +/// FrameworkunifiedDispatchProcess. +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedCloseDispatcher(HANDLE hApp); + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedPopedDeferedMessage +/// Checks the Defer'ed Message Queue should be pop'ed off +/// the front of the queue! +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// BOOL - TRUE (a message has been pop'ed of the defer'ed msg queue) +/// FALSE (no msg was pop'ed of the defer'ed msg queue) +/// +/// \see FrameworkunifiedCreateDispatcher, FrameworkunifiedDispatchBlock +/// FrameworkunifiedDispatchProcess. +/// +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL FrameworkunifiedPopedDeferedMessage(HANDLE hApp); + + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedDispatcherMain +/// Main processing loop that is shared between FrameworkunifiedDispacther and FrameworkunifiedDispatcherWithCmdLnArguments. +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// BOOL - TRUE (a message has been pop'ed of the defer'ed msg queue) +/// FALSE (no msg was pop'ed of the defer'ed msg queue) +/// +/// \see FrameworkunifiedCreateDispatcher, FrameworkunifiedDispatchBlock +/// FrameworkunifiedDispatchProcess. +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedDispatcherMain(HANDLE hApp); + +EFrameworkunifiedStatus FrameworkunifiedHSMDispatcherMain(HANDLE hApp); + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedDispatcherMain +/// Main processing loop that is shared between FrameworkunifiedDispacther and FrameworkunifiedDispatcherWithCmdLnArguments. +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// BOOL - TRUE (a message has been pop'ed of the defer'ed msg queue) +/// FALSE (no msg was pop'ed of the defer'ed msg queue) +/// +/// \see FrameworkunifiedCreateDispatcher, FrameworkunifiedDispatchBlock +/// FrameworkunifiedDispatchProcess. +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedArgumentParser(HANDLE hApp, int argc, char *argv[], CustomCommandLineOptions *cmdLineOptions); + + +EFrameworkunifiedStatus FrameworkunifiedOnInitializationInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnDestroyInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnStartInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnStopInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnPreStartInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnPreStopInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStartInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStopInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedOnDebugDumpInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedCreateStateMachineInternal(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedSSFrameworkInterfaceInternal(HANDLE hApp); +EFrameworkunifiedStatus RegistDefaultCbHandler(const FrameworkunifiedDefaultCallbackHandler *CbHandler); + + +////////////////////////////////////////////////// +// message center internal functions +////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// frameworkunifiedGetIsTypeOfSync +/// Gets if message type is sync, return TRUE. or not return FALSE +/// +/// \param [in] hApp +/// HANDLE - Handle to a Application Framework +/// +/// \return status +/// BOOL - TRUE or FALSE +/// +/// \see FrameworkunifiedInvokeSync, frameworkunifiedSendSyncResponse +/// +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL frameworkunifiedGetIsTypeOfSync(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedSendSyncResponse +/// Send Sync Response to the hApp. +/// +/// \param [in] hApp +/// HANDLE - Handle to the dispatcher to receive message +/// \param [in] seq_id +/// UI_32 - Sync sequence ID +/// \param [in] retValue +/// EFrameworkunifiedStatus - Return Status +/// \param [in] length +/// UI_32 - Length of the data to be receive response. +/// \param [in] data +/// PVOID - Pointer to the response data. +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +/// +/// \see FrameworkunifiedInvokeSync +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus frameworkunifiedSendSyncResponse(HANDLE hApp, UI_32 iCmd, UI_32 seq_id, EFrameworkunifiedStatus retValue, UI_32 length, PCVOID data); + +////////////////////////////////////////////////// +// logger internal functions +////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedAttachLoggerCallbacksDispatcher(HANDLE hApp); + +#ifdef DISPATCHER_PROFILER +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedAttachMsgProfilerCallbacksDispatcher +/// This function attaches callback function for profiler protocol for main thread. +/// Protocol is attached considering the source as "nsprofilerutil" +/// +/// \param [in] hApp +/// HANDLE - Handle to a Application Framework +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedAttachMsgProfilerCallbacksDispatcher(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedAttachMsgProfilerCallbacksDispatcher +/// This function attaches callback function for profiler protocol for child threads. +/// Protocol is attached considering the source as parent thread +/// +/// \param [in] hApp +/// HANDLE - Handle to a Application Framework +/// +/// \return status +/// EFrameworkunifiedStatus - success or error +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus FrameworkunifiedAttachChildMsgProfilerCallbacksDispatcher(HANDLE hApp); +#endif + +EFrameworkunifiedStatus FrameworkunifiedSetLogMask(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedGetLogMask(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedSetOutputLogOpts(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedGetOutputLogOpts(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedSetLogSeverity(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedGetLogSeverity(HANDLE hApp); +EFrameworkunifiedStatus FrameworkunifiedDebugDumpRequest(HANDLE hApp); + +EFrameworkunifiedStatus NSRcsSetLogSettings(HANDLE hApp); +EFrameworkunifiedStatus NSRcsGetLogSettings(HANDLE hApp); +EFrameworkunifiedStatus NSRcsSetLogMask(HANDLE hApp); +EFrameworkunifiedStatus NSRcsSetOutputLogOpts(HANDLE hApp); +EFrameworkunifiedStatus NSRcsSetLogSeverity(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// SetConfigHandle +/// This Function opens the configuration file from given path and sets the file handle in hApp +/// +/// \param [in] cAppname +/// HANDLE - Application handle +/// \param [in] sFilePath +/// PCHAR - File path of the config file +/// +/// \return status of the operation +/// +/// \see SetDefaultFilePath, +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SetConfigHandle(HANDLE hApp, PCHAR sFilePath); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// SetDefaultFilePath +/// This Function fetches the default config path, opens the configuration file and sets the file +/// handle in the application +/// +/// \param [in] cAppname +/// HANDLE - Application handle +/// \param [in] sFilePath +/// PCHAR - File path of the config file +/// +/// \return status of the operation +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SetDefaultConfigFile(HANDLE hApp); + +EFrameworkunifiedStatus FrameworkunifiedProcessServiceProtocolHSMEvent(HANDLE hApp, PCSTR pRequester); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// ProcessProtocolEvents +/// This Function registers the events of server with the client. +/// If the event is published previously and is a state event then send the event data to the client. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// +/// \return status of the operation +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus ProcessProtocolEvents(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// ProcessPrivateEvents +/// This Function registers the events of server with the client. +/// If the event is published previously and is a state event then send the event data to the client. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// +/// \return status of the operation +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus ProcessPrivateEvents(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// CleanAllEventsOfSession +/// This Function closes the session handle and removes its entry from the table of +/// ServiceSessionHandleTable of application framework handle. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] serviceName +/// PCSTR - Name of a service +/// \param [in] sessionId +/// UI_32 - Session id +/// +/// \return status of the operation +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CleanAllEventsOfSession(HANDLE hApp, PCSTR serviceName, UI_32 sessionId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// RemoveEntryFromSessionEventInfoTable +/// This Function removes the entry of event id from the session table based on the service +/// name and session id. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] serviceName +/// PCSTR - Name of service +/// \param [in] sessionId +/// UI_32 - Session id +/// \param [in] eventId +/// UI_32 - Event id which needs to be removed from internal table +/// +/// \return eFrameworkunifiedStatusOK- Success, or eFrameworkunifiedStatusFail +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus RemoveEntryFromSessionEventInfoTable(HANDLE hApp, PCSTR serviceName, UI_32 sessionId, UI_32 eventId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// HandleSessionEventOnCloseSession +/// This Function does the handling of session events on close session request +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// +/// \return status of the operation +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus HandleSessionEventOnCloseSession(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// UnregisterPrivateEvents +/// This Function unregisters the private event. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// +/// \return status of the operation +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus UnregisterPrivateEvents(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// GetMsgQueueHandle +/// Gets the message queue handle from servicesessionhandletable map. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] serviceName +/// PCSTR - Service name of receiver +/// \param [in] uiSessionId +/// UI_32 - session id +/// +/// \return Message queue handle +/// +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE GetMsgQueueHandle(HANDLE hApp, PCSTR serviceName, const UI_32 uiSessionId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// GetNewMsgQueueHandle +/// This function creates and returns the message queue handle. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] serviceName +/// PCSTR - Service name of receiver +/// \param [in] uiSessionId +/// UI_32 - session id +/// \param [in] uiEventId +/// const UI_32 - event id +/// +/// \return Message queue handle +/// +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE GetNewHandleAndUpdateEventInfoTable(HANDLE hApp, PCSTR serviceName, const UI_32 uiSessionId, + const UI_32 uiEventId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// IsEventAlreadyRegistered +/// Searches for the session id in the vector +/// +/// \param [in] vSessionIdList +/// SessionIdList - list of sessions id's +/// \param [in] uiSessionId +/// UI_32 - session id +/// +/// \return true or false +/// +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL IsEventAlreadyRegistered(const SessionIdList &vSessionIdList, const UI_32 uiSessionId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// RemoveEventEntryFromEventTable +/// This Function removes the entry of event for received service on the active session id +/// from Event Table. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] uiEventId +/// UI_32 - event id +/// \param [in] serviceName +/// PCSTR - Service name of receiver +/// \param [in] uiSessionId +/// UI_32 - session id +/// +/// \return success or failure +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus RemoveEventEntryFromEventTable(HANDLE hApp, UI_32 uiEventId, PCSTR cServiceName, const UI_32 uiSessionId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// SendEventMessage +/// This function sends the private event message to all the sessions of service registered +/// for event. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] vSessionIdList +/// SessionIdList - session id list +/// \param [in] uiEventId +/// UI_32 - event id +/// \param [in] cServiceName +/// PCSTR - Service name of receiver +/// \param [in] pData +/// PCVOID - data to send +/// \param [in] uiLength +/// UI_32 - length of data +/// +/// \return success or failure +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendEventMessage(HANDLE hApp, const SessionIdList &vSessionIdList, UI_32 uiEventId, PCSTR cServiceName, + PCVOID pData, UI_32 uiLength); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// UpdatePublicStateEventData +/// This API updates the event data of public state event for all the session of +/// all subscribed clients. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] uiEventId +/// UI_32 - event id +/// \param [in] pData +/// PCVOID - data to send +/// \param [in] uiLength +/// UI_32 - length of data +/// +/// \return success or failure +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus UpdatePublicStateEventData(HANDLE hApp, UI_32 uiEventId, PCVOID pData, UI_32 uiLength); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// UpdatePrivateStateEventData +/// This API updates the event data of private state event for session with +/// session id uiSessionId of client pClientName. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] uiEventId +/// UI_32 - event id +/// \param [in] pClientName +/// PCSTR - Event Subscriber name +/// \param [in] uiSessionId +/// UI_32 - session id +/// \param [in] pData +/// PCVOID - data to send +/// \param [in] uiLength +/// UI_32 - length of data +/// +/// \return success or failure +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus UpdatePrivateStateEventData(HANDLE hApp, UI_32 uiEventId, PCSTR pClientName, UI_32 uiSessionId, PCVOID pData, + UI_32 uiLength); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// DeleteSessionEventData +/// This function is called while destroying the session with client. +/// This method removes the private event data associated with the session. +/// +/// \param [in] hApp +/// HANDLE - Application handle +/// \param [in] pClientName +/// PCSTR - Event Subscriber name +/// \param [in] uiSessionId +/// UI_32 - session id +/// +/// \return success or failure +/// +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus DeleteSessionEventData(HANDLE hApp, PCSTR pClientName, UI_32 uiSessionId); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedGetDataUSID +/// Gets the shared memory ID +/// +/// \param [in] hApp +/// HANDLE - Application framework handle +/// +/// \return status +/// UI_32 - success or error +/// +/// \see FrameworkunifiedMcOpenSender, FrameworkunifiedMcClose, FrameworkunifiedSendMsg, FrameworkunifiedGetMsgLength, FrameworkunifiedGetMsgSrc, FrameworkunifiedGetMsgDataOfSize, +/// FrameworkunifiedClearMsgData, FrameworkunifiedForwardMessage, FrameworkunifiedGetSystemInfo +/// +//////////////////////////////////////////////////////////////////////////////////////////// +TMemID FrameworkunifiedGetDataUSID(HANDLE hApp); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedIsAutoPublishServiceAvailableEnabled +/// This function is used to check whether auto publishing of service availability is +/// enabled or not. +/// +/// \param None +/// +/// \return BOOL +/// BOOL - true if auto publish is enabled for service else false +/// +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL FrameworkunifiedIsAutoPublishServiceAvailableEnabled(); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// FrameworkunifiedIsWaitInStoppingStateEnabled +/// Check if wait in stopping state is enabled. +/// +/// \param [in] none +/// +/// \return BOOL - TRUE if enabled or FALSE +/// +//////////////////////////////////////////////////////////////////////////////////////////// +BOOL FrameworkunifiedIsWaitInStoppingStateEnabled(); + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_INTERNAL_H_ diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_utility.h b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_utility.h new file mode 100755 index 0000000..b78297e --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_framework_utility.h @@ -0,0 +1,41 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_UTILITY_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_UTILITY_H_ + +#include +#include "frameworkunified_framework_internal.h" + +DEFINE_EXCEPTION(happ_error, std::runtime_error); + +class HAppTraits { + public: + typedef HANDLE Type; + typedef happ_error Exception; + static void Release(Type rsrc) { + FrameworkunifiedOnDestroyInternal(rsrc); + FrameworkunifiedCloseDispatcher(rsrc); + } + + static BOOL BadValue(Type rsrc) { + return NULL == rsrc; + } +}; + +typedef ResourceMgr< HANDLE, HAppTraits > THApp; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_FRAMEWORK_UTILITY_H_ diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_msgprofiler.h b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_msgprofiler.h new file mode 100755 index 0000000..f512e76 --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/frameworkunified_msgprofiler.h @@ -0,0 +1,148 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +////////////////////////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSFramework +/// \brief File declares FrameworkunifiedMsgProfiler class which keeps profiler information for message dispatcher +/// +/// +/// +////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_MSGPROFILER_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_MSGPROFILER_H_ + +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// Profiler class which keeps and manage profiler information for message dispatcher +/////////////////////////////////////////////////////////////////////////////////////////////////// +class FrameworkunifiedMsgProfiler { + public: + /////////////////////////////////////////////////////////////////////////////////////////// + /// FrameworkunifiedMsgProfiler + /// Parameterized constructor + /// \param [in] f_cAppName + /// const std::string& - Name of the application or dispatcher + /// + /// \return none + /////////////////////////////////////////////////////////////////////////////////////////// + explicit FrameworkunifiedMsgProfiler(const std::string &f_cAppName); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// ~FrameworkunifiedMsgProfiler + /// Class destructor + /// + /// \return none + /////////////////////////////////////////////////////////////////////////////////////////// + ~FrameworkunifiedMsgProfiler(); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// GetAppName + /// Returns application name corresponding to profiler + /// + /// \param [in] none + /// + /// \return std::string + /// std::string - Returns application name corresponding to profiler + /// + /////////////////////////////////////////////////////////////////////////////////////////// + std::string GetAppName(); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// AddChildName + /// Returns application name corresponding to profiler + /// + /// \param [in] f_cChildName + /// const std::string& - Add the name of child dispatcher profiler + /// + /// \return none + /// + /////////////////////////////////////////////////////////////////////////////////////////// + VOID AddChildName(const std::string &f_cChildName); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// MsgReceived + /// Updates the profiler information once the message is received. + /// e.g. increaments msg count, save the time of msg received + /// + /// \param [in] none + /// + /// \return none + /// + /////////////////////////////////////////////////////////////////////////////////////////// + VOID MsgReceived(); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// MsgProcessed + /// Updates the profiler information once the message is processed. + /// e.g. Updates the frequency of execution of message + /// + /// \param [in] none + /// + /// \return none + /// + /////////////////////////////////////////////////////////////////////////////////////////// + VOID MsgProcessed(); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// PrintProfileInfo + /// All the profiler information which FrameworkunifiedMsgProfiler class has prints it in message + /// queue FRAMEWORKUNIFIED_NS_MSGPROFILERUTIL + /// + /// \param [in] f_hApp + /// HANDLE - Application framework handle + /// + /// \return status + /// EFrameworkunifiedStatus - success or failure + /// + /////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus PrintProfileInfo(HANDLE f_hApp); + + static BOOL m_bMsgProfilerEnabled; /// Flag is enabled when command line argument -q is passed. + /// Otherwise no profiler information is maintained. + + private: + /////////////////////////////////////////////////////////////////////////////////////////// + /// GetClock + /// GetClock of milliseconds + /// + /// \param [in] none + /// + /// \return UI_64 + /// UI_64 - returns time in Milliseconds + /// + /////////////////////////////////////////////////////////////////////////////////////////// + UI_64 GetClock(); + + std::vector m_vChildNames; /// vector to save list of all child threads dispatcher + std::string m_cAppName; /// Dispacther application name + UI_32 m_ui32TotalNoOfMsgsReceived; /// Total number of messages received by the dispatcher + + // NOTE: Storing time in ClockCycle. So that it will not add overhead for converting it to miliseconds. + // It will get converted only when information is required to print. + UI_64 m_ui64MinMsgProcessingTime; // time is in clock cycles + UI_64 m_ui64MaxMsgProcessingTime; // time is in clock cycles + + UI_64 m_ui64TotalMsgExecutionTime; /// total time spent in message execution + UI_64 m_ui64LastMsgReceivedTime; /// save the time when last message was received + UI_64 m_ui64AppInitTime; /// save the time when application got initialized + BOOL m_bLastMsgWasPrintProfile; /// TRUE if the last message received +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_FRAMEWORKUNIFIED_MSGPROFILER_H_ diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_finalstate.h b/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_finalstate.h new file mode 100755 index 0000000..20ed3f6 --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_finalstate.h @@ -0,0 +1,97 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_StateMachine +/// \brief +/// +/// This file has the CFrameworkunifiedFinalState class definitions. CFrameworkunifiedFinalState is derived from +/// CFrameworkunifiedState class.This class implements the additional functionality supported by HSM Final +/// state. +/// +/////////////////////////////////////////////////////////////////////////////// +//@{ + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_FINALSTATE_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_FINALSTATE_H_ + + +#include + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// This class implements the additional functionality supported by HSM Final state. +/////////////////////////////////////////////////////////////////////////////////////////////////// +class CFrameworkunifiedFinalState : public CFrameworkunifiedState { + public : + + /////////////////////////////////////////////////////////////////////////////////////////// + /// CFrameworkunifiedFinalState + /// Parameterized constructor + /// \param [in] f_pName + /// string - Name of the state + /// + /// \return none + /////////////////////////////////////////////////////////////////////////////////////////// + CFrameworkunifiedFinalState(std::string f_pName); // NOLINT (readability/nolint) + + /////////////////////////////////////////////////////////////////////////////////////////// + /// ~CFrameworkunifiedFinalState + /// Class destructor + /// + /// \return none + /////////////////////////////////////////////////////////////////////////////////////////// + virtual ~CFrameworkunifiedFinalState(); + + virtual CFrameworkunifiedState *FrameworkunifiedGetActiveState(); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// UpdateHistory + /// This function stores the last active state + /// + /// \return EFrameworkunifiedStatus + /// EFrameworkunifiedStatus - Returns status of operation + /////////////////////////////////////////////////////////////////////////////////////////// + EFrameworkunifiedStatus UpdateHistory(); + + protected : + + /////////////////////////////////////////////////////////////////////////////////////////// + /// FrameworkunifiedOnEntry + /// state initialization can be performed in this function. + /// + /// \param [in] f_pEventData + /// CEventDataPtr - Event data + /// + /// \return EFrameworkunifiedStatus + /// EFrameworkunifiedStatus - Returns status of operation + /////////////////////////////////////////////////////////////////////////////////////////// + virtual EFrameworkunifiedStatus FrameworkunifiedOnEntry(CEventDataPtr f_pEventData); + + /////////////////////////////////////////////////////////////////////////////////////////// + /// FrameworkunifiedOnExit + /// state cleanup can be performed in this function. + /// + /// \param [in] f_pEventData + /// CEventDataPtr - Event data + /// + /// \return EFrameworkunifiedStatus + /// EFrameworkunifiedStatus - Returns status of operation + /////////////////////////////////////////////////////////////////////////////////////////// + virtual EFrameworkunifiedStatus FrameworkunifiedOnExit(CEventDataPtr f_pEventData); +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_FINALSTATE_H_ +// @} diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_framework_core.h b/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_framework_core.h new file mode 100755 index 0000000..ea564df --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_framework_core.h @@ -0,0 +1,89 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_StateMachine +/// \brief +/// +/// This File has public Macro definition that simplifies the statemachine implementation +/// +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_FRAMEWORK_CORE_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_FRAMEWORK_CORE_H_ +/// Include files +#include +#include +#include + +/// connect child state to parent state and sets it as default state +#define CONNECT_DEFAULTSTATE(parent, child) \ + FrameworkunifiedConnect(l_p## parent, l_p## child, TRUE); + +/// connect child state to parent state +#define CONNECT_STATE(parent, child) \ + FrameworkunifiedConnect(l_p## parent, l_p## child); + +/// connect the deferred event and reactions and associate them with the state +#define CONNECT_DEFERREDEVENT(state, eventid) \ + FrameworkunifiedConnect(l_p## state, _## eventid, NULL, #eventid, TRUE); \ + +/// connect the event and reactions and associate them with the state +#define CONNECT_EVENT(state, eventid, reaction) \ + FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn## reaction, #eventid); + +/// connect the event and reactions and associate them with the state +#define CONNECT_LOCAL_EVENT(state, eventid, reaction) \ + FrameworkunifiedConnect(l_p## state, _## eventid, l_pLocalTrn## reaction, #eventid); + +/// Sets the state as root state in the statemachine +#define CONNECTROOT(state) \ + FrameworkunifiedConnect(l_p## state); + +/// Creates the state +#define CREATE_STATE(class_name) \ + CHKNULL(m_pFrameworkunifiedStateList) \ + C## class_name *l_p## class_name = new C## class_name(#class_name); \ + CHKNULL(l_p## class_name) \ + m_pFrameworkunifiedStateList->insert(std::pair(e## class_name, l_p## class_name)); + +// create a new shallow history state and add it in parent state +#define ADD_SHALLOWHISTORYSTATE(parent) \ + CFrameworkunifiedShallowHistoryState *l_p##parent##SHALLOWHISTORYSTATE = new CFrameworkunifiedShallowHistoryState(SHALLOWHISTORYSTATE);\ + FrameworkunifiedConnect(l_p## parent, l_p##parent##SHALLOWHISTORYSTATE);\ + l_p##parent##SHALLOWHISTORYSTATE->SetDefaultHistory(); + +// create a new shallow history state and add it in parent state +#define ADD_DEEPHISTORYSTATE(parent) \ + CFrameworkunifiedDeepHistoryState *l_p##parent##DEEPHISTORYSTATE = new CFrameworkunifiedDeepHistoryState(DEEPHISTORYSTATE);\ + FrameworkunifiedConnect(l_p## parent, l_p##parent##DEEPHISTORYSTATE);\ + l_p##parent##DEEPHISTORYSTATE->SetDefaultHistory(); + +/// connect deep history event to reaction and add to state +#define CONNECT_DEEPHISTORYEVENT(state, eventid, reaction) \ + FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn##reaction##DEEPHISTORYSTATE, #eventid); + +/// connect shallow history event to reaction and add to state +#define CONNECT_SHALLOWHISTORYEVENT(state, eventid, reaction) \ + FrameworkunifiedConnect(l_p## state, _## eventid, l_pTrn##reaction##SHALLOWHISTORYSTATE, #eventid); + +typedef struct _HSMConfigOptions { + EUserChangeOptions eUserChange; + BOOL bAutoPublishServiceAvaialble; + BOOL bWaitInStoppingState; +} HSMConfigOptions; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_FRAMEWORK_CORE_H_ diff --git a/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_multithreading_internal.h b/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_multithreading_internal.h new file mode 100755 index 0000000..ff67029 --- /dev/null +++ b/service/native/framework_unified/client/NS_FrameworkCore/include/statemachine/frameworkunified_sm_multithreading_internal.h @@ -0,0 +1,30 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +////////////////////////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSFramework +/// \brief Internal functions related to state machine child threads +/// +/// +/// +////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_MULTITHREADING_INTERNAL_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_MULTITHREADING_INTERNAL_H_ + +void *child_hsm_thread_proc(void *args); + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_FRAMEWORKCORE_INCLUDE_STATEMACHINE_FRAMEWORKUNIFIED_SM_MULTITHREADING_INTERNAL_H_ -- cgit 1.2.3-korg