summaryrefslogtreecommitdiffstats
path: root/nsframework/framework_unified/client/include/native_service/frameworkunified_sm_dispatcher.h
blob: 2f392bab062284e5ab5c6d22b9d1927e29591f99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * @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 dispatch interface functions
///
///
///
///////////////////////////////////////////////////////////////////////////////
//@{
/**
 * @file frameworkunified_sm_dispatcher.h
 * @brief \~english Application dispatch interface functions
 *
 */
/** @addtogroup BaseSystem
 *  @{
 */
/** @addtogroup native_service
 *  @ingroup BaseSystem
 *  @{
 */
/** @addtogroup framework_unified
 *  @ingroup native_service
 *  @{
 */
/** @addtogroup framework
 *  @ingroup framework_unified
 *  @{
 */
/** @addtogroup statemachine
 *  @ingroup framework
 *  @{
 */
#ifndef __NATIVESERVICES_FRAMEWORK_FRAMEWORKUNIFIED_SM_DISPATCHER_H__  // NOLINT  (build/header_guard)
#define __NATIVESERVICES_FRAMEWORK_FRAMEWORKUNIFIED_SM_DISPATCHER_H__
#include <native_service/frameworkunified_framework_types.h>
#include <native_service/frameworkunified_sm_framework_types.h>

class CFrameworkunifiedHSMFramework;

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedHSMDispatcher
/// \~english @par Brief
///        Creates, initializes and runs the HSM dispatcher.
/// \~english @param [in] cAppName
///        PCSTR - pointer of Application/ thread name
/// \~english @retval EFrameworkunifiedStatus
/// \~english @par Prerequisite
///        - Prerequisites are nothing.
/// \~english @par Change of internal state
///        - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///        - none
/// \~english @par Detail
///        - none
/// \~english @par Classification
///        Public
/// \~english @par Type
///        none
/// \~english @see
///
////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedHSMDispatcher(PCSTR cAppName);

