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