- expand $ variables in filenames
[oweals/gnunet.git] / src / testbed / testbed_api_operations.h
1 /*
2       This file is part of GNUnet
3       (C) 2008--2013 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  * Destroys the operation queue if it is empty.  If not empty return GNUNET_NO.
63  *
64  * @param queue the queue to destroy if empty
65  * @return GNUNET_YES if the queue is destroyed.  GNUNET_NO if not (because it
66  *           is not empty)
67  */
68 int
69 GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue);
70
71
72 /**
73  * Function to reset the maximum number of operations in the given queue. If
74  * max_active is lesser than the number of currently active operations, the
75  * active operations are not stopped immediately.
76  *
77  * @param queue the operation queue which has to be modified
78  * @param max_active the new maximum number of active operations
79  */
80 void
81 GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
82                                                   unsigned int max_active);
83
84
85 /**
86  * Add an operation to a queue.  An operation can be in multiple queues at
87  * once. Once the operation is inserted into all the queues
88  * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
89  * waiting for the operation to become active.
90  *
91  * @param queue queue to add the operation to
92  * @param op operation to add to the queue
93  * @param nres the number of units of the resources of queue needed by the
94  *          operation. Should be greater than 0.
95  */
96 void
97 GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
98                                          struct GNUNET_TESTBED_Operation *op,
99                                          unsigned int nres);
100
101
102 /**
103  * Add an operation to a queue.  An operation can be in multiple queues at
104  * once. Once the operation is inserted into all the queues
105  * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
106  * waiting for the operation to become active.
107  *
108  * @param queue queue to add the operation to
109  * @param op operation to add to the queue
110  */
111 void
112 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
113                                         struct GNUNET_TESTBED_Operation *op);
114
115
116 /**
117  * Marks the given operation as waiting on the queues.  Once all queues permit
118  * the operation to become active, the operation will be activated.  The actual
119  * activation will occur in a separate task (thus allowing multiple queue
120  * insertions to be made without having the first one instantly trigger the
121  * operation if the first queue has sufficient resources).
122  *
123  * @param op the operation to marks as waiting
124  */
125 void
126 GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op);
127
128
129 /**
130  * Function to call to start an operation once all
131  * queues the operation is part of declare that the
132  * operation can be activated.
133  *
134  * @param cls the closure from GNUNET_TESTBED_operation_create_()
135  */
136 typedef void (*OperationStart) (void *cls);
137
138
139 /**
140  * Function to call to cancel an operation (release all associated
141  * resources).  This can be because of a call to
142  * "GNUNET_TESTBED_operation_cancel" (before the operation generated
143  * an event) or AFTER the operation generated an event due to a call
144  * to "GNUNET_TESTBED_operation_done".  Thus it is not guaranteed that
145  * a callback to the 'OperationStart' preceeds the call to
146  * 'OperationRelease'.  Implementations of this function are expected
147  * to clean up whatever state is in 'cls' and release all resources
148  * associated with the operation.
149  *
150  * @param cls the closure from GNUNET_TESTBED_operation_create_()
151  */
152 typedef void (*OperationRelease) (void *cls);
153
154
155 /**
156  * Create an 'operation' to be performed.
157  *
158  * @param cls closure for the callbacks
159  * @param start function to call to start the operation
160  * @param release function to call to close down the operation
161  * @return handle to the operation
162  */
163 struct GNUNET_TESTBED_Operation *
164 GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
165                                   OperationRelease release);
166
167
168 /**
169  * An operation is 'done' (was cancelled or finished); remove
170  * it from the queues and release associated resources.
171  *
172  * @param op operation that finished
173  */
174 void
175 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op);
176
177
178 /**
179  * Marks an active operation as inactive - the operation will be kept in a
180  * ready-to-be-released state and continues to hold resources until another
181  * operation contents for them.
182  *
183  * @param op the operation to be marked as inactive.  The operation start
184  *          callback should have been called before for this operation to mark
185  *          it as inactive.
186  */
187 void
188 GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op);
189
190
191 /**
192  * Marks and inactive operation as active.  This fuction should be called to
193  * ensure that the oprelease callback will not be called until it is either
194  * marked as inactive or released.
195  *
196  * @param op the operation to be marked as active
197  */
198 void
199 GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op);
200
201
202 #endif
203 /* end of testbed_api_operations.h */