2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file testbed/testbed_api_operations.h
21 * @brief internal API to access the 'operations' subsystem
22 * @author Christian Grothoff
24 #ifndef NEW_TESTING_API_OPERATIONS_H
25 #define NEW_TESTING_API_OPERATIONS_H
27 #include "gnunet_testbed_service.h"
28 #include "gnunet_helper_lib.h"
32 * Queue of operations where we can only support a certain
33 * number of concurrent operations of a particular type.
35 struct OperationQueue;
39 * The type of operation queue
41 enum OperationQueueType
44 * Operation queue which permits a fixed maximum number of operations to be
47 OPERATION_QUEUE_TYPE_FIXED,
50 * Operation queue which adapts the number of operations to be active based on
51 * the operation completion times of previously executed operation in it
53 OPERATION_QUEUE_TYPE_ADAPTIVE
58 * Create an operation queue.
60 * @param type the type of operation queue
61 * @param max_active maximum number of operations in this queue that can be
62 * active in parallel at the same time.
63 * @return handle to the queue
65 struct OperationQueue *
66 GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type,
67 unsigned int max_active);
71 * Destroy an operation queue. The queue MUST be empty
74 * @param queue queue to destroy
77 GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
81 * Destroys the operation queue if it is empty. If not empty return GNUNET_NO.
83 * @param queue the queue to destroy if empty
84 * @return GNUNET_YES if the queue is destroyed. GNUNET_NO if not (because it
88 GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue);
92 * Function to reset the maximum number of operations in the given queue. If
93 * max_active is lesser than the number of currently active operations, the
94 * active operations are not stopped immediately.
96 * @param queue the operation queue which has to be modified
97 * @param max_active the new maximum number of active operations
100 GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
101 unsigned int max_active);
105 * Add an operation to a queue. An operation can be in multiple queues at
106 * once. Once the operation is inserted into all the queues
107 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
108 * waiting for the operation to become active.
110 * @param queue queue to add the operation to
111 * @param op operation to add to the queue
112 * @param nres the number of units of the resources of queue needed by the
113 * operation. Should be greater than 0.
116 GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
117 struct GNUNET_TESTBED_Operation *op,
122 * Add an operation to a queue. An operation can be in multiple queues at
123 * once. Once the operation is inserted into all the queues
124 * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
125 * waiting for the operation to become active.
127 * @param queue queue to add the operation to
128 * @param op operation to add to the queue
131 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
132 struct GNUNET_TESTBED_Operation *op);
136 * Marks the given operation as waiting on the queues. Once all queues permit
137 * the operation to become active, the operation will be activated. The actual
138 * activation will occur in a separate task (thus allowing multiple queue
139 * insertions to be made without having the first one instantly trigger the
140 * operation if the first queue has sufficient resources).
142 * @param op the operation to marks as waiting
145 GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op);
149 * Function to call to start an operation once all
150 * queues the operation is part of declare that the
151 * operation can be activated.
153 * @param cls the closure from GNUNET_TESTBED_operation_create_()
155 typedef void (*OperationStart) (void *cls);
159 * Function to call to cancel an operation (release all associated
160 * resources). This can be because of a call to
161 * "GNUNET_TESTBED_operation_cancel" (before the operation generated
162 * an event) or AFTER the operation generated an event due to a call
163 * to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that
164 * a callback to the 'OperationStart' preceeds the call to
165 * 'OperationRelease'. Implementations of this function are expected
166 * to clean up whatever state is in 'cls' and release all resources
167 * associated with the operation.
169 * @param cls the closure from GNUNET_TESTBED_operation_create_()
171 typedef void (*OperationRelease) (void *cls);
175 * Create an 'operation' to be performed.
177 * @param cls closure for the callbacks
178 * @param start function to call to start the operation
179 * @param release function to call to close down the operation
180 * @return handle to the operation
182 struct GNUNET_TESTBED_Operation *
183 GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
184 OperationRelease release);
188 * An operation is 'done' (was cancelled or finished); remove
189 * it from the queues and release associated resources.
191 * @param op operation that finished
194 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op);
198 * Marks an active operation as inactive - the operation will be kept in a
199 * ready-to-be-released state and continues to hold resources until another
200 * operation contents for them.
202 * @param op the operation to be marked as inactive. The operation start
203 * callback should have been called before for this operation to mark
207 GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op);
211 * Marks and inactive operation as active. This fuction should be called to
212 * ensure that the oprelease callback will not be called until it is either
213 * marked as inactive or released.
215 * @param op the operation to be marked as active
218 GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op);
222 * Marks an operation as failed
224 * @param op the operation to be marked as failed
227 GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op);
231 /* end of testbed_api_operations.h */