Index: vtcross/trunk/src/shell/CognitiveRadioShell.cpp
===================================================================
--- vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 230)
+++ vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 231)
@@ -111,64 +111,63 @@
 
 
+// TODO what is the point of always returning a 1?
 bool
-CognitiveRadioShell::SendRadioConfiguration(int32_t socketfd)
+CognitiveRadioShell::SendRadioConfiguration(int32_t socketFD)
 {
     LOG("Cognitive Radio Shell:: Sending radio configuration to Cognitive Engine.\n");
-    uint32_t i,j;
+
     char counter[55];
     char var[50];
 
-    // utilities
-    // Send number of utilities
-    sprintf(counter,"%d",radio_info->numUtilities);
-    SendMessage(socketfd,counter);
-    // send utility	
-    for(i = 0; i < radio_info->numUtilities; i++) {
-        SendMessage(socketfd, utils[i].name.c_str());
-        SendMessage(socketfd, utils[i].units.c_str());
-        SendMessage(socketfd, utils[i].goal.c_str());
+    /* Send utilities */
+    sprintf(counter, "%d", radio_info->numUtilities);
+    SendMessage(socketFD, counter);
+    for(size_t i = 0; i < radio_info->numUtilities; i++) {
+        SendMessage(socketFD, utils[i].name.c_str());
+        SendMessage(socketFD, utils[i].units.c_str());
+        SendMessage(socketFD, utils[i].goal.c_str());
         sprintf(var,"%f", utils[i].target);
-        SendMessage(socketfd, var);
-    }
-
-    // parameters
+        SendMessage(socketFD, var);
+    }
+
+    /* Send parameters */
     sprintf(counter,"%i",radio_info->numParameters);
-    SendMessage(socketfd,counter);
-    for(i = 0; i < radio_info->numParameters; i++) {
-        SendMessage(socketfd, params[i].name.c_str());
-        SendMessage(socketfd, params[i].units.c_str());
+    SendMessage(socketFD,counter);
+    for(size_t i = 0; i < radio_info->numParameters; i++) {
+        SendMessage(socketFD, params[i].name.c_str());
+        SendMessage(socketFD, params[i].units.c_str());
         sprintf(var, "%f", params[i].min);
-        SendMessage(socketfd,var);
+        SendMessage(socketFD,var);
         sprintf(var, "%f", params[i].max);
-        SendMessage(socketfd, var);
+        SendMessage(socketFD, var);
         sprintf(var, "%f", params[i].step);
-        SendMessage(socketfd, var);
+        SendMessage(socketFD, var);
 
         sprintf(counter, "%i", params[i].numAffects); 
-        SendMessage(socketfd, counter);
-        for(j = 0; j < params[i].numAffects; j++) {
-            SendMessage(socketfd, params[i].affection_list[j].u->name.c_str());
-            SendMessage(socketfd, params[i].affection_list[j].relation.c_str());
+        SendMessage(socketFD, counter);
+        for(size_t j = 0; j < params[i].numAffects; j++) {
+            SendMessage(socketFD, params[i].affection_list[j].u->name.c_str());
+            SendMessage(socketFD, params[i].affection_list[j].relation.c_str());
         }
     }
 
-    // observables
+    /* Send observables */
     sprintf(counter,"%i",radio_info->numObservables);
-    SendMessage(socketfd, counter);
-    for(i = 0; i < radio_info->numObservables; i++) {
-        SendMessage(socketfd, observables[i].name.c_str());
+    SendMessage(socketFD, counter);
+    for(size_t i = 0; i < radio_info->numObservables; i++) {
+        SendMessage(socketFD, observables[i].name.c_str());
 		
         sprintf(counter, "%i", observables[i].numAffects); 
-        SendMessage(socketfd, counter);
-        for(j = 0; j < observables[i].numAffects; j++) {
-            SendMessage(socketfd, observables[i].affection_list[j].u->name.c_str());
-            SendMessage(socketfd, observables[i].affection_list[j].relation.c_str());
+        SendMessage(socketFD, counter);
+        for(size_t j = 0; j < observables[i].numAffects; j++) {
+            SendMessage(socketFD, observables[i].affection_list[j].u->name.c_str());
+            SendMessage(socketFD, observables[i].affection_list[j].relation.c_str());
         }
     }
 	
-    // Receive ACK for utils
+    /* Receive ACK for radio configuration */
     char buffer[256];
     memset(buffer, 0, 256); 
-    ReadMessage(socketfd, buffer);
+    ReadMessage(socketFD, buffer);
 
     if(strcmp(buffer, "receive_config_ack") != 0) {
@@ -178,5 +177,4 @@
 
     return 1;
-
 }
 
@@ -189,5 +187,5 @@
 	char numberExpString[50];
 
-    sprintf(numberExpString,"%i",numberExp);
+    sprintf(numberExpString, "%i", numberExp);
     SendMessage(socketFD, numberExpString); 
 
@@ -196,7 +194,9 @@
     ReadMessage(socketFD, buffer);
     if(strcmp(buffer, "receive_exp_ack") != 0) {
-        LOG("Cognitive Radio Shell:: Unexpected response: %s\n",buffer);
+        // TODO perhaps this should be a WARNING instead of a LOG?
+        LOG("Cognitive Radio Shell:: Unexpected response: %s\n", buffer);
         return 0;
     }
+
     return 1;
 }
@@ -446,5 +446,4 @@
 
     return 1;
-
 }
 
@@ -454,5 +453,4 @@
 {
     char buffer[256];
-    uint32_t numObservables,numParameters,numCurrentParameters;
     char counter[55];
     char var[50];
@@ -462,5 +460,5 @@
     memset(buffer, 0, 256);
     ReadMessage(commandSocketFD, buffer);
-    numObservables = atoi(buffer);
+    uint32_t numObservables = atoi(buffer);
   
 	LOG("Cognitive Radio Shell:: Attempting to get %i observables.\n", numObservables);
@@ -476,8 +474,9 @@
         o[i].value = atof(buffer);
     }
+
 	/* Receive Set of Current Parameters */
     memset(buffer, 0, 256);
     ReadMessage(commandSocketFD,buffer);
-    numCurrentParameters = atoi(buffer);
+    uint32_t numCurrentParameters = atoi(buffer);
   
 	LOG("Cognitive Radio Shell:: Attempting to get %i parameters.\n",numCurrentParameters);
@@ -492,9 +491,9 @@
         cp[i].value = atof(buffer);
     }
+
     /* Send to Cognitive Engine 
 	 * TODO: With multiple CEs we need to make a decision about where
 	 * to send this information
 	 */
-
 	if(!SML_present) { 
 	    LOG("Cognitive Radio Shell:: Passing on observables to Cognitive Engine\n");
@@ -522,5 +521,5 @@
     memset(buffer, 0, 256);
     ReadMessage(ceSocketFD, buffer);
-    numParameters = atoi(buffer);
+    uint32_t numParameters = atoi(buffer);
    
     Parameter *p = new Parameter[numParameters];
@@ -552,9 +551,9 @@
 }
 
+// TODO point of always returning 1?
 bool
 CognitiveRadioShell::UpdateParameterPerformance(int32_t socketFD)
 {
     char counter[55];
-    uint32_t numObservables,numParameters;
     char var[50];
     char buffer[256];
@@ -563,5 +562,5 @@
     memset(buffer, 0, 256);
     ReadMessage(commandSocketFD,buffer);
-    numParameters = atoi(buffer);
+    uint32_t numParameters = atoi(buffer);
   
     Parameter *p = new Parameter[numParameters];
@@ -579,5 +578,5 @@
     memset(buffer, 0, 256);
     ReadMessage(commandSocketFD, buffer);
-    numObservables = atoi(buffer);
+    uint32_t numObservables = atoi(buffer);
   
     Observable *o = new Observable[numObservables];
@@ -593,8 +592,7 @@
     }
 
-
     SendMessage(ceSocketFD, "update_performance");
    
-    // Send Parameters 
+    /* Send Parameters */
     memset(counter, 0, 55);
     sprintf(counter, "%i", numParameters);
@@ -607,5 +605,5 @@
     }   
     
-    // Send Observables
+    /* Send Observables */
     sprintf(counter, "%i", numObservables);
     SendMessage(ceSocketFD, counter);
@@ -615,7 +613,12 @@
         SendMessage(ceSocketFD, var); 
     }   
+
+    delete [] p;
+    delet [] o;
     
     return 1;
 }
+
+
 void
 CognitiveRadioShell::HandleMessage(int32_t socketFD)
@@ -625,4 +628,5 @@
     ReadMessage(socketFD, buffer);
 
+    // TODO trying to read this code lock makes my eyes bleed
     if(strcmp(buffer, "register_engine_cognitive") == 0) { 
         RegisterCognitiveEngine(socketFD);
@@ -639,20 +643,20 @@
     } else if(strcmp(buffer, "update_performance") == 0) {
         UpdateParameterPerformance(socketFD);
-    } else if(strcmp(buffer,"get_number_utilities") == 0) {
+    } else if(strcmp(buffer, "get_number_utilities") == 0) {
 		char numUtilities[20];
-		sprintf(numUtilities,"%i",radio_info->numUtilities);
-        SendMessage(commandSocketFD,numUtilities);
-    } else if(strcmp(buffer,"get_number_observables") == 0) {
+		sprintf(numUtilities, "%i", radio_info->numUtilities);
+        SendMessage(commandSocketFD, numUtilities);
+    } else if(strcmp(buffer, "get_number_observables") == 0) {
 		char numObservables[20];
-		sprintf(numObservables,"%i",radio_info->numObservables);
-        SendMessage(commandSocketFD,numObservables);
-    } else if(strcmp(buffer,"get_number_parameters") == 0) {
+		sprintf(numObservables, "%i", radio_info->numObservables);
+        SendMessage(commandSocketFD, numObservables);
+    } else if(strcmp(buffer, "get_number_parameters") == 0) {
 		char numParameters[20];
-		sprintf(numParameters,"%i",radio_info->numParameters);
-        SendMessage(commandSocketFD,numParameters);
-    } else if(strcmp(buffer,"request_optimization") == 0) {
+		sprintf(numParameters, "%i", radio_info->numParameters);
+        SendMessage(commandSocketFD, numParameters);
+    } else if(strcmp(buffer, "request_optimization") == 0) {
         /* Receive optimization request and current environment */
         GetOptimalParameters(socketFD);  
-    } else if(strcmp(buffer,"request_optimization_service") == 0) {
+    } else if(strcmp(buffer, "request_optimization_service") == 0) {
         /* Receive optimization request and current environment */
         //GetOptimalParametersService(socketFD);  
