Index: /vtcross/branches/trnewman/CR_shell/src/main_cognitive_engine.cpp
===================================================================
--- /vtcross/branches/trnewman/CR_shell/src/main_cognitive_engine.cpp	(revision 71)
+++ /vtcross/branches/trnewman/CR_shell/src/main_cognitive_engine.cpp	(revision 73)
@@ -69,22 +69,183 @@
 }
 
+int GetXMLFromServer(int sockfd, Utility uList[], Parameter pList[], 
+        Observable oList[], CE_Info *ce_info)
+{
+    char buffer[256];
+    int i,j;
+
+    // read unitilities
+    // numUtilities
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+    ce_info->numUtilities = atoi(buffer);
+    printf("number of utilities: %d\n", ce_info->numUtilities);
+        
+    for (i = 0; i < ce_info->numUtilities; i++){
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+	    printf("Name: %s\n", buffer);
+        strcpy(uList[i].name, buffer);
+                 
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+	    printf("Units: %s\n", buffer);
+        strcpy(uList[i].units, buffer);
+
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+        printf("Goal: %s\n", buffer);
+        strcpy(uList[i].goal, buffer);
+        
+	    bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+        printf("Target: %s\n", buffer);
+        uList[i].target = atof(buffer);
+    }
+
+    // read parameters
+    // numParameters
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+    ce_info->numParameters = atoi(buffer);
+    printf("number of parameters: %d\n", ce_info->numParameters);
+        
+    for (i = 0; i < ce_info->numParameters; i++){
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+	    printf("Name: %s\n", buffer);
+        strcpy(pList[i].name, buffer);
+                 
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+	    printf("Units: %s\n", buffer);
+        strcpy(pList[i].units, buffer);
+
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+        printf("Min: %s\n", buffer);
+        pList[i].min = atof(buffer);
+        
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+        printf("Max: %s\n", buffer);
+        pList[i].max = atof(buffer);
+        
+	    bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+        printf("Step: %s\n", buffer);
+        pList[i].step = atof(buffer);
+    
+        // numAffects
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        pList[i].numAffects = atoi(buffer);
+        printf("number of affects: %d\n", pList[i].numAffects);
+        
+        for (j = 0; j < pList[i].numAffects; j++){
+            bzero(buffer,256);
+	        ReadMessage(sockfd,buffer);
+	        printf("Utility name: %s\n", buffer);
+            strcpy(pList[i].affection_list[j].u.name, buffer);
+                 
+            bzero(buffer,256);
+	        ReadMessage(sockfd,buffer);
+	        printf("Relation: %s\n", buffer);
+            strcpy(pList[i].affection_list[j].relation, buffer);
+        }
+
+    }
+    
+    // read obervables
+    // numParameters
+    bzero(buffer,256);
+    ReadMessage(sockfd,buffer);
+    ce_info->numObservables = atoi(buffer);
+    printf("number of observables: %d\n", ce_info->numObservables);
+        
+    for (i = 0; i < ce_info->numObservables; i++){
+        bzero(buffer,256);
+	    ReadMessage(sockfd,buffer);
+	    printf("Name: %s\n", buffer);
+        strcpy(pList[i].name, buffer);
+                 
+        // numAffects
+        bzero(buffer,256);
+        ReadMessage(sockfd,buffer);
+        oList[i].numAffects = atoi(buffer);
+        printf("number of affects: %d\n", oList[i].numAffects);
+        
+        for (j = 0; j < oList[i].numAffects; j++){
+            bzero(buffer,256);
+	        ReadMessage(sockfd,buffer);
+	        printf("Utility name: %s\n", buffer);
+            strcpy(oList[i].affection_list[j].u.name, buffer);
+                 
+            bzero(buffer,256);
+	        ReadMessage(sockfd,buffer);
+	        printf("Relation: %s\n", buffer);
+            strcpy(oList[i].affection_list[j].relation, buffer);
+        }
+    }
+
+    printf("xml reception done\n");
+    
+    return 0;
+}
+
+void print_current_config(Utility * uList[], Parameter * pList[], 
+        Observable * oList[], CE_Info * ce_info) 
+{    
+    int i = 0;
+    int j = 0;
+
+    // utilities
+    for(i = 0; i < ce_info->numUtilities ; i++) {
+        cout << "Utility:  " << uList[i]->name << endl;
+        cout << "     Units:  " << uList[i]->units << endl;
+        cout << "     Goal:   " << uList[i]->goal << endl;
+        cout << "     Target: " << uList[i]->target << endl;
+    }
+                       
+    // parameters                        
+    for(i = 0; i < ce_info->numParameters; i++) {
+        cout << "Parameter:  " << pList[i]->name << endl;
+        cout << "       Units:   " << pList[i]->units << endl;
+        cout << "       Min:     " << pList[i]->min << endl;
+        cout << "       Max:     " << pList[i]->max << endl;
+        cout << "       Step:    " << pList[i]->step << endl;
+        for(j = 0; j < pList[i]->numAffects; j++) {
+            cout << "       Affect: " << pList[i]->affection_list[j].u.name << " -> " << pList[i]->affection_list[j].relation << endl;
+        }
+    }
+
+    // observables
+    for(i = 0; i < ce_info->numObservables; i++) {
+        cout << "Observable:  " << oList[i]->name << endl;
+        for(j = 0; j < oList[i]->numAffects; j++) {
+            cout << "       Affect: " << oList[i]->affection_list[j].u.name << " -> " << oList[i]->affection_list[j].relation << endl;
+        }
+    }
+}
+
+
 // main client socket
 int main(int argc, char *argv[])
 {
-    int sockfd, portno, n;
+    Utility uList[10];
+    Parameter pList[10];
+    Observable oList[10];
+    CE_Info ce_info;
+
+    int sockfd, portno;
     struct sockaddr_in serv_addr;
     struct hostent *server;
 
-    // create a socket
-    char buffer[256];
-    char buffer1[256];
+    // setup client socket connection
     if (argc < 3) {
-       fprintf(stderr,"usage %s hostname port\n", argv[0]);
+       fprintf(stderr,"usage: %s hostname port\n", argv[0]);
        exit(0);
     }
-    portno = atoi(argv[2]);
-    sockfd = socket(AF_INET, SOCK_STREAM, 0);
-    if (sockfd < 0) 
-        error("ERROR opening socket");
+    // server name
     server = gethostbyname(argv[1]);
     if (server == NULL) {
@@ -92,136 +253,28 @@
         exit(0);
     }
+    // port no.
+    portno = atoi(argv[2]);
+    // socket file descriptor
+    sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    if (sockfd < 0) 
+        error("ERROR opening socket");
+    // initiate struct socketaddr_in
     bzero((char *) &serv_addr, sizeof(serv_addr));
     serv_addr.sin_family = AF_INET;
+    serv_addr.sin_port = htons(portno);
     bcopy((char *)server->h_addr, 
          (char *)&serv_addr.sin_addr.s_addr,
          server->h_length);
-    serv_addr.sin_port = htons(portno);
     // cast sockaddr_in to sockaddr
     if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) 
         error("ERROR connecting");
     