/////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedHSMDispatcherWithArguments
/// \~english @par Brief
///        This API creates, initializes the dispatcher and runs loop with command-line options.
/// \~english @param [in] cAppName
///        PCSTR   - Pointer to application thread name
/// \~english @param [in] argc
///        int   - Number of command-line options
/// \~english @param [in] argv
///        char *[]   - Array of pointer to command-line options
/// \~english @param [in] CbHandler
///        const FrameworkunifiedDefaultCallbackHandler*   - Pointer to default callback functions.
/// \~english @param [in] f_pFrameworkunifiedHSM
///        CFrameworkunifiedHSMFramework* - state machine object pointer(default NULL)
/// \~english @param [in] cmdLineOptions
///        CustomCommandLineOptions*   - Parser setting of command-line options(Optional. When don't use, set NULL.)
/// \~english @par
///        FrameworkunifiedDefaultCallbackHandler Structure
/// \~english @code
///                 typedef struct _FrameworkunifiedDefaultCallbackHandler
///                 {
///                       CbFuncPtr onInitilization;      /* Function is called when a Dispatcher is created.      */
///                       CbFuncPtr onDestroy;            /* Function is called when the Dispatcher is released.   */
///                       CbFuncPtr onStart;              /* Function is called when the Dispatcher is started.    */
///                       CbFuncPtr onStop;               /* Function is called when the Dispatcher is stopped.    */
///                       CbFuncPtr onPreStart;           /* Function is called when the Dispatcher is pre started. */
///                       CbFuncPtr onPreStop;            /* Function is called when the Dispatcher is pre stoped. */
///                       CbFuncPtr onBackgroundStart;    /* Function is called when the Dispatcher is Background started. */
///                       CbFuncPtr onBackgroundStop;     /* Function is called when the Dispatcher is Background stopped. */
///                       CbFuncPtr onDebugDump;  /* Function is called when the Dispatcher detects abnormal state. */
///                       CbFuncPtr createStateMachine;      /* Set dummy function that does nothing.               */
///                       CbFuncPtr ssFrameworkInterface;     /* Function to connect to SystemManager               */
///                 } FrameworkunifiedDefaultCallbackHandler;
///            @endcode
/// \~english @par
///        CustomCommandLineOptions Structure
/// \~english @code
///                 typedef struct _CustomCommandLineOptions
///                 {
///                     PCSTR            cShortOptions;          /* Short options list. */
///                     PCHAR            cLongOptions;           /* Reserved. Set to NULL. */
///                     CbArgumentParser callback;  /* Pointer to callback function to parse command-line options. */
///                 } CustomCommandLineOptions;
///            @endcode
/// \~english @par
///        About setting of default callback functions(FrameworkunifiedDefaultCallbackHandler)
///        - Use FRAMEWORKUNIFIED_MAKE_DEFAULT_CALLBACK when initialize of FrameworkunifiedDefaultCallbackHandler structure as argument CbHandler.
///        - Application that run this API need to define functions below.(allow to dummy function that does nothing.)
///            - EFrameworkunifiedStatus FrameworkunifiedOnInitialization(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnStart(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnStop(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnPreStart(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnPreStop(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStart(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnBackgroundStop(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnDebugDump(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedOnDestroy(HANDLE hApp)
///            - EFrameworkunifiedStatus FrameworkunifiedCreateStateMachine(HANDLE hApp)
///        - If application is resident service, link library libSS_SystemIfUnified
///          (This library provides the function FrameworkunifiedSSFrameworkInterface to connect to SystemManager.).
///        - If application is nonresident service, define function that does nothing below.
///            - EFrameworkunifiedStatus FrameworkunifiedSSFrameworkInterface(HANDLE hApp)
/// \~english @retval eFrameworkunifiedStatusNullPointer NULL pointer specified
/// \~english @retval eFrameworkunifiedStatusInvldParam Invalid parameter
/// \~english @retval eFrameworkunifiedStatusFail Some sort of error occurred
/// \~english @retval eFrameworkunifiedStatusDuplicate Duplication error of entry
/// \~english @retval eFrameworkunifiedStatusInvldHandle Invalid handle
/// \~english @retval eFrameworkunifiedStatusErrOther Other error has occurred(Cannot access shared memory, etc.)
/// \~english @retval eFrameworkunifiedStatusMsgQFull Message queue is full
/// \~english @retval eFrameworkunifiedStatusErrNoEBADF Invalid File-Descriptor
/// \~english @retval eFrameworkunifiedStatusErrNoEINTR An interrupt is generated by the system call (signal)
/// \~english @retval eFrameworkunifiedStatusInvldBufSize Invalid buffer-size
/// \~english @par Prerequisite
///       - Prerequisites are nothing.
/// \~english @par Change of internal state
///       - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///       - Application thread name specified in the argument (cAppName) is NULL. [eFrameworkunifiedStatusNullPointer]
///       - Pointer to default callback functions specified in the argument (CbHandler) is NULL. [eFrameworkunifiedStatusNullPointer]
///       - One of members in default callback functions specified in the argument (CbHandler) is NULL.
///       [eFrameworkunifiedStatusInvldParam]
///       - Application thread name specified in the argument (cAppName) is not appropriate(The name is more than
///       15byte). [eFrameworkunifiedStatusNullPointer]
///       - Failed to open message queue (mq_open). [eFrameworkunifiedStatusNullPointer]
///       - Failed to get memory (malloc) of message queue info area. [eFrameworkunifiedStatusNullPointer]
///       - Failed to initialize socket for monitoring abnormal state (socket, bind, listen). [eFrameworkunifiedStatusFail]
///       - Session message queue is full to the NPP Service. [eFrameworkunifiedStatusMsgQFull]
///       - It is invalid transmission file descriptor of the session message to the NPP Service. [eFrameworkunifiedStatusErrNoEBADF]
///       - Interruption by the system call (signal) has occurred during the transmission of the session message for the
///       NPP Service. [eFrameworkunifiedStatusErrNoEINTR]
///       - Incorrect size of the transmit buffer of the session message to the NPP Service. [eFrameworkunifiedStatusInvldBufSize]
///       - Any errors occur during the transmission of a session message to the NPP Service. [eFrameworkunifiedStatusFail]
///       - Failed to create of epoll instance (epoll_create1). [eFrameworkunifiedStatusInvldHandle]
///       - Failed to register of a descriptor of the message queue to the epoll instance (epoll_ctl).
///       [eFrameworkunifiedStatusInvldHandle]
///       - Failed to create file descriptor for receive event (eventfd). [eFrameworkunifiedStatusFail]
///       - Failed to register of a descriptor for receive event to the epoll instance (epoll_ctl). [eFrameworkunifiedStatusFail]
///       - Failed to register of a socket for detect abnormal state to the epoll instance (epoll_ctl). [eFrameworkunifiedStatusFail]
///       - The result of FrameworkunifiedOnInitialization is not eFrameworkunifiedStatusOK. [eFrameworkunifiedStatusNullPointer]
/// \~english @par Detail
///        This API creates and initializes the dispatcher with command-line options.\n
///        It starts to mainloop that receives request or notification, and runs registered callback to dispatcher.
///        When success starting mainloop, never return.
///        Use this API to take over a command-line options to the dispatcher.
/// \~english @par
///        Please note the following points when using this API for application.
///        - Error handling is not performed when the state machine event registration process (CFrameworkunifiedHSMFramework::FrameworkunifiedCreate) fails.\n
///          The behavior of state machine objects must be guaranteed by the application implementation.
///        - When an exception occurs during Dispatcher generating, an error log is output and eFrameworkunifiedStatusOK is returned.
/// \~english @par Classification
///          Public
/// \~english @par Type
///        No match
/// \~english @see none
////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus FrameworkunifiedHSMDispatcherWithArguments(PCSTR cAppName, int argc, char *argv[],
                                         const FrameworkunifiedDefaultCallbackHandler *CbHandler,
                                         CFrameworkunifiedHSMFramework *f_pFrameworkunifiedHSM = NULL,
                                         CustomCommandLineOptions *cmdLineOptions = NULL);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedSetHSMType
