summaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_operations.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-29 11:24:08 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-29 11:24:08 +0000
commitaf106ded69593d7f4676f32da6e0058cf1577ce2 (patch)
treee09e73d77cb1b137346defe393a86882b779712d /src/testbed/testbed_api_operations.c
parentcc7efcc843411a956524a00c91425b9d626b03c3 (diff)
downloadgnunet-af106ded69593d7f4676f32da6e0058cf1577ce2.tar.gz
gnunet-af106ded69593d7f4676f32da6e0058cf1577ce2.zip
testbed operations
Diffstat (limited to 'src/testbed/testbed_api_operations.c')
-rw-r--r--src/testbed/testbed_api_operations.c55
1 files changed, 48 insertions, 7 deletions
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 10e9071c6..1692171e3 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -116,6 +116,11 @@ struct GNUNET_TESTBED_Operation
116 struct OperationQueue **queues; 116 struct OperationQueue **queues;
117 117
118 /** 118 /**
119 * Pointer to operation's data
120 */
121 void *data;
122
123 /**
119 * The Operation ID 124 * The Operation ID
120 */ 125 */
121 uint64_t id; 126 uint64_t id;
@@ -135,6 +140,11 @@ struct GNUNET_TESTBED_Operation
135 */ 140 */
136 enum OperationState state; 141 enum OperationState state;
137 142
143 /**
144 * The type of the operation
145 */
146 enum OperationType type;
147
138}; 148};
139 149
140 150
@@ -149,12 +159,12 @@ call_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
149{ 159{
150 struct GNUNET_TESTBED_Operation *op = cls; 160 struct GNUNET_TESTBED_Operation *op = cls;
151 161
152 op->start_task_id = GNUNET_SCHEDULER_NO_TASK; 162 op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
163 op->state = OP_STATE_STARTED;
153 if (NULL != op->start) 164 if (NULL != op->start)
154 { 165 {
155 op->start (op->cb_cls); 166 op->start (op->cb_cls);
156 } 167 }
157 op->state = OP_STATE_STARTED;
158} 168}
159 169
160 170
@@ -183,6 +193,35 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
183 193
184 194
185/** 195/**
196 * Create an 'operation' to be performed.
197 *
198 * @param cls closure for the callbacks
199 * @param start function to call to start the operation
200 * @param release function to call to close down the operation
201 * @param type the type of the operation
202 * @param data operation's relavant data
203 * @return handle to the operation
204 */
205struct GNUNET_TESTBED_Operation *
206GNUNET_TESTBED_operation_create_ (void *cls,
207 OperationStart start,
208 OperationRelease release,
209 enum OperationType type,
210 void *data)
211{
212 struct GNUNET_TESTBED_Operation *op;
213
214 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
215 op->start = start;
216 op->release = release;
217 op->cb_cls = cls;
218 op->type = type;
219 op->data = data;
220 return op;
221}
222
223
224/**
186 * Create an operation queue. 225 * Create an operation queue.
187 * 226 *
188 * @param max_active maximum number of operations in this 227 * @param max_active maximum number of operations in this
@@ -210,7 +249,7 @@ void
210GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) 249GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
211{ 250{
212 GNUNET_assert (NULL == queue->head); 251 GNUNET_assert (NULL == queue->head);
213 GNUNET_assert (NULL == queue->tail); 252 GNUNET_assert (NULL == queue->tail);
214 GNUNET_free (queue); 253 GNUNET_free (queue);
215} 254}
216 255
@@ -266,8 +305,8 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
266 GNUNET_assert (NULL != entry); 305 GNUNET_assert (NULL != entry);
267 if (OP_STATE_STARTED == operation->state) 306 if (OP_STATE_STARTED == operation->state)
268 queue->active++; 307 queue->active++;
269 GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry);
270 entry2 = entry->next; 308 entry2 = entry->next;
309 GNUNET_CONTAINER_DLL_remove (queue->head, queue->tail, entry);
271 GNUNET_free (entry); 310 GNUNET_free (entry);
272 for (; NULL != entry2; entry2 = entry2->next) 311 for (; NULL != entry2; entry2 = entry2->next)
273 if (OP_STATE_STARTED != entry2->op->state) 312 if (OP_STATE_STARTED != entry2->op->state)
@@ -294,10 +333,12 @@ GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation)
294 GNUNET_SCHEDULER_cancel (operation->start_task_id); 333 GNUNET_SCHEDULER_cancel (operation->start_task_id);
295 operation->start_task_id = GNUNET_SCHEDULER_NO_TASK; 334 operation->start_task_id = GNUNET_SCHEDULER_NO_TASK;
296 } 335 }
297 if (NULL != operation->release)
298 operation->release (operation->cb_cls);
299 for (i = 0; i < operation->nqueues; i++) 336 for (i = 0; i < operation->nqueues; i++)
300 GNUNET_TESTBED_operation_queue_remove_ (operation->queues[i], operation); 337 GNUNET_TESTBED_operation_queue_remove_ (operation->queues[i], operation);
338 GNUNET_free (operation->queues);
339 if (NULL != operation->release)
340 operation->release (operation->cb_cls);
341 GNUNET_free (operation);
301} 342}
302 343
303 344