Index: vtcross/trunk/src/lib/socketcomm/socketcomm.cpp
===================================================================
--- vtcross/trunk/src/lib/socketcomm/socketcomm.cpp	(revision 164)
+++ vtcross/trunk/src/lib/socketcomm/socketcomm.cpp	(revision 166)
@@ -7,4 +7,5 @@
 /* TODO DESCRIPTION OF FILE.
  */
+
 
 #include <cstdlib>
Index: vtcross/trunk/src/shell/cr_shell.cpp
===================================================================
--- vtcross/trunk/src/shell/cr_shell.cpp	(revision 161)
+++ vtcross/trunk/src/shell/cr_shell.cpp	(revision 166)
@@ -1,59 +1,68 @@
+/* Virginia Tech Cognitive Radio Open Source Systems
+ * Virginia Tech, 2009
+ *
+ * TODO LICENSE INFORMATION GOES HERE
+ */
+
+/* TODO DESCRIPTION OF FILE.
+ */
+
+
+#include <arpa/inet.h>
 #include <iostream>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-//#include "socket/ServerSocket.h"
-//#include "socket/SocketException.h"
-
-#include "vtcross/containers.h"
-#include "vtcross/common.h"
+
 #include "tinyxml/tinyxml.h"
 #include "tinyxml/tinystr.h"
 
+#include "vtcross/common.h"
+#include "vtcross/components.h"
+#include "vtcross/containers.h"
+#include "vtcross/debug.h"
+#include "vtcross/error.h"
+#include "vtcross/socketcomm.h"
+
+
 using namespace std;
 
+
 #define CE_SERVER_PORT 30001
