2 This file is part of GNUnet
3 (C) 2008--2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file testbed/testbed_api_operations.h
23 * @brief internal API to access the 'operations' subsystem
24 * @author Christian Grothoff
26 #ifndef NEW_TESTING_API_OPERATIONS_H
27 #define NEW_TESTING_API_OPERATIONS_H
29 #include "gnunet_testbed_service.h"
30 #include "gnunet_helper_lib.h"
34 * Queue of operations where we can only support a certain
35 * number of concurrent operations of a particular type.
37 struct OperationQueue;
41 * Create an operation queue.
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
47 struct OperationQueue *
48 GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active);
52 * Destroy an operation queue. The queue MUST be empty
55 * @param queue queue to destroy
58 GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
62 * Destroys the operation queue if it is empty. If not empty return GNUNET_NO.
64 * @param queue the queue to destroy if empty
65 * @return GNUNET_YES if the queue is destroyed. GNUNET_NO if not (because it
69 GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue);
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.
77 * @param queue the operation queue which has to be modified
78 * @param max_active the new maximum number of active operations
81 GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
82 unsigned int max_active);
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.
91 * @param queue queue to add the operation to
92 * @param operation 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.
97 GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
98 struct GNUNET_TESTBED_Operation
99 *operation, unsigned int nres);
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.
108 * @param queue queue to add the operation to
109 * @param operation operation to add to the queue
112 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
113 struct GNUNET_TESTBED_Operation
118 * Marks the given operation as waiting on the queues. Once all queues permit
119 * the operation to become active, the operation will be activated. The actual
120 * activation will occur in a separate task (thus allowing multiple queue
121 * insertions to be made without having the first one instantly trigger the
122 * operation if the first queue has sufficient resources).
124 * @param operation the operation to marks as waiting
127 GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation
132 * Remove an operation from a queue. This can be because the
133 * oeration was active and has completed (and the resources have
134 * been released), or because the operation was cancelled and
135 * thus scheduling the operation is no longer required.
137 * @param queue queue to add the operation to
138 * @param operation operation to add to the queue
141 GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
142 struct GNUNET_TESTBED_Operation
148 * Function to call to start an operation once all
149 * queues the operation is part of declare that the
150 * operation can be activated.
152 * @param cls the closure from GNUNET_TESTBED_operation_create_()
154 typedef void (*OperationStart) (void *cls);
158 * Function to call to cancel an operation (release all associated
159 * resources). This can be because of a call to
160 * "GNUNET_TESTBED_operation_cancel" (before the operation generated
161 * an event) or AFTER the operation generated an event due to a call
162 * to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that
163 * a callback to the 'OperationStart' preceeds the call to
164 * 'OperationRelease'. Implementations of this function are expected
165 * to clean up whatever state is in 'cls' and release all resources
166 * associated with the operation.
168 * @param cls the closure from GNUNET_TESTBED_operation_create_()
170 typedef void (*OperationRelease) (void *cls);
174 * Create an 'operation' to be performed.
176 * @param cls closure for the callbacks
177 * @param start function to call to start the operation
178 * @param release function to call to close down the operation
179 * @return handle to the operation
181 struct GNUNET_TESTBED_Operation *
182 GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
183 OperationRelease release);
187 * An operation is 'done' (was cancelled or finished); remove
188 * it from the queues and release associated resources.
190 * @param operation operation that finished
193 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation);
197 /* end of testbed_api_operations.h */