42 | | |
43 | | LoadConfiguration(); |
44 | | } |
45 | | |
46 | | |
| 141 | CE_List = (CE_Reg *) malloc(10*sizeof(struct CE_Reg)); |
| 142 | CE_List = new CE_Reg[10]; |
| 143 | |
| 144 | miss = new Mission[10]; |
| 145 | for(int i = 0; i < 10; i++) |
| 146 | miss[i].services = new Service[20]; |
| 147 | |
| 148 | Current_ID = 0; |
| 149 | |
| 150 | LoadConfiguration(SML_Config, miss); |
| 151 | CreateServicesDB(); |
| 152 | CreateDataDB(); |
| 153 | } |
| 154 | |
| 155 | /* CALLED BY: constructor |
| 156 | * INPUTS: <none> |
| 157 | * OUTPUTS: <none> |
| 158 | * |
| 159 | * DESCRIPTION: Create and initialize a DB to hold the services registered by components |
| 160 | */ |
| 161 | void |
| 162 | ServiceManagementLayer::CreateServicesDB() |
| 163 | { |
| 164 | _services_DB = (services_DB) malloc(sizeof(struct services_s)); |
| 165 | char *errorMsg; |
| 166 | |
| 167 | // create database |
| 168 | |
| 169 | // copy filename |
| 170 | unsigned int i=0; |
| 171 | strcpy(_services_DB->filename, "Services_Table"); |
| 172 | |
| 173 | // execute create database command |
| 174 | // database handle |
| 175 | //_services_DB->db = NULL; |
| 176 | sqlite3_open(_services_DB->filename, &(_services_DB->db)); |
| 177 | char* cols[] = {(char *)"ID_Num", (char *)"Service_Name"}; |
| 178 | |
| 179 | // create table |
| 180 | |
| 181 | // copy tablename |
| 182 | strcpy(_services_DB->tablename, "Services"); |
| 183 | |
| 184 | // number of columns in the table |
| 185 | _services_DB->num_columns = 2; |
| 186 | |
| 187 | // generate command |
| 188 | strcpy(_services_DB->command, "CREATE TABLE "); |
| 189 | strcat(_services_DB->command, _services_DB->tablename); |
| 190 | strcat(_services_DB->command, "("); |
| 191 | strcat(_services_DB->command, cols[0]); |
| 192 | strcat(_services_DB->command, " INT, "); |
| 193 | strcat(_services_DB->command, cols[1]); |
| 194 | strcat(_services_DB->command, " TEXT"); |
| 195 | strcat(_services_DB->command, ");"); |
| 196 | |
| 197 | // execute create table command |
| 198 | sqlite3_stmt *ppStmt; /* OUT: Statement handle */ |
| 199 | const char *pzTail; /* OUT: Pointer to unused portion of zSql */ |
| 200 | |
| 201 | int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command, 128, &ppStmt, &pzTail); |
| 202 | if( rc!=SQLITE_OK && rc!=101 ) |
| 203 | printf("ServiceManagementLayer::CreateServicesDB 'prepare_stmt' error %d\n", rc); |
| 204 | rc = sqlite3_step(ppStmt); |
| 205 | if( rc!=SQLITE_OK && rc!=101 ) |
| 206 | printf("ServiceManagementLayer::CreateServicesDB 'step' error %d\n"); |
| 207 | } |
| 208 | |
| 209 | /* CALLED BY: constructor |
| 210 | * INPUTS: <none> |
| 211 | * OUTPUTS: <none> |
| 212 | * |
| 213 | * DESCRIPTION: Create and initialize a DB to hold the data sent by components |
| 214 | */ |
| 215 | void |
| 216 | ServiceManagementLayer::CreateDataDB() |
| 217 | { |
| 218 | _data_DB = (data_DB) malloc(sizeof(struct data_s)); |
| 219 | char *errorMsg; |
| 220 | |
| 221 | // create database |
| 222 | |
| 223 | // copy filename |
| 224 | unsigned int i=0; |
| 225 | strcpy(_data_DB->filename, "Data_Table"); |
| 226 | |
| 227 | // execute create database command |
| 228 | // database handle |
| 229 | //_services_DB->db = NULL; |
| 230 | sqlite3_open(_data_DB->filename, &(_data_DB->db)); |
| 231 | char* cols[] = {(char *)"Tag", (char *)"Data"}; |
| 232 | |
| 233 | // create table |
| 234 | |
| 235 | // copy tablename |
| 236 | strcpy(_data_DB->tablename, "Data"); |
| 237 | |
| 238 | // number of columns in the table |
| 239 | _data_DB->num_columns = 2; |
| 240 | |
| 241 | // generate command |
| 242 | strcpy(_data_DB->command, "CREATE TABLE "); |
| 243 | strcat(_data_DB->command, _data_DB->tablename); |
| 244 | strcat(_data_DB->command, "("); |
| 245 | strcat(_data_DB->command, cols[0]); |
| 246 | //First column is the name of the data (coresponding to the name of the output/input pair) |
| 247 | //It is the primary key so any subsequent data with the same name will replace the row |
| 248 | strcat(_data_DB->command, " TEXT PRIMARY KEY ON CONFLICT REPLACE, "); |
| 249 | strcat(_data_DB->command, cols[1]); |
| 250 | strcat(_data_DB->command, " TEXT"); |
| 251 | strcat(_data_DB->command, ");"); |
| 252 | |
| 253 | // execute create table command |
| 254 | sqlite3_stmt *ppStmt; /* OUT: Statement handle */ |
| 255 | const char *pzTail; /* OUT: Pointer to unused portion of zSql */ |
| 256 | |
| 257 | int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, 128, &ppStmt, &pzTail); |
| 258 | if( rc!=SQLITE_OK && rc!=101 ) |
| 259 | printf("ServiceManagementLayer::CreateDataDB 'prepare_stmt' error %d\n", rc); |
| 260 | rc = sqlite3_step(ppStmt); |
| 261 | if( rc!=SQLITE_OK && rc!=101 ) |
| 262 | printf("ServiceManagementLayer::CreateDataDB 'step' error %d\n"); |
| 263 | } |
| 264 | |
| 265 | /* CALLED BY: MessageHandler |
| 266 | * INPUTS: <none> |
| 267 | * OUTPUTS: <none> |
| 268 | * |
| 269 | * DESCRIPTION: Sends a message identifying this component as an SML to the Shell |
| 270 | */ |
169 | | } |
170 | | |
171 | | |
| 561 | char buffer[256]; |
| 562 | memset(buffer, 0, 256); |
| 563 | ReadMessage(shellSocketFD, buffer); |
| 564 | int32_t missID = atoi(buffer); |
| 565 | for(activeMission = 0; activeMission < 10; activeMission++) |
| 566 | { |
| 567 | //Find the active mission by comparing mission ID's |
| 568 | if(miss[activeMission].missionID == missID) |
| 569 | break; |
| 570 | } |
| 571 | //For each service in the mission |
| 572 | for(int i = 0; i < miss[activeMission].numServices; i++) |
| 573 | { |
| 574 | //Check whether the current service is an actual service or a conditional |
| 575 | if(miss[activeMission].services[i].name.compare("if") && miss[activeMission].services[i].name.compare("while")){ |
| 576 | //If it is a service, search the database of registered services to find the ID of the component that registered it |
| 577 | strcpy(_services_DB->command, "select "); |
| 578 | strcat(_services_DB->command, _services_DB->tablename); |
| 579 | strcat(_services_DB->command, ".* from "); |
| 580 | strcat(_services_DB->command, _services_DB->tablename); |
| 581 | strcat(_services_DB->command, " where Service_Name=="); |
| 582 | sprintf(_services_DB->command, "%s'%s';", _services_DB->command, miss[activeMission].services[i].name.c_str()); |
| 583 | |
| 584 | sqlite3_stmt * pStatement; |
| 585 | int rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command, -1, &pStatement, NULL); |
| 586 | if (rc == SQLITE_OK){ |
| 587 | if (sqlite3_step(pStatement) == SQLITE_ROW) |
| 588 | miss[activeMission].services[i].componentID = sqlite3_column_int(pStatement, 0); |
| 589 | else { |
| 590 | printf("services_DB:: Mission requires service not provided by any connected component.\n"); |
| 591 | rc=31337; |
| 592 | } |
| 593 | } else { |
| 594 | printf("services_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_services_DB->command); |
| 595 | } |
| 596 | |
| 597 | sqlite3_finalize(pStatement); |
| 598 | miss[activeMission].services[i].socketFD = CE_List[miss[activeMission].services[i].componentID].FD; |
| 599 | //Set the FD and ID of the service to refer to the component where the service exists |
| 600 | } |
| 601 | //Nothing to be done for conditionals at this stage |
| 602 | } |
| 603 | |
| 604 | |
| 605 | //printf("\nhere ---%d, %d---\n", miss[activeMission].services[0].componentID, miss[activeMission].services[1].componentID); |
| 606 | } |
| 607 | |
| 608 | /* CALLED BY: PerformActiveMission |
| 609 | * INPUTS: |sourceID| ID of the service that is being processed |
| 610 | * OUTPUTS: <none> |
| 611 | * |
| 612 | * DESCRIPTION: This is a helper method for the "PerformActiveMission" function |
| 613 | * NOTE: This function has changed durrastically from the previous implementation |
| 614 | * Takes an ID of a service |
| 615 | * For that service, finds inputs in DB and forwords those on to the engine after sending comm-starting messages |
| 616 | * Afterwords, listenes for the outputs so that it can store those in the database for future services or the overall output |
| 617 | */ |
| 618 | void |
| 619 | ServiceManagementLayer::TransactData(int32_t sourceID) |
| 620 | { |
| 621 | printf("TransactData Occuring\n"); |
| 622 | char buffer[256]; |
| 623 | std::string data; |
| 624 | char* cols[] = {(char *)"Tag", (char *)"Data"}; |
| 625 | int i = 0; |
| 626 | fd_set sockSet; |
| 627 | struct timeval selTimeout; |
| 628 | //Transmission starting messages |
| 629 | SendMessage(miss[activeMission].services[sourceID].socketFD, "request_optimization_service"); |
| 630 | SendMessage(miss[activeMission].services[sourceID].socketFD, miss[activeMission].services[sourceID].name.c_str()); |
| 631 | //Find and load the input data |
| 632 | while(i < 3 && !miss[activeMission].services[sourceID].input[i].empty()){ |
| 633 | //printf("pulling input data out of DB for ID#=%d\n", sourceID); |
| 634 | strcpy(_data_DB->command, "select "); |
| 635 | strcat(_data_DB->command, _data_DB->tablename); |
| 636 | strcat(_data_DB->command, ".* from "); |
| 637 | strcat(_data_DB->command, _data_DB->tablename); |
| 638 | strcat(_data_DB->command, " where Tag=="); |
| 639 | sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].services[sourceID].input[i].c_str()); |
| 640 | sqlite3_stmt * pStatement; |
| 641 | int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); |
| 642 | if (rc == SQLITE_OK){ |
| 643 | if (sqlite3_step(pStatement) == SQLITE_ROW) |
| 644 | data.append((const char*) sqlite3_column_text(pStatement, 1)); |
| 645 | else { |
| 646 | printf("data_DB:: Data not yet in DB.\n"); |
| 647 | rc=31337; |
| 648 | } |
| 649 | } |
| 650 | else { |
| 651 | printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); |
| 652 | } |
| 653 | |
| 654 | sqlite3_finalize(pStatement); |
| 655 | char *data_ch = (char *) data.c_str(); |
| 656 | //Tokenize the data and pass it along |
| 657 | char *token = strtok(data_ch, "@"); |
| 658 | while(token){ |
| 659 | SendMessage(miss[activeMission].services[sourceID].socketFD, token); |
| 660 | token = strtok(NULL, "@"); |
| 661 | } |
| 662 | //printf("done pulling input data out of DB for ID#=%d\n", sourceID); |
| 663 | i++; |
| 664 | } |
| 665 | |
| 666 | int32_t j = 0; |
| 667 | FD_ZERO(&sockSet); |
| 668 | FD_SET(miss[activeMission].services[sourceID].socketFD, &sockSet); |
| 669 | //TODO neccessary? |
| 670 | selTimeout.tv_sec = 5; |
| 671 | selTimeout.tv_usec = 0; |
| 672 | //Use select command to force wait for processing to finish |
| 673 | select(miss[activeMission].services[sourceID].socketFD + 1, &sockSet, NULL, NULL, &selTimeout); |
| 674 | while(j < 3 && !miss[activeMission].services[sourceID].output[j].empty()){ |
| 675 | int rc; |
| 676 | data.clear(); |
| 677 | while(true){ |
| 678 | //Read the data incrementally and deliminate it with the "@" symbol |
| 679 | memset(buffer, 0, 256); |
| 680 | ReadMessage(miss[activeMission].services[sourceID].socketFD, buffer); |
| 681 | if(strcmp(buffer, "output_finished")==0) |
| 682 | break; |
| 683 | data.append(buffer); |
| 684 | data.append("@");; |
| 685 | } |
| 686 | printf("SML: putting output data into DB for ID#=%d\n", sourceID); |
| 687 | |
| 688 | strcpy(_data_DB->command, "insert or replace into "); |
| 689 | strcat(_data_DB->command, _data_DB->tablename); |
| 690 | strcat(_data_DB->command, " ("); |
| 691 | strcat(_data_DB->command, cols[0]); |
| 692 | strcat(_data_DB->command, ", "); |
| 693 | strcat(_data_DB->command, cols[1]); |
| 694 | strcat(_data_DB->command, ") "); |
| 695 | strcat(_data_DB->command, " values('"); |
| 696 | strcat(_data_DB->command, miss[activeMission].services[sourceID].output[j].c_str()); |
| 697 | strcat(_data_DB->command, "', '"); |
| 698 | strcat(_data_DB->command, data.c_str()); |
| 699 | strcat(_data_DB->command, "');"); |
| 700 | char *errorMsg; |
| 701 | rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg); |
| 702 | if( rc!=SQLITE_OK && rc!=101 ) |
| 703 | fprintf(stderr, "SQL error: %s\n", errorMsg); |
| 704 | printf("SML: done putting ouptut data into DB for ID#='%d', data=%s\n", sourceID, data.c_str()); |
| 705 | j++; |
| 706 | } |
| 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"); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | |
| 729 | /* CALLED BY: MessageHandler |
| 730 | * INPUTS: <none> |
| 731 | * OUTPUTS: <none> |
| 732 | * |
| 733 | * DESCRIPTION: This function works by first sending the inputs from the shell to the appropriate components |
| 734 | * The first service should begin immeadiately, as should any others who have all of their input paramaters |
| 735 | * When they complete, the output path is found and the data is transfered as it becomes available |
| 736 | * Presumably at this point the second function has all of it's paramaters, so it begins to compute, and the cycle repeats |
| 737 | * If the generated output is an overall output, it is sent on to the shell |
| 738 | * "if" and "while" statements are handled by setting up a faux service that has a true input, a false input, and a boolean flag |
| 739 | * If the true input is non-NULL and the flag is true, the statements execute |
| 740 | * Likewise, if the false input is non-NULL and the flag is false, the statements execute |
| 741 | * These flags are set during execution any time one of these faux services' inputs appear in an output statement |
| 742 | * |
| 743 | * |
| 744 | * Rules for active missions (currently) |
| 745 | * -Three inputs/outputs per service and per mission |
| 746 | * -Inputs simply define a path, so multiple variables can be transmitted over the same input |
| 747 | * -Each component that sends data must include the "output_finished" statement after each output is finished sending it's data |
| 748 | * -All ordering constraints have been relaxed in this version; all data is stored locally and only sent when requested |
| 749 | * -If support fully implemented |
| 750 | * -Conditions must be boolean flags |
| 751 | * -Flags are set by putting either the character string "true" or "false" on the buffer |
| 752 | * -IMPORTANT: DB uses '@' to seperate individual statements; using '@' in the data stream will result in incorrect behavior |
| 753 | */ |
| 754 | void |
| 755 | ServiceManagementLayer::PerformActiveMission() |
| 756 | { |
| 757 | int i = 0; |
| 758 | std::string data; |
| 759 | std::string input; |
| 760 | std::string check; |
| 761 | char buffer[256]; |
| 762 | fd_set sockSet; |
| 763 | char* cols[] = {(char *)"Tag", (char *)"Data"}; |
| 764 | struct timeval selTimeout; |
| 765 | //Get the inputs |
| 766 | while(i < 3 && !miss[activeMission].input[i].empty()){ |
| 767 | //New data being added to DB |
| 768 | printf("inserting data from shell\n"); |
| 769 | int rc; |
| 770 | while(true){ |
| 771 | memset(buffer, 0, 256); |
| 772 | ReadMessage(shellSocketFD, buffer); |
| 773 | if(strcmp(buffer, "input_finished")==0) |
| 774 | break; |
| 775 | data.append(buffer); |
| 776 | data.append("@"); |
| 777 | /*FD_ZERO(&sockSet); |
| 778 | FD_SET(miss[activeMission].services[sourceID].socketFD, &sockSet); |
| 779 | selTimeout.tv_sec = 0; |
| 780 | selTimeout.tv_usec = 50000; |
| 781 | //Check if there is a message on the CE socket ready to be processed |
| 782 | rc=select(miss[activeMission].services[sourceID].socketFD + 1, &sockSet, NULL, NULL, &selTimeout);*/ |
| 783 | }//while(rc!=0);; |
| 784 | |
| 785 | strcpy(_data_DB->command, "insert into "); |
| 786 | strcat(_data_DB->command, _data_DB->tablename); |
| 787 | strcat(_data_DB->command, " ("); |
| 788 | strcat(_data_DB->command, cols[0]); |
| 789 | strcat(_data_DB->command, ", "); |
| 790 | strcat(_data_DB->command, cols[1]); |
| 791 | strcat(_data_DB->command, ") "); |
| 792 | strcat(_data_DB->command, " values('"); |
| 793 | strcat(_data_DB->command, miss[activeMission].input[i].c_str()); |
| 794 | strcat(_data_DB->command, "', '"); |
| 795 | strcat(_data_DB->command, data.c_str()); |
| 796 | strcat(_data_DB->command, "');"); |
| 797 | char *errorMsg; |
| 798 | rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg); |
| 799 | if( rc!=SQLITE_OK && rc!=101 ) |
| 800 | fprintf(stderr, "SQL error: %s\n", errorMsg); |
| 801 | printf("SML: finished adding data from shell on input %d\n", i); |
| 802 | i++; |
| 803 | |
| 804 | } |
| 805 | i=0; |
| 806 | data.clear(); |
| 807 | while(i < miss[activeMission].numServices) |
| 808 | { |
| 809 | if(miss[activeMission].services[i].name.compare("if")==0) |
| 810 | { |
| 811 | printf("if detected\n"); |
| 812 | input.clear(); |
| 813 | check.clear(); |
| 814 | if(!miss[activeMission].services[i].input[0].empty()){ |
| 815 | input=miss[activeMission].services[i].input[0]; |
| 816 | check = "true@"; |
| 817 | } |
| 818 | else{ |
| 819 | input=miss[activeMission].services[i].input[1]; |
| 820 | check = "false@"; |
| 821 | } |
| 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); |
| 828 | strcat(_data_DB->command, " where Tag=="); |
| 829 | sprintf(_data_DB->command, "%s'%s';", _data_DB->command, input.c_str()); |
| 830 | sqlite3_stmt * pStatement; |
| 831 | int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); |
| 832 | if (rc == SQLITE_OK){ |
| 833 | if (sqlite3_step(pStatement) == SQLITE_ROW) |
| 834 | data = (const char *) sqlite3_column_text(pStatement, 1); |
| 835 | else { |
| 836 | printf("1 data_DB:: Data not yet in DB. %d\n", i); |
| 837 | rc=31337; |
| 838 | } |
| 839 | } else { |
| 840 | printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); |
| 841 | } |
| 842 | |
| 843 | sqlite3_finalize(pStatement); |
| 844 | printf("data=%s, check=%s\n", data.c_str(), check.c_str()); |
| 845 | if(data.compare(check)==0){ |
| 846 | printf("if taken\n"); |
| 847 | for(int k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++) |
| 848 | TransactData(k); |
| 849 | } |
| 850 | else{ |
| 851 | i+=miss[activeMission].services[i].num_conds; |
| 852 | printf("if not taken %d\n", miss[activeMission].services[i].num_conds); |
| 853 | } |
| 854 | } |
| 855 | else if(miss[activeMission].services[i].name.compare("while")==0) |
| 856 | { |
| 857 | printf("while detected\n"); |
| 858 | while(true){ |
| 859 | data.clear(); |
| 860 | input.clear(); |
| 861 | check.clear(); |
| 862 | if(!miss[activeMission].services[i].input[0].empty()){ |
| 863 | input=miss[activeMission].services[i].input[0]; |
| 864 | check = "true@"; |
| 865 | } |
| 866 | else{ |
| 867 | input=miss[activeMission].services[i].input[1]; |
| 868 | check = "false@"; |
| 869 | } |
| 870 | strcpy(_data_DB->command, "select "); |
| 871 | strcat(_data_DB->command, _data_DB->tablename); |
| 872 | strcat(_data_DB->command, ".* from "); |
| 873 | strcat(_data_DB->command, _data_DB->tablename); |
| 874 | strcat(_data_DB->command, " where Tag=="); |
| 875 | sprintf(_data_DB->command, "%s'%s';", _data_DB->command, input.c_str()); |
| 876 | sqlite3_stmt * pStatement; |
| 877 | int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); |
| 878 | if (rc == SQLITE_OK){ |
| 879 | if (sqlite3_step(pStatement) == SQLITE_ROW) |
| 880 | data = (const char *) sqlite3_column_text(pStatement, 1); |
| 881 | else |
| 882 | printf("1 data_DB:: Data not yet in DB. %d\n", i); |
| 883 | } |
| 884 | else { |
| 885 | printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); |
| 886 | } |
| 887 | |
| 888 | sqlite3_finalize(pStatement); |
| 889 | printf("data=%s, check=%s\n", data.c_str(), check.c_str()); |
| 890 | if(data.compare(check)==0){ |
| 891 | printf("while taken\n"); |
| 892 | for(int k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++) |
| 893 | TransactData(k); |
| 894 | } |
| 895 | else{ |
| 896 | i+=miss[activeMission].services[i].num_conds; |
| 897 | printf("while not taken %d\n", miss[activeMission].services[i].num_conds); |
| 898 | break; |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | else{ |
| 903 | TransactData(i);} |
| 904 | i++; |
| 905 | } |
| 906 | i=0; |
| 907 | data.clear(); |
| 908 | //get the ouptuts |
| 909 | while(i < 3 && !miss[activeMission].output[i].empty()){ |
| 910 | printf("sending output data to shell\n"); |
| 911 | strcpy(_data_DB->command, "select "); |
| 912 | strcat(_data_DB->command, _data_DB->tablename); |
| 913 | strcat(_data_DB->command, ".* from "); |
| 914 | strcat(_data_DB->command, _data_DB->tablename); |
| 915 | strcat(_data_DB->command, " where Tag=="); |
| 916 | sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].output[i].c_str()); |
| 917 | sqlite3_stmt * pStatement; |
| 918 | int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); |
| 919 | if (rc == SQLITE_OK){ |
| 920 | if (sqlite3_step(pStatement) == SQLITE_ROW) |
| 921 | data.append((const char*) sqlite3_column_text(pStatement, 1)); |
| 922 | else { |
| 923 | printf("data_DB:: Data not yet in DB.\n"); |
| 924 | rc=31337; |
| 925 | } |
| 926 | } |
| 927 | else { |
| 928 | printf("services_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); |
| 929 | } |
| 930 | sqlite3_finalize(pStatement); |
| 931 | char *data_ch = (char *) data.c_str(); |
| 932 | char *token = strtok(data_ch, "@"); |
| 933 | while(token){ |
| 934 | SendMessage(shellSocketFD, token); |
| 935 | token = strtok(NULL, "@"); |
| 936 | } |
| 937 | i++; |
| 938 | printf("done sending output data to shell\n"); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | |
| 943 | /* CALLED BY: MessageHandler |
| 944 | * INPUTS: <none> |
| 945 | * OUTPUTS: <none> |
| 946 | * |
| 947 | * DESCRIPTION: Print a list of the services currently registered and the ID's of the components that registered them |
| 948 | */ |
186 | | ServiceManagementLayer::LoadConfiguration() |
187 | | { |
188 | | LOG("ServiceManagementLayer:: Loading Configuration.\n"); |
189 | | } |
190 | | |
| 999 | ServiceManagementLayer::LoadConfiguration(const char *SML_Config, Mission* &mList) |
| 1000 | { |
| 1001 | TiXmlElement *pMission; |
| 1002 | TiXmlElement *pService; |
| 1003 | TiXmlElement *pChild0, *pChild1, *pChild2, *pChild3; |
| 1004 | TiXmlHandle hRoot(0); |
| 1005 | //printf("ServiceManagementLayer:: Loading Configuration.\n"); |
| 1006 | TiXmlDocument doc("."); |
| 1007 | doc.LoadFile(SML_Config); |
| 1008 | bool loadOkay = doc.LoadFile(); |
| 1009 | if(!loadOkay) |
| 1010 | printf("Loading SML configuration failed: %s\n", SML_Config); |
| 1011 | |
| 1012 | TiXmlHandle hDoc(&doc); |
| 1013 | |
| 1014 | pMission = hDoc.FirstChildElement().Element(); |
| 1015 | |
| 1016 | if(!pMission) |
| 1017 | printf("No valid root!"); |
| 1018 | |
| 1019 | hRoot = TiXmlHandle(pMission); |
| 1020 | pService = pMission->FirstChildElement(); |
| 1021 | int32_t mission_num = 0; |
| 1022 | //Iterate through the missions |
| 1023 | for(pChild0 = pMission->FirstChildElement(); pChild0 ; \ |
| 1024 | pChild0 = pChild0->NextSiblingElement()) |
| 1025 | { |
| 1026 | int32_t service_num = 0; |
| 1027 | uint16_t cond_array[] = {0, 0}; |
| 1028 | //printf("mission_num = %d\n", mission_num); |
| 1029 | memset(cond_array, 0, 2); |
| 1030 | |
| 1031 | for(pChild1 = pChild0->FirstChildElement(); pChild1; \ |
| 1032 | pChild1 = pChild1->NextSiblingElement()) |
| 1033 | { |
| 1034 | int32_t conditional_0 = service_num; |
| 1035 | for(pChild2 = pChild1->FirstChildElement(); \ |
| 1036 | pChild2; pChild2 = pChild2->NextSiblingElement()) |
| 1037 | { |
| 1038 | service_num++; |
| 1039 | int32_t conditional_1 = service_num; |
| 1040 | for(pChild3 = pChild2->FirstChildElement(); \ |
| 1041 | pChild3; pChild3 = pChild3 ->NextSiblingElement()) |
| 1042 | { |
| 1043 | service_num++; |
| 1044 | mList[mission_num].services[service_num].name = pChild3->Attribute("name"); |
| 1045 | if(pChild3->Attribute("input1")) |
| 1046 | mList[mission_num].services[service_num].input[0] = pChild3->Attribute("input1"); |
| 1047 | if(pChild3->Attribute("input2")) |
| 1048 | mList[mission_num].services[service_num].input[1] = pChild3->Attribute("input2"); |
| 1049 | if(pChild3->Attribute("input3")) |
| 1050 | mList[mission_num].services[service_num].input[2] = pChild3->Attribute("input3"); |
| 1051 | if(pChild3->Attribute("output1")) |
| 1052 | mList[mission_num].services[service_num].output[0] = pChild3->Attribute("output1"); |
| 1053 | if(pChild3->Attribute("output2")) |
| 1054 | mList[mission_num].services[service_num].output[1] = pChild3->Attribute("output2"); |
| 1055 | if(pChild3->Attribute("output3")) |
| 1056 | mList[mission_num].services[service_num].output[2] = pChild3->Attribute("output3"); |
| 1057 | cond_array[1]++; |
| 1058 | } |
| 1059 | |
| 1060 | if(conditional_1 != service_num){ |
| 1061 | mList[mission_num].services[conditional_1].name = pChild2->Value(); |
| 1062 | if(pChild2->Attribute("input_t")) |
| 1063 | mList[mission_num].services[conditional_1].input[0] = pChild2->Attribute("input_t"); |
| 1064 | if(pChild2->Attribute("input_f")) |
| 1065 | mList[mission_num].services[conditional_1].input[1] = pChild2->Attribute("input_f"); |
| 1066 | } |
| 1067 | else{ |
| 1068 | mList[mission_num].services[conditional_1].name = pChild2->Attribute("name"); |
| 1069 | if(pChild2->Attribute("input1")) |
| 1070 | mList[mission_num].services[service_num].input[0] = pChild2->Attribute("input1"); |
| 1071 | if(pChild2->Attribute("input2")) |
| 1072 | mList[mission_num].services[service_num].input[1] = pChild2->Attribute("input2"); |
| 1073 | if(pChild2->Attribute("input3")) |
| 1074 | mList[mission_num].services[service_num].input[2] = pChild2->Attribute("input3"); |
| 1075 | if(pChild2->Attribute("output1")) |
| 1076 | mList[mission_num].services[service_num].output[0] = pChild2->Attribute("output1"); |
| 1077 | if(pChild2->Attribute("output2")) |
| 1078 | mList[mission_num].services[service_num].output[1] = pChild2->Attribute("output2"); |
| 1079 | if(pChild2->Attribute("output3")) |
| 1080 | mList[mission_num].services[service_num].output[2] = pChild2->Attribute("output3"); |
| 1081 | } |
| 1082 | |
| 1083 | mList[mission_num].services[conditional_1].num_conds = cond_array[1]; |
| 1084 | cond_array[1] = 0; |
| 1085 | cond_array[0]++; |
| 1086 | } |
| 1087 | if(conditional_0 != service_num){ |
| 1088 | mList[mission_num].services[conditional_0].name = pChild1->Value(); |
| 1089 | if(pChild1->Attribute("input_t")) |
| 1090 | mList[mission_num].services[conditional_0].input[0] = pChild1->Attribute("input_t"); |
| 1091 | if(pChild1->Attribute("input_f")) |
| 1092 | mList[mission_num].services[conditional_0].input[1] = pChild1->Attribute("input_f"); |
| 1093 | //printf("---input_t=%s\n", mList[mission_num].services[conditional_0].input[0].c_str()); |
| 1094 | } |
| 1095 | else{ |
| 1096 | mList[mission_num].services[conditional_0].name = pChild1->Attribute("name"); |
| 1097 | if(pChild1->Attribute("input1")) |
| 1098 | mList[mission_num].services[service_num].input[0] = pChild1->Attribute("input1"); |
| 1099 | if(pChild1->Attribute("input2")) |
| 1100 | mList[mission_num].services[service_num].input[1] = pChild1->Attribute("input2"); |
| 1101 | if(pChild1->Attribute("input3")) |
| 1102 | mList[mission_num].services[service_num].input[2] = pChild1->Attribute("input3"); |
| 1103 | if(pChild1->Attribute("output1")) |
| 1104 | mList[mission_num].services[service_num].output[0] = pChild1->Attribute("output1"); |
| 1105 | if(pChild1->Attribute("output2")) |
| 1106 | mList[mission_num].services[service_num].output[1] = pChild1->Attribute("output2"); |
| 1107 | if(pChild1->Attribute("output3")) |
| 1108 | mList[mission_num].services[service_num].output[2] = pChild1->Attribute("output3"); |
| 1109 | } |
| 1110 | |
| 1111 | mList[mission_num].services[conditional_0].num_conds = cond_array[0]; |
| 1112 | cond_array[0] = 0; |
| 1113 | service_num++; |
| 1114 | } |
| 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()); |
| 1117 | |
| 1118 | mList[mission_num].numServices = service_num; |
| 1119 | mList[mission_num].name = pChild0->Attribute("name"); |
| 1120 | mList[mission_num].missionID = atoi(pChild0->Attribute("id")); |
| 1121 | if(pChild0->Attribute("input1")) |
| 1122 | mList[mission_num].input[0] = pChild0->Attribute("input1"); |
| 1123 | if(pChild0->Attribute("input2")) |
| 1124 | mList[mission_num].input[1] = pChild0->Attribute("input2"); |
| 1125 | if(pChild0->Attribute("input3")) |
| 1126 | mList[mission_num].input[2] = pChild0->Attribute("input3"); |
| 1127 | if(pChild0->Attribute("output1")) |
| 1128 | mList[mission_num].output[0] = pChild0->Attribute("output1"); |
| 1129 | if(pChild0->Attribute("output2")) |
| 1130 | mList[mission_num].output[1] = pChild0->Attribute("output2"); |
| 1131 | if(pChild0->Attribute("output3")) |
| 1132 | mList[mission_num].output[2] = pChild0->Attribute("output3"); |
| 1133 | //printf("mis, input1=%s, output1=%s\n", mList[mission_num].input[0].c_str(), mList[mission_num].output[0].c_str()); |
| 1134 | mission_num++; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | /* CALLED BY: MessageHandler |
| 1139 | * INPUTS: |ID| The ID number of the engine to be registered |
| 1140 | * OUTPUTS: <none> |
| 1141 | * |
| 1142 | * DESCRIPTION: Sends a registration message onto the shell and sends the ACK back to the component |
| 1143 | */ |
| 1144 | void |
| 1145 | ServiceManagementLayer::RegisterCognitiveEngine(int32_t ID) |
| 1146 | { |
| 1147 | SendMessage(shellSocketFD, "register_engine_cognitive"); |
| 1148 | LOG("ServiceManagementLayer:: CE registration message forwarded to shell.\n"); |
| 1149 | char buffer[256]; |
| 1150 | memset(buffer, 0, 256); |
| 1151 | ReadMessage(shellSocketFD, buffer); |
| 1152 | SendMessage(CE_List[ID].FD, buffer); |
| 1153 | |
| 1154 | //TODO UNCOMMENT!!! |
| 1155 | //TODO UNCOMMENT!!! |
| 1156 | /*TransferRadioConfiguration(ID); |
| 1157 | memset(buffer, 0, 256); |
| 1158 | TransferExperience(ID); |
| 1159 | memset(buffer, 0, 256);*/ |
| 1160 | numberOfCognitiveEngines++; |
| 1161 | CE_Present = true; |
| 1162 | } |
| 1163 | |
| 1164 | /* CALLED BY: MessageHandler |
| 1165 | * INPUTS: |ID| The ID number of the engine to have it's services deregistered |
| 1166 | * OUTPUTS: <none> |
| 1167 | * |
| 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 | */ |
| 1173 | void |
| 1174 | ServiceManagementLayer::DeregisterServices(int32_t ID) |
| 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 |
| 1220 | strcpy(_services_DB->command, "DELETE FROM "); |
| 1221 | strcat(_services_DB->command, _services_DB->tablename); |
| 1222 | strcat(_services_DB->command, " WHERE "); |
| 1223 | strcat(_services_DB->command, "ID_Num"); |
| 1224 | strcat(_services_DB->command, "=="); |
| 1225 | sprintf(_services_DB->command, "%s%d;", _services_DB->command, ID); |
| 1226 | char *errorMsg; |
| 1227 | int rc = sqlite3_exec(_services_DB->db, _services_DB->command, callback, 0, &errorMsg); |
| 1228 | if( rc!=SQLITE_OK && rc!=101 ) |
| 1229 | fprintf(stderr, "SQL error: %s\n", errorMsg); |
| 1230 | |
| 1231 | |
| 1232 | CE_List[ID].FD = -1; |
| 1233 | CE_List[ID].ID_num = -1; |
| 1234 | |
| 1235 | LOG("Cognitive Radio Shell:: CE Socket closed for engine #%d.\n", ID); |
| 1236 | } |
| 1237 | |
| 1238 | |
| 1239 | /* CALLED BY: test class |
| 1240 | * INPUTS: <none> |
| 1241 | * OUTPUTS: <none> |
| 1242 | * |
| 1243 | * DESCRIPTION: Sets up a server socket and listens for communication on either that or the shell socket |
| 1244 | */ |
| 1245 | void |
| 1246 | ServiceManagementLayer::StartSMLServer() |
| 1247 | { |
| 1248 | struct timeval selTimeout; |
| 1249 | int32_t running = 1; |
| 1250 | int32_t port, rc, new_sd = 1; |
| 1251 | int32_t desc_ready = 1; |
| 1252 | int32_t timeout = 10; |
| 1253 | //If there is, call the MessageHandler with the Shell_Msg code of -1 |
| 1254 | fd_set sockSet, shellSet; |
| 1255 | |
| 1256 | cogEngSrv = CreateTCPServerSocket(2044); |
| 1257 | int32_t maxDescriptor = cogEngSrv; |
| 1258 | |
| 1259 | if(InitializeTCPServerPort(cogEngSrv) == -1) |
| 1260 | ERROR(1,"Error initializing primary port\n"); |
| 1261 | |
| 1262 | int i = 10000000; //TODO change to "running" if endpoint can be reached |
| 1263 | while (i>0) { |
| 1264 | i--; |
| 1265 | /* Zero socket descriptor vector and set for server sockets */ |
| 1266 | /* This must be reset every time select() is called */ |
| 1267 | FD_ZERO(&sockSet); |
| 1268 | FD_SET(cogEngSrv, &sockSet); |
| 1269 | for(int k = 0; k < Current_ID; k++){ |
| 1270 | if(CE_List[k].ID_num != -1) |
| 1271 | FD_SET(CE_List[k].FD, &sockSet); |
| 1272 | } |
| 1273 | //printf("k=%d, CID=%d\n", k, CE_List[k].FD); |
| 1274 | |
| 1275 | /* Timeout specification */ |
| 1276 | /* This must be reset every time select() is called */ |
| 1277 | selTimeout.tv_sec = 0; /* timeout (secs.) */ |
| 1278 | selTimeout.tv_usec = 0; /* 0 microseconds */ |
| 1279 | //Changed both to zero so that select will check messages from the shell instead of blocking |
| 1280 | //when there is no command from the CE's to be processed |
| 1281 | |
| 1282 | //Check if there is a message on the socket waiting to be read |
| 1283 | rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); |
| 1284 | //printf("rc=%d\n", rc); |
| 1285 | if(rc == 0){ |
| 1286 | //LOG("No echo requests for %i secs...Server still alive\n", timeout); |
| 1287 | |
| 1288 | FD_ZERO(&shellSet); |
| 1289 | FD_SET(shellSocketFD, &shellSet); |
| 1290 | selTimeout.tv_sec = 0; |
| 1291 | selTimeout.tv_usec = 0; |
| 1292 | //Check if there is a message on the shell socket ready to be processed |
| 1293 | int rc2 = select(shellSocketFD + 1, &shellSet, NULL, NULL, &selTimeout); |
| 1294 | //printf("rc2=%d\n", rc2); |
| 1295 | //If there is, call the MessageHandler with the Shell_Msg code of -1 |
| 1296 | if(FD_ISSET(shellSocketFD, &shellSet)){ |
| 1297 | //printf("shell_msg, %d\n", rc2); |
| 1298 | MessageHandler(-1);} |
| 1299 | } |
| 1300 | else { |
| 1301 | desc_ready = rc; |
| 1302 | for(port = 0; port <= maxDescriptor && desc_ready > 0; port++) { |
| 1303 | if(FD_ISSET(port, &sockSet)) { |
| 1304 | desc_ready -= 1; |
| 1305 | |
| 1306 | //Check if request is new or on an existing open descriptor |
| 1307 | if(port == cogEngSrv) { |
| 1308 | //If new, assign it a descriptor and give it an ID |
| 1309 | new_sd = AcceptTCPConnection(port); |
| 1310 | |
| 1311 | if(new_sd < 0) |
| 1312 | break; |
| 1313 | |
| 1314 | CE_List[Current_ID].FD = new_sd; |
| 1315 | CE_List[Current_ID].ID_num = Current_ID; |
| 1316 | MessageHandler(Current_ID); |
| 1317 | Current_ID++; |
| 1318 | |
| 1319 | FD_SET(new_sd,&sockSet); |
| 1320 | if(new_sd > maxDescriptor) |
| 1321 | maxDescriptor = new_sd; |
| 1322 | } |
| 1323 | else { |
| 1324 | //If old, figure out which ID it coresponds to and handle it accordingly |
| 1325 | for(int16_t z = 0; z < Current_ID; z++) |
| 1326 | { |
| 1327 | if(CE_List[z].FD == port){ |
| 1328 | MessageHandler(z);} |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | /* Close sockets */ |
| 1337 | close(cogEngSrv); |
| 1338 | |
| 1339 | //delete &cogEngSrv; |
| 1340 | return; |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | /*TiXmlElement *pMission; |
| 1347 | TiXmlElement *pService; |
| 1348 | TiXmlElement *pChild0, *pChild1, *pChild2, *pChild3; |
| 1349 | TiXmlHandle hRoot(0); |
| 1350 | //printf("ServiceManagementLayer:: Loading Configuration.\n"); |
| 1351 | TiXmlDocument doc("."); |
| 1352 | doc.LoadFile(SML_Config); |
| 1353 | bool loadOkay = doc.LoadFile(); |
| 1354 | if(!loadOkay) |
| 1355 | printf("Loading SML configuration failed: %s\n", SML_Config); |
| 1356 | |
| 1357 | TiXmlHandle hDoc(&doc); |
| 1358 | |
| 1359 | pMission = hDoc.FirstChildElement().Element(); |
| 1360 | |
| 1361 | if(!pMission) |
| 1362 | printf("No valid root!"); |
| 1363 | |
| 1364 | hRoot = TiXmlHandle(pMission); |
| 1365 | pService = pMission->FirstChildElement(); |
| 1366 | int32_t mission_num = 0; |
| 1367 | //Iterate through the missions |
| 1368 | for(pChild0 = pMission->FirstChildElement(); pChild0 ; \ |
| 1369 | pChild0 = pChild0->NextSiblingElement()) |
| 1370 | { |
| 1371 | int32_t service_num = 0; |
| 1372 | uint16_t cond_array[] = {0, 0}; |
| 1373 | //printf("mission_num = %d\n", mission_num); |
| 1374 | memset(cond_array, 0, 2); |
| 1375 | |
| 1376 | for(pChild1 = pChild0->FirstChildElement(); pChild1; \ |
| 1377 | pChild1 = pChild1->NextSiblingElement()) |
| 1378 | { |
| 1379 | int32_t conditional_0 = service_num; |
| 1380 | for(pChild2 = pChild1->FirstChildElement(); \ |
| 1381 | pChild2; pChild2 = pChild2->NextSiblingElement()) |
| 1382 | { |
| 1383 | service_num++; |
| 1384 | int32_t conditional_1 = service_num; |
| 1385 | for(pChild3 = pChild2->FirstChildElement(); \ |
| 1386 | pChild3; pChild3 = pChild3 ->NextSiblingElement()) |
| 1387 | { |
| 1388 | service_num++; |
| 1389 | mList[mission_num].services[service_num].name = pChild3->Attribute("name"); |
| 1390 | if(pChild3->Attribute("input1")) |
| 1391 | mList[mission_num].services[service_num].input[0] = pChild3->Attribute("input1"); |
| 1392 | if(pChild3->Attribute("input2")) |
| 1393 | mList[mission_num].services[service_num].input[1] = pChild3->Attribute("input2"); |
| 1394 | if(pChild3->Attribute("input3")) |
| 1395 | mList[mission_num].services[service_num].input[2] = pChild3->Attribute("input3"); |
| 1396 | if(pChild3->Attribute("output1")) |
| 1397 | mList[mission_num].services[service_num].output[0] = pChild3->Attribute("output1"); |
| 1398 | if(pChild3->Attribute("output2")) |
| 1399 | mList[mission_num].services[service_num].output[1] = pChild3->Attribute("output2"); |
| 1400 | if(pChild3->Attribute("output3")) |
| 1401 | mList[mission_num].services[service_num].output[2] = pChild3->Attribute("output3"); |
| 1402 | cond_array[1]++; |
| 1403 | } |
| 1404 | |
| 1405 | if(conditional_1 != service_num){ |
| 1406 | mList[mission_num].services[conditional_1].name = pChild2->Value(); |
| 1407 | if(pChild2->Attribute("input_t")) |
| 1408 | mList[mission_num].services[conditional_1].input[0] = pChild2->Attribute("input_t"); |
| 1409 | if(pChild2->Attribute("input_f")) |
| 1410 | mList[mission_num].services[conditional_1].input[1] = pChild2->Attribute("input_f"); |
| 1411 | } |
| 1412 | else{ |
| 1413 | mList[mission_num].services[service_num].name = pChild2->Attribute("name"); |
| 1414 | if(pChild2->Attribute("input1")) |
| 1415 | mList[mission_num].services[service_num].input[0] = pChild2->Attribute("input1"); |
| 1416 | if(pChild2->Attribute("input2")) |
| 1417 | mList[mission_num].services[service_num].input[1] = pChild2->Attribute("input2"); |
| 1418 | if(pChild2->Attribute("input3")) |
| 1419 | mList[mission_num].services[service_num].input[2] = pChild2->Attribute("input3"); |
| 1420 | if(pChild2->Attribute("output1")) |
| 1421 | mList[mission_num].services[service_num].output[0] = pChild2->Attribute("output1"); |
| 1422 | if(pChild2->Attribute("output2")) |
| 1423 | mList[mission_num].services[service_num].output[1] = pChild2->Attribute("output2"); |
| 1424 | if(pChild2->Attribute("output3")) |
| 1425 | mList[mission_num].services[service_num].output[2] = pChild2->Attribute("output3"); |
| 1426 | } |
| 1427 | |
| 1428 | mList[mission_num].services[conditional_1].num_conds = cond_array[1]; |
| 1429 | cond_array[1] = 0; |
| 1430 | cond_array[0]++; |
| 1431 | } |
| 1432 | if(conditional_0 != service_num){ |
| 1433 | mList[mission_num].services[conditional_0].name = pChild1->Value(); |
| 1434 | if(pChild1->Attribute("input_t")) |
| 1435 | mList[mission_num].services[conditional_0].input[0] = pChild1->Attribute("input_t"); |
| 1436 | if(pChild1->Attribute("input_f")) |
| 1437 | mList[mission_num].services[conditional_0].input[1] = pChild1->Attribute("input_f"); |
| 1438 | printf("if detected %s, %s\n", pChild1->Attribute("input_f"), pChild1->Attribute("input_t")); |
| 1439 | } |
| 1440 | else{ |
| 1441 | mList[mission_num].services[service_num].name = pChild1->Attribute("name"); |
| 1442 | if(pChild1->Attribute("input1")) |
| 1443 | mList[mission_num].services[service_num].input[0] = pChild1->Attribute("input1"); |
| 1444 | if(pChild1->Attribute("input2")) |
| 1445 | mList[mission_num].services[service_num].input[1] = pChild1->Attribute("input2"); |
| 1446 | if(pChild1->Attribute("input3")) |
| 1447 | mList[mission_num].services[service_num].input[2] = pChild1->Attribute("input3"); |
| 1448 | if(pChild1->Attribute("output1")) |
| 1449 | mList[mission_num].services[service_num].output[0] = pChild1->Attribute("output1"); |
| 1450 | if(pChild1->Attribute("output2")) |
| 1451 | mList[mission_num].services[service_num].output[1] = pChild1->Attribute("output2"); |
| 1452 | if(pChild1->Attribute("output3")) |
| 1453 | mList[mission_num].services[service_num].output[2] = pChild1->Attribute("output3"); |
| 1454 | } |
| 1455 | |
| 1456 | mList[mission_num].services[conditional_0].num_conds = cond_array[0]; |
| 1457 | //printf("hello\n"); |
| 1458 | |
| 1459 | cond_array[0] = 0; |
| 1460 | service_num++; |
| 1461 | } |
| 1462 | for(int i = 0; i < service_num; i++) |
| 1463 | printf("input1=%s, output1=%s\n", mList[mission_num].services[i].input[0].c_str(), mList[mission_num].services[service_num].output[0].c_str()); |
| 1464 | |
| 1465 | mList[mission_num].numServices = service_num; |
| 1466 | mList[mission_num].name = pChild0->Attribute("name"); |
| 1467 | mList[mission_num].missionID = atoi(pChild0->Attribute("id")); |
| 1468 | if(pChild0->Attribute("input1")) |
| 1469 | mList[mission_num].input[0] = pChild0->Attribute("input1"); |
| 1470 | if(pChild0->Attribute("input2")) |
| 1471 | mList[mission_num].input[1] = pChild0->Attribute("input2"); |
| 1472 | if(pChild0->Attribute("input3")) |
| 1473 | mList[mission_num].input[2] = pChild0->Attribute("input3"); |
| 1474 | if(pChild0->Attribute("output1")) |
| 1475 | mList[mission_num].output[0] = pChild0->Attribute("output1"); |
| 1476 | if(pChild0->Attribute("output2")) |
| 1477 | mList[mission_num].output[1] = pChild0->Attribute("output2"); |
| 1478 | if(pChild0->Attribute("output3")) |
| 1479 | mList[mission_num].output[2] = pChild0->Attribute("output3"); |
| 1480 | printf("input1=%s, outpu1=%s\n", mList[mission_num].input[0].c_str(), mList[mission_num].output[0].c_str()); |
| 1481 | mission_num++; |
| 1482 | }*/ |