summaryrefslogtreecommitdiffstats
path: root/nsframework/framework_unified/client/include/native_service/ns_timer_if.h
blob: 549fc4c3190fc62782a17b4b8cdd93c97f4f8152 (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
/*
 * @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.
 */

/**
 * @file ns_timer_if.h
 * @brief \~english APIs to create, delete and use Native Service timers .
 *
 */
/** @addtogroup BaseSystem
 *  @{
 */
/** @addtogroup native_service
 *  @ingroup BaseSystem
 *  @{
 */
/** @addtogroup framework_unified
 *  @ingroup native_service
 *  @{
 */
/** @addtogroup native
 *  @ingroup framework_unified
 *  @{
 */
#ifndef __NATIVESERVICES_TIMER_H__  // NOLINT  (build/header_guard)
#define __NATIVESERVICES_TIMER_H__

#include <native_service/frameworkunified_types.h>


#ifdef __cplusplus
extern "C" {
#endif

#define TIMER_QUE "TIMER"

#define MAX_SERVICE_NAME 15

/// \brief Timer Function Pointer definition
/// Detailed description of the class
typedef void (*TimerCb)(UI_16 cmd);

/// \brief Timer info, defines the initial
/// start of a timer, the repeat timer
/// values and the cmd id for a timer
typedef struct _NSTimerInfo {

//  UI_32 t_sec;
  time_t t_sec;
  UI_64 t_nsec;
  UI_16 iCmd;

//  UI_32 rpt_sec;
  time_t rpt_sec;
  UI_64 rpt_nsec;
} NSTimerInfo;

/// \brief Enum Types for valid Callback Mechanisms for
/// a NS_Timer
typedef enum _NSTimerCallbackMechanism {
  CALLBACK_MESSAGE
} eNSTimerCallbackMechanism;

/// \brief Helper methods that convert time provided in MS.
/// mseconds

/////////////////////////////////////////////////////////////////////////////////////
/// \ingroup WholeSeconds
/// \~english @par Brief
///        Converts a time value in milliseconds (ms) to a time value in secods (s).
/// \~english @param [in] ms
///        UI_32 - Time value in milliseconds(0 to ULONG_MAX)
/// \~english @retval Time value in seconds
/// \~english @par Preconditons
///       - none
/// \~english @par Change of internal status
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///       - none
/// \~english @par Detail
///       This function converts a time value in ms to a time value in s and returns it.\n
///       For example, 12345ms obtains 12s as the conversion result.
/// \~english @par Classification
///          Public
/// \~english @par Type
///          Not applicable
/// \~english @see
///          none
///
/// \~english @par Brief
///        Get the number of whole seconds in the milsecond number that was passed.
/// \~english @param[in] ms
///        UI_32 - time value in mil seconds
/// \~english @retval Number of whole seconds in the number passed.
/// \~english @par Preconditons
/// \~english @par Change of internal status
/// \~english @par Conditions of processing failure
/// \~english @par Detail
/// \~english @par Classification
/// \~english @par Type
/// \~english @see
///         none
/////////////////////////////////////////////////////////////////////////////////////

//UI_32 WholeSeconds(UI_32 ms);
time_t WholeSeconds(UI_32 ms);

/////////////////////////////////////////////////////////////////////////////////////
/// \ingroup RemainderMs
/// \~english @par Brief
///        Get the number of remaining milseconds out of whole second for the number passed.
/// \~english @param[in] ms
///        UI_32 - time value in mil seconds
/// \~english @retval Number of remaining mil seconds in the number passed.
/// \~english @par Preconditons
///         none
/// \~english @par Change of internal status
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///         none
/// \~english @par Detail
///       This function returns the time value in ms of the remainder from converting the time value in ms to the time value in s.\n
///       For example, 12345ms obtains 345ms as the conversion result.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see
///         none
/////////////////////////////////////////////////////////////////////////////////////
UI_32 RemainderMs(UI_32 ms);

/////////////////////////////////////////////////////////////////////////////////////
/// \ingroup MSToNS
/// \~english @par Brief
///        Converts mil seconds to nano seconds.
/// \~english @param[in] ms
///        UI_32 - time value in mil seconds
/// \~english @retval Number of nano seconds there are in mil seconds in the number passed.
/// \~english @par Preconditons
///         none
/// \~english @par Change of internal status
///       - The internal state is not changed.
/// \~english @par Conditions of processing failure
///         none
/// \~english @par Detail
///       This function converts a time value in ms to a time value in ns and returns it.\n
///       For example, 1234ms obtains 1234000000ns as the conversion result.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see
///         none
/////////////////////////////////////////////////////////////////////////////////////
UI_64 MSToNS(UI_32 ms);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup NS_TimerCreate
/// \~english @par Brief
///        to create an instance of a timer object, and start it
/// \~english @param[in] timer_info
///        NSTimerInfo - timer value represents an absolute expiration timeout
/// \~english @param[in] cbMech
///        eNSTimerCallbackMechanism - CALLBACKMECHANISM_ENUM - specifies the callback mechanism associated with the
///        timer\n
///                                    CALLBACK_MESSAGE   will send a message to a message queue
/// \~english @param[in] sndMqHndl
///        HANDLE - implies a MESSAGE QUE HANDLE generated by McOpenSender() is specified
/// \~english @retval Handle to the timer object or NULL on failure
/// \~english @par Preconditons
///         none
/// \~english @par Change of internal status
/// - The internal state is not changed.
/// \~english @par Conditions of processing failure
/// - If HANDLE(sndMqHndl) is NULL, [NULL]
/// - If the Callback mechanism (cbMech) specified in the arguments is not CALLBACK_MESSAGE [NULL]
/// - If thread creation fails (reateTimerMonitoringThread(); returns eFrameworkunifiedStatusFail) [NULL]
/// - Unable to allocate memory for timer handle structures [NULL]
/// - Memory cannot be allocated for the timer-information struct. [NULL]
/// - When the message queue name of the handle (sndMqHndl) specified in the arguments is NULL,[NULL]
/// - If a system call (such as epoll_ctl()) is in error,[NULL]
/// \~english @par Detail
///   Creates an instance of a timer object, sends a CALLBACK_MESSAGE message to the message queue, and starts the timer.\n
///   When McOpenSender() is executed to execute NS_TimerCreate, the handles should be closed if not needed.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see NS_TimerDelete,NS_TimerSetTime
////////////////////////////////////////////////////////////////////////////////////////////
HANDLE NS_TimerCreate(NSTimerInfo timer_info, eNSTimerCallbackMechanism cbMech, HANDLE sndMqHndl);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup NS_TimerDelete
/// \~english @par Brief
///        to delete an instance of a timer object
/// \~english @param[in] hTimer
///        HANDLE - a timer handle that was created via NS_TimerCreate
/// \~english @retval EFrameworkunifiedStatus indicates if the timer handle was delete successfully
/// \~english @retval eFrameworkunifiedStatusOK
/// \~english @retval eFrameworkunifiedStatusFail
/// \~english @retval eFrameworkunifiedStatusInvldParam
/// \~english @par Preconditons
/// - NS_TimerCreate has generated a HANDLE of timers
/// \~english @par Change of internal status
///     - The internal state is not changed.
/// \~english @par Conditions of processing failure
///     - If HANDLE(hTimer) is NULL,[eFrameworkunifiedStatusInvldParam]
///     - Initializes the state. [eFrameworkunifiedStatusFail]
/// - Invalid timed objects for HANDLE(hTimer specified by arguments:[eFrameworkunifiedStatusInvldParam]
/// - If semaphoring fails, [eFrameworkunifiedStatusFail]
/// \~english @par Detail
/// If the timer is set, the timer is stopped.\n
/// Delete an instance of a timer object.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see NS_TimerCreate, NS_TimerSetTime
////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus NS_TimerDelete(HANDLE hTimer);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup NS_TimerSetTime
/// \~english @par Brief
///        to start or stop a timer by setting the time interval associated
///           with a timer, value of 0 in t_sec & t_nsec, will stop the timer.
/// \~english @param[in] hTimer
///        HANDLE - handle to timer that your specifying the timer to be set
/// \~english @param[in] timer_info
///        NSTimerInfo - timer value represents an absolute expiration timeout
/// \~english @retval EFrameworkunifiedStatus indicates if the timer info was set successfully
/// \~english @retval eFrameworkunifiedStatusOK
/// \~english @retval eFrameworkunifiedStatusInvldHandle
/// \~english @retval eFrameworkunifiedStatusFail
/// \~english @par Preconditons
///        the timer must have already been created with NS_TimerCreate
/// \~english @par Change of internal status
///     - The internal state is not changed.
/// \~english @par Conditions of processing failure
///     - If HANDLE(hTimer) is NULL,[eFrameworkunifiedStatusInvldHandle]
///     - Initializes the state. [eFrameworkunifiedStatusFail]
/// - Retrieving timers fails [eFrameworkunifiedStatusFail]
/// \~english @par Detail
/// When the timer information (t_sec and t_nsec) is 0, the timer is stopped.\n
/// If it is not 0, the timer is started based on the timer information.\n
/// The hTimer must have been created with NS_TimerCreate.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see NS_TimerCreate, NS_TimerGetTime
////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus NS_TimerSetTime(HANDLE hTimer, NSTimerInfo timer_info);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup NS_TimerGetTime
/// \~english @par Brief
///        to retrieve the time until a timer expires
/// \~english @param[in] hTimer
///        HANDLE - handle to timer that your trying to get information about
/// \~english @param[out] timer_info
///        NSTimerInfo* - a structure to store the delay time until the timer expires
/// \~english @retval EFrameworkunifiedStatus indicates if the timer info was get successfully
/// \~english @retval eFrameworkunifiedStatusOK
/// \~english @retval eFrameworkunifiedStatusInvldHandle
/// \~english @retval eFrameworkunifiedStatusFail
/// \~english @par Preconditons
///     - NS_TimerCreate has generated a HANDLE of timers
/// \~english @par Change of internal status
///     - The internal state is not changed.
/// \~english @par Conditions of processing failure
///     - If HANDLE(hTimer) is NULL,[eFrameworkunifiedStatusInvldHandle]
/// - If the timer_info specified in the arguments is NULL,... [eFrameworkunifiedStatusInvldHandle]
///     - Initializes the state. [eFrameworkunifiedStatusFail]
///     - If the timerdelete fails.... [eFrameworkunifiedStatusFail]
/// \~english @par Detail
/// Gets the time until the timer expires.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see NS_TimerCreate, NS_TimerSetTime
////////////////////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus NS_TimerGetTime(HANDLE hTimer, NSTimerInfo *timer_info);

////////////////////////////////////////////////////////////////////////////////////////////
/// \ingroup NS_TimerDebugOn
/// \~english @par Brief
///        to make a flag for the debugging process. for debug.
/// \~english @param[in] FlagState
///        BOOL - DebugFlag state
/// \~english @retval none
/// \~english @par Preconditons
///     none
/// \~english @par Change of internal status
///     - The internal state is not changed.
/// \~english @par Conditions of processing failure
///     none
/// \~english @par Detail
///     Sets the debug flag specified by the argument.\n
/// However, if the set flag is the same as the flag specified in the argument, no operation is performed.
/// \~english @par Classification
/// \~english @par Type
/// \~english @see none
////////////////////////////////////////////////////////////////////////////////////////////
void NS_TimerDebugOn(BOOL FlagState);

#ifdef __cplusplus
}
#endif
#endif /* __NATIVESERVICES_TIMER_H__ */  // NOLINT  (build/header_guard)
/** @}*/
/** @}*/
/** @}*/
/** @}*/