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