Changeset 479 for vtcross/trunk/src
- Timestamp:
- 09/18/09 10:25:13 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
r465 r479 108 108 109 109 110 /* Useful for spotchecking what's in the database */111 void112 printDatabase()113 {114 /*115 LOG("\n\n\n");116 data_DB->command = "select ";117 data_DB->command.append(data_DB->tablename);118 data_DB->command.append(".* from ");119 data_DB->command.append(data_DB->tablename);120 data_DB->command.append(";");121 122 char *errorMsg;123 int32_t rc = sqlite3_exec(data_DB->db, data_DB->command.c_str(), callback, 0, &errorMsg);124 if((rc != SQLITE_OK) && (rc != 101))125 WARNING("SQL error: %s\n", errorMsg);126 127 LOG("database %s, table %s:\n", data_DB->filename, data_DB->tablename);128 LOG("\n\n\n");129 */130 }131 132 110 ServiceManagementLayer::ServiceManagementLayer() 133 111 { … … 139 117 cogEngSrv = 1; 140 118 } 119 141 120 142 121 /* Free and clear the DB's associated with this SML in the destructor. … … 177 156 } 178 157 158 179 159 /* Note that sizes of CE_List, miss, and service are hardcoded for now. 180 160 * Also, their sizes are hardcoded into the code in various places; a fix … … 204 184 } 205 185 186 206 187 /* CALLED BY: constructor 207 188 * INPUTS: <none> … … 221 202 sqlite3_open(services_DB->filename.c_str(), &(services_DB->db)); 222 203 223 char *cols[] = {(char *)"ID_Num", (char *)"Service_Name"};224 225 204 services_DB->tablename="Services"; 226 205 227 /* ifprogram execution ends in anything other than a ordered shutdown, DB's will still206 /* If program execution ends in anything other than a ordered shutdown, DB's will still 228 207 * be there for next run. Need to get rid of it so that old data isn't inadvertantly 229 208 * used in the next execution cycle. */ 230 services_DB->command = "DROP TABLE if EXISTS Services;";209 services_DB->command = "DROP TABLE if EXISTS Services;"; 231 210 232 211 rc = sqlite3_prepare_v2(services_DB->db, services_DB->command.c_str(), 128, &ppStmt, &pzTail); … … 243 222 services_DB->command="CREATE TABLE "; 244 223 services_DB->command.append(services_DB->tablename); 245 services_DB->command.append("("); 246 services_DB->command.append(cols[0]); 247 services_DB->command.append(" INT, "); 248 services_DB->command.append(cols[1]); 249 services_DB->command.append(" TEXT);"); 224 services_DB->command.append("(ID_Num INT, Service_Name TEXT);"); 250 225 251 226 /* Execute create table command */ … … 259 234 } 260 235 236 261 237 /* CALLED BY: constructor 262 238 * INPUTS: <none> … … 277 253 sqlite3_open(data_DB->filename.c_str(), &(data_DB->db)); 278 254 279 char *cols[] = {(char *)"Tag", (char *)"Data"};280 281 255 data_DB->tablename = "Data"; 282 data_DB->command = "DROP TABLE if EXISTS Data;";256 data_DB->command = "DROP TABLE if EXISTS Data;"; 283 257 284 258 rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), 128, &ppStmt, &pzTail); … … 292 266 data_DB->num_columns = 2; 293 267 294 /* Generate command */ 268 /* First column is the name of the data (corresponding to the name of the output/input pair) 269 * It is the primary key so any subsequent data with the same name will replace the row. */ 295 270 data_DB->command = "CREATE TABLE "; 296 271 data_DB->command.append(data_DB->tablename); 297 data_DB->command.append("("); 298 data_DB->command.append(cols[0]); 299 300 /* First column is the name of the data (corresponding to the name of the output/input pair) 301 * It is the primary key so any subsequent data with the same name will replace the row. */ 302 data_DB->command.append(" TEXT PRIMARY KEY ON CONFLICT REPLACE, "); 303 data_DB->command.append(cols[1]); 304 data_DB->command.append(" TEXT);"); 272 data_DB->command.append("(Tag TEXT PRIMARY KEY ON CONFLICT REPLACE, Data TEXT);"); 305 273 306 274 rc = sqlite3_prepare_v2(data_DB->db, data_DB->command.c_str(), 128, &ppStmt, &pzTail); … … 313 281 } 314 282 283 315 284 /* CALLED BY: MessageHandler 316 285 * INPUTS: <none> … … 325 294 LOG("SML responded to GetRemoteComponentType query.\n"); 326 295 } 296 327 297 328 298 /* CALLED BY: constructor … … 342 312 RegisterComponent(); 343 313 } 314 344 315 345 316 /* CALLED BY: StartSMLServer … … 363 334 364 335 ReadMessage(_FD, buffer); 365 366 //--------Policy Engine Stuff - no policy engine support in this version-------// 367 368 //printf("********* %s **********\n", buffer); 369 // TODO 370 // ifwe send integer op codes rather than strings, this process will be 371 // MUCH faster since instead of donig string compares we can simply 372 // switch on the integer value... 373 /*if(strcmp(buffer, "register_service") == 0) { 374 if(strcmp(buffer, "policy_geo") == 0) { 375 } 376 else if(strcmp(buffer, "policy_time") == 0) { 377 } 378 else if(strcmp(buffer, "policy_spectrum") == 0) { 379 } 380 else if(strcmp(buffer, "policy_spacial") == 0) { 381 } 382 } 383 else if(strcmp(buffer, "deregister_service") == 0) { 384 if(strcmp(buffer, "policy_geo") == 0) { 385 } 386 else if(strcmp(buffer, "policy_time") == 0) { 387 } 388 else if(strcmp(buffer, "policy_spectrum") == 0) { 389 } 390 else if(strcmp(buffer, "policy_spacial") == 0) { 391 } 392 }*/ 393 394 //Go down the list to call the appropriate function 336 337 /* Go down the list to call the appropriate function */ 395 338 if(strcmp(buffer, "query_component_type") == 0) { 396 339 SendComponentType(); … … 428 371 } 429 372 430 //TODO Finish 373 431 374 /* CALLED BY: MessageHandler 432 375 * INPUTS: <none> … … 441 384 } 442 385 443 //TODO Finish 386 444 387 /* CALLED BY: MessageHandler 445 388 * INPUTS: <none> … … 455 398 } 456 399 400 457 401 /* CALLED BY: ConnectToShell 458 402 * INPUTS: <none> … … 467 411 LOG("ServiceManagementLayer:: Registration message sent.\n"); 468 412 } 413 469 414 470 415 /* CALLED BY: Shutdown … … 571 516 } 572 517 518 573 519 /* CALLED BY: MessageHandler 574 520 * INPUTS: |ID| The ID number of the component where service is located … … 584 530 ReadMessage(CE_List[ID].FD, buffer); 585 531 586 char *cols[] = {(char *) "ID_Num", (char *) "Service_Name"};587 588 532 /* Generate command */ 589 533 services_DB->command = "insert into "; 590 534 services_DB->command.append(services_DB->tablename); 591 services_DB->command.append(" ("); 592 services_DB->command.append(cols[0]); 593 services_DB->command.append(", "); 594 services_DB->command.append(cols[1]); 595 services_DB->command.append(") "); 596 services_DB->command.append(" values("); 535 services_DB->command.append(" (ID_Num, Service_Name) values("); 597 536 598 537 char temp[3]; … … 611 550 WARNING("ServiceManagementLayer::RecieveServices DB Error %s\n", errorMsg); 612 551 } 552 613 553 614 554 /* CALLED BY: MessageHandler … … 682 622 } 683 623 624 684 625 /* CALLED BY: PerformActiveMission 685 626 * INPUTS: |sourceID| ID of the service that is being processed … … 699 640 char buffer[256]; 700 641 std::string data; 701 char *cols[] = {(char *) "Tag", (char *) "Data"};702 642 char *token; 703 643 … … 795 735 int32_t rc; 796 736 char *errorMsg; 797 char *cols[] = {(char *) "Tag", (char *) "Data"};798 737 799 738 LOG("ServiceManagementLayer:: Received PerformActiveMission command.\n"); … … 812 751 data_DB->command="insert into "; 813 752 data_DB->command.append(data_DB->tablename); 814 data_DB->command.append(" ("); 815 data_DB->command.append(cols[0]); 816 data_DB->command.append(", "); 817 data_DB->command.append(cols[1]); 818 data_DB->command.append(") "); 753 data_DB->command.append(" (Tag, Data) "); 819 754 820 755 memset(buffer, 0, 256); … … 1300 1235 } 1301 1236 1237 1302 1238 /* CALLED BY: Reset 1303 1239 * INPUTS: <none> … … 1319 1255 LoadConfiguration(_SML_Config.c_str(), miss); 1320 1256 } 1257 1321 1258 1322 1259 /* CALLED BY: constructor … … 1498 1435 } 1499 1436 1437 1500 1438 /* CALLED BY: MessageHandler 1501 1439 * INPUTS: |ID| The ID number of the engine to be registered … … 1522 1460 CE_Present = true; 1523 1461 } 1462 1524 1463 1525 1464 /* CALLED BY: MessageHandler … … 1558 1497 WARNING("SQL error: %s\n", errorMsg); 1559 1498 } 1499 1560 1500 1561 1501 /* CALLED BY: MessageHandler