Index: vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
===================================================================
--- vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 279)
+++ vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 282)
@@ -162,4 +162,10 @@
 ServiceManagementLayer::CreateServicesDB()
 {
+
+
+  sqlite3_stmt *ppStmt;  /* OUT: Statement handle */
+  const char *pzTail;     /* OUT: Pointer to unused portion of zSql */
+
+
     _services_DB = (services_DB) malloc(sizeof(struct services_s));
     char *errorMsg;
@@ -181,4 +187,12 @@
     // copy tablename
     strcpy(_services_DB->tablename, "Services");
+    sprintf(_services_DB->command, "DROP TABLE IF EXISTS Services;");     
+
+    int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command, 128, &ppStmt, &pzTail);
+    if( rc!=SQLITE_OK && rc!=101 )
+        printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
+    rc = sqlite3_step(ppStmt);
+    if( rc!=SQLITE_OK && rc!=101 )
+        printf("ServiceManagementLayer::CreateServicesDB 'step' error %d\n");
 
     // number of columns in the table
@@ -196,8 +210,6 @@
 
     // execute create table command
-  sqlite3_stmt *ppStmt;  /* OUT: Statement handle */
-  const char *pzTail;     /* OUT: Pointer to unused portion of zSql */
-
-    int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command, 128, &ppStmt, &pzTail);
+
+    rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command, 128, &ppStmt, &pzTail);
     if( rc!=SQLITE_OK && rc!=101 )
         printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
@@ -312,4 +324,5 @@
 	_FD = shellSocketFD;
     ReadMessage(_FD, buffer);
+    //printf("MH_buffer = %s\n", buffer);
     
     //--------Policy Engine Stuff - no policy engine support in this version-------//
@@ -415,4 +428,5 @@
     SendMessage(shellSocketFD, "register_sml");
     LOG("ServiceManagementLayer:: Registration message sent.\n");
+    //printf("SSFD = %d\n", shellSocketFD);
 }
 
@@ -449,8 +463,8 @@
 ServiceManagementLayer::TransferRadioConfiguration(int32_t ID)
 {
-    printf("transRadConfig\n");
+    //printf("transRadConfig\n");
     struct timeval selTimeout;
     fd_set sockSet;
-    int32_t rc = 0;
+    int32_t rc = 1;
     char buffer[256];
     //Send data until the CE sends an ACK message back
@@ -459,4 +473,5 @@
 	//Receive data from Shell
 	ReadMessage(shellSocketFD, buffer);
+	//printf("buffer = %s\n", buffer);
 	//Send data to CE
 	SendMessage(CE_List[ID].FD, buffer);
@@ -471,4 +486,5 @@
     ReadMessage(CE_List[ID].FD, buffer);
     SendMessage(shellSocketFD, buffer);
+    //printf("transfer done!\n");
 }
 
@@ -487,11 +503,13 @@
     struct timeval selTimeout;
     fd_set sockSet;
-    int32_t rc = 0;
+    int32_t rc = 1;
     char buffer[256];
     //Send data until the CE sends an ACK message back
     while(rc!=0){
+	//printf("transfering...\n");
         memset(buffer, 0, 256);
 	//Receive data from Shell
 	ReadMessage(shellSocketFD, buffer);
+	//printf("buffer = %s\n", buffer);
 	//Send data to CE
 	SendMessage(CE_List[ID].FD, buffer);
@@ -504,4 +522,5 @@
     }
     memset(buffer, 0, 256);
+    //printf("done trans exp!\n");
     ReadMessage(CE_List[ID].FD, buffer);
     SendMessage(shellSocketFD, buffer);
@@ -521,5 +540,5 @@
     ReadMessage(CE_List[ID].FD, buffer);
     char* cols[] = {(char *)"ID_Num", (char *)"Service_Name"};
-    
+    printf("RS_buffer = %s\n", buffer);
     // generate command
     strcpy(_services_DB->command, "insert into ");
@@ -543,7 +562,6 @@
         fprintf(stderr, "ServiceManagementLayer::RecieveServices DB Error %s\n", errorMsg);
     char *outBuffer;
-    sprintf(outBuffer, "SML: Registering service '%s' from component number '%d'\n", buffer, ID);
-    LOG(outBuffer);
-
+    /*sprintf(outBuffer, "SML: Registering service '%s' from component number '%d'", buffer, ID);
+    LOG(outBuffer);*/
 }
 
@@ -1146,17 +1164,23 @@
 ServiceManagementLayer::RegisterCognitiveEngine(int32_t ID)
 {
+    //LOG("SML::regcogeng");
     SendMessage(shellSocketFD, "register_engine_cognitive");
+
+   // printf("SSFD = %d\n", shellSocketFD);
     LOG("ServiceManagementLayer:: CE registration message forwarded to shell.\n");
     char buffer[256];
     memset(buffer, 0, 256);
     ReadMessage(shellSocketFD, buffer);
+    //printf("ServiceManagementLayer::buffer = %s\n", buffer);
     SendMessage(CE_List[ID].FD, buffer);
 
     TransferRadioConfiguration(ID);
     memset(buffer, 0, 256);
+    //printf("start trans exp\n");
     TransferExperience(ID);
     memset(buffer, 0, 256);
     numberOfCognitiveEngines++;
     CE_Present = true;
+    //printf("done registering CE!\n");
 }
 
@@ -1245,5 +1269,5 @@
 ServiceManagementLayer::StartSMLServer()
 {
-    printf("Ready for CE Signal! (registration done)\n");
+    //printf("Ready for CE Signal! (registration done)\n");
     struct timeval selTimeout;
     int32_t running = 1;
@@ -1261,5 +1285,5 @@
 
     int i = 10000000;  //TODO change to "running" if endpoint can be reached
-    while (i>0) {
+    while (running) {
         i--;
         /* Zero socket descriptor vector and set for server sockets */
