]>
Commit | Line | Data |
---|---|---|
ae758c79 JH |
1 | /** |
2 | * @file event_queue.h | |
c3dc6f1a | 3 | * |
d048df5c | 4 | * @brief Interface of job_queue_t. |
c3dc6f1a | 5 | * |
ae758c79 JH |
6 | */ |
7 | ||
8 | /* | |
c71d53ba MW |
9 | * Copyright (C) 2005-2006 Martin Willi |
10 | * Copyright (C) 2005 Jan Hutter | |
ae758c79 JH |
11 | * Hochschule fuer Technik Rapperswil |
12 | * | |
13 | * This program is free software; you can redistribute it and/or modify it | |
14 | * under the terms of the GNU General Public License as published by the | |
15 | * Free Software Foundation; either version 2 of the License, or (at your | |
16 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, but | |
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
20 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
21 | * for more details. | |
22 | */ | |
23 | ||
24 | #ifndef EVENT_QUEUE_H_ | |
25 | #define EVENT_QUEUE_H_ | |
26 | ||
382b4817 MW |
27 | typedef struct event_queue_t event_queue_t; |
28 | ||
ae758c79 JH |
29 | #include <sys/time.h> |
30 | ||
db7ef624 | 31 | #include <library.h> |
e0fe7651 | 32 | #include <processing/jobs/job.h> |
ae758c79 JH |
33 | |
34 | /** | |
1061c878 | 35 | * @brief Event-Queue used to store timed events. |
a6cbf648 MW |
36 | * |
37 | * Added events are sorted. The get method blocks until | |
38 | * the time is elapsed to process the next event. The get | |
39 | * method is called from the scheduler_t thread, which | |
40 | * will add the jobs to to job_queue_t for further processing. | |
ae758c79 | 41 | * |
c3dc6f1a | 42 | * Although the event-queue is based on a linked_list_t |
1061c878 | 43 | * all access functions are thread-save implemented. |
df3c59d0 | 44 | * |
a6cbf648 MW |
45 | * @b Constructors: |
46 | * - event_queue_create() | |
47 | * | |
df3c59d0 | 48 | * @ingroup queues |
ae758c79 | 49 | */ |
95c61cb9 | 50 | struct event_queue_t { |
c3dc6f1a | 51 | |
ae758c79 | 52 | /** |
1061c878 | 53 | * @brief Returns number of events in queue. |
c3dc6f1a | 54 | * |
f4fae0be JH |
55 | * @param event_queue calling object |
56 | * @return number of events in queue | |
ae758c79 | 57 | */ |
1061c878 | 58 | int (*get_count) (event_queue_t *event_queue); |
ae758c79 JH |
59 | |
60 | /** | |
f4fae0be | 61 | * @brief Get the next job from the event-queue. |
c3dc6f1a | 62 | * |
ae758c79 | 63 | * If no event is pending, this function blocks until a job can be returned. |
c3dc6f1a | 64 | * |
1061c878 JH |
65 | * @param event_queue calling object |
66 | * @param[out] job pointer to a job pointer where to job is returned to | |
d048df5c | 67 | * @return next job |
ae758c79 | 68 | */ |
d048df5c | 69 | job_t *(*get) (event_queue_t *event_queue); |
c3dc6f1a | 70 | |
ae758c79 | 71 | /** |
f4fae0be | 72 | * @brief Adds a event to the queue, using a relative time. |
c3dc6f1a | 73 | * |
ae758c79 | 74 | * This function is non blocking and adds a job_t at a specific time to the list. |
c3dc6f1a | 75 | * The specific job object has to get destroyed by the thread which |
ae758c79 | 76 | * removes the job. |
c3dc6f1a | 77 | * |
f4fae0be JH |
78 | * @param event_queue calling object |
79 | * @param[in] job job to add to the queue (job is not copied) | |
80 | * @param[in] time relative time, when the event has to get fired | |
ae758c79 | 81 | */ |
d048df5c | 82 | void (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms); |
c3dc6f1a | 83 | |
ab4f404e | 84 | /** |
f4fae0be | 85 | * @brief Adds a event to the queue, using an absolute time. |
c3dc6f1a | 86 | * |
ab4f404e | 87 | * This function is non blocking and adds a job_t at a specific time to the list. |
c3dc6f1a | 88 | * The specific job object has to get destroyed by the thread which |
ab4f404e | 89 | * removes the job. |
c3dc6f1a | 90 | * |
f4fae0be | 91 | * @param event_queue calling object |
1396815a MW |
92 | * @param[in] job job to add to the queue (job is not copied) |
93 | * @param[in] time absolute time, when the event has to get fired | |
ab4f404e | 94 | */ |
d048df5c | 95 | void (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time); |
ae758c79 JH |
96 | |
97 | /** | |
f4fae0be | 98 | * @brief Destroys a event_queue object. |
c3dc6f1a | 99 | * |
ae758c79 JH |
100 | * @warning The caller of this function has to make sure |
101 | * that no thread is going to add or get an event from the event_queue | |
102 | * after calling this function. | |
c3dc6f1a | 103 | * |
f4fae0be | 104 | * @param event_queue calling object |
ae758c79 | 105 | */ |
d048df5c | 106 | void (*destroy) (event_queue_t *event_queue); |
ae758c79 JH |
107 | }; |
108 | ||
109 | /** | |
a6cbf648 | 110 | * @brief Creates an empty event_queue. |
c3dc6f1a | 111 | * |
a6cbf648 | 112 | * @returns event_queue_t object |
df3c59d0 MW |
113 | * |
114 | * @ingroup queues | |
ae758c79 | 115 | */ |
f768bdc3 | 116 | event_queue_t *event_queue_create(void); |
df3c59d0 | 117 | |
ae758c79 | 118 | #endif /*EVENT_QUEUE_H_*/ |