2f0ef19b6f6336d766bfdf0b24c206ec284da750
[oweals/gnunet.git] / src / testbed / testbed_api_operations.h
1 /*
2       This file is part of GNUnet
3       (C) 2008--2012 Christian Grothoff (and other contributing authors)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18       Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file testbed/testbed_api_operations.h
23  * @brief internal API to access the 'operations' subsystem
24  * @author Christian Grothoff
25  */
26 #ifndef NEW_TESTING_API_OPERATIONS_H
27 #define NEW_TESTING_API_OPERATIONS_H
28
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_helper_lib.h"
31
32
33 /**
34  * Queue of operations where we can only support a certain
35  * number of concurrent operations of a particular type.
36  */
37 struct OperationQueue;
38
39
40 /**
41  * Create an operation queue.
42  *
43  * @param max_active maximum number of operations in this
44  *        queue that can be active in parallel at the same time
45  * @return handle to the queue
46  */
47 struct OperationQueue *
48 GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active);
49
50
51 /**
52  * Destroy an operation queue.  The queue MUST be empty
53  * at this time.
54  *
55  * @param queue queue to destroy
56  */
57 void
58 GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
59
60
61 /**
62  * Function to reset the maximum number of operations in the given queue. If
63  * max_active is lesser than the number of currently active operations, the
64  * active operations are not stopped immediately.
65  *
66  * @param queue the operation queue which has to be modified
67  * @param max_active the new maximum number of active operations
68  */
69 void
70 GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
71                                                   unsigned int max_active);
72
73
74 /**
75  * Add an operation to a queue.  An operation can be in multiple queues at
76  * once. Once the operation is inserted into all the queues
77  * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
78  * waiting for the operation to become active.
79  *
80  * @param queue queue to add the operation to
81  * @param operation operation to add to the queue
82  * @param nres the number of units of the resources of queue needed by the
83  *          operation. Should be greater than 0.
84  */
85 void
86 GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
87                                          struct GNUNET_TESTBED_Operation
88                                          *operation,
89                                          unsigned int nres);
90
91
92 /**
93  * Add an operation to a queue.  An operation can be in multiple queues at
94  * once. Once the operation is inserted into all the queues
95  * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
96  * waiting for the operation to become active.
97  *
98  * @param queue queue to add the operation to
99  * @param operation operation to add to the queue
100  */
101 void
102 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
103                                         struct GNUNET_TESTBED_Operation
104                                         *operation);
105
106
107 /**
108  * Marks the given operation as waiting on the queues.  Once all queues permit
109  * the operation to become active, the operation will be activated.  The actual
110  * activation will occur in a separate task (thus allowing multiple queue
111  * insertions to be made without having the first one instantly trigger the
112  * operation if the first queue has sufficient resources).
113  *
114  * @param operation the operation to marks as waiting
115  */
116 void
117 GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation
118                                       *operation);
119
120
121 /**
122  * Remove an operation from a queue.  This can be because the
123  * oeration was active and has completed (and the resources have
124  * been released), or because the operation was cancelled and
125  * thus scheduling the operation is no longer required.
126  *
127  * @param queue queue to add the operation to
128  * @param operation operation to add to the queue
129  */
130 void
131 GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
132                                         struct GNUNET_TESTBED_Operation
133                                         *operation);
134
135
136
137 /**
138  * Function to call to start an operation once all
139  * queues the operation is part of declare that the
140  * operation can be activated.
141  *
142  * @param cls the closure from GNUNET_TESTBED_operation_create_()
143  */
144 typedef void (*OperationStart) (void *cls);
145
146
147 /**
148  * Function to call to cancel an operation (release all associated
149  * resources).  This can be because of a call to
150  * "GNUNET_TESTBED_operation_cancel" (before the operation generated
151  * an event) or AFTER the operation generated an event due to a call
152  * to "GNUNET_TESTBED_operation_done".  Thus it is not guaranteed that
153  * a callback to the 'OperationStart' preceeds the call to
154  * 'OperationRelease'.  Implementations of this function are expected
155  * to clean up whatever state is in 'cls' and release all resources
156  * associated with the operation.
157  *
158  * @param cls the closure from GNUNET_TESTBED_operation_create_()
159  */
160 typedef void (*OperationRelease) (void *cls);
161
162
163 /**
164  * Create an 'operation' to be performed.
165  *
166  * @param cls closure for the callbacks
167  * @param start function to call to start the operation
168  * @param release function to call to close down the operation
169  * @return handle to the operation
170  */
171 struct GNUNET_TESTBED_Operation *
172 GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
173                                   OperationRelease release);
174
175
176 /**
177  * An operation is 'done' (was cancelled or finished); remove
178  * it from the queues and release associated resources.
179  *
180  * @param operation operation that finished
181  */
182 void
183 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation);
184
185
186 #endif
187 /* end of testbed_api_operations.h */