Index: vtcross/trunk/src/cognitive_engines/cbr_demo.cpp
===================================================================
--- vtcross/trunk/src/cognitive_engines/cbr_demo.cpp	(revision 218)
+++ vtcross/trunk/src/cognitive_engines/cbr_demo.cpp	(revision 222)
@@ -35,5 +35,5 @@
     LOG("Waiting for signal...\n");
     while(1) {
-//        cognitiveEngine.WaitForSignal();
+        cognitiveEngine.WaitForSignal();
     }
 
Index: vtcross/trunk/src/cognitive_engines/CognitiveEngine.cpp
===================================================================
--- vtcross/trunk/src/cognitive_engines/CognitiveEngine.cpp	(revision 218)
+++ vtcross/trunk/src/cognitive_engines/CognitiveEngine.cpp	(revision 222)
@@ -88,4 +88,5 @@
 {
     char buffer[256];
+    uint16_t i;
 
     while(true) {
@@ -102,6 +103,28 @@
         // switch on the integer value...
         if(strcmp(buffer, "get_solution") == 0) {
-        
-
+            
+            /* Receive Set of Observables */
+			LOG("Cognitive Engine:: Receiving observables.\n");
+
+            memset(buffer, 0, 256);
+            ReadMessage(commandSocketFD,buffer);
+            uint32_t numObservables = atoi(buffer);
+   
+            Observable * o = new Observable[numObservables];
+ 
+            for (i = 0; i < numObservables; i++){
+                memset(buffer, 0, 256);
+                ReadMessage(commandSocketFD,buffer);
+                o[i].name = std::string(buffer);
+    
+                memset(buffer, 0, 256);
+                ReadMessage(commandSocketFD,buffer);
+                o[i].value = atof(buffer);
+            }  
+
+			LOG("Cognitive Engine:: Sending Optimal Parameters.\n");
+            SendMessage(commandSocketFD,"1");
+            SendMessage(commandSocketFD,"txPower");
+            SendMessage(commandSocketFD,"10");
         }
         else if(strcmp(buffer, "query_component_type") == 0) {
@@ -266,5 +289,4 @@
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD,buffer);
-        LOG("socket_comm::Get Utility - Name: %s\n", buffer);
         uList[i].name = std::string(buffer);
     
@@ -286,36 +308,28 @@
     ReadMessage(commandSocketFD, buffer);
     radioInfo->numParameters = atoi(buffer);
-    LOG("socket_comm::GetParameter - Number of parameters: %d\n", \
-            radioInfo->numParameters);
     
     for(size_t i = 0; i < radioInfo->numParameters; i++) {
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD, buffer);
-        LOG("socket_comm::GetParameter - Name: %s\n", buffer);
         pList[i].name = std::string(buffer);
     
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD, buffer);
-        LOG("socket_comm::GetParameter - Units: %s\n", buffer);
         pList[i].units = std::string(buffer);
 
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD, buffer);
-        LOG("socket_comm::GetParameter - Min: %s\n", buffer);
         pList[i].min = atof(buffer);
     
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD, buffer);
-        LOG("socket_comm::GetParameter - Max: %s\n", buffer);
         pList[i].max = atof(buffer);
     
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD, buffer);
-        LOG("socket_comm::GetParameter - Step: %s\n", buffer);
         pList[i].step = atof(buffer);
     
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD,buffer);
-        LOG("socket_comm::GetParameter - Number of Affects: %s\n", buffer);
         pList[i].numAffects = atoi(buffer);
     
@@ -323,5 +337,4 @@
             memset(buffer, 0, 256);
             ReadMessage(commandSocketFD,buffer);
-            LOG("socket_comm::GetParameter - Affect Name: %s\n", buffer);
             for (k = 0; k < radioInfo->numUtilities; k++){
 	        if(uList[k].name == std::string(buffer)){    
@@ -333,5 +346,4 @@
             memset(buffer, 0, 256);
             ReadMessage(commandSocketFD,buffer);
-            LOG("socket_comm::GetParameter - Affect Relation: %s\n", buffer);
             pList[i].affection_list[j].relation = std::string(buffer);   
         }
@@ -346,10 +358,8 @@
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD,buffer);
-        LOG("socket_comm::Get Observable - Name: %s\n", buffer);
         oList[i].name = std::string(buffer);
     
         memset(buffer, 0, 256);
         ReadMessage(commandSocketFD,buffer);