-    int i, j;
-    Utility uList[10];
-    Parameter pList[10];
-    Observable oList[10];
-    CE_Info ce_info;
-
-    // read unitilities
-    // numUtilities
-    bzero(buffer,256);
-    ReadMessage(sockfd,buffer);
-    ce_info.numUtilities = atoi(buffer);
-    printf("number of utilities: %d\n", ce_info.numUtilities);
-        
-    for (i = 0; i < ce_info.numUtilities; i++){
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-	    printf("Name: %s\n", buffer);
-        strcpy(uList[i].name, buffer);
-                 
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-	    printf("Units: %s\n", buffer);
-        strcpy(uList[i].units, buffer);
-
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-        printf("Goal: %s\n", buffer);
-        strcpy(uList[i].goal, buffer);
-        
-	    bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-        printf("Target: %s\n", buffer);
-        uList[i].target = atof(buffer);
-    }
-
-    // read parameters
-    // numParameters
-    bzero(buffer,256);
-    ReadMessage(sockfd,buffer);
-    ce_info.numParameters = atoi(buffer);
-    printf("number of parameters: %d\n", ce_info.numParameters);
-        
-    for (i = 0; i < ce_info.numParameters; i++){
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-	    printf("Name: %s\n", buffer);
-        strcpy(pList[i].name, buffer);
-                 
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-	    printf("Units: %s\n", buffer);
-        strcpy(pList[i].units, buffer);
-
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-        printf("Min: %s\n", buffer);
-        pList[i].min = atof(buffer);
-        
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-        printf("Max: %s\n", buffer);
-        pList[i].max = atof(buffer);
-        
-	    bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-        printf("Step: %s\n", buffer);
-        pList[i].step = atof(buffer);
-    
-        // numAffects
-        bzero(buffer,256);
-        ReadMessage(sockfd,buffer);
-        pList[i].numAffects = atoi(buffer);
-        printf("number of affects: %d\n", pList[i].numAffects);
-        
-        for (j = 0; j < pList[i].numAffects; j++){
-            bzero(buffer,256);
-	        ReadMessage(sockfd,buffer);
-	        printf("Utility name: %s\n", buffer);
-            strcpy(pList[i].affection_list[j].u.name, buffer);
-                 
-            bzero(buffer,256);
-	        ReadMessage(sockfd,buffer);
-	        printf("Relation: %s\n", buffer);
-            strcpy(pList[i].affection_list[j].relation, buffer);
-        }
-
-    }
-    
-    // read obervables
-    // numParameters
-    bzero(buffer,256);
-    ReadMessage(sockfd,buffer);
-    ce_info.numObservables = atoi(buffer);
-    printf("number of observables: %d\n", ce_info.numObservables);
-        
-    for (i = 0; i < ce_info.numObservables; i++){
-        bzero(buffer,256);
-	    ReadMessage(sockfd,buffer);
-	    printf("Name: %s\n", buffer);
-        strcpy(pList[i].name, buffer);
-                 
-        // numAffects
-        bzero(buffer,256);
-        ReadMessage(sockfd,buffer);
-        oList[i].numAffects = atoi(buffer);
-        printf("number of affects: %d\n", oList[i].numAffects);
-        
-        for (j = 0; j < oList[i].numAffects; j++){
-            bzero(buffer,256);
-	        ReadMessage(sockfd,buffer);
-	        printf("Utility name: %s\n", buffer);
-            strcpy(oList[i].affection_list[j].u.name, buffer);
-                 
-            bzero(buffer,256);
-	        ReadMessage(sockfd,buffer);
-	        printf("Relation: %s\n", buffer);
-            strcpy(oList[i].affection_list[j].relation, buffer);
-        }
-    }
-
-    
-    printf("xml transmission done\n");
+    // get xml info from server
+    GetXMLFromServer(sockfd, uList, pList, oList, &ce_info);
+
+    printf("utility:\n name: %s, units: %s, goal: %s, target: %f\n", 
+            uList[0].name, uList[0].units, uList[0].goal, uList[0].target);
+    
+    //print_current_config(&uList, &pList, &oList, &ce_info); 
 
 
Index: /vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp
===================================================================
--- /vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 72)
+++ /vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 73)
@@ -378,13 +378,12 @@
      	struct sockaddr_in serv_addr, cli_addr;
 
-     	// Setup socket connection
-     
-     	sockfd = socket(AF_INET, SOCK_STREAM, 0);
+     	// Setup server socket connection
+        sockfd = socket(AF_INET, SOCK_STREAM, 0);
      	if (sockfd < 0) 
         	error("ERROR opening socket");
      	bzero((char *) &serv_addr, sizeof(serv_addr));
      	serv_addr.sin_family = AF_INET;
+     	serv_addr.sin_port = htons(port);
      	serv_addr.sin_addr.s_addr = INADDR_ANY;
-     	serv_addr.sin_port = htons(port);
      	if (bind(sockfd, (struct sockaddr *) &serv_addr,
              	sizeof(serv_addr)) < 0) 
