diff LossyCom.c @ 5:95a03e431480

corrected comments and variable renaming
author Merten Sach <msach@mailbox.tu-berlin.de>
date Tue, 13 Mar 2012 19:07:49 +0100
parents 7ba5a3a6102d
children
line diff
     1.1 --- a/LossyCom.c	Tue Mar 13 18:22:12 2012 +0100
     1.2 +++ b/LossyCom.c	Tue Mar 13 19:07:49 2012 +0100
     1.3 @@ -1,4 +1,3 @@
     1.4 -
     1.5  /*
     1.6   * For a detailed description see header file.
     1.7   */
     1.8 @@ -9,44 +8,44 @@
     1.9  #include "VMS_Implementations/VMS_impl/vmalloc.h"
    1.10  
    1.11  /*
    1.12 - * Initializes the central exchange structure.
    1.13 + * Initializes the central exchange structure and sets all trigger counter to 0
    1.14   * Allocates memory to fit the number of endpoints.
    1.15   * Returns NULL if an error occurs.
    1.16   */
    1.17  lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints)
    1.18  {
    1.19 -    lossyCom__exchange_t* exchange;
    1.20 +    lossyCom__exchange_t* centralExchange;
    1.21      
    1.22 -    exchange = VMS_WL__malloc(sizeof(lossyCom__exchange_t));
    1.23 -    if(exchange == NULL)
    1.24 +    centralExchange = VMS_WL__malloc(sizeof(lossyCom__exchange_t));
    1.25 +    if(centralExchange == NULL)
    1.26          return NULL;
    1.27      
    1.28 -    exchange->BroadcastTriggerCounter = 0;
    1.29 -    exchange->numEndpoints = numEndpoints;
    1.30 -    exchange->outboxArray = VMS_WL__malloc(sizeof(lossyCom__msg_t)*numEndpoints);
    1.31 -    if(exchange->outboxArray == NULL){
    1.32 -        VMS_WL__free(exchange);
    1.33 +    centralExchange->broadcastTriggerCounter = 0;
    1.34 +    centralExchange->numEndpoints = numEndpoints;
    1.35 +    centralExchange->outboxArray = VMS_WL__malloc(sizeof(lossyCom__msg_t)*numEndpoints);
    1.36 +    if(centralExchange->outboxArray == NULL){
    1.37 +        VMS_WL__free(centralExchange);
    1.38          return NULL;
    1.39      }
    1.40      
    1.41 -    exchange->p2pTriggerCounter = VMS_WL__malloc(sizeof(uint16_t)*numEndpoints);
    1.42 -    if(exchange->p2pTriggerCounter == NULL){
    1.43 -        VMS_WL__free(exchange->outboxArray);
    1.44 -        VMS_WL__free(exchange);
    1.45 +    centralExchange->p2pTriggerCounters = VMS_WL__malloc(sizeof(uint16_t)*numEndpoints);
    1.46 +    if(centralExchange->p2pTriggerCounters == NULL){
    1.47 +        VMS_WL__free(centralExchange->outboxArray);
    1.48 +        VMS_WL__free(centralExchange);
    1.49          return NULL;
    1.50      }
    1.51      
    1.52      //reset all point 2 point trigger counter
    1.53 -    memset((void*)exchange->p2pTriggerCounter, 0, sizeof(uint16_t)*numEndpoints);
    1.54 +    memset((void*)centralExchange->p2pTriggerCounters, 0, sizeof(uint16_t)*numEndpoints);
    1.55      
    1.56 -    return exchange;    
    1.57 +    return centralExchange;    
    1.58  }
    1.59  
    1.60  /*
    1.61   * Connects the local endpoint to the central exchange structure.
    1.62 - * This registers a message handler that handles all the incomming messages.
    1.63 + * This registers a message handler that handles all incoming messages.
    1.64   * Also an endpointID is set this ID has to be between 0 and total number of
    1.65 - * endpoints-1 and the number has to be unique.
    1.66 + * endpoints-1 and unique.
    1.67   */
    1.68  void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
    1.69                                     lossyCom__exchange_t* centralExchange,
    1.70 @@ -61,13 +60,17 @@
    1.71      localEndpoint->msgHandlerData = msgHandlerData;
    1.72  }
    1.73  
    1.74 +/*
    1.75 + * Prepare a lossyCom__msg_t in the correct format that contains the trigger 
    1.76 + * value, the receiver endpoint ID and the message body
    1.77 + */
    1.78  inline lossyCom__msg_t prepareMsg(uint16_t triggerValue,
    1.79                                    lossyCom__endpointID_t receiverEndpointID,
    1.80 -                                  lossyCom__msgBody_t msg)
    1.81 +                                  lossyCom__msgBody_t msgBody)
    1.82  {
    1.83      lossyCom__msg_t msgDraft;
    1.84      
    1.85 -    msgDraft = (0 | msg);
    1.86 +    msgDraft = (0 | msgBody);
    1.87      msgDraft |= ((lossyCom__msg_t)receiverEndpointID << ENDPOINT_ID_SHIFT);
    1.88      msgDraft |= ((lossyCom__msg_t)triggerValue << TRIGGER_SHIFT);
    1.89      
    1.90 @@ -84,7 +87,7 @@
    1.91      uint16_t increasedTrigger;
    1.92      lossyCom__msg_t msg;
    1.93      
    1.94 -    increasedTrigger = centralExchange->BroadcastTriggerCounter +1;
    1.95 +    increasedTrigger = centralExchange->broadcastTriggerCounter +1;
    1.96      
    1.97      //build message
    1.98      msg = prepareMsg(increasedTrigger, BROADCAST_ID, msgBody);
    1.99 @@ -93,7 +96,7 @@
   1.100      centralExchange->outboxArray[localEndpoint->endpointID] = msg;
   1.101      
   1.102      //update broadcast trigger counter
   1.103 -    centralExchange->BroadcastTriggerCounter = increasedTrigger;
   1.104 +    centralExchange->broadcastTriggerCounter = increasedTrigger;
   1.105  }
   1.106  
   1.107  /*
   1.108 @@ -109,7 +112,7 @@
   1.109      uint16_t increasedTrigger;
   1.110      
   1.111      increasedTrigger =
   1.112 -            centralExchange->p2pTriggerCounter[receiverEndpointID] +1;
   1.113 +            centralExchange->p2pTriggerCounters[receiverEndpointID] +1;
   1.114      
   1.115          //build message
   1.116      msg = prepareMsg(increasedTrigger, receiverEndpointID, msgBody);
   1.117 @@ -118,7 +121,7 @@
   1.118      centralExchange->outboxArray[localEndpoint->endpointID] = msg;
   1.119      
   1.120      //write back increased trigger counter
   1.121 -    centralExchange->p2pTriggerCounter[receiverEndpointID] = increasedTrigger;
   1.122 +    centralExchange->p2pTriggerCounters[receiverEndpointID] = increasedTrigger;
   1.123  }
   1.124  
   1.125  int inline isUnreceivedMsg(uint16_t msgTrigger, 
   1.126 @@ -153,9 +156,9 @@
   1.127      
   1.128      centralExchange = localEndpoint->centralExchange;
   1.129      //save trigger counter to know find valid messages
   1.130 -    broadcastTriggerSnapshot = centralExchange->BroadcastTriggerCounter;
   1.131 +    broadcastTriggerSnapshot = centralExchange->broadcastTriggerCounter;
   1.132      p2pTriggerSnapshot = 
   1.133 -            centralExchange->p2pTriggerCounter[localEndpoint->endpointID];    
   1.134 +            centralExchange->p2pTriggerCounters[localEndpoint->endpointID];    
   1.135      
   1.136      //new message arrived if trigger counter is higher than the last time read
   1.137      if( broadcastTriggerSnapshot > localEndpoint->lastReceivedBroadcastTrigger ||