/// \~english @par Brief
///        Set the Application Statemachine Type
/// \~english @param [in] cAppName
///        PCSTR - pointer of Application/ thread name
/// \~english @code
///     typedef enum _EUserChangeOptions {
///       eUserchangeIgnore = 0,
///       eUserchangeReInit,
///       eUserchangeRetPrevState
///     } EUserChangeOptions;
///            @endcode
/// \~english @retval EFrameworkunifiedStatus
/// \~english @par Prerequisite
///        - Prerequisites are nothing.
/// \~english @par Change of internal state
///        - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///        - none
/// \~english @par Detail
///        - none
/// \~english @par Classification
///        Public
/// \~english @par Type
///        none
/// \~english @see 
///
////////////////////////////////////////////////////////////////////////////////////////////
void FrameworkunifiedSetHSMType(EUserChangeOptions f_eHSMType);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedEnableAutoPublishServiceAvailable
/// \~english @par Brief
///        Enables the AutoPublishServiceAvailability Feature
/// \~english @param none
/// \~english @retval EFrameworkunifiedStatus
/// \~english @par Prerequisite
///        - Prerequisites are nothing.
/// \~english @par Change of internal state
///        - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///        - none
/// \~english @par Detail
///           Enables the AutoPublishServiceAvailability Feature that publishes the service
///           availability on entry of sFrameworkunifiedReady state and publishes the service unavailability
///           on exit of sFrameworkunifiedReady state.
/// \~english @par Classification
///        Public
/// \~english @par Type
///        none
/// \~english @see 
///
////////////////////////////////////////////////////////////////////////////////////////////
void FrameworkunifiedEnableAutoPublishServiceAvailable();

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedDisableAutoPublishServiceAvailable
/// \~english @par Brief
///        Disable to the AutoPublishServiceAvailability Feature.
/// \~english @retval None
/// \~english @par Prerequisite
///       - Prerequisite is nothing.
/// \~english @par Change of internal state
///       - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///       None.
/// \~english @par Detail
///        This API disable feature that notify automatically service availability to clients
///        at the timing of changing of internal state.\n
///        If you disable this feature, the application needs to publish service availability state explicitly
///        using FrameworkunifiedPublishServiceAvailability.
/// \~english @par Classification
///          Forbidden
/// \~english @see FrameworkunifiedHSMDispatcherWithArguments FrameworkunifiedPublishServiceAvailability
////////////////////////////////////////////////////////////////////////////////////////////
/// FrameworkunifiedDisableAutoPublishServiceAvailable
/// Disables the AutoPublishServiceAvailability Feature that publishes the service
/// availability on entry of sFrameworkunifiedReady state and publishes the service unavailability
/// on exit of sFrameworkunifiedReady state. Applications are responsible for publishing the service
/// availability.
void FrameworkunifiedDisableAutoPublishServiceAvailable();

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedHSMEnableWaitInStoppingState
////////////////////////////////////////////////////////////////////////////////////////////
/// FrameworkunifiedHSMEnableWaitInStoppingState
/// If HSM application should wait in sStoppingState until user explicitly publishes evFrameworkunifiedStopComplete,
/// then call this function before FrameworkunifiedHSMDispatcher APIs.
/// Default behavior is application will not wait is sStoppingState.
///
/// \~english @par Brief
///         Change state application when call FrameworkunifiedOnStop().
/// \~english @retval None
/// \~english @par Prerequisite
///       - Prerequisite is nothing.
/// \~english @par Change of internal state
///       - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///       None.
/// \~english @par Detail
///            If HSM application should wait in sStoppingState until user explicitly publishes evFrameworkunifiedStopComplete,
///            then call this function before FrameworkunifiedHSMDispatcher APIs.
///            Default behavior is application will not wait in sStoppingState.
/// \~english @par Classification
///        Public
/// \~english @par Type
///        none
/// \~english @see FrameworkunifiedHSMDisableWaitInStoppingState
VOID FrameworkunifiedHSMEnableWaitInStoppingState();

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup FrameworkunifiedHSMDisableWaitInStoppingState
/// \~english @par Brief
///         Chanage state to not wait in sStoppingState.
/// \~english @retval None
/// \~english @par Prerequisite
///       - Prerequisite is nothing.
/// \~english @par Change of internal state
///       - Change of internal state according to the API does not occur.
/// \~english @par Conditions of processing failure
///       None.
/// \~english @par Detail
///       If HSM application should not wait in sStoppingState, then call this function before FrameworkunifiedHSMDispatcher APIs.\n
///       Default behavior is application will not wait is sStoppingState. So, it's not mandatory to use it.\n
/// \~english @par Classification
///        Public
/// \~english @par Type
///        none
/// \~english @see FrameworkunifiedHSMEnableWaitInStoppingState
VOID FrameworkunifiedHSMDisableWaitInStoppingState();

#endif  // __NATIVESERVICES_FRAMEWORK_FRAMEWORKUNIFIED_SM_DISPATCHER_H__  // NOLINT  (build/header_guard)
/** @}*/
/** @}*/
/** @}*/
/** @}*/
/** @}*/
//@}