Index: /vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
===================================================================
--- /vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 442)
+++ /vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 443)
@@ -157,6 +157,7 @@
 
     miss = new Mission[10];
-    for(size_t i = 0; i < 10; i++)
+    for(size_t i = 0; i < 10; i++) {
         miss[i].services = new Service[30];
+    }
 
     Current_ID = 0;
@@ -177,36 +178,32 @@
 ServiceManagementLayer::CreateServicesDB()
 {
-    sqlite3_stmt *ppStmt;  /* OUT: Statement handle */
+    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));
+    int32_t rc;             /* sqlite command return code */
+
     _services_DB = new services_s;
-    // copy filename
     _services_DB->filename="Services_Table";
-    // execute create database command
-    // database handle
-    //_services_DB->db = NULL;
     sqlite3_open(_services_DB->filename.c_str(), &(_services_DB->db));
+
     char* cols[] = {(char *)"ID_Num", (char *)"Service_Name"};
 
-
-    // copy tablename
     _services_DB->tablename="Services";
 
-    //If program execution ends in anything other than a ordered shutdown, DB's will still be there for next run
-    //Need to get rid of it so that old data isn't inadvertantly used in the next execution cycle
+    /* If program execution ends in anything other than a ordered shutdown, DB's will still 
+     * be there for next run. Need to get rid of it so that old data isn't inadvertantly 
+     * used in the next execution cycle. */
     _services_DB->command = "DROP TABLE IF EXISTS Services;";     
 
-    int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
+    rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
+
     rc = sqlite3_step(ppStmt);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateServicesDB 'step' error\n");
-
-    // number of columns in the table
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n");
+
     _services_DB->num_columns = 2;
 
-    // generate command
+    /* Generate command */
     _services_DB->command="CREATE TABLE ";
     _services_DB->command.append(_services_DB->tablename);
@@ -217,12 +214,12 @@
     _services_DB->command.append(" TEXT);");
 
-    // execute create table command
-
+    /* Execute create table command */
     rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
+
     rc = sqlite3_step(ppStmt);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateServicesDB 'step' error\n");
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateServicesDB 'step' error\n");
 }
 
@@ -236,55 +233,47 @@
 ServiceManagementLayer::CreateDataDB()
 {
-    sqlite3_stmt *ppStmt;  /* OUT: Statement handle */
+    sqlite3_stmt *ppStmt;   /* OUT: Statement handle */
     const char *pzTail;     /* OUT: Pointer to unused portion of zSql */
-
-    _data_DB = new data_s;//(data_DB) malloc(sizeof(struct data_s));
-
-    // create database
-
-    // copy filename
+    int32_t rc;             /* sqlite command return code */
+
+    _data_DB = new data_s;
+
     _data_DB->filename="Data_Table";
-    // execute create database command
-    // database handle
-    //_services_DB->db = NULL;
     sqlite3_open(_data_DB->filename.c_str(), &(_data_DB->db));
+
     char* cols[] = {(char *)"Tag", (char *)"Data"};
 
-    // create table
-
-    // copy tablename
     _data_DB->tablename="Data";
     _data_DB->command="DROP TABLE IF EXISTS Data;";     
 
-    int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc);
+    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc);
+
     rc = sqlite3_step(ppStmt);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateServicesDB 'step' error\n");
-
-
-    // number of columns in the table
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n");
+
     _data_DB->num_columns = 2;
 
-    // generate command
+    /* Generate command */
     _data_DB->command="CREATE TABLE ";
     _data_DB->command.append(_data_DB->tablename);
     _data_DB->command.append("(");
     _data_DB->command.append(cols[0]);
-    //First column is the name of the data (coresponding to the name of the output/input pair)
-    //It is the primary key so any subsequent data with the same name will replace the row
+
+    /* First column is the name of the data (corresponding to the name of the output/input pair)
+     * It is the primary key so any subsequent data with the same name will replace the row. */
     _data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, ");
     _data_DB->command.append(cols[1]);
     _data_DB->command.append(" TEXT);");
 
-    // execute create table command
-
     rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc);
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc);
+
     rc = sqlite3_step(ppStmt);
-    if( rc!=SQLITE_OK && rc!=101 )
-        printf("ServiceManagementLayer::CreateDataDB 'step' error\n");
+    if((rc != SQLITE_OK) && (rc != 101))
+        WARNING("ServiceManagementLayer::CreateDataDB 'step' error\n");
 }
 
