- jobs moved into queues
[strongswan.git] / Source / charon / queues / event_queue.h
1 /**
2 * @file event_queue.h
3 *
4 * @brief Event-Queue based on class linked_list_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 /**
32 * @brief Event-Queue used to store timed events.
33 *
34 * Although the event-queue is based on a linked_list_t
35 * all access functions are thread-save implemented.
36 */
37 typedef struct event_queue_s event_queue_t;
38
39 struct event_queue_s {
40
41 /**
42 * @brief Returns number of events in queue.
43 *
44 * @param event_queue calling object
45 * @return number of events in queue
46 */
47 int (*get_count) (event_queue_t *event_queue);
48
49 /**
50 * @brief Get the next job from the event-queue.
51 *
52 * If no event is pending, this function blocks until a job can be returned.
53 *
54 * @param event_queue calling object
55 * @param[out] job pointer to a job pointer where to job is returned to
56 * @return - SUCCESS if succeeded
57 * - FAILED otherwisesa
58 */
59 status_t (*get) (event_queue_t *event_queue, job_t **job);
60
61 /**
62 * @brief Adds a event to the queue, using a relative time.
63 *
64 * This function is non blocking and adds a job_t at a specific time to the list.
65 * The specific job object has to get destroyed by the thread which
66 * removes the job.
67 *
68 * @param event_queue calling object
69 * @param[in] job job to add to the queue (job is not copied)
70 * @param[in] time relative time, when the event has to get fired
71 * @returns
72 * - SUCCESS if succeeded
73 * - FAILED otherwise
74 */
75 status_t (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms);
76
77 /**
78 * @brief Adds a event to the queue, using an absolute time.
79 *
80 * This function is non blocking and adds a job_t at a specific time to the list.
81 * The specific job object has to get destroyed by the thread which
82 * removes the job.
83 *
84 * @param event_queue calling object
85 * @param[in] job job to add to the queue (job is not copied)
86 * @param[in] absolute time time, when the event has to get fired
87 * @returns
88 * - SUCCESS if succeeded
89 * - FAILED otherwise
90 */
91 status_t (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time);
92
93 /**
94 * @brief Destroys a event_queue object.
95 *
96 * @warning The caller of this function has to make sure
97 * that no thread is going to add or get an event from the event_queue
98 * after calling this function.
99 *
100 * @param event_queue calling object
101 * @returns always SUCCESS
102 */
103 status_t (*destroy) (event_queue_t *event_queue);
104 };
105
106 /**
107 * @brief Creates an empty event_queue
108 *
109 * @returns
110 * - Empty event_queue_t object
111 * - NULL if memory allocation failed
112 */
113 event_queue_t *event_queue_create();
114 #endif /*EVENT_QUEUE_H_*/