blob: 240bc48087a7626002334c25bbeb2fea43ec06ca [file] [log] [blame]
Harald Welteec8b4502010-02-20 20:34:29 +01001/*
2 * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <stdio.h>
22
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010023#include <osmocom/core/timer.h>
24#include <osmocom/core/select.h>
Harald Welteec8b4502010-02-20 20:34:29 +010025
Harald Weltee94ad582010-02-20 22:06:24 +010026#include "../../config.h"
Harald Welteec8b4502010-02-20 20:34:29 +010027
Holger Hans Peter Freytherd60c7a82010-02-26 20:03:13 +010028static void timer_fired(void *data);
Harald Welteec8b4502010-02-20 20:34:29 +010029
Pablo Neira Ayuso0b21c1c2011-05-07 12:42:28 +020030static struct osmo_timer_list timer_one = {
Harald Welteec8b4502010-02-20 20:34:29 +010031 .cb = timer_fired,
32 .data = (void*)1,
33};
34
Pablo Neira Ayuso0b21c1c2011-05-07 12:42:28 +020035static struct osmo_timer_list timer_two = {
Harald Welteec8b4502010-02-20 20:34:29 +010036 .cb = timer_fired,
37 .data = (void*)2,
38};
39
Pablo Neira Ayuso0b21c1c2011-05-07 12:42:28 +020040static struct osmo_timer_list timer_three = {
Harald Welteec8b4502010-02-20 20:34:29 +010041 .cb = timer_fired,
42 .data = (void*)3,
43};
44
Holger Hans Peter Freytherd60c7a82010-02-26 20:03:13 +010045static void timer_fired(void *_data)
Harald Welteec8b4502010-02-20 20:34:29 +010046{
Holger Hans Peter Freytherd60c7a82010-02-26 20:03:13 +010047 unsigned long data = (unsigned long) _data;
Harald Welteec8b4502010-02-20 20:34:29 +010048 printf("Fired timer: %lu\n", data);
49
50 if (data == 1) {
Pablo Neira Ayuso0b21c1c2011-05-07 12:42:28 +020051 osmo_timer_schedule(&timer_one, 3, 0);
52 osmo_timer_del(&timer_two);
Harald Welteec8b4502010-02-20 20:34:29 +010053 } else if (data == 2) {
54 printf("Should not be fired... bug in del_timer\n");
55 } else if (data == 3) {
56 printf("Timer fired not registering again\n");
57 } else {
58 printf("wtf... wrong data\n");
59 }
60}
61
62int main(int argc, char** argv)
63{
64 printf("Starting... timer\n");
65
Pablo Neira Ayuso0b21c1c2011-05-07 12:42:28 +020066 osmo_timer_schedule(&timer_one, 3, 0);
67 osmo_timer_schedule(&timer_two, 5, 0);
68 osmo_timer_schedule(&timer_three, 4, 0);
Harald Welteec8b4502010-02-20 20:34:29 +010069
70#ifdef HAVE_SYS_SELECT_H
71 while (1) {
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020072 osmo_select_main(0);
Harald Welteec8b4502010-02-20 20:34:29 +010073 }
74#else
75 printf("Select not supported on this platform!\n");
76#endif
77}