testbed operations
[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  * Enumeration of operation types
42  */
43 enum OperationType
44   {
45     /**
46      * Peer create operation
47      */
48     OP_PEER_CREATE,
49     
50     /**
51      * Peer start operation
52      */
53     OP_PEER_START,
54
55     /**
56      * Peer stop operation
57      */
58     OP_PEER_STOP,
59
60     /**
61      * Peer destroy operation
62      */
63     OP_PEER_DESTROY,
64
65     /**
66      * Get peer information operation
67      */
68     OP_PEER_INFO,
69
70     /**
71      * Overlay connection operation
72      */
73     OP_OVERLAY_CONNECT,
74
75   };
76
77
78 /**
79  * Create an operation queue.
80  *
81  * @param max_active maximum number of operations in this
82  *        queue that can be active in parallel at the same time
83  * @return handle to the queue
84  */
85 struct OperationQueue *
86 GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active);
87
88
89 /**
90  * Destroy an operation queue.  The queue MUST be empty
91  * at this time.
92  *
93  * @param queue queue to destroy
94  */
95 void
96 GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
97
98
99 /**
100  * Add an operation to a queue.  An operation can be in multiple
101  * queues at once.  Once all queues permit the operation to become
102  * active, the operation will be activated.  The actual activation
103  * will occur in a separate task (thus allowing multiple queue 
104  * insertions to be made without having the first one instantly
105  * trigger the operation if the first queue has sufficient 
106  * resources).
107  *
108  * @param queue queue to add the operation to
109  * @param operation operation to add to the queue
110  */
111 void
112 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
113                                         struct GNUNET_TESTBED_Operation *operation);
114
115
116 /**
117  * Remove an operation from a queue.  This can be because the
118  * oeration was active and has completed (and the resources have
119  * been released), or because the operation was cancelled and
120  * thus scheduling the operation is no longer required.
121  *
122  * @param queue queue to add the operation to
123  * @param operation operation to add to the queue
124  */
125 void
126 GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
127                                         struct GNUNET_TESTBED_Operation *operation);
128
129
130
131 /**
132  * Function to call to start an operation once all
133  * queues the operation is part of declare that the
134  * operation can be activated.
135  *
136  * @param cls the closure from GNUNET_TESTBED_operation_create_()
137  */
138 typedef void (*OperationStart)(void *cls);
139
140
141 /**
142  * Function to call to cancel an operation (release all associated
143  * resources).  This can be because of a call to
144  * "GNUNET_TESTBED_operation_cancel" (before the operation generated
145  * an event) or AFTER the operation generated an event due to a call
146  * to "GNUNET_TESTBED_operation_done".  Thus it is not guaranteed that
147  * a callback to the 'OperationStart' preceeds the call to
148  * 'OperationRelease'.  Implementations of this function are expected
149  * to clean up whatever state is in 'cls' and release all resources
150  * associated with the operation.
151  *
152  * @param cls the closure from GNUNET_TESTBED_operation_create_()
153  */
154 typedef void (*OperationRelease)(void *cls);
155
156
157 /**
158  * Create an 'operation' to be performed.
159  *
160  * @param cls closure for the callbacks
161  * @param start function to call to start the operation
162  * @param release function to call to close down the operation
163  * @param type the type of the operation
164  * @param data operation's relavant data
165  * @return handle to the operation
166  */
167 struct GNUNET_TESTBED_Operation *
168 GNUNET_TESTBED_operation_create_ (void *cls,
169                                   OperationStart start,
170                                   OperationRelease release,
171                                   enum OperationType type, 
172                                   void *data);
173
174
175 /**
176  * An operation is 'done' (was cancelled or finished); remove
177  * it from the queues and release associated resources.
178  *
179  * @param operation operation that finished
180  */
181 void
182 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation);
183
184
185 #endif
186 /* end of testbed_api_operations.h */