Holger Freyther | 1bad601 | 2008-12-27 09:42:59 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | #include <openbsc/timer.h> |
| 24 | #include <openbsc/select.h> |
| 25 | |
| 26 | static void timer_fired(unsigned long data); |
| 27 | |
| 28 | static struct timer_list timer_one = { |
| 29 | .cb = timer_fired, |
| 30 | .data = (void*)1, |
| 31 | }; |
| 32 | |
| 33 | static struct timer_list timer_two = { |
| 34 | .cb = timer_fired, |
| 35 | .data = (void*)2, |
| 36 | }; |
| 37 | |
Holger Freyther | 6e30972 | 2009-01-04 03:45:13 +0000 | [diff] [blame] | 38 | static struct timer_list timer_three = { |
| 39 | .cb = timer_fired, |
| 40 | .data = (void*)3, |
| 41 | }; |
| 42 | |
Holger Freyther | 1bad601 | 2008-12-27 09:42:59 +0000 | [diff] [blame] | 43 | static void timer_fired(unsigned long data) |
| 44 | { |
| 45 | printf("Fired timer: %lu\n", data); |
| 46 | |
| 47 | if (data == 1) { |
Harald Welte | c0279f8 | 2009-05-23 05:22:08 +0000 | [diff] [blame^] | 48 | bsc_schedule_timer(&timer_one, 3, 0); |
| 49 | bsc_del_timer(&timer_two); |
Holger Freyther | 1bad601 | 2008-12-27 09:42:59 +0000 | [diff] [blame] | 50 | } else if (data == 2) { |
| 51 | printf("Should not be fired... bug in del_timer\n"); |
Holger Freyther | 6e30972 | 2009-01-04 03:45:13 +0000 | [diff] [blame] | 52 | } else if (data == 3) { |
| 53 | printf("Timer fired not registering again\n"); |
Holger Freyther | 1bad601 | 2008-12-27 09:42:59 +0000 | [diff] [blame] | 54 | } else { |
| 55 | printf("wtf... wrong data\n"); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | int main(int argc, char** argv) |
| 60 | { |
| 61 | printf("Starting... timer\n"); |
| 62 | |
Harald Welte | c0279f8 | 2009-05-23 05:22:08 +0000 | [diff] [blame^] | 63 | bsc_schedule_timer(&timer_one, 3, 0); |
| 64 | bsc_schedule_timer(&timer_two, 5, 0); |
| 65 | bsc_schedule_timer(&timer_three, 4, 0); |
Holger Freyther | 1bad601 | 2008-12-27 09:42:59 +0000 | [diff] [blame] | 66 | |
| 67 | while (1) { |
| 68 | bsc_select_main(); |
| 69 | } |
| 70 | } |