- job_t is now defined in its own files job.h and job.c
[strongswan.git] / Source / charon / job_queue.h
1 /**
2 * @file job_queue.h
3 *
4 * @brief Job-Queue based on 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 JOB_QUEUE_H_
24 #define JOB_QUEUE_H_
25
26 #include "types.h"
27 #include "job.h"
28 #include "linked_list.h"
29
30 /**
31 * @brief Job-Queue
32 *
33 * Despite the job-queue is based on a linked_list_t
34 * all access functions are thread-save implemented
35 */
36 typedef struct job_queue_s job_queue_t;
37
38 struct job_queue_s {
39
40 /**
41 * @brief returns number of jobs in queue
42 *
43 * @param job_queue_t calling object
44 * @param[out] count integer pointer to store the job count in
45 * @returns SUCCESS if succeeded, FAILED otherwise
46 */
47 status_t (*get_count) (job_queue_t *job_queue, int *count);
48
49 /**
50 * @brief get the next job from the queue
51 *
52 * If the queue is empty, this function blocks until a job can be returned.
53 *
54 * After using, the returned job has to get destroyed by the caller.
55 *
56 * @param job_queue_t calling object
57 * @param[out] job pointer to a job pointer where to job is returned to
58 * @returns SUCCESS if succeeded, FAILED otherwise
59 */
60 status_t (*get) (job_queue_t *job_queue, job_t **job);
61
62 /**
63 * @brief adds a job to the queue
64 *
65 * This function is non blocking and adds a job_t to the list.
66 * The specific job-object has to get destroyed by the thread which
67 * removes the job.
68 *
69 * @param job_queue_t calling object
70 * @param[in] job job to add to the queue (job is not copied)
71 * @returns SUCCESS if succeeded, FAILED otherwise
72 */
73 status_t (*add) (job_queue_t *job_queue, job_t *job);
74
75 /**
76 * @brief destroys a job_queue object
77 *
78 * @warning The caller of this function has to make sure
79 * that no thread is going to add or get a job from the job_queue
80 * after calling this function.
81 *
82 * @param job_queue_t calling object
83 * @returns SUCCESS if succeeded, FAILED otherwise
84 */
85 status_t (*destroy) (job_queue_t *job_queue);
86 };
87
88 /**
89 * @brief Creates an empty job_queue
90 *
91 * @return job_queue_t empty job_queue
92 */
93 job_queue_t *job_queue_create();
94 #endif /*JOB_QUEUE_H_*/