File: test_timer.c

package info (click to toggle)
wengophone 2.1.2.dfsg0-6
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 55,932 kB
  • ctags: 43,474
  • sloc: ansic: 349,331; cpp: 76,915; sh: 23,573; perl: 3,481; python: 2,087; makefile: 1,997; xml: 729; cs: 201; tcl: 86; pascal: 66; lisp: 33
file content (50 lines) | stat: -rw-r--r-- 879 bytes parent folder | download | duplicates (4)
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

#include <wtimer.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

//in sec
#define TEST_TIME 10

//in msec
#define DELAY 100

struct timer_impl *timpl;

void callback(void *userdata) {
    int *data = (int *) userdata;
    printf("Timer elapsed, data %d\n", *data);
}

w_timer_t * create_timer(int udata) {
    w_timer_t *ti;

    int *data = (int *) malloc (sizeof(int));
    *data = udata;

    ti = timpl->timer_create();
    timpl->timer_set_delay(ti, DELAY);
    timpl->timer_set_callback(ti, callback);
    timpl->timer_set_userdata(ti, data);
    timpl->timer_start(ti);

    return ti;
}

int main(int argc, char **argv) {
    w_timer_t *ti1, *ti2;

    timer_init();

    timpl = timer_impl_getfirst();

    ti1 = create_timer(1);
    ti2 = create_timer(2);

    sleep (TEST_TIME);

    timpl->timer_stop(ti1);
    timpl->timer_stop(ti2);
    return 0;
}