spiv: Fix image list counter
[gfxprim.git] / demos / c_simple / timers.c
blobe98315374e4e7b28b19349c4fd541c17b72181c5
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
25 Simple example how to use raw timer priority queue.
29 #include <GP.h>
31 uint32_t callback1()
33 return 0;
36 uint32_t callback3()
38 return random() % 30 + 1;
41 #define MAX 10
43 int main(void)
45 GP_TIMER_DECLARE(oneshot, 30, 0, "Oneshot", callback1, NULL);
46 GP_TIMER_DECLARE(recurrent, 0, 4, "Recurrent", callback1, NULL);
47 GP_TIMER_DECLARE(random, 10, 0, "Random", callback3, NULL);
48 GP_Timer timers[MAX];
49 GP_Timer *queue = NULL;
50 uint64_t now;
51 int i, ret;
52 char ids[MAX][8];
54 GP_SetDebugLevel(10);
56 GP_TimerQueueInsert(&queue, 0, &oneshot);
57 GP_TimerQueueInsert(&queue, 0, &recurrent);
58 GP_TimerQueueInsert(&queue, 0, &random);
60 for (i = 0; i < MAX; i++) {
61 timers[i].expires = MAX - i;
62 timers[i].period = 0;
63 timers[i].Callback = callback1;
64 timers[i].priv = NULL;
65 sprintf(ids[i], "Timer%i", MAX - i);
66 timers[i].id = ids[i];
67 GP_TimerQueueInsert(&queue, 0, &timers[i]);
70 GP_TimerQueueDump(queue);
72 GP_TimerQueueRemove(&queue, &timers[MAX-1]);
74 GP_TimerQueueDump(queue);
76 for (now = 0; now < 100; now += 3) {
77 printf("NOW %u\n", (unsigned int) now);
78 printf("-------------------------------------\n");
79 ret = GP_TimerQueueProcess(&queue, now);
80 printf("Processed %i timer events\n", ret);
81 printf("--------------------------------------\n");
82 GP_TimerQueueDump(queue);
83 printf("--------------------------------------\n\n");
86 return 0;