doxygen
[oweals/gnunet.git] / src / testbed / testbed_api_operations.c
index 1692171e3da4f0e631c24342a3099b6e4ff6b40c..b897cb453ddb480889e5154b08c5bdd6529711e2 100644 (file)
@@ -69,24 +69,25 @@ struct OperationQueue
    * Number of operations that can be concurrently
    * active in this queue.
    */
-  unsigned int active;  
+  unsigned int active;
 };
 
 
+/**
+ * Operation state
+ */
 enum OperationState
-  {
+{
     /**
      * The operation is currently waiting for resources
      */
-    OP_STATE_WAITING,
+  OP_STATE_WAITING,
 
     /**
      * The operation has started
      */
-    OP_STATE_STARTED,
-  };
-
-  
+  OP_STATE_STARTED
+};
 
 
 /**
@@ -104,7 +105,7 @@ struct GNUNET_TESTBED_Operation
    * not have been started yet).
    */
   OperationRelease release;
-                                
+
   /**
    * Closure for callbacks.
    */
@@ -115,16 +116,6 @@ struct GNUNET_TESTBED_Operation
    */
   struct OperationQueue **queues;
 
-  /**
-   * Pointer to operation's data
-   */
-  void *data;
-  
-  /**
-   * The Operation ID
-   */
-  uint64_t id;  
-
   /**
    * The id of the task which calls OperationStart for this operation
    */
@@ -138,13 +129,8 @@ struct GNUNET_TESTBED_Operation
   /**
    * The state of the operation
    */
-  enum OperationState state;  
-  
-  /**
-   * The type of the operation
-   */
-  enum OperationType type;
-  
+  enum OperationState state;
+
 };
 
 
@@ -156,15 +142,15 @@ struct GNUNET_TESTBED_Operation
  */
 static void
 call_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{  
+{
   struct GNUNET_TESTBED_Operation *op = cls;
-  
+
   op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
   op->state = OP_STATE_STARTED;
   if (NULL != op->start)
   {
     op->start (op->cb_cls);
-  }  
+  }
 }
 
 
@@ -175,9 +161,11 @@ call_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 static void
 check_readiness (struct GNUNET_TESTBED_Operation *op)
-{   
+{
   unsigned int i;
-  
+
+  if (GNUNET_SCHEDULER_NO_TASK != op->start_task_id)
+    return;
   for (i = 0; i < op->nqueues; i++)
   {
     if (0 == op->queues[i]->active)
@@ -187,8 +175,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
   {
     op->queues[i]->active--;
   }
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id);
-  op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);  
+  op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);
 }
 
 
@@ -198,16 +185,11 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
  * @param cls closure for the callbacks
  * @param start function to call to start the operation
  * @param release function to call to close down the operation
- * @param type the type of the operation
- * @param data operation's relavant data
  * @return handle to the operation
  */
 struct GNUNET_TESTBED_Operation *
-GNUNET_TESTBED_operation_create_ (void *cls,
-                                 OperationStart start,
-                                 OperationRelease release,
-                                 enum OperationType type, 
-                                  void *data)
+GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
+                                  OperationRelease release)
 {
   struct GNUNET_TESTBED_Operation *op;
 
@@ -215,9 +197,8 @@ GNUNET_TESTBED_operation_create_ (void *cls,
   op->start = start;
   op->release = release;
   op->cb_cls = cls;
-  op->type = type;
-  op->data = data;
-  return op;  
+  op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
+  return op;
 }
 
 
@@ -248,8 +229,8 @@ GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active)
 void
 GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
 {
-  GNUNET_assert (NULL == queue->head);
-  GNUNET_assert (NULL == queue->tail);
+  GNUNET_break (NULL == queue->head);
+  GNUNET_break (NULL == queue->tail);
   GNUNET_free (queue);
 }
 
@@ -258,9 +239,9 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
  * Add an operation to a queue.  An operation can be in multiple
  * queues at once.  Once all queues permit the operation to become
  * active, the operation will be activated.  The actual activation
- * will occur in a separate task (thus allowing multiple queue 
+ * will occur in a separate task (thus allowing multiple queue
  * insertions to be made without having the first one instantly
- * trigger the operation if the first queue has sufficient 
+ * trigger the operation if the first queue has sufficient
  * resources).
  *
  * @param queue queue to add the operation to
@@ -268,7 +249,8 @@ GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
  */
 void
 GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
-                                       struct GNUNET_TESTBED_Operation *operation)
+                                        struct GNUNET_TESTBED_Operation
+                                        *operation)
 {
   struct QueueEntry *entry;
 
@@ -276,8 +258,9 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
   entry->op = operation;
   GNUNET_CONTAINER_DLL_insert_tail (queue->head, queue->tail, entry);
   operation->queues =
-    GNUNET_realloc (operation->queues,
-                    sizeof (struct OperationQueue *) * (++operation->nqueues));
+      GNUNET_realloc (operation->queues,
+                      sizeof (struct OperationQueue *) *
+                      (++operation->nqueues));
   operation->queues[operation->nqueues - 1] = queue;
   check_readiness (operation);
 }
@@ -294,11 +277,12 @@ GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
  */
 void
 GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
-                                       struct GNUNET_TESTBED_Operation *operation)
+                                        struct GNUNET_TESTBED_Operation
+                                        *operation)
 {
   struct QueueEntry *entry;
   struct QueueEntry *entry2;
-  
+
   for (entry = queue->head; NULL != entry; entry = entry->next)
     if (entry->op == operation)
       break;
@@ -327,7 +311,7 @@ void
 GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *operation)
 {
   unsigned int i;
-    
+
   if (GNUNET_SCHEDULER_NO_TASK != operation->start_task_id)
   {
     GNUNET_SCHEDULER_cancel (operation->start_task_id);