Changeset 277
- Timestamp:
- 06/16/09 11:03:58 (15 years ago)
- Location:
- vtcross/branches
- Files:
-
- 92 added
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/wrodgers/src/cognitive_engines/CognitiveEngine.cpp
r275 r277 363 363 } 364 364 365 RegisterServices();366 365 367 366 void … … 404 403 405 404 //Combined with deregister component since those two things must happen togeather 406 /*void405 void 407 406 CognitiveEngine::DeregisterServices() 408 407 { … … 421 420 SendMessage(commandSocketFD, "jam_bluetooth"); 422 421 423 } */422 } 424 423 425 424 void -
vtcross/branches/wrodgers/src/include/vtcross/components.h
r275 r277 97 97 */ 98 98 virtual void RegisterServices() = 0; 99 //virtual void DeregisterServices() = 0;99 virtual void DeregisterServices() = 0; 100 100 }; 101 101 … … 268 268 269 269 void RegisterServices(); 270 //void DeregisterServices();270 void DeregisterServices(); 271 271 272 272 private: -
vtcross/branches/wrodgers/src/service_management_layer/Makefile.am
r200 r277 6 6 7 7 sml_demo_SOURCES = ServiceManagementLayer.cpp sml_demo.cpp 8 sml_demo_LDADD = ../lib/socketcomm/libsocketcomm.a8 sml_demo_LDADD = -ldl -lpthread -lsqlite3 ../lib/tinyxml/libtinyxml.a ../lib/socketcomm/libsocketcomm.a 9 9 -
vtcross/branches/wrodgers/src/service_management_layer/ServiceManagementLayer.cpp
r275 r277 14 14 * and run. See the documentation for the "PerformActiveMission" below for important 15 15 * info. 16 * 17 * NOTE THAT the RegisterServices method works differently than it is described in the documentation 18 * this will be fixed in a future release 19 */ 20 21 //TODO Verify while 16 */ 17 22 18 //TODO Add nested conditional support 23 19 //TODO Verify update functionality 24 20 //TODO Better shutdown 21 //TODO Verify Deregister services 22 //TODO printf's 25 23 26 24 #include <stdlib.h> … … 30 28 #include <stdint.h> 31 29 32 #include "../include/vtcross/common.h" 33 34 #include "../include/vtcross/components.h" 35 #include "../include/vtcross/containers.h" 36 #include "../include/vtcross/debug.h" 37 #include "../include/vtcross/error.h" 38 #include "../include/vtcross/socketcomm.h" 39 40 /*#include "../../trunk/src/include/vtcross/common.h" 41 42 #include "../../trunk/src/include/vtcross/components.h" 43 #include "../../trunk/src/include/vtcross/containers.h" 44 #include "../../trunk/src/include/vtcross/debug.h" 45 #include "../../trunk/src/include/vtcross/error.h" 46 #include "../../trunk/src/include/vtcross/socketcomm.h"*/ 47 48 49 #include <cstdlib> 30 #include "vtcross/common.h" 31 32 #include "components.h" 33 #include "vtcross/containers.h" 34 #include "vtcross/debug.h" 35 #include "vtcross/error.h" 36 #include "vtcross/socketcomm.h" 50 37 #include <cstring> 51 38 #include <stdint.h> … … 63 50 #include <sys/wait.h> 64 51 65 //#include "../../trunk/src/include/tinyxml/tinyxml.h" 66 //#include "../../trunk/src/include/tinyxml/tinystr.h" 67 68 #include "../include/tinyxml/tinyxml.h" 69 #include "../include/tinyxml/tinystr.h" 52 #include "tinyxml/tinyxml.h" 53 #include "tinyxml/tinystr.h" 70 54 71 55 #include "sqlite3.h" 72 //#include "sqlite3ext.h"73 56 74 57 typedef struct services_s *services_DB; … … 128 111 int rc = sqlite3_exec(_services_DB->db, _services_DB->command, callback, 0, &errorMsg); 129 112 if( rc!=SQLITE_OK && rc!=101 ) 130 fprintf(stderr, " 1SQLerror: %s\n", errorMsg);113 fprintf(stderr, "ServiceManagementLayer::Destructor services 'drop table' error: %s\n", errorMsg); 131 114 strcpy(_services_DB->command, "vacuum"); 132 115 rc = sqlite3_exec(_services_DB->db, _services_DB->command, callback, 0, &errorMsg); 133 116 if( rc!=SQLITE_OK && rc!=101 ) 134 fprintf(stderr, " 1SQLerror: %s\n", errorMsg);117 fprintf(stderr, "ServiceManagementLayer::Destructor services 'vacuum' error: %s\n", errorMsg); 135 118 free(_services_DB); 136 119 … … 139 122 rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg); 140 123 if( rc!=SQLITE_OK && rc!=101 ) 141 fprintf(stderr, " 2SQL error (1): %s\n", errorMsg);124 fprintf(stderr, "ServiceManagementLayer::Destructor data 'drop table' error: %s\n", errorMsg); 142 125 strcpy(_data_DB->command, "vacuum"); 143 126 rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg); 144 127 if( rc!=SQLITE_OK && rc!=101 ) 145 fprintf(stderr, " 2SQL error (2): %s\n", errorMsg);128 fprintf(stderr, "ServiceManagementLayer::Destructor data 'vacuum' error: %s\n", errorMsg); 146 129 free(_data_DB); 147 130 } … … 206 189 strcat(_services_DB->command, _services_DB->tablename); 207 190 strcat(_services_DB->command, "("); 208 //strcat(_services_DB->command, "SRVID INTEGER PRIMARY KEY, ");209 191 strcat(_services_DB->command, cols[0]); 210 192 strcat(_services_DB->command, " INT, "); … … 219 201 int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command, 128, &ppStmt, &pzTail); 220 202 if( rc!=SQLITE_OK && rc!=101 ) 221 printf("S QL error(1):%d\n", rc);203 printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); 222 204 rc = sqlite3_step(ppStmt); 223 205 if( rc!=SQLITE_OK && rc!=101 ) 224 printf("S QL error(2): %d\n", rc);206 printf("ServiceManagementLayer::CreateServicesDB 'step' error %d\n"); 225 207 } 226 208 … … 275 257 int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, 128, &ppStmt, &pzTail); 276 258 if( rc!=SQLITE_OK && rc!=101 ) 277 printf("S QL error(1):%d\n", rc);259 printf("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); 278 260 rc = sqlite3_step(ppStmt); 279 261 if( rc!=SQLITE_OK && rc!=101 ) 280 printf("S QL error(2): %d\n", rc);262 printf("ServiceManagementLayer::CreateDataDB 'step' error %d\n"); 281 263 } 282 264 … … 323 305 char buffer[256]; 324 306 memset(buffer, 0, 256); 325 int32_t _FD; 326 //printf("ID= %d\n", ID); 307 int32_t _FD; 327 308 328 309 if(ID != -1) … … 331 312 _FD = shellSocketFD; 332 313 ReadMessage(_FD, buffer); 333 /*//printf("FD=%d, shellFD=%d", _FD, shellSocketFD); 334 ssize_t msgLength = recv(_FD, buffer, 256, MSG_PEEK); 335 if(msgLength == 0){ 336 //printf("Error reading from socket.\n"); 337 //sleep(5); 338 return; 339 } 340 341 342 size_t i; 343 for(i = 0; i < 256; i++) { 344 if(strcmp(&buffer[i], "\0") == 0) 345 break; 346 } 347 // Read the message into msgBuffer 348 recv(_FD, buffer, i + 1, 0);*/ 349 314 350 315 //--------Policy Engine Stuff - no policy engine support in this version-------// 351 316 … … 405 370 } 406 371 else if(strcmp(buffer, "deregister_engine_cognitive") == 0) { 372 DeregisterCognitiveEngine(ID); 373 } 374 else if(strcmp(buffer, "deregister_service") == 0) { 407 375 DeregisterServices(ID); 408 DeregisterCognitiveEngine(ID);409 376 } 410 377 } … … 434 401 { 435 402 DeregisterComponent(); 436 LoadConfiguration(_SML_Config, miss);403 ReloadConfiguration(); 437 404 } 438 405 … … 478 445 */ 479 446 480 // TODO backwards check instead of forwords check to avoid waiting every data loop?447 //Modified to check the incoming message buffer rather than the outgoing message buffer to avoid a portion of the delay 481 448 void 482 449 ServiceManagementLayer::TransferRadioConfiguration(int32_t ID) … … 487 454 char buffer[256]; 488 455 //Send data until the CE sends an ACK message back 489 while(rc ==0){456 while(rc!=0){ 490 457 memset(buffer, 0, 256); 491 458 //Receive data from Shell … … 494 461 SendMessage(CE_List[ID].FD, buffer); 495 462 FD_ZERO(&sockSet); 496 FD_SET( CE_List[ID].FD, &sockSet);463 FD_SET(shellSocketFD, &sockSet); 497 464 selTimeout.tv_sec = 0; 498 465 selTimeout.tv_usec = 50000; 499 //Check if there is a message on the CE socketready to be processed500 rc=select( CE_List[ID].FD + 1, &sockSet, NULL, NULL, &selTimeout);466 //Check if there is a message on the shell ready to be processed 467 rc=select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); 501 468 } 502 469 memset(buffer, 0, 256); … … 512 479 * DESCRIPTION: Simmilar to TransferRadioConfig, just with Experience data 513 480 */ 481 482 //Modified to check the incoming message buffer rather than the outgoing message buffer to avoid a portion of the delay 514 483 void 515 484 ServiceManagementLayer::TransferExperience(int32_t ID) … … 520 489 char buffer[256]; 521 490 //Send data until the CE sends an ACK message back 522 while(rc ==0){491 while(rc!=0){ 523 492 memset(buffer, 0, 256); 524 493 //Receive data from Shell … … 527 496 SendMessage(CE_List[ID].FD, buffer); 528 497 FD_ZERO(&sockSet); 529 FD_SET( CE_List[ID].FD, &sockSet);498 FD_SET(shellSocketFD, &sockSet); 530 499 selTimeout.tv_sec = 0; 531 500 selTimeout.tv_usec = 50000; 532 //Check if there is a message on the CE socketready to be processed533 rc = select(CE_List[ID].FD + 1, &sockSet, NULL, NULL, &selTimeout);501 //Check if there is a message on the shell ready to be processed 502 rc=select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); 534 503 } 535 504 memset(buffer, 0, 256); … … 553 522 554 523 // generate command 555 //printf("%s\n", _services_DB->command);556 524 strcpy(_services_DB->command, "insert into "); 557 525 strcat(_services_DB->command, _services_DB->tablename); … … 572 540 int rc = sqlite3_exec(_services_DB->db, _services_DB->command, callback, 0, &errorMsg); 573 541 if( rc!=SQLITE_OK && rc!=101 ) 574 fprintf(stderr, "SQL error: %s\n", errorMsg); 575 printf("SML: Registering service '%s' from component number '%d'\n", buffer, ID); 542 fprintf(stderr, "ServiceManagementLayer::RecieveServices DB Error %s\n", errorMsg); 543 char *outBuffer; 544 sprintf(outBuffer, "SML: Registering service '%s' from component number '%d'\n", buffer, ID); 545 LOG(outBuffer); 576 546 577 547 } … … 633 603 634 604 635 printf("\nhere ---%d, %d---\n", miss[activeMission].services[0].componentID, miss[activeMission].services[1].componentID);605 //printf("\nhere ---%d, %d---\n", miss[activeMission].services[0].componentID, miss[activeMission].services[1].componentID); 636 606 } 637 607 … … 649 619 ServiceManagementLayer::TransactData(int32_t sourceID) 650 620 { 651 printf(" transactData\n");621 printf("TransactData Occuring\n"); 652 622 char buffer[256]; 653 623 std::string data; … … 661 631 //Find and load the input data 662 632 while(i < 3 && !miss[activeMission].services[sourceID].input[i].empty()){ 663 printf("pulling input data out of DB for ID#=%d\n", sourceID);633 //printf("pulling input data out of DB for ID#=%d\n", sourceID); 664 634 strcpy(_data_DB->command, "select "); 665 635 strcat(_data_DB->command, _data_DB->tablename); … … 690 660 token = strtok(NULL, "@"); 691 661 } 692 printf("done pulling input data out of DB for ID#=%d\n", sourceID);662 //printf("done pulling input data out of DB for ID#=%d\n", sourceID); 693 663 i++; 694 664 } … … 702 672 //Use select command to force wait for processing to finish 703 673 select(miss[activeMission].services[sourceID].socketFD + 1, &sockSet, NULL, NULL, &selTimeout); 704 data.clear();705 674 while(j < 3 && !miss[activeMission].services[sourceID].output[j].empty()){ 706 675 int rc; 676 data.clear(); 707 677 while(true){ 708 678 //Read the data incrementally and deliminate it with the "@" symbol … … 712 682 break; 713 683 data.append(buffer); 714 data.append("@"); 684 data.append("@");; 715 685 } 716 686 printf("SML: putting output data into DB for ID#=%d\n", sourceID); … … 732 702 if( rc!=SQLITE_OK && rc!=101 ) 733 703 fprintf(stderr, "SQL error: %s\n", errorMsg); 734 printf("SML: done putting ouptut data into DB for ID#='%d' \n", sourceID);704 printf("SML: done putting ouptut data into DB for ID#='%d', data=%s\n", sourceID, data.c_str()); 735 705 j++; 736 706 } 737 707 printf("done transact data!\n"); 708 709 710 printf("\n\n\n"); 711 // generate commandi 712 strcpy(_data_DB->command, "select "); 713 strcat(_data_DB->command, _data_DB->tablename); 714 strcat(_data_DB->command, ".* from "); 715 strcat(_data_DB->command, _data_DB->tablename); 716 strcat(_data_DB->command, ";"); 717 718 // execute print (select all) command 719 char *errorMsg; 720 int rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg); 721 if( rc!=SQLITE_OK && rc!=101 ) 722 fprintf(stderr, "SQL error: %s\n", errorMsg); 723 printf("database %s, table %s:\n", _data_DB->filename, _data_DB->tablename); 724 printf("\n\n\n"); 738 725 } 739 726 … … 768 755 ServiceManagementLayer::PerformActiveMission() 769 756 { 770 //TODO verify while771 757 int i = 0; 772 758 std::string data; … … 834 820 check = "false@"; 835 821 } 836 strcpy(_data_DB->command, "select "); 837 strcat(_data_DB->command, _services_DB->tablename); 838 strcat(_data_DB->command, ".* from "); 839 strcat(_data_DB->command, _services_DB->tablename); 822 printf("input=%s\n", input.c_str()); 823 824 strcpy(_data_DB->command, "SELECT "); 825 strcat(_data_DB->command, _data_DB->tablename); 826 strcat(_data_DB->command, ".* from "); 827 strcat(_data_DB->command, _data_DB->tablename); 840 828 strcat(_data_DB->command, " where Tag=="); 841 829 sprintf(_data_DB->command, "%s'%s';", _data_DB->command, input.c_str()); … … 857 845 if(data.compare(check)==0){ 858 846 printf("if taken\n"); 859 for(int k = i + 1; k < i + miss[activeMission].services[i].num_conds; k++)847 for(int k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++) 860 848 TransactData(k); 861 849 } … … 865 853 } 866 854 } 867 //TODO test while868 855 else if(miss[activeMission].services[i].name.compare("while")==0) 869 856 { 870 857 printf("while detected\n"); 871 input.clear();872 check.clear();873 858 while(true){ 859 data.clear(); 860 input.clear(); 861 check.clear(); 874 862 if(!miss[activeMission].services[i].input[0].empty()){ 875 863 input=miss[activeMission].services[i].input[0]; … … 881 869 } 882 870 strcpy(_data_DB->command, "select "); 883 strcat(_data_DB->command, _ services_DB->tablename);871 strcat(_data_DB->command, _data_DB->tablename); 884 872 strcat(_data_DB->command, ".* from "); 885 strcat(_data_DB->command, _ services_DB->tablename);873 strcat(_data_DB->command, _data_DB->tablename); 886 874 strcat(_data_DB->command, " where Tag=="); 887 875 sprintf(_data_DB->command, "%s'%s';", _data_DB->command, input.c_str()); … … 902 890 if(data.compare(check)==0){ 903 891 printf("while taken\n"); 904 for(int k = i + 1; k < i + miss[activeMission].services[i].num_conds; k++)892 for(int k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++) 905 893 TransactData(k); 906 894 } 907 895 else{ 908 896 i+=miss[activeMission].services[i].num_conds; 909 printf(" ifnot taken %d\n", miss[activeMission].services[i].num_conds);897 printf("while not taken %d\n", miss[activeMission].services[i].num_conds); 910 898 break; 911 899 } … … 994 982 } 995 983 996 /* CALLED BY: constructor , Reset984 /* CALLED BY: constructor 997 985 * INPUTS: |SML_Config| Address (either relitive or full) of the XML file containing mission data 998 986 * |mList| Mission array to be modified … … 1094 1082 1095 1083 mList[mission_num].services[conditional_1].num_conds = cond_array[1]; 1096 printf("hello\n");1097 1084 cond_array[1] = 0; 1098 1085 cond_array[0]++; … … 1104 1091 if(pChild1->Attribute("input_f")) 1105 1092 mList[mission_num].services[conditional_0].input[1] = pChild1->Attribute("input_f"); 1106 printf("---input_t=%s\n", mList[mission_num].services[conditional_0].input[0].c_str());1093 //printf("---input_t=%s\n", mList[mission_num].services[conditional_0].input[0].c_str()); 1107 1094 } 1108 1095 else{ … … 1123 1110 1124 1111 mList[mission_num].services[conditional_0].num_conds = cond_array[0]; 1125 //printf("hello\n");1126 1112 cond_array[0] = 0; 1127 1113 service_num++; 1128 1114 } 1129 for(int i = 0; i < service_num; i++)1130 1115 //for(int i = 0; i < service_num; i++) 1116 //printf("%d, input1=%s, output1=%s\n", i, mList[mission_num].services[i].input[0].c_str(), mList[mission_num].services[i].output[0].c_str()); 1131 1117 1132 1118 mList[mission_num].numServices = service_num; … … 1145 1131 if(pChild0->Attribute("output3")) 1146 1132 mList[mission_num].output[2] = pChild0->Attribute("output3"); 1147 printf("mis, input1=%s, output1=%s\n", mList[mission_num].input[0].c_str(), mList[mission_num].output[0].c_str());1133 //printf("mis, input1=%s, output1=%s\n", mList[mission_num].input[0].c_str(), mList[mission_num].output[0].c_str()); 1148 1134 mission_num++; 1149 1135 } … … 1180 1166 * OUTPUTS: <none> 1181 1167 * 1182 * DESCRIPTION: Deleates the services from the DB coresponding to the component ID 1183 */ 1184 //----NOTE---- 1185 //The behavior of this method is different than described in the documentation. 1186 //This function deregisteres all of the services when a component deregistes, 1187 //whereas the one in the documentation describes a function where an individual 1188 //service is deregistered. This may be changed in the future. 1168 * DESCRIPTION: Deletes individual services from the DB 1169 * NOTE THAT this function only needs to be called if service deregistration is going 1170 * to be done at a different time than component deregistration; it is handled 1171 * more efficiently and directly during that deregistration process. 1172 */ 1189 1173 void 1190 1174 ServiceManagementLayer::DeregisterServices(int32_t ID) 1191 1175 { 1176 char buffer[256]; 1177 memset(buffer, 0, 256); 1178 ReadMessage(CE_List[ID].FD, buffer); 1179 strcpy(_services_DB->command, "DELETE FROM "); 1180 strcat(_services_DB->command, _services_DB->tablename); 1181 strcat(_services_DB->command, " WHERE ID_Num IN (SELECT"); 1182 sprintf(_services_DB->command, " %s %d",_services_DB->command, ID); 1183 strcat(_services_DB->command, " FROM "); 1184 strcat(_services_DB->command, _services_DB->tablename); 1185 strcat(_services_DB->command, " WHERE Service_Name"); 1186 strcat(_services_DB->command, "=="); 1187 sprintf(_services_DB->command, "%s'%s');", _services_DB->command, buffer); 1188 char *errorMsg; 1189 int rc = sqlite3_exec(_services_DB->db, _services_DB->command, callback, 0, &errorMsg); 1190 if( rc!=SQLITE_OK && rc!=101 ) 1191 fprintf(stderr, "SQL error: %s\n", errorMsg); 1192 } 1193 1194 /* CALLED BY: MessageHandler 1195 * INPUTS: |ID| The ID number of the engine to have it's services deregistered 1196 * OUTPUTS: <none> 1197 * 1198 * DESCRIPTION: Deletes the contact info for the cognitive engine, forwards a deregistration message to the shell 1199 * Also, deletes the services from the DB 1200 */ 1201 void 1202 ServiceManagementLayer::DeregisterCognitiveEngine(int32_t ID) 1203 { 1204 LOG("ServiceManagementLayer:: CE deregistration message forwarded to shell.\n"); 1205 1206 numberOfCognitiveEngines--; 1207 if(numberOfCognitiveEngines == 0) 1208 CE_Present = false; 1209 1210 SendMessage(shellSocketFD, "deregister_engine_cognitive"); 1211 char buffer[256]; 1212 memset(buffer, 0, 256); 1213 ReadMessage(shellSocketFD, buffer); 1214 SendMessage(CE_List[ID].FD, buffer); 1215 if(strcmp("deregister_ack", buffer) != 0) { 1216 ERROR(1, "SML:: Failed to close CE socket\n"); 1217 } 1218 1219 //Deregister the services 1192 1220 strcpy(_services_DB->command, "DELETE FROM "); 1193 1221 strcat(_services_DB->command, _services_DB->tablename); … … 1200 1228 if( rc!=SQLITE_OK && rc!=101 ) 1201 1229 fprintf(stderr, "SQL error: %s\n", errorMsg); 1202 } 1203 1204 /* CALLED BY: MessageHandler 1205 * INPUTS: |ID| The ID number of the engine to have it's services deregistered 1206 * OUTPUTS: <none> 1207 * 1208 * DESCRIPTION: Deletes the contact info for the cognitive engine, forwards a deregistration message to the shell 1209 */ 1210 void 1211 ServiceManagementLayer::DeregisterCognitiveEngine(int32_t ID) 1212 { 1213 LOG("ServiceManagementLayer:: CE deregistration message forwarded to shell.\n"); 1214 1215 numberOfCognitiveEngines--; 1216 if(numberOfCognitiveEngines == 0) 1217 CE_Present = false; 1218 1219 SendMessage(shellSocketFD, "deregister_engine_cognitive"); 1220 char buffer[256]; 1221 memset(buffer, 0, 256); 1222 ReadMessage(shellSocketFD, buffer); 1223 SendMessage(CE_List[ID].FD, buffer); 1224 if(strcmp("deregister_ack", buffer) != 0) { 1225 ERROR(1, "SML:: Failed to close CE socket\n"); 1226 } 1230 1231 1227 1232 CE_List[ID].FD = -1; 1228 1233 CE_List[ID].ID_num = -1; 1229 1234 1230 LOG("Cognitive Radio Shell:: Socket closed.\n");1235 LOG("Cognitive Radio Shell:: CE Socket closed for engine #%d.\n", ID); 1231 1236 } 1232 1237 … … 1255 1260 ERROR(1,"Error initializing primary port\n"); 1256 1261 1257 int i = 10000000; 1262 int i = 10000000; //TODO change to "running" if endpoint can be reached 1258 1263 while (i>0) { 1259 1264 i--; -
vtcross/branches/wrodgers/src/service_management_layer/sml_demo.cpp
r200 r277 1 /* Virginia Tech Cognitive Radio Open Source Systems2 * Virginia Tech, 20093 *4 * TODO LICENSE INFORMATION GOES HERE5 */6 7 /* TODO DESCRIPTION OF FILE.8 *9 * This file is a temporary demo of a service management layer using some of10 * our socket communication functions. This is *not* an actual implementation11 * of our defined ServiceManagement class.12 */13 14 15 1 #include <cstdlib> 16 2 #include <cstring> 17 3 #include <stdint.h> 4 #include <string> 5 #include <stdlib.h> 6 7 #include <arpa/inet.h> 8 #include <iostream> 9 #include <netinet/in.h> 10 #include <netdb.h> 11 #include <fcntl.h> 12 #include <sys/ioctl.h> 13 #include <sys/mman.h> 14 #include <sys/socket.h> 15 #include <sys/types.h> 16 #include <sys/wait.h> 17 18 #include "sqlite3.h" 19 20 21 22 //#include "tinyxml.h" 23 //#include "tinyxml.cpp" 24 //#include "tinystr.h" 18 25 19 26 #include "vtcross/common.h" … … 25 32 26 33 27 int32_t 28 main(int32_t argc, char *argv[]) 29 { 30 if(argc < 3) 31 ERROR(1, "Usage: %s hostname port\n", argv[0]); 34 35 /*#include <stdio.h> 36 #include <sys/types.h> 37 #include <sys/socket.h> 38 #include <netinet/in.h> 39 #include <netdb.h> 40 //#include <iostream> 41 #include <stdlib.h> 42 #include <string.h> 43 #include <sqlite3.h> 44 #include <sqlite3ext.h>*/ 45 46 //#include "common.h" 47 48 //using namespace std; 49 50 51 int main(int argc, char *argv[]) 52 { 53 int shell = CreateTCPServerSocket(1979); 54 //sleep(2); 55 int temp = AcceptTCPConnection(shell); 56 // SendMessage(temp, "list_services"); 57 sleep(1); 58 int FD = ClientSocket("127.0.0.1", "2036"); 59 SendMessage(FD, "register_engine_cognitive"); 60 SendMessage(FD, "register_service"); 61 SendMessage(FD, "test_srv"); 62 SendMessage(FD, "list_services"); 63 int FD2 = ClientSocket("127.0.0.1", "2036"); 64 SendMessage(FD2, "register_engine_cognitive"); 65 SendMessage(FD2, "register_service"); 66 SendMessage(FD2, "test_srv1"); 67 SendMessage(FD2, "register_service"); 68 SendMessage(FD2, "test_srv2"); 69 SendMessage(FD2, "list_services"); 70 sleep(1); 71 printf("preread1\n"); 72 73 char buffer[256]; 74 memset(buffer, 0, 256); 75 76 SendMessage(temp, "set_active_mission"); 77 SendMessage(temp, "0"); 78 SendMessage(temp, "request_optimization"); 79 SendMessage(temp, "params"); 80 ReadMessage(FD, buffer); 81 printf("preread2\n"); 82 printf("-----buffer1= %s-------\n", buffer); 83 ReadMessage(FD, buffer); 84 printf("-----buffer2= %s-------\n", buffer); 85 memset(buffer, 0, 256); 86 ReadMessage(FD, buffer); 87 printf("-----buffer3= %s-------\n", buffer); 88 SendMessage(FD, "ACK"); 89 SendMessage(FD, "temp"); 90 SendMessage(FD, "raw_data"); 91 ReadMessage(FD2, buffer); 92 printf("-----buffer4= %s-------\n", buffer); 93 ReadMessage(FD2, buffer); 94 printf("-----buffer5= %s-------\n", buffer); 95 ReadMessage(FD2, buffer); 96 printf("-----buffer6= %s-------\n", buffer); 97 SendMessage(FD2, "ACK"); 98 ReadMessage(FD2, buffer); 99 printf("-----buffer7= %s-------\n", buffer); 100 ReadMessage(FD2, buffer); 101 printf("-----buffer8= %s-------\n", buffer); 102 ReadMessage(FD2, buffer); 103 printf("-----buffer9= %s-------\n", buffer); 104 SendMessage(FD2, "ACK"); 105 SendMessage(FD2, "trans"); 106 ReadMessage(temp, buffer); 107 printf("-----buffer10= %s-------\n", buffer); 108 SendMessage(temp, "ACK"); 109 /*ReadMessage(FD, buffer); 110 printf("-----buffer1= %s-------\n", buffer); 111 ReadMessage(FD, buffer); 112 printf("-----buffer2= %s-------\n", buffer); 113 memset(buffer, 0, 256); 114 ReadMessage(FD, buffer); 115 printf("-----buffer3= %s-------\n", buffer); 116 SendMessage(FD, "ACK"); 117 SendMessage(FD, "true"); 118 SendMessage(FD, "data"); 119 ReadMessage(FD2, buffer); 120 printf("-----buffer4= %s-------\n", buffer); 121 ReadMessage(FD2, buffer); 122 printf("-----buffer5= %s-------\n", buffer); 123 memset(buffer, 0, 256); 124 ReadMessage(FD2, buffer); 125 printf("-----buffer6= %s-------\n", buffer); 126 SendMessage(FD2, "ACK"); 127 SendMessage(FD2, "trans"); 128 ReadMessage(temp, buffer); 129 printf("-----buffer7= %s-------\n", buffer); 130 SendMessage(temp, "ACK");*/ 131 32 132 33 ServiceManagementLayer sml;34 133 35 LOG("Waiting for signal...\n"); 36 while(1) { 37 // policyEngine.WaitForSignal(); 38 } 39 40 return 0; 134 //SendMessage(temp, "list_services"); 135 while(true){ 136 char buffer[256]; 137 memset(buffer, 0, 256); 138 ReadMessage(temp, buffer); 139 printf("------%s------\n", buffer);} 140 /*memset(buffer, 0, 256); 141 ReadMessage(temp, buffer); 142 printf("------%s------\n", buffer);*/ 41 143 } 42