gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23029 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r23029 - gnunet/src/testbed
Date: Wed, 1 Aug 2012 13:48:20 +0200

Author: harsha
Date: 2012-08-01 13:48:20 +0200 (Wed, 01 Aug 2012)
New Revision: 23029

Modified:
   gnunet/src/testbed/testbed_api.c
   gnunet/src/testbed/testbed_api.h
   gnunet/src/testbed/testbed_api_peers.c
Log:
state information for OperationContext

Modified: gnunet/src/testbed/testbed_api.c
===================================================================
--- gnunet/src/testbed/testbed_api.c    2012-08-01 11:24:47 UTC (rev 23028)
+++ gnunet/src/testbed/testbed_api.c    2012-08-01 11:48:20 UTC (rev 23029)
@@ -261,7 +261,7 @@
   if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
     event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation));
   if (NULL != event)
-    event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 
+    event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
   switch (opc->type)
   {
   case OP_PEER_DESTROY:
@@ -284,13 +284,15 @@
     break;
   default:
     GNUNET_assert (0);
-  }  
+  }
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  opc->state = OPC_STATE_FINISHED;
   if (NULL != event)
   {
     if (NULL != c->cc)
       c->cc (c->cc_cls, event);
     GNUNET_free (event);
-  }
+  }  
   return GNUNET_YES;  
 }
 
@@ -332,7 +334,10 @@
   GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
   peer->state = PS_CREATED;
   cb = data->cb;
-  cls = data->cls;  
+  cls = data->cls;
+  GNUNET_free (opc->data);  
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  opc->state = OPC_STATE_FINISHED;
   if (NULL != cb)
     cb (cls, peer, NULL);
   return GNUNET_YES;
@@ -383,12 +388,14 @@
   default:
     GNUNET_assert (0);         /* We should never reach this state */
   }
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  opc->state = OPC_STATE_FINISHED;
   if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP)
            & c->event_mask))
   {
     if (NULL != c->cc)
       c->cc (c->cc_cls, &event);
-  }
+  }    
   return GNUNET_YES;
 }
 
@@ -424,7 +431,6 @@
   peer = data->peer;
   GNUNET_assert (NULL != peer);
   GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
-  opc->completed = GNUNET_YES;
   if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
   {
     LOG_DEBUG ("Skipping operation callback as flag not set\n");
@@ -482,7 +488,9 @@
     break;
   }
   opc->data = response_data;
-  c->cc (c->cc_cls, &info);
+  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  opc->state = OPC_STATE_FINISHED;
+  c->cc (c->cc_cls, &info);  
   return GNUNET_YES;
 }
 

Modified: gnunet/src/testbed/testbed_api.h
===================================================================
--- gnunet/src/testbed/testbed_api.h    2012-08-01 11:24:47 UTC (rev 23028)
+++ gnunet/src/testbed/testbed_api.h    2012-08-01 11:48:20 UTC (rev 23029)
@@ -113,7 +113,33 @@
  */
 struct ControllerLink;
 
+
 /**
+ * Enumeration of states of OperationContext
+ */
+enum OperationContextState
+  {
+    /**
+     * The initial state where the associated operation has just been created
+     * and is waiting in the operation queues to be started
+     */
+    OPC_STATE_INIT = 0,
+    
+    /**
+     * The operation has been started. It may occupy some resources which are 
to
+     * be freed if cancelled.
+     */
+    OPC_STATE_STARTED,
+
+    /**
+     * The operation has finished. The end results of this operation may occupy
+     * some resources which are to be freed by operation_done
+     */
+    OPC_STATE_FINISHED
+  };
+
+
+/**
  * Context information for GNUNET_TESTBED_Operation
  */
 struct OperationContext
@@ -154,10 +180,9 @@
   enum OperationType type;
 
   /**
-   * Is this operation completed? (has there been a reply from the service)
+   * The state of the operation
    */
-  int completed;
-
+  enum OperationContextState state;
 };
 
 

Modified: gnunet/src/testbed/testbed_api_peers.c
===================================================================
--- gnunet/src/testbed/testbed_api_peers.c      2012-08-01 11:24:47 UTC (rev 
23028)
+++ gnunet/src/testbed/testbed_api_peers.c      2012-08-01 11:48:20 UTC (rev 
23029)
@@ -54,6 +54,7 @@
   data = opc->data;
   GNUNET_assert (NULL != data);
   GNUNET_assert (NULL != data->peer);
+  opc->state = OPC_STATE_STARTED;
   config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size);
   xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
   GNUNET_free (config);
@@ -83,9 +84,12 @@
 {
   struct OperationContext *opc = cls;  
 
-  GNUNET_assert (NULL != opc->data);
-  GNUNET_free (opc->data);  
-  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  if (OPC_STATE_FINISHED != opc->state)
+  {
+    GNUNET_free (((struct PeerCreateData *) opc->data)->peer);
+    GNUNET_free (opc->data);
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  }
   GNUNET_free (opc);
 }
 
@@ -105,6 +109,7 @@
   GNUNET_assert (OP_PEER_DESTROY == opc->type);
   peer = opc->data;
   GNUNET_assert (NULL != peer);
+  opc->state = OPC_STATE_STARTED;
   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
@@ -126,7 +131,8 @@
 {
   struct OperationContext *opc = cls;
   
-  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  if (OPC_STATE_FINISHED != opc->state)
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
   GNUNET_free (opc);
 }
 
@@ -147,6 +153,7 @@
   GNUNET_assert (NULL != opc->data);
   peer = opc->data;
   GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
+  opc->state = OPC_STATE_STARTED;
   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
@@ -167,7 +174,8 @@
 {
   struct OperationContext *opc = cls;
   
-  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  if (OPC_STATE_FINISHED != opc->state)
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
   GNUNET_free (opc);
 }
 
@@ -187,6 +195,7 @@
   GNUNET_assert (NULL != opc->data);
   peer = opc->data;
   GNUNET_assert (PS_STARTED == peer->state); 
+  opc->state = OPC_STATE_STARTED;  
   msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
   msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
@@ -207,7 +216,8 @@
 {
   struct OperationContext *opc = cls;
   
-  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
+  if (OPC_STATE_FINISHED != opc->state)
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
   GNUNET_free (opc);
 }
 
@@ -225,7 +235,8 @@
   struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
 
   data = opc->data;
-  GNUNET_assert (NULL != data);  
+  GNUNET_assert (NULL != data);
+  opc->state = OPC_STATE_STARTED;
   msg = GNUNET_malloc (sizeof (struct
                                GNUNET_TESTBED_PeerGetConfigurationMessage));
   msg->header.size = htons
@@ -249,8 +260,11 @@
   struct OperationContext *opc = cls;
   struct PeerInfoData2 *data;
   
-  if (GNUNET_YES != opc->completed)
+  if (OPC_STATE_FINISHED != opc->state)
+  {
     GNUNET_free_non_null (opc->data);
+    GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);  
+  }
   else
   {
     data = opc->data;
@@ -268,7 +282,6 @@
     }
     GNUNET_free (data);
   }
-  GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
   GNUNET_free (opc);
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]