Changeset 441
- Timestamp:
- 08/26/09 18:35:43 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
r439 r441 39 39 #include <netdb.h> 40 40 #include <fcntl.h> 41 #include <sqlite3.h> 41 42 #include <sys/ioctl.h> 42 43 #include <sys/mman.h> … … 47 48 #include "tinyxml/tinyxml.h" 48 49 #include "tinyxml/tinystr.h" 49 50 #include <sqlite3.h>51 50 52 51 #include "vtcross/debug.h" … … 84 83 bool shellFound; 85 84 86 //Callback function used internally by some of the SQLite3 commands 87 int callback(void *notUsed, int argc, char **argv, char **azColName){ 88 int i; 89 for(i=0; i<argc; i++){ 85 /* Callback function used internally by some of the SQLite3 commands */ 86 int32_t 87 callback(void *notUsed, int32_t argc, char **argv, char **azColName) 88 { 89 for(size_t i = 0; i < argc; i++) { 90 90 printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); 91 91 } 92 92 93 printf("\n"); 93 94 return 0; 94 95 } 95 96 96 97 98 97 ServiceManagementLayer::ServiceManagementLayer() 99 98 { 100 99 LOG("Creating Service Management Layer.\n"); 100 101 101 shellSocketFD = -1; 102 102 numberOfCognitiveEngines = 0; … … 105 105 } 106 106 107 //Free and clear the DB's associated with this SML in the destructor 108 //Note that exiting with an error condition will cause SML to not be destructed, 109 // resulting in the DB's staying in memory until the destructor is encountered in future executions 107 /* Free and clear the DB's associated with this SML in the destructor. 108 * 109 * Note that exiting with an error condition will cause SML to not be destructed, 110 * resulting in the DB's staying in memory until the destructor is encountered in 111 * future executions. */ 110 112 ServiceManagementLayer::~ServiceManagementLayer() 111 113 { 112 114 char *errorMsg; 115 int32_t rc; /* sqlite command return code */ 116 113 117 _services_DB->command="drop table "; 114 118 _services_DB->command.append(_services_DB->tablename); 115 int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 116 if( rc!=SQLITE_OK && rc!=101 ) 117 fprintf(stderr, "ServiceManagementLayer::Destructor services 'drop table' error: %s\n", errorMsg); 119 rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 120 if((rc != SQLITE_OK) && (rc != 101)) 121 WARNING("ServiceManagementLayer::Destructor services 'drop table' error: %s\n", errorMsg); 122 118 123 _services_DB->command="vacuum"; 119 124 rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 120 if( rc!=SQLITE_OK && rc!=101 ) 121 fprintf(stderr, "ServiceManagementLayer::Destructor services 'vacuum' error: %s\n", errorMsg); 125 if((rc != SQLITE_OK) && (rc != 101)) 126 WARNING("ServiceManagementLayer::Destructor services 'vacuum' error: %s\n", errorMsg); 127 122 128 free(_services_DB); 123 129 … … 125 131 _data_DB->command.append(_data_DB->tablename); 126 132 rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg); 127 if( rc!=SQLITE_OK && rc!=101 ) 128 fprintf(stderr, "ServiceManagementLayer::Destructor data 'drop table' error: %s\n", errorMsg); 133 if((rc != SQLITE_OK) && (rc != 101)) 134 WARNING("ServiceManagementLayer::Destructor data 'drop table' error: %s\n", errorMsg); 135 129 136 _data_DB->command="vacuum"; 130 137 rc = sqlite3_exec(_data_DB->db, _data_DB->command.c_str(), callback, 0, &errorMsg); 131 if( rc!=SQLITE_OK && rc!=101 ) 132 fprintf(stderr, "ServiceManagementLayer::Destructor data 'vacuum' error: %s\n", errorMsg); 138 if((rc != SQLITE_OK) && (rc != 101)) 139 WARNING("ServiceManagementLayer::Destructor data 'vacuum' error: %s\n", errorMsg); 140 133 141 free(_data_DB); 134 142 }