Introduce a simple timer API....

One can use add_timer or schedule_timer to add a timer. After
the timeout time has been reached the callback will be called.
One can call add_time/schedule_timer and del_timer from within
the callback.
diff --git a/Makefile.am b/Makefile.am
index b3a37ee..1ba0604 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,7 @@
 AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6
 
 INCLUDES = $(all_includes) -I$(top_srcdir)/include
-SUBDIRS = include src
+SUBDIRS = include src tests
 
 #dist-hook:
 #	rm -rf `find $(distdir) -name .svn`
diff --git a/configure.in b/configure.in
index 1c4070c..034972a 100644
--- a/configure.in
+++ b/configure.in
@@ -16,4 +16,10 @@
 
 dnl Checks for typedefs, structures and compiler characteristics
 
-AC_OUTPUT(include/openbsc/Makefile include/Makefile src/Makefile Makefile)
+AC_OUTPUT(
+    include/openbsc/Makefile
+    include/Makefile
+    src/Makefile
+    tests/Makefile
+    tests/timer/Makefile
+    Makefile)
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..f7cfd54
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = timer
diff --git a/tests/timer/Makefile.am b/tests/timer/Makefile.am
new file mode 100644
index 0000000..726fb7f
--- /dev/null
+++ b/tests/timer/Makefile.am
@@ -0,0 +1,5 @@
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+bin_PROGRAMS = timer_test
+
+timer_test_SOURCES = timer_test.c $(top_srcdir)/src/timer.c $(top_srcdir)/src/select.c
+
diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c
new file mode 100644
index 0000000..4d98aef
--- /dev/null
+++ b/tests/timer/timer_test.c
@@ -0,0 +1,62 @@
+/*
+ * (C) 2008 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+
+#include <openbsc/timer.h>
+#include <openbsc/select.h>
+
+static void timer_fired(unsigned long data);
+
+static struct timer_list timer_one = {
+    .cb = timer_fired,
+    .data = (void*)1,
+};
+
+static struct timer_list timer_two = {
+    .cb = timer_fired,
+    .data = (void*)2,
+};
+
+static void timer_fired(unsigned long data)
+{
+    printf("Fired timer: %lu\n", data);
+
+    if (data == 1) {
+        schedule_timer(&timer_one, 3, 0);
+        del_timer(&timer_two);
+    } else if (data == 2) {
+        printf("Should not be fired... bug in del_timer\n");
+    } else  {
+        printf("wtf... wrong data\n");
+    }
+}
+
+int main(int argc, char** argv)
+{
+    printf("Starting... timer\n");
+
+    schedule_timer(&timer_one, 3, 0);
+    schedule_timer(&timer_two, 5, 0);
+
+    while (1) {
+        bsc_select_main();
+    }
+}