65d805f86b82363b003f6e325f414cbf8d3facad
[AGL/documentation.git] / docs / 3_Developer_Guides / 6_AFB_Helper_Guide / 3.7.2_AFB_Timer.md
1 ---
2 edit_link: ''
3 title: AFB Timer
4 origin_url: >-
5   https://git.automotivelinux.org/src/libafb-helpers/plain/docs/afb-timer.md?h=master
6 ---
7
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/devguides/master/afb-helpers-function-references-afb-helpers-book.yml -->
9
10 # AFB Timer functions reference
11
12 ## TimerHandleT
13
14 Members are:
15
16 * `count`: integer representing the number of times the timers should run.
17 * `delay`: millisecond integer representing the delay to wait before and between
18  the callback run.
19 * `uid`: a string identifying the timer.
20 * `context`: an opaq pointer that could be used in the callback function.
21 * `evtSource`: a systemd event source struct. Should be NULL.
22 * `api`: the AFB api pointer.
23 * `callback`: a function pointer for the callback to call at timer expiration
24 * `freeCB`: a function pointer called after expiration of the timer. Mainly meant
25  to release the context pointer by example.
26
27 ## void TimerEvtStart(afb_api_t api, TimerHandleT *timerHandle, timerCallbackT callback, void *context)
28
29 Start a timer which invokes the callback when the delay expires for `count`
30 times.
31
32 * `api`: AFB api pointer.
33 * `timerHandle`: pointer to struct representing a timer.
34 * `callback`: a function pointer for the callback to call at timer expiration
35 * `context`: an opaq pointer that could be used in the callback function.
36
37 ## void TimerEvtStop(TimerHandleT *timerHandle)
38
39 Manually stop the timer's run. If the `count` isn't finished then it will end
40 the timer and no other runs will occur.
41
42 * `timerHandle`: pointer to struct representing a timer.
43
44 ## uint64_t LockWait(afb_api_t api, uint64_t utimeout)
45
46 It is function acting like a non-blocking sleep for an API. It lets the main API
47 event loop runs while you are waiting and will unlock at the first received
48 event and returns the remaining time to wait if an event occurs or 0 if no events
49 occured and timeout hits. Then you have to manually ensure that once an event
50 has been received that it was the one you are waiting for and if not launch again
51 the wait with the remaining time returned.
52
53 * `api`: AFB api pointer.
54 * `timeout`: timeout in microsecond.
55
56 Returns the remaining time in microsecond to wait if an event occurs or 0 if no
57 events occured and timeout hits