-        LOG("socket_comm::Get Observable - Number Affects: %s\n", buffer);
         oList[i].numAffects = atoi(buffer);
     
@@ -357,5 +367,4 @@
             memset(buffer, 0, 256);
             ReadMessage(commandSocketFD,buffer);
-            LOG("socket_comm::Get Observable - Affect Name: %s\n", buffer);
             for (k = 0; k < radioInfo->numUtilities; k++){
 	        if(uList[k].name == std::string(buffer)){    
@@ -367,5 +376,4 @@
             memset(buffer, 0, 256);
             ReadMessage(commandSocketFD,buffer);
-            LOG("socket_comm::Get Observable - Affect Relation: %s\n", buffer);
             oList[i].affection_list[j].relation = std::string(buffer);   
         }
Index: vtcross/trunk/src/include/vtcross/libvtcross.h
===================================================================
--- vtcross/trunk/src/include/vtcross/libvtcross.h	(revision 196)
+++ vtcross/trunk/src/include/vtcross/libvtcross.h	(revision 222)
@@ -46,7 +46,7 @@
  * functions will still be valid by the time the client code receives them.
  */
-Observables* GetRadioObservables();
-Parameters* GetRadioParameters();
-Utilities* GetRadioUtilities();
+Observable* GetRadioObservables();
+Parameter* GetRadioParameters();
+Utility* GetRadioUtilities();
 
 
@@ -76,5 +76,5 @@
  * use this?  Shouldn't this be internal to the radio operation? 
  */
-Parameters* GetOptimalParameters(Observables *radioObservables);
+Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables);
 
 
@@ -85,6 +85,6 @@
  * radio's performance?
  */
-bool UpdateParameterPerformance(Parameters *radioParameters, \
-        Observables *radioObservables, Utilies *radioUtilies);
+bool UpdateParameterPerformance(Parameter *radioParameters, \
+        Observable *radioObservables, Utility *radioUtilies);
 
 
Index: vtcross/trunk/src/include/vtcross/components.h
===================================================================
--- vtcross/trunk/src/include/vtcross/components.h	(revision 217)
+++ vtcross/trunk/src/include/vtcross/components.h	(revision 222)
@@ -353,4 +353,8 @@
         int16_t commandPort;
 
+        int32_t ceSocketFD;
+        int32_t commandSocketFD;
+        int32_t policySocketFD;
+
         Utility *utils;
         Parameter *params;
Index: vtcross/trunk/src/include/vtcross/containers.h
===================================================================
--- vtcross/trunk/src/include/vtcross/containers.h	(revision 221)
+++ vtcross/trunk/src/include/vtcross/containers.h	(revision 222)
@@ -81,4 +81,13 @@
  *
  */
+struct Service {
+    std::string name;
+    uint16_t socketFD;
+}; 
+
+
+/* TODO
+ *
+ */
 struct Mission {
     std::string name;
@@ -88,12 +97,3 @@
 };
 
-
-/* TODO
- *
- */
-struct Service {
-    std::string name;
-    uint16_t socketFD;
-}; 
-
 #endif
Index: vtcross/trunk/src/lib/socketcomm/socketcomm.cpp
===================================================================
--- vtcross/trunk/src/lib/socketcomm/socketcomm.cpp	(revision 219)
+++ vtcross/trunk/src/lib/socketcomm/socketcomm.cpp	(revision 222)
@@ -41,4 +41,8 @@
     // Messages are termination with a "\0" to denote EOM.
     ssize_t msgLength = recv(socketFD, msgBuffer, 256, MSG_PEEK);
+    if (msgLength < 0)
+        ERROR(1, "Error reading from socket.\n");
+    if (msgLength == 0)
+        ERROR(1, "Remote component closed connection.\n");
 
     size_t i;
@@ -51,5 +55,7 @@
     msgLength = recv(socketFD, msgBuffer, i + 1, 0);
     if (msgLength < 0)
-        ERROR(1, "Error reading from socket");
+        ERROR(1, "Error reading from socket.\n");
+    if (msgLength == 0)
+        ERROR(1, "Remote component closed connection.\n");
 }
 
@@ -66,5 +72,5 @@
     server = gethostbyname(serverName);
     if(server == NULL)
-        ERROR(1, "No server found by that hostname.");
+        ERROR(1, "No server found by that hostname.\n");
 
     portNumber = atoi(serverPort);
@@ -72,5 +78,5 @@
     socketFD = socket(AF_INET, SOCK_STREAM, 0);
     if(socketFD < 0) 
-        ERROR(1, "Error opening socket");
+        ERROR(1, "Error opening socket\n");
 
     memset((void *) &serv_addr, 0, sizeof(serv_addr));
@@ -81,5 +87,5 @@
 
     if(connect(socketFD, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) 
-        ERROR(1, "Error connecting to remote socket.");
+        ERROR(1, "Error connecting to remote socket.\n");
 
     return socketFD;
@@ -117,6 +123,6 @@
 {
     ssize_t numSentBytes = send(socketFD, message, (strlen(message) + 1), 0);
-    if(numSentBytes < 0) {
-        ERROR(1, "Error sending to server.");
+	if(numSentBytes < 0) {
+        ERROR(1, "Error sending to server.\n");
     }
     else if(numSentBytes == 0) {
@@ -210,5 +216,5 @@
     int32_t clientSocket = accept(serverSock, NULL, NULL);
     if(clientSocket < 0) { 
-        WARNING("ALERT: Could not establish connection with client socket.\n");
+        //WARNING("ALERT: Could not establish connection with client socket.\n");
         return -1;
     }
Index: vtcross/trunk/src/shell/CognitiveRadioShell.cpp
===================================================================
--- vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 218)
+++ vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 222)
@@ -125,8 +125,8 @@
     // send utility	
     for(i = 0; i < radio_info->numUtilities; i++) {
-        SendMessage(socketfd, u[i].name.c_str());
-        SendMessage(socketfd, u[i].units.c_str());
-        SendMessage(socketfd, u[i].goal.c_str());
-        sprintf(var,"%f", u[i].target);
+        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);
     }
@@ -136,18 +136,18 @@
     SendMessage(socketfd,counter);
     for(i = 0; i < radio_info->numParameters; i++) {
-        SendMessage(socketfd,p[i].name.c_str());
-        SendMessage(socketfd,p[i].units.c_str());
-        sprintf(var,"%f",p[i].min);
+        SendMessage(socketfd,params[i].name.c_str());
+        SendMessage(socketfd,params[i].units.c_str());
+        sprintf(var,"%f",params[i].min);
         SendMessage(socketfd,var);
-        sprintf(var,"%f",p[i].max);
+        sprintf(var,"%f",params[i].max);
         SendMessage(socketfd,var);
-        sprintf(var,"%f",p[i].step);
+        sprintf(var,"%f",params[i].step);
         SendMessage(socketfd,var);
 
-        sprintf(counter,"%i",p[i].numAffects); 
+        sprintf(counter,"%i",params[i].numAffects); 
         SendMessage(socketfd,counter);
-        for(j = 0; j < p[i].numAffects; j++) {
-            SendMessage(socketfd,p[i].affection_list[j].u->name.c_str());
-            SendMessage(socketfd,p[i].affection_list[j].relation.c_str());
+        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());
         }
     }
@@ -157,11 +157,11 @@
     SendMessage(socketfd,counter);
     for(i = 0; i < radio_info->numObservables; i++) {
-        SendMessage(socketfd,o[i].name.c_str());
+        SendMessage(socketfd,observables[i].name.c_str());
 		
-        sprintf(counter,"%i",o[i].numAffects); 
+        sprintf(counter,"%i",observables[i].numAffects); 
         SendMessage(socketfd,counter);
-        for(j = 0; j < o[i].numAffects; j++) {
-            SendMessage(socketfd,o[i].affection_list[j].u->name.c_str());
-            SendMessage(socketfd,o[i].affection_list[j].relation.c_str());
+        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());
         }
     }
@@ -186,7 +186,8 @@
     LOG("Cognitive Radio Shell:: Sending radio experience to Cognitive Engine.\n");
     int32_t numberExp = 4;
-    
-    std::string numberExpString = numberExp;
-    SendMessage(socketFD, numberExp); 
+	char numberExpString[50];
+
+    sprintf(numberExpString,"%i",numberExp);
+    SendMessage(socketFD, numberExpString); 
 
     char buffer[256];
@@ -451,4 +452,76 @@
 CognitiveRadioShell::GetOptimalParameters(int32_t socketFD)
 {
+    char buffer[256];
+    uint32_t numObservables,numParameters;
+    char counter[55];
+    uint16_t i;
+    char var[50];
+
+    /* Receive Set of Observables */
+    LOG("Cognitive Radio Shell:: Got request for optimization.\n");
+    memset(buffer, 0, 256);
+    ReadMessage(commandSocketFD,buffer);
+    numObservables = atoi(buffer);
+  
+	LOG("Cognitive Radio Shell:: Attempting to get %i observables.\n",numObservables);
+    Observable * o = new Observable[numObservables];
+ 
+    for (i = 0; i < numObservables; i++){
+        memset(buffer, 0, 256);
+        ReadMessage(commandSocketFD,buffer);
+        o[i].name = std::string(buffer);
+    
+        memset(buffer, 0, 256);
+        ReadMessage(commandSocketFD,buffer);
+        o[i].value = atof(buffer);
+    }
+
+    /* Send to Cognitive Engine 
+	 * TODO: With multiple CEs we need to make a decision about where
+	 * to send this information
+	 */
+
+	LOG("Cognitive Radio Shell:: Passing on observables to Cognitive Engine\n");
+    SendMessage(ceSocketFD,"get_solution");
+    sprintf(counter,"%i",numObservables);
+    SendMessage(ceSocketFD,counter);
+    for(i = 0; i < numObservables; i++) {
+        SendMessage(ceSocketFD,o[i].name.c_str());
+        sprintf(var,"%f",o[i].value);
+	    SendMessage(ceSocketFD,var);
+    }
+
+
+	LOG("Cognitive Radio Shell:: Receiving optimized parameters from Cognitive Engine.\n");
+    /* Receive Set of Parameters */
+    memset(buffer, 0, 256);
+    ReadMessage(ceSocketFD,buffer);
+    numParameters = atoi(buffer);
+   
+    Parameter * p = new Parameter[numParameters];
+ 
+    for (i = 0; i < numParameters; i++){
+        memset(buffer, 0, 256);
+        ReadMessage(ceSocketFD,buffer);
+        LOG("socket_comm::Get Parameter - Name: %s\n", buffer);
+        p[i].name = std::string(buffer);
+    
+        memset(buffer, 0, 256);
+        ReadMessage(ceSocketFD,buffer);
+        LOG("socket_comm::Get Parameter - Value: %s\n", buffer);
+        p[i].value = atof(buffer);
+    }
+
+    /* Send to Application 
+	 */
+	LOG("Cognitive Radio Shell:: Sending optimized parameters to Application.\n");
+    memset(counter, 0, 55);
+    sprintf(counter,"%i",numParameters);
+    SendMessage(commandSocketFD,counter);
+    for(i = 0; i < numParameters; i++) {
+        SendMessage(commandSocketFD,p[i].name.c_str());
+        sprintf(var,"%f",p[i].value);
+	    SendMessage(commandSocketFD,var);
+    }
 }
 
@@ -473,5 +546,5 @@
     } else if(strcmp(buffer,"deregister_sml") == 0) {
         DeregisterSML(socketFD);
-    } else if(strcmp(buffer,"optimize") == 0) {
+    } else if(strcmp(buffer,"request_optimization") == 0) {
         /* Receive optimization request and current environment */
         GetOptimalParameters(socketFD);  
@@ -499,5 +572,13 @@
     servSock[command] = CreateTCPServerSocket(commandPort);
 
-    int32_t maxDescriptor = servSock[command];
+    int32_t maxDescriptor; 
+
+	if(servSock[primary] > servSock[policy])
+		maxDescriptor = servSock[primary];
+    else 
+		maxDescriptor = servSock[policy];
+
+	if(servSock[command] > maxDescriptor)
+		maxDescriptor = servSock[command];
 
     if(InitializeTCPServerPort(servSock[primary]) == -1)
@@ -540,5 +621,12 @@
                             if(new_sd < 0) 
                                 break;
-                            
+                           
+                            if(port == servSock[primary])
+                                ceSocketFD = new_sd;
+                            if(port == servSock[command])
+                                commandSocketFD = new_sd;
+                            if(port == servSock[policy])
+                                policySocketFD = new_sd;
+
                             HandleMessage(new_sd);
                             FD_SET(new_sd,&sockSet);
Index: vtcross/trunk/src/libvtcross/libvtcross_demo.cpp
===================================================================
--- vtcross/trunk/src/libvtcross/libvtcross_demo.cpp	(revision 222)
+++ vtcross/trunk/src/libvtcross/libvtcross_demo.cpp	(revision 222)
@@ -0,0 +1,39 @@
+/* Virginia Tech Cognitive Radio Open Source Systems
+ * Virginia Tech, 2009
+ *
+ * TODO LICENSE INFORMATION GOES HERE
+ */
+
+/* TODO DESCRIPTION OF FILE.
+ *
+ * This file is a temporary demo of a policy engine using some of our socket
+ * communication functions. This is *not* an actual implementation of our
+ * defined PolicyEngine class.
+ */
+
+
+#include <cstdlib>
+#include <cstring>
+#include <stdint.h>
+
+#include "vtcross/libvtcross.h"
+#include "vtcross/socketcomm.h"
+
+int32_t 
+main(int32_t argc, char *argv[])
+{
+    Observable * o = new Observable[1];
+    Parameter * p;
+
+    o[0].name = "Test123";
+	o[0].value = 1243.00;
+
+    p = GetOptimalParameters(o,1);
+
+	printf("Application:: Received the following parameters.\n");
+	printf("%s:: %f\n",p[0].name.c_str(),p[0].value);
+
+
+	return 0;
+}
+
Index: vtcross/trunk/src/libvtcross/Makefile.am
===================================================================
--- vtcross/trunk/src/libvtcross/Makefile.am	(revision 161)
+++ vtcross/trunk/src/libvtcross/Makefile.am	(revision 222)
@@ -0,0 +1,11 @@
+INCLUDES = -I$(top_srcdir)/src/include
+
+lib_LTLIBRARIES = libvtcross.la
+bin_PROGRAMS = libvtcross_demo
+
+libvtcross_la_SOURCES = libvtcross.cpp
+libvtcross_la_LDFLAGS = -version-info 1:0:0
+libvtcross_la_LIBADD = ../lib/socketcomm/libsocketcomm.a
+
+libvtcross_demo_SOURCES = libvtcross_demo.cpp
+libvtcross_demo_LDADD = libvtcross.la
Index: vtcross/trunk/src/libvtcross/libvtcross.cpp
===================================================================
--- vtcross/trunk/src/libvtcross/libvtcross.cpp	(revision 161)
+++ vtcross/trunk/src/libvtcross/libvtcross.cpp	(revision 222)
@@ -13,3 +13,59 @@
 #include "vtcross/libvtcross.h"
 #include "vtcross/common.h"
+#include "vtcross/debug.h"
 
+uint32_t
+ConnectToRemoteComponent()
+{
+   	uint32_t socket; 
+    socket = ClientSocket("localhost", "40000");
+    
+    return socket;
+}
+
+/* Given a certain set of observables, ask the radio to find the optimum radio
+ * parameters and return them. 
+ *
+ * TODO I'm a little confused about this function... why would anyone need to
+ * use this?  Shouldn't this be internal to the radio operation? 
+ */
+Parameter* GetOptimalParameters(Observable *radioObservables, uint32_t numObservables) {
+    uint32_t i,socketfd,numParameters;
+    char var[50];
+    char counter[55];
+	char buffer[256];
+
+    socketfd = ConnectToRemoteComponent();
+    SendMessage(socketfd,"request_optimization");
+
+    /* Get number of observables to send.  This information needs to be 
+     * sent to the Cognitive Radio Shell also.   
+     */
+
+    // Send Observables
+    sprintf(counter,"%i",numObservables);
+    SendMessage(socketfd,counter);
+    for(i = 0; i < numObservables; i++) {
+        SendMessage(socketfd,radioObservables[i].name.c_str());
+        sprintf(var,"%f",radioObservables[i].value);
+        SendMessage(socketfd,var);	
+    }
+
+    /* Receive Set of Parameters */
+    memset(buffer, 0, 256);
+    ReadMessage(socketfd, buffer);
+    numParameters = atoi(buffer);
+    Parameter * pList = new Parameter[numParameters];
+    
+    for(size_t i = 0; i < numParameters; i++) {
+        memset(buffer, 0, 256);
+        ReadMessage(socketfd, buffer);
+        pList[i].name = std::string(buffer);
+        
+		memset(buffer, 0, 256);
+        ReadMessage(socketfd, buffer);
+        pList[i].value = atof(buffer);
+    }   
+
+    return pList;
+}