-#define POLICY_SERVER_PORT 30003
-
-void DieWithError(char *errorMessage)
-{
-        perror(errorMessage);
-            exit(1);
-}
-
-void print_current_config(Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
-	int i = 0;
-	int j = 0;
-
-	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;
-	}
-
-	for(i = 0; i < ce_info->numParameters; i++) {
-		cout << "Parameter:  " << pList[i]->name << endl;
-	printf("Cognitive Radio:: Radio Operation Profile has been sucessfully sent.\n");
-		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;
+#define PE_SERVER_PORT 30003
+
+
+void 
+print_current_config(Utility* uList[], Parameter* pList[], \
+        Observable* oList[], CE_Info* ce_info)
+{
+	for(size_t i = 0; i < ce_info->numUtilities ; i++) {
+        LOG("Shell:: Utility: %s\n\tUnits: %s\n\tGoal: %s\n\tTarget: %s\n", \
+                uList[i]->name, uList[i]->units, uList[i]->goal, \
+                uList[i]->target);
+	}
+
+	for(size_t i = 0; i < ce_info->numParameters; i++) {
+	    LOG("Shell:: Radio Operation Profile has been sucessfully sent.\n");
+        LOG("Shell:: Parameter: %s\n\tUnits: %s\n\tMin: %s\n\t", \
+                pList[i]->name, pList[i]->units, pList[i]->min);
+        LOG("\tMax: %s\n\tStep: %s\n", pList[i]->max, pList[i]->step);
+
+		for(size_t j = 0; j < pList[i]->numAffects; j++) {
+			LOG("\t\tAffect %s -> %s\n", pList[i]->affection_list[j].u->name, \
+                    pList[i]->affection_list[j].relation);
 		}
 	}
 	
-    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;
+    for(size_t i = 0; i < ce_info->numObservables; i++) {
+		LOG("Observable: %s\n", oList[i]->name);
+		for(size_t j = 0; j < oList[i]->numAffects; j++) {
+			LOG("\t\tAffect %s -> %s ", oList[i]->affection_list[j].u->name, \
+                    oList[i]->affection_list[j].relation);
 		}
 	}
@@ -61,5 +70,8 @@
 
 
-int parse_ce_config( TiXmlDocument * doc , Utility * u[], Parameter * p[], Observable * o[], CE_Info * ce_info) {
+int32_t
+parse_ce_config(TiXmlDocument* doc, Utility* u[], Parameter* p[], \
+        Observable* o[], CE_Info* ce_info)
+{
 
 	TiXmlElement* pElem;	//!current element
@@ -70,9 +82,9 @@
 	TiXmlHandle hRoot(0); //! handle to root element 
 
-	int count = 0;
-	int i = 0;
-	int j = 0;
-	int k = 0;
-	int match_found = 0;
+	int32_t count = 0;
+	int32_t i = 0;
+	int32_t j = 0;
+	int32_t k = 0;
+	int32_t match_found = 0;
 
 	pElem = hDoc.FirstChildElement().Element();
@@ -199,14 +211,8 @@
 
 
-void error(char *msg)
-{
-    perror(msg);
-    exit(1);
-}
-
-
-int ReceiveMessage(int socket,char * buffer) 
-{
-    int i,n;
+int32_t 
+ReceiveMessage(int32_t socket, char* buffer) 
+{
+    int32_t i,n;
    
     n = recv(socket,buffer,256,MSG_PEEK);
@@ -218,5 +224,5 @@
     if (n < 0)
         error("ERROR reading from socket");
-    //    printf("ReadMessage:%s %d\n",buffer,n);
+    //    print32_tf("ReadMessage:%s %d\n",buffer,n);
 
     return n;
@@ -224,6 +230,8 @@
 
 
-int SendMessage(int socketfd, string message) {
-	int n;
+int32_t
+SendMessage(int32_t socketfd, string message) 
+{
+	int32_t n;
 
 	message.append("\0");	
@@ -233,30 +241,23 @@
         error("Error sending to client\n");
     if(n == 0)
-        printf("Client closed the socket.\n");
-
-	//printf("SendMessage:%s %d\n",message.c_str(),n);	
+        print32_tf("Client closed the socket.\n");
+
+	//print32_tf("SendMessage:%s %d\n",message.c_str(),n);	
     return n;
 }
 
-void GetEnvironment() {
-
-}
-
-void Policy_ValidateSettings() {
-
-}
-
-
-void LoadCEConfiguration(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info){
-	int n,i,j;
+
+void 
+LoadCEConfiguration(int32_t socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info){
+	int32_t n,i,j;
 	char counter[55];
 	char var[50];
-	//int total_bytes;   
-
-	printf("Cognitive Radio:: Sending Radio Operating Profile to Cognitive Engine.\n\n");
+	//int32_t total_bytes;   
+
+	print32_tf("Cognitive Radio:: Sending Radio Operating Profile to Cognitive Engine.\n\n");
  
  	// utilities
 	// Send number of utilities
-	sprintf(counter,"%d",ce_info->numUtilities);
+	sprint32_tf(counter,"%d",ce_info->numUtilities);
 	SendMessage(socketfd,counter);
 	// send utility	
@@ -265,22 +266,22 @@
 		SendMessage(socketfd,uList[i]->units);
 		SendMessage(socketfd,uList[i]->goal);
-		sprintf(var,"%f",uList[i]->target);
+		sprint32_tf(var,"%f",uList[i]->target);
 		SendMessage(socketfd,var);
 	}
 
 	// parameters
-    sprintf(counter,"%i",ce_info->numParameters);
+    sprint32_tf(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);
+		sprint32_tf(var,"%f",pList[i]->min);
+		SendMessage(socketfd,var);
+		sprint32_tf(var,"%f",pList[i]->max);
+		SendMessage(socketfd,var);
+		sprint32_tf(var,"%f",pList[i]->step);
 		SendMessage(socketfd,var);
 		
-		sprintf(counter,"%i",pList[i]->numAffects); 
+		sprint32_tf(counter,"%i",pList[i]->numAffects); 
 		SendMessage(socketfd,counter);
 		for(j = 0; j < pList[i]->numAffects; j++) {
@@ -291,10 +292,10 @@
 
     // observables
-	sprintf(counter,"%i",ce_info->numObservables);
+	sprint32_tf(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); 
+		sprint32_tf(counter,"%i",oList[i]->numAffects); 
 		SendMessage(socketfd,counter);
 		for(j = 0; j < oList[i]->numAffects; j++) {
@@ -308,7 +309,7 @@
         string message;
 	n = ReceiveMessage(socketfd, buffer);
-    //printf("%s\n", buffer);
+    //print32_tf("%s\n", buffer);
         //cout << message << endl;
-	//printf("ACK received.\n");
+	//print32_tf("ACK received.\n");
 
 }
@@ -322,8 +323,8 @@
 }
 
-void UpdateCEExperience(int socketfd, int num_rows, int num_cols, 
+void UpdateCEExperience(int32_t socketfd, int32_t num_rows, int32_t num_cols, 
         float * past_exp[]) 
 {
-    int i, j;
+    int32_t i, j;
 	char counter[55];
 	char var[50];
@@ -331,20 +332,20 @@
     for (i = 0; i < num_rows; i++){
         for (j = 0; j< num_cols; j++){
-		sprintf(var,"%f",past_exp[i][j]);
-        //printf("%f, \n", past_exp[i][j]);
-        //printf("%s, \n", var);
+		sprint32_tf(var,"%f",past_exp[i][j]);
+        //print32_tf("%f, \n", past_exp[i][j]);
+        //print32_tf("%s, \n", var);
         }
     }
     
     // send the number of rows to the ce first
-	sprintf(counter,"%d",num_rows);
+	sprint32_tf(counter,"%d",num_rows);
 	SendMessage(socketfd,counter);
     // send the number of columns to the ce
-	sprintf(counter,"%d",num_cols);
+	sprint32_tf(counter,"%d",num_cols);
 	SendMessage(socketfd,counter);
     // update ce with experience
     for (i = 0; i < num_rows; i++){
         for (j = 0; j< num_cols; j++){
-		sprintf(var,"%f",past_exp[i][j]);
+		sprint32_tf(var,"%f",past_exp[i][j]);
 		SendMessage(socketfd,var);
         }
@@ -358,5 +359,5 @@
 
 // Update operating settings
-// This function will interact with the hardware "drivers"
+// This function will int32_teract with the hardware "drivers"
 void UpdateRadioSettings() 
 {
@@ -364,12 +365,12 @@
 
 
-int RequestPolicyValidation(Parameter * pList[], CE_Info *ce_info)
+int32_t RequestPolicyValidation(Parameter * pList[], CE_Info *ce_info)
 {
 	char counter[55];
 	char var[50];
-    int i;
+    int32_t i;
     string control_msg;
     
-    int socketfd = ce_info->policy_socket;
+    int32_t socketfd = ce_info->policy_socket;
 
     // Control message that validation request is coming
@@ -377,19 +378,19 @@
 	SendMessage(socketfd,control_msg);
 
-    printf("Cognitive Radio:: Here. %i\n\n", socketfd);
+    print32_tf("Cognitive Radio:: Here. %i\n\n", socketfd);
 
 	// Send parameter information 
-    sprintf(counter,"%i",ce_info->numParameters);
+    sprint32_tf(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(var,"%f",pList[i]->value);
+		sprint32_tf(var,"%f",pList[i]->min);
+		SendMessage(socketfd,var);
+		sprint32_tf(var,"%f",pList[i]->max);
+		SendMessage(socketfd,var);
+		sprint32_tf(var,"%f",pList[i]->step);
+		SendMessage(socketfd,var);
+		sprint32_tf(var,"%f",pList[i]->value);
 		SendMessage(socketfd,var);
 		
@@ -400,10 +401,10 @@
 
 
-int RequestCEOptimization(int sockfd, Utility *uList[], 
+int32_t RequestCEOptimization(int32_t sockfd, Utility *uList[], 
         Parameter *pList[], Observable *oList[],
         CE_Info *ce_info)
 {
     char buffer[256];
-    int i;
+    int32_t i;
     float var;
 
@@ -428,8 +429,8 @@
     if(ce_info->policy_engine == 1) {
 
-        printf("Cognitive Radio:: Found Policy Engine!\n");
-        printf("Cognitive Radio:: Validating parameters with Policy Engine\n\n");
+        print32_tf("Cognitive Radio:: Found Policy Engine!\n");
+        print32_tf("Cognitive Radio:: Validating parameters with Policy Engine\n\n");
         RequestPolicyValidation(pList,ce_info); 
-        printf("Cognitive Radio:: Done\n\n");
+        print32_tf("Cognitive Radio:: Done\n\n");
 
     }
@@ -439,10 +440,10 @@
 }
 
-void RunSimulator(int socketfd, Utility * uList[], 
+void RunSimulator(int32_t socketfd, Utility * uList[], 
         Parameter * pList[], Observable * oList[], 
         CE_Info * ce_info) {
 	
 	float **past_exp;
-    int num_rows, num_cols;
+    int32_t num_rows, num_cols;
 
 	// Set fake current environment params = current environment
@@ -457,5 +458,5 @@
 }
 
-void InitializePE(int socket, CE_Info * ce_info) 
+void InitializePE(int32_t socket, CE_Info * ce_info) 
 {
     // Policy Engine is connected
@@ -467,5 +468,5 @@
 }
 
-void InitializeCE(int socketfd, Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) 
+void InitializeCE(int32_t socketfd, Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) 
 {
 	LoadCEConfiguration(socketfd, uList, pList, oList, ce_info);
@@ -473,12 +474,12 @@
     // cr experience
     float **past_exp;
-	int num_cols;
+	int32_t num_cols;
     // get number of columns
     num_cols = ce_info->numUtilities + ce_info->numParameters;
     num_cols = num_cols + ce_info->numObservables;
     num_cols = num_cols + 1;    // overall utility
-    int num_rows = 2;
+    int32_t num_rows = 2;
     past_exp = (float **)malloc(sizeof(float)*num_rows);
-    int i;
+    int32_t i;
     for (i=0; i<num_rows; i++){
         past_exp[i] = (float*)malloc(sizeof(float)*num_cols);
@@ -502,5 +503,5 @@
 
 	// update ce with experience
-    printf("Cognitive Radio:: Sending Previous Experience to New Cognitive Engine.\n\n");
+    print32_tf("Cognitive Radio:: Sending Previous Experience to New Cognitive Engine.\n\n");
     UpdateCEExperience(socketfd, num_rows, num_cols, past_exp);	
 
@@ -508,9 +509,9 @@
 }
 
-int AcceptTCPConnection(int servSock)
-{
-    int clntSock;                    /* Socket descriptor for client */
+int32_t AcceptTCPConnection(int32_t servSock)
+{
+    int32_t clntSock;                    /* Socket descriptor for client */
     struct sockaddr_in echoClntAddr;
-    unsigned int clntLen;
+    unsigned int32_t clntLen;
 
     /* Set the size of the in-out parameter */
@@ -525,12 +526,12 @@
     /* clntSock is connected to a client! */
     
-    printf("Handling client %s\n", inet_ntoa(echoClntAddr.sin_addr));
+    print32_tf("Handling client %s\n", inet_ntoa(echoClntAddr.sin_addr));
 
     return clntSock;
 }
 
-int CreateTCPServerSocket(unsigned short port)
-{
-    int sock;                        /* socket to create */
+int32_t CreateTCPServerSocket(unsigned short port)
+{
+    int32_t sock;                        /* socket to create */
     struct sockaddr_in echoServAddr; /* Local address */
 
@@ -541,6 +542,6 @@
     /* Construct local address structure */
     memset(&echoServAddr, 0, sizeof(echoServAddr));   /* Zero out structure */
-    echoServAddr.sin_family = AF_INET;                /* Internet address family */
-    echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
+    echoServAddr.sin_family = AF_INET;                /* int32_ternet address family */
+    echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming int32_terface */
     echoServAddr.sin_port = htons(port);              /* Local port */
 
@@ -551,5 +552,5 @@
     /* Mark the socket so it will listen for incoming connections */
     if (listen(sock, 5) < 0) {
-        printf("listen() failed\n");
+        print32_tf("listen() failed\n");
         return 0;
     }
@@ -558,5 +559,5 @@
 }
 
-void HandleTCPClient(int socketfd, Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) 
+void HandleTCPClient(int32_t socketfd, Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) 
 {
     char buffer[256];        /* Buffer for echo string */
@@ -566,5 +567,5 @@
     ReceiveMessage(socketfd,buffer);
 
-    printf("Cognitive Radio:: Message Received - %s.\n\n", buffer);
+    print32_tf("Cognitive Radio:: Message Received - %s.\n\n", buffer);
 
     if(strcmp(buffer,"c_register") == 0) 
@@ -580,23 +581,23 @@
 }
 
-int StartServers(Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
-    int * servSock; 
-    int running = 1;
+int32_t StartServers(Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
+    int32_t * servSock; 
+    int32_t running = 1;
     struct timeval selTimeout;
-    int timeout = 10;
-    int cognitive_engine = 0; 
-    int policy_engine = 1; 
-    int port, rc, on = 1;
-    int new_sd;
-    int desc_ready = 0;
+    int32_t timeout = 10;
+    int32_t cognitive_engine = 0; 
+    int32_t policy_engine = 1; 
+    int32_t port, rc, on = 1;
+    int32_t new_sd;
+    int32_t desc_ready = 0;
     fd_set sockSet;
     
-    servSock = (int *) malloc(2 * sizeof(int));
+    servSock = (int32_t *) malloc(2 * sizeof(int32_t));
 
     servSock[cognitive_engine] = CreateTCPServerSocket(CE_SERVER_PORT);
-    servSock[policy_engine] = CreateTCPServerSocket(POLICY_SERVER_PORT);
-
-
-    int maxDescriptor = servSock[cognitive_engine];
+    servSock[policy_engine] = CreateTCPServerSocket(PE_SERVER_PORT);
+
+
+    int32_t maxDescriptor = servSock[cognitive_engine];
 
     if(servSock[cognitive_engine] < servSock[policy_engine])
@@ -635,5 +636,5 @@
     }
     
-    printf("Starting server:  Hit return to shutdown\n");
+    print32_tf("Starting server:  Hit return to shutdown\n");
     while (running)
     {
@@ -654,10 +655,10 @@
         rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); 
         if (rc == 0)
-            printf("No echo requests for %i secs...Server still alive\n", timeout);
+            print32_tf("No echo requests for %i secs...Server still alive\n", timeout);
         else 
         {
             if (FD_ISSET(0, &sockSet)) /* Check keyboard */
             {
-                printf("Shutting down server\n");
+                print32_tf("Shutting down server\n");
                 getchar();
                 running = 0;
@@ -669,5 +670,5 @@
                 if (FD_ISSET(port, &sockSet))
                 {
-                    printf("Request on port %d:  ", port);
+                    print32_tf("Request on port %d:  ", port);
 	                desc_ready -= 1;
 
@@ -687,9 +688,9 @@
                             if(new_sd > maxDescriptor) 
                                 maxDescriptor = new_sd;
-                            printf("New incoming connection - %i\n\n",new_sd);
+                            print32_tf("New incoming connection - %i\n\n",new_sd);
                         } while(new_sd != -1);
                     } else {
                         
-                        printf("Request on already open descriptor.\n\n");
+                        print32_tf("Request on already open descriptor.\n\n");
                         HandleTCPClient(port, uList, pList, oList, ce_info);
 
@@ -711,11 +712,11 @@
 }
 
-int main(int argc, char* argv[]) {
-
-
+int32_t 
+main(int32_t argc, char* argv[])
+{
 	// CognitiveEngine CE;
 	// CognitiveEngineShell Shell;
 	string pFilename; 
-    int fd;
+    int32_t fd;
 
 	Utility * uList[10];
@@ -750,5 +751,5 @@
 	cout << "Initialize:: Configuration file parsing completed.\n" << endl;
 
-    //print_current_config(uList, pList, oList, &ce_info);
+    //print32_t_current_config(uList, pList, oList, &ce_info);
 	
    StartServers(uList, pList, oList, ce_info);
