2 This file is part of GNUnet
3 (C) 2008--2013 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 * The type of operation queue
43 enum OperationQueueType
46 * Operation queue which permits a fixed maximum number of operations to be
49 OPERATION_QUEUE_TYPE_FIXED,
52 * Operation queue which adapts the number of operations to be active based on
53 * the operation completion times of previously executed operation in it
55 OPERATION_QUEUE_TYPE_ADAPTIVE
60 * Create an operation queue.
62 * @param type the type of operation queue
63 * @param max_active maximum number of operations in this queue that can be
64 * active in parallel at the same time.
65 * @return handle to the queue
67 struct OperationQueue *
68 GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type,
69 unsigned int max_active);
73 * Destroy an operation queue. The queue MUST be empty
76 * @param queue queue to destroy
79 GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
83 * Destroys the operation queue if it is empty. If not empty return GNUNET_NO.
85 * @param queue the queue to destroy if empty
86 * @return GNUNET_YES if the queue is destroyed. GNUNET_NO if not (because it
90 GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue);
94 * Function to reset the maximum number of operations in the given queue. If
95 * max_active is lesser than the number of currently active operations, the
96 * active operations are not stopped immediately.
98 * @param queue the operation queue which has to be modified
99 * @param max_active the new maximum number of active operations
102 GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
103 unsigned int max_active);
107 * Add an operation to a queue. An operation can be in multiple queues at
108 * once. Once the operation is inserted into all the queues
109 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
110 * waiting for the operation to become active.
112 * @param queue queue to add the operation to
113 * @param op operation to add to the queue
114 * @param nres the number of units of the resources of queue needed by the
115 * operation. Should be greater than 0.
118 GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
119 struct GNUNET_TESTBED_Operation *op,
124 * Add an operation to a queue. An operation can be in multiple queues at
125 * once. Once the operation is inserted into all the queues
126 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
127 * waiting for the operation to become active.
129 * @param queue queue to add the operation to
130 * @param op operation to add to the queue
133 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
134 struct GNUNET_TESTBED_Operation *op);
138 * Marks the given operation as waiting on the queues. Once all queues permit
139 * the operation to become active, the operation will be activated. The actual
140 * activation will occur in a separate task (thus allowing multiple queue
141 * insertions to be made without having the first one instantly trigger the
142 * operation if the first queue has sufficient resources).
144 * @param op the operation to marks as waiting
147 GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op);
151 * Function to call to start an operation once all
152 * queues the operation is part of declare that the
153 * operation can be activated.
155 * @param cls the closure from GNUNET_TESTBED_operation_create_()
157 typedef void (*OperationStart) (void *cls);
161 * Function to call to cancel an operation (release all associated
162 * resources). This can be because of a call to
163 * "GNUNET_TESTBED_operation_cancel" (before the operation generated
164 * an event) or AFTER the operation generated an event due to a call
165 * to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that
166 * a callback to the 'OperationStart' preceeds the call to
167 * 'OperationRelease'. Implementations of this function are expected
168 * to clean up whatever state is in 'cls' and release all resources
169 * associated with the operation.
171 * @param cls the closure from GNUNET_TESTBED_operation_create_()
173 typedef void (*OperationRelease) (void *cls);
177 * Create an 'operation' to be performed.
179 * @param cls closure for the callbacks
180 * @param start function to call to start the operation
181 * @param release function to call to close down the operation
182 * @return handle to the operation
184 struct GNUNET_TESTBED_Operation *
185 GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
186 OperationRelease release);
190 * An operation is 'done' (was cancelled or finished); remove
191 * it from the queues and release associated resources.
193 * @param op operation that finished
196 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op);
200 * Marks an active operation as inactive - the operation will be kept in a
201 * ready-to-be-released state and continues to hold resources until another
202 * operation contents for them.
204 * @param op the operation to be marked as inactive. The operation start
205 * callback should have been called before for this operation to mark
209 GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op);
213 * Marks and inactive operation as active. This fuction should be called to
214 * ensure that the oprelease callback will not be called until it is either
215 * marked as inactive or released.
217 * @param op the operation to be marked as active
220 GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op);
224 * Marks an operation as failed
226 * @param op the operation to be marked as failed
229 GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op);
233 /* end of testbed_api_operations.h */