- summary message changed
[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 "linked_list.h"
27
28 /**
29 * Type of Jobs
30 */
31 typedef enum job_type_e job_type_t;
32
33 enum job_type_e{
34 /**
35 * Job is to process an incoming IKEv2-Message
36 */
37 INCOMING_PACKET,
38 /**
39 * Job is to retransmit an IKEv2-Message
40 */
41 RETRANSMIT_REQUEST,
42 /**
43 * Job is to establish an ike sa as initiator
44 */
45 ESTABLISH_IKE_SA
46 };
47
48
49 /**
50 * @brief Job like it is represented in the job queue
51 */
52 typedef struct job_s job_t;
53
54
55 struct job_s{
56 job_type_t type;
57 /**
58 * Every job has its assigned_data
59 */
60 void * assigned_data;
61
62 /**
63 * @brief Destroys a job_t object
64 *
65 * @param job_t calling object
66 * @returns SUCCESS if succeeded, FAILED otherwise
67 */
68 status_t (*destroy) (job_t *job);
69 };
70
71 /**
72 * @brief Creates a job of specific type
73 *
74 * @param type type of the job
75 * @param assigned_data value to assign to the job
76 *
77 * @return job_t job object
78 */
79 job_t *job_create(job_type_t type, void *assigned_data);
80
81 /**
82 * @brief Job-Queue
83 */
84 typedef struct job_queue_s job_queue_t;
85
86 struct job_queue_s {
87
88 /**
89 * @brief Returns number of jobs in queue
90 *
91 * @param job_queue_t calling object
92 * @param count integer pointer to store the job count in
93 * @returns SUCCESS if succeeded, FAILED otherwise
94 */
95 status_t (*get_count) (job_queue_t *job_queue, int *count);
96
97 /**
98 * @brief Get the next job from the queue
99 *
100 * If the queue is empty, this function blocks until job can be returned.
101 *
102 * After using, the returned job has to get destroyed.
103 *
104 * @param job_queue_t calling object
105 * @param job pointer to a job pointer where to job is returned to
106 * @returns SUCCESS if succeeded, FAILED otherwise
107 */
108 status_t (*get) (job_queue_t *job_queue, job_t **job);
109
110 /**
111 * @brief Adds a job to the queue
112 *
113 * This function is non blocking
114 *
115 * @param job_queue_t calling object
116 * @param job job to add to the queue (job is not copied)
117 * @returns SUCCESS if succeeded, FAILED otherwise
118 */
119 status_t (*add) (job_queue_t *job_queue, job_t *job);
120
121 /**
122 * @brief Destroys a job_queue object
123 *
124 * @warning Has only to be called if no other thread is accessing the queue
125 *
126 * @param job_queue_t calling object
127 * @returns SUCCESS if succeeded, FAILED otherwise
128 */
129 status_t (*destroy) (job_queue_t *job_queue);
130 };
131
132 /**
133 * @brief Creates a job_queue
134 * *
135 * @return job_queue_t empty job_queue
136 */
137 job_queue_t *job_queue_create();
138 #endif /*JOB_QUEUE_H_*/