1 /* Copyright (C) 2007-2008 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 #include "sysdeps.h" 13 #include <stdio.h> 14 15 #define MAX_COUNTER 10 16 17 static int counter = 0; 18 19 static void 20 timer_func( void* _timer ) 21 { 22 SysTimer timer = _timer; 23 SysTime now = sys_time_ms(); 24 25 ++counter; 26 printf( "tick %d/%d a %.2fs\n", counter, MAX_COUNTER, now/1000. ); 27 if (counter < MAX_COUNTER) 28 sys_timer_set( timer, now + 2000, timer_func, timer ); 29 else 30 sys_timer_destroy( timer ); 31 } 32 33 34 int main( void ) 35 { 36 SysTimer timer; 37 38 /* initialize event subsystem */ 39 sys_main_init(); 40 41 /* create timer and register it */ 42 timer = sys_timer_create(); 43 sys_timer_set( timer, sys_time_ms() + 1000, timer_func, timer ); 44 45 printf("entering event loop\n"); 46 sys_main_loop(); 47 printf("exiting event loop\n" ); 48 return 0; 49 } 50