Index: vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp
===================================================================
--- vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 71)
+++ vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 72)
@@ -6,5 +6,4 @@
 #include "socket/ServerSocket.h"
 #include "socket/SocketException.h"
-
 
 using namespace std;
@@ -221,5 +220,5 @@
 
 	// Clear incoming data buffer
-    bzero(buffer,256);
+    	bzero(buffer,256);
     
 	// Wait for incoming message
@@ -227,17 +226,14 @@
 	
 	// Print message
-    if (n > 0) 
-        printf("Here is the received meessage: %s\n",buffer);
-    //printf("n = %d\n",n);
-	
-    return n;
+    	if (n > 0) 
+        	printf("Here is the received meessage: %s\n",buffer);
+    	if(n == 0)
+        	printf("Client closed the socket.\n");
+	
+    	return n;
 }
 
 int SendMessage(int socketfd, string message) {
 	int n;
-    int len;
-    
-    char LEN[8];
-    char * temp;
 
 	message.append("\0000");	
@@ -246,82 +242,133 @@
     	if (n<0)
         	error("Error sending to client\n");
-    	printf("sent: %s %i\n", message.c_str(),n);
+    	if(n == 0)
+        	printf("Client closed the socket.\n");
 	
     	return n;
 }
 
-void StartMessaging(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
+void GetEnvironment() {
+
+}
+
+void Policy_ValidateSettings() {
+
+}
+
+// Update operating settings
+// This function will interact with the hardware "drivers"
+void UpdateRadioSettings() {
+
+}
+
+void LoadCEConfiguration(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info){
 	int n,i,j;
 	char counter[55];
 	char var[50];
-    
-//    while(1) {
-		// Send number of utilities
-		sprintf(counter,"%d",ce_info->numUtilities);
+	int total_bytes;   
+
+	printf("Sending configuration to CE.\n");
+ 
+	// Send number of utilities
+	sprintf(counter,"%d",ce_info->numUtilities);
+	SendMessage(socketfd,counter);
+		
+ 	// utilities
+        for(i = 0; i < ce_info->numUtilities; i++) {
+		SendMessage(socketfd,uList[i]->name);
+		SendMessage(socketfd,uList[i]->units);
+		SendMessage(socketfd,uList[i]->goal);
+		sprintf(var,"%f",uList[i]->target);
+		SendMessage(socketfd,var);
+	}
+
+	// parameters
+        sprintf(counter,"%i",ce_info->numParameters);
+	SendMessage(socketfd,counter);
+	for(i = 0; i < ce_info->numParameters; i++) {
+		SendMessage(socketfd,pList[i]->name);
+		SendMessage(socketfd,pList[i]->units);
+		sprintf(var,"%f",pList[i]->min);
+		SendMessage(socketfd,var);
+		sprintf(var,"%f",pList[i]->max);
+		SendMessage(socketfd,var);
+		sprintf(var,"%f",pList[i]->step);
+		SendMessage(socketfd,var);
+		
+		sprintf(counter,"%i",pList[i]->numAffects); 
 		SendMessage(socketfd,counter);
-		
- 		// utilities
-        for(i = 0; i < ce_info->numUtilities; i++) {
-        //for(i = 0; i < 1; i++) {
-			SendMessage(socketfd,uList[i]->name);
-			SendMessage(socketfd,uList[i]->units);
-			SendMessage(socketfd,uList[i]->goal);
-			sprintf(var,"%f",uList[i]->target);
-			SendMessage(socketfd,var);
-		}
-
-		// parameters
-        sprintf(counter,"%i",ce_info->numParameters);
+		for(j = 0; j < pList[i]->numAffects; j++) {
+			SendMessage(socketfd,pList[i]->affection_list[j].u->name);
+			SendMessage(socketfd,pList[i]->affection_list[j].relation);
+		}
+	}
+
+        // observables
+	sprintf(counter,"%i",ce_info->numObservables);
+	SendMessage(socketfd,counter);
+	for(i = 0; i < ce_info->numObservables; i++) {
+		SendMessage(socketfd,oList[i]->name);
+		
+		sprintf(counter,"%i",oList[i]->numAffects); 
 		SendMessage(socketfd,counter);
-		for(i = 0; i < ce_info->numParameters; i++) {
-			SendMessage(socketfd,pList[i]->name);
-			SendMessage(socketfd,pList[i]->units);
-			sprintf(var,"%f",pList[i]->min);
-			SendMessage(socketfd,var);
-			sprintf(var,"%f",pList[i]->max);
-			SendMessage(socketfd,var);
-			sprintf(var,"%f",pList[i]->step);
-			SendMessage(socketfd,var);
-		
-			sprintf(counter,"%i",pList[i]->numAffects); 
-			SendMessage(socketfd,counter);
-			for(j = 0; j < pList[i]->numAffects; j++) {
-				SendMessage(socketfd,pList[i]->affection_list[j].u->name);
-				SendMessage(socketfd,pList[i]->affection_list[j].relation);
-			}
-		}
-
-        // observables
-		sprintf(counter,"%i",ce_info->numObservables);
-		SendMessage(socketfd,counter);
-		for(i = 0; i < ce_info->numObservables; i++) {
-			SendMessage(socketfd,oList[i]->name);
-			
-			sprintf(counter,"%i",oList[i]->numAffects); 
-			SendMessage(socketfd,counter);
-			for(j = 0; j < oList[i]->numAffects; j++) {
-				SendMessage(socketfd,oList[i]->affection_list[j].u->name);
-				SendMessage(socketfd,oList[i]->affection_list[j].relation);
-			}
-		}
-	
-		// Receive a message
+		for(j = 0; j < oList[i]->numAffects; j++) {
+			SendMessage(socketfd,oList[i]->affection_list[j].u->name);
+			SendMessage(socketfd,oList[i]->affection_list[j].relation);
+		}
+	}
+	
+	printf("Configuration sent, waiting for ACK...\n");
+	// Receive ACK for utils
         string message;
-		n = ReceiveMessage(socketfd, message);
+	n = ReceiveMessage(socketfd, message);
         cout << message << endl;
-
-
-        //printf("n = %d\n", n);
-		/*if (n < 0) {
-			printf("ERROR reading from socket\n");
-			close(socketfd);
-     			return;
-		}
-		if (n == 0) {
-			printf("Client has closed the connection.\n");
-			return;
-		}*/
-	
-//    }
+	printf("ACK received.\n");
+
+}
+
+void UpdateCEConfiguration() {
+
+}
+
+void ResetCEConfiguration(){
+
+}
+
+void LoadCEExperience(){
+
+}
+
+void UpdateCEExperience() {
+
+}
+
+void ResetCEExperience() {
+
+}
+
+void RequestCEOptimization() {
+
+}
+
+void RunSimulator(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
+
+	// Set fake past environment
+	LoadCEExperience();
+	
+	// Set fake current environment
+	RequestCEOptimization();
+
+	// Act like we are updating the hardware tranmission settings
+	UpdateRadioSettings();
+
+	// Send back fake utility values
+	UpdateCEExperience();	
+}
+
+void StartMessaging(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
+
+	LoadCEConfiguration(socketfd,uList, pList, oList, ce_info);
+
+	RunSimulator(socketfd,uList, pList, oList, ce_info);
 }
 
@@ -391,5 +438,5 @@
 	cout << "Configuration file parsing completed." << endl;
 
-    print_current_config(uList, pList, oList, &ce_info);
+    //print_current_config(uList, pList, oList, &ce_info);
 	
     pid = fork();
