2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 //////////////////////////////////////////////////////////////////////////////////////////////////
19 /// \brief Header file for Timer class.
21 //////////////////////////////////////////////////////////////////////////////////////////////////
24 * @file ns_timer_if.hpp
25 * @brief \~english Header file for Timer class.
28 /** @addtogroup BaseSystem
31 /** @addtogroup native_service
35 /** @addtogroup framework_unified
36 * @ingroup native_service
39 /** @addtogroup native
40 * @ingroup framework_unified
43 #ifndef NS_TIMER_IF_HPP_ // NOLINT (build/header_guard)
44 #define NS_TIMER_IF_HPP_
46 #include <native_service/frameworkunified_types.h>
47 #include <native_service/ns_timer_if.h>
51 * \~english @brief Handle Timer
52 * \~english @par Brief Introduction
53 * Timer class is using to handle the timer.creating, starting, stopping,and so on.
58 /////////////////////////////////////////////////////////////////////////////////////
60 /// \~english @par Brief
61 /// Creates a timer object with default behavior as single timeout timer.
62 /// \~english @retval none
63 /// \~english @par Preconditons
65 /// \~english @par Change of internal status
67 /// \~english @par Conditions of processing failure
69 /// \~english @par Detail
70 /// -To create the instance of this class.init the member var using m_hTimer, m_u64TimeInterval,
72 /// Default status,all time will be set 0.
73 /// \~english @par Classification
75 /// \~english @par Type
77 /// \~english @see ~NSTimer
78 ////////////////////////////////////////////////////////////////////////////////////
81 /////////////////////////////////////////////////////////////////////////////////////
83 /// \~english @par Brief
84 /// Deletes a timer object.
85 /// \~english @retval none
86 /// \~english @par Preconditons
87 /// -Instance of this class is created successfully.
88 /// \~english @par Change of internal status
90 /// \~english @par Conditions of processing failure
92 /// \~english @par Detail
93 /// -Destruct the instance of this class.
94 /// \~english @par Classification
96 /// \~english @par Type
98 /// \~english @see NSTimer
99 ////////////////////////////////////////////////////////////////////////////////////
102 /////////////////////////////////////////////////////////////////////////////////////
104 /// \~english @par Brief
105 /// This function overloads \ref SetNotifyMethod().
106 /// On timeout, sends the command id to the message queue of specified application.
107 /// Resets previous notify method if any.
108 /// \~english @param[in] notifyCmdId
109 /// UI_16 - command id.
110 /// \~english @param[in] notifyToAppName
111 /// PCSTR - Send command id to the message queue of this application
112 /// \~english @retval EFrameworkunifiedStatus - Returns eFrameworkunifiedStatusOK if the action is set otherwise eFrameworkunifiedStatusFail
113 /// \~english @retval eFrameworkunifiedStatusOK - Success
114 /// \~english @retval eFrameworkunifiedStatusInvldParam - Invalid parameter
115 /// \~english @retval eFrameworkunifiedStatusFail - process error
116 /// \~english @par Preconditons
118 /// \~english @par Change of internal status
120 /// \~english @par Conditions of processing failure
121 /// - Pointer of AppName specified by argument(notifyToAppName) is NULL [eFrameworkunifiedStatusInvldParam]
122 /// - Bytes of AppName specified by argument(notifyToAppName) are larger then MAX_SERVICE_NAME(15byte)
123 /// [eFrameworkunifiedStatusInvldParam]
124 /// - There isn't enough buffer(malloc) to storage message queue name, when getting(McOpenSender) message queue
125 /// handle [eFrameworkunifiedStatusFail]
126 /// - Bytes of message queue name are larger then LIMIT_QUEUE_NAME_SIZE(16byte), when getting(McOpenSender)
127 /// message queue handle [eFrameworkunifiedStatusFail]
128 /// - Failed to get message queue(mq_open), when getting(McOpenSender) message queue handle [eFrameworkunifiedStatusFail]
129 /// - There isn't enough buffer(malloc) to storage message queue information, when getting(McOpenSender) message
130 /// queue handle [eFrameworkunifiedStatusFail]
131 /// - Failed to create(epoll_create1) file descriptor for epoll, when creating timer handle(NS_TimerCreate)
132 /// [eFrameworkunifiedStatusFail]
133 /// - Failed to create(eventfd) file descriptor for event notification, when creating timer
134 /// handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
135 /// - Failed to connect(epoll_ctl) file descriptors for epoll and event notification, when creating timer
136 /// handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
137 /// - Failed to create(pthread_create) timer thread for event notification, when creating timer
138 /// handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
139 /// - There isn't enough buffer(malloc) to storage timer handle structure, when creating timer
140 /// handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
141 /// - There isn't enough buffer(malloc) to storage timer information structure,, when creating timer
142 /// handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
143 /// - Message queue handle is INVALID_HANDLE(-1), when creating timer handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
144 /// - Checking code of message queue handle is not MQ_CHECK_CODE, when creating timer handle(NS_TimerCreate)
145 /// [eFrameworkunifiedStatusFail]
146 /// - Type of message queue handle is not send/receive, when creating timer handle(NS_TimerCreate)
147 /// [eFrameworkunifiedStatusFail]
148 /// - Failed to create(timerfd_create) file descriptor for timer, when creating timer handle(NS_TimerCreate)
149 /// [eFrameworkunifiedStatusFail]
150 /// - Failed to connect(epoll_ctl) file descriptors for epoll and timer, when creating timer
151 /// handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
152 /// - Timer handle state of instance has been deleted(DELETED_STATE), when creating timer handle(NS_TimerCreate)
153 /// [eFrameworkunifiedStatusFail]
154 /// - Failed to start/stop(timerfd_settime) timer, when creating timer handle(NS_TimerCreate) [eFrameworkunifiedStatusFail]
155 /// \~english @par Detail
156 /// This function overloads \ref SetNotifyMethod().
157 /// On timeout, sends the command id to the message queue of specified application.
158 /// Create a timer handle(m_hTimer) of instance, if the time handle already exits, delete it then create a new
160 /// If there is resource for timer notification before, reset it.
161 /// \~english @par Classification
163 /// \~english @par Type
165 /// \~english @see McOpenSender, McClose, NS_TimerCreate
166 ////////////////////////////////////////////////////////////////////////////////////
167 EFrameworkunifiedStatus SetNotifyMethod(UI_16 notifyCmdId, PCSTR notifyToAppName);
169 /////////////////////////////////////////////////////////////////////////////////////
171 /// \~english @par Brief
172 /// Sets the timer as a repeat timer. Timer timeouts repeatedly as per the interval set.
173 /// Default timer fires only once.
174 /// Not effective, if the timer is running. Effective on next \ref Start() or \ref Start(seconds, msecs) call.
175 /// \~english @param[in] repeatTimer
176 /// BOOL - TRUE - set repeat timer
177 /// FALSE - set single timeout timer. (Default behavior)
178 /// \~english @retval none
179 /// \~english @par Preconditons
181 /// \~english @par Change of internal status
183 /// \~english @par Conditions of processing failure
185 /// \~english @par Detail
186 /// Sets the timer as a repeat timer. Timer timeouts repeatedly as per the interval set.
187 /// Default timer fires only once.
188 /// Not effective, if the timer is running. Effective on next \ref Start() or \ref Start(seconds, msecs) call.
189 /// \~english @par Classification
191 /// \~english @par Type
193 /// \~english @see none
194 ////////////////////////////////////////////////////////////////////////////////////
195 VOID SetRepeatTimer(BOOL repeatTimer);
197 /////////////////////////////////////////////////////////////////////////////////////
199 /// \~english @par Brief
200 /// Set the interval of timeout. Interval is addition of seconds and milliseconds passed as an arguments.
201 /// \~english @param[in] seconds
202 /// UI_32 - Time in seconds
203 /// \~english @param[in] msecs
204 /// UI_64 - Time in milliseconds
205 /// \~english @retval none
206 /// \~english @par Preconditons
208 /// \~english @par Change of internal status
210 /// \~english @par Conditions of processing failure
212 /// \~english @par Detail
213 /// Set the interval of timeout. Interval is addition of seconds and milliseconds passed as an arguments.
214 /// The default value of interval time is 0.
215 /// If interval time is 0, stop timer.
216 /// \~english @par Classification
218 /// \~english @par Type
220 /// \~english @see none
221 ////////////////////////////////////////////////////////////////////////////////////
222 VOID SetTime(UI_32 seconds, UI_64 msecs);
224 ////////////////////////////////////////////////////////////////////////////////////////////////
226 /// \~english @par Brief
227 /// This function overloads SetTime(). Set the interval of timeout. Interval is addition of hrs,
228 /// mins, seconds and milliseconds passed as an arguments.
229 /// \~english @param[in] hrs
230 /// UI_32 - Time in hours
231 /// \~english @param[in] mins
232 /// UI_64 - Time in minutes
233 /// \~english @param[in] seconds
234 /// UI_32 - Time in seconds
235 /// \~english @param[in] msecs
236 /// UI_64 - Time in milliseconds
237 /// \~english @retval none
238 /// \~english @par Preconditons
240 /// \~english @par Change of internal status
242 /// \~english @par Conditions of processing failure
244 /// \~english @par Detail
245 /// This function overloads SetTime(). Set the interval of timeout. Interval is addition of hrs,
246 /// mins, seconds and milliseconds passed as an arguments.
247 /// The default value of interval time is 0.
248 /// If interval time is 0, stop timer.
249 /// \~english @par Classification
251 /// \~english @par Type
253 /// \~english @see none
254 ////////////////////////////////////////////////////////////////////////////////////////////////
255 VOID SetTime(UI_32 hrs, UI_32 mins, UI_32 seconds, UI_64 msecs);
257 /////////////////////////////////////////////////////////////////////////////////////
259 /// \~english @par Brief
260 /// Starts or restarts timer with specified time interval. Interval is addition of seconds and
261 /// milliseconds passed as an arguments.
262 /// \~english @param[in] seconds
263 /// UI_32 - Time in seconds
264 /// \~english @param[in] msecs
265 /// UI_64 - Time in milliseconds
266 /// \~english @retval EFrameworkunifiedStatus - Returns eFrameworkunifiedStatusOK on success otherwise eFrameworkunifiedStatusFail
267 /// \~english @par Preconditons
268 /// - Create a timer handle of instance by SetNotifyMethod()
269 /// \~english @par Change of internal status
271 /// \~english @par Conditions of processing failure
272 /// - Timer handle of instance is NULL [eFrameworkunifiedStatusFail]
273 /// - Timer handle state of instance has been deleted(DELETED_STATE) [eFrameworkunifiedStatusFail]
274 /// - Failed to start/stop(timerfd_settime) timer [eFrameworkunifiedStatusFail]
275 /// \~english @par Detail
276 /// Starts or restarts timer with specified time interval. Interval is addition of seconds and
277 /// milliseconds passed as an arguments.
278 /// Interval time setted by this method will overwrite interval time setted by SetTime(UI_32, UI_64).
279 /// If interval time is 0, stop timer.
280 /// \~english @par Classification
282 /// \~english @par Type
284 /// \~english @see SetTime(UI_32, UI_64), Start, Stop, SetNotifyMethod
285 ////////////////////////////////////////////////////////////////////////////////////
286 EFrameworkunifiedStatus Start(UI_32 seconds, UI_64 msecs);
288 /////////////////////////////////////////////////////////////////////////////////////
290 /// \~english @par Brief
291 /// This function overloads Start(). Starts or restarts timer with interval specified using SetTime()
292 /// or last interval (if the timer was started before using Start(seconds, msecs)).
293 /// \~english @retval EFrameworkunifiedStatus - Returns eFrameworkunifiedStatusOK on success otherwise eFrameworkunifiedStatusFail
294 /// \~english @par Preconditons
295 /// - Create a timer handle of instance by SetNotifyMethod()
296 /// \~english @par Change of internal status
298 /// \~english @par Conditions of processing failure
299 /// - Timer handle of instance is NULL [eFrameworkunifiedStatusFail]
300 /// - Timer handle state of instance has been deleted(DELETED_STATE) [eFrameworkunifiedStatusFail]
301 /// - Failed to start/stop(timerfd_settime) timer [eFrameworkunifiedStatusFail]
302 /// \~english @par Detail
303 /// - Starts or restarts timer with interval specified using SetTime(UI_32, UI_64) or Start(UI_32, UI_64).
304 /// If interval time is not setted, default value is 0. If interval time is 0, stop timer.
305 /// \~english @par Classification
307 /// \~english @par Type
309 /// \~english @see SetTime(UI_32, UI_64), Stop, SetNotifyMethod, WholeSeconds, MSToNS, NS_TimerSetTime
310 ////////////////////////////////////////////////////////////////////////////////////
311 EFrameworkunifiedStatus Start();
313 /////////////////////////////////////////////////////////////////////////////////////
315 /// \~english @par Brief
317 /// \~english @retval EFrameworkunifiedStatus - Returns eFrameworkunifiedStatusOK on success otherwise eFrameworkunifiedStatusFail
318 /// \~english @par Preconditons
319 /// - Create a timer handle of instance by SetNotifyMethod()
320 /// \~english @par Change of internal status
322 /// \~english @par Conditions of processing failure
323 /// - Timer handle of instance is NULL [eFrameworkunifiedStatusFail]
324 /// - Timer handle state of instance has been deleted(DELETED_STATE) [eFrameworkunifiedStatusFail]
325 /// - Failed to stop(timerfd_settime) timer [eFrameworkunifiedStatusFail]
326 /// \~english @par Detail
327 /// - Stops the timer
328 /// \~english @par Classification
330 /// \~english @par Type
332 /// \~english @see Start, Start(UI_32, UI_64), SetNotifyMethod, NS_TimerSetTime
333 ////////////////////////////////////////////////////////////////////////////////////
334 EFrameworkunifiedStatus Stop();
336 ////////////////////////////////////////////////////////////////////////////////////////////////
338 /// \~english @par Brief
339 /// Returns timer running status
340 /// \~english @retval BOOL - TRUE if timer is running else FALSE
341 /// \~english @par Preconditons
343 /// \~english @par Change of internal status
345 /// \~english @par Conditions of processing failure
347 /// \~english @par Detail
348 /// -Returns timer running status
349 /// \~english @par Classification
351 /// \~english @par Type
353 /// \~english @see Start, Start(UI_32, UI_64), SetNotifyMethod, NS_TimerSetTime
354 ////////////////////////////////////////////////////////////////////////////////////////////////
357 ////////////////////////////////////////////////////////////////////////////////////////////////
359 /// \~english @par Brief
360 /// Returns timeout interval in milliseconds
361 /// \~english @retval UI_64 - Timeout interval in milliseconds
362 /// \~english @par Preconditons
364 /// \~english @par Change of internal status
366 /// \~english @par Conditions of processing failure
368 /// \~english @par Detail
369 /// - Returns timeout interval in milliseconds
370 /// \~english @par Classification
372 /// \~english @par Type
374 /// \~english @see None
375 ////////////////////////////////////////////////////////////////////////////////////////////////
380 HANDLE m_hTimer; ///< Corresponding NS timer handle
382 UI_64 m_u64TimeInterval; ///< time interval in milliseconds
384 BOOL m_bRepeatTimer; ///< if it is a repeat timer. Default value is false.
388 #endif // NS_TIMER_IF_HPP_ // NOLINT (build/header_guard)