Changeset 446

Show
Ignore:
Timestamp:
08/31/09 17:30:09 (15 years ago)
Author:
bhilburn
Message:

Cleaned up the code, but it still needs to be heavily refactored. Lots
of scoping issues that I think may be breaking functionality.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp

    r445 r446  
    211211    _services_DB->tablename="Services"; 
    212212 
    213     /* If program execution ends in anything other than a ordered shutdown, DB's will still  
     213    /* ifprogram execution ends in anything other than a ordered shutdown, DB's will still  
    214214     * be there for next run. Need to get rid of it so that old data isn't inadvertantly  
    215215     * used in the next execution cycle. */ 
    216     _services_DB->command = "DROP TABLE IF EXISTS Services;";      
     216    _services_DB->command = "DROP TABLE ifEXISTS Services;";      
    217217 
    218218    rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); 
     
    266266 
    267267    _data_DB->tablename = "Data"; 
    268     _data_DB->command = "DROP TABLE IF EXISTS Data;";      
     268    _data_DB->command = "DROP TABLE ifEXISTS Data;";      
    269269 
    270270    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); 
     
    354354    //printf("********* %s **********\n", buffer); 
    355355    // TODO 
    356     // If we send integer op codes rather than strings, this process will be 
     356    // ifwe send integer op codes rather than strings, this process will be 
    357357    // MUCH faster since instead of donig string compares we can simply 
    358358    // switch on the integer value... 
     
    507507        selTimeout.tv_usec = 5000; 
    508508 
    509         /* Check if there is a message on the shell ready to be processed */ 
     509        /* Check ifthere is a message on the shell ready to be processed */ 
    510510        rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); 
    511511    } 
     
    548548        selTimeout.tv_usec = 5000; 
    549549 
    550         /* Check if there is a message on the shell ready to be processed */ 
     550        /* Check ifthere is a message on the shell ready to be processed */ 
    551551        rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); 
    552552    } 
     
    605605 * services that are requested in the mission. Each service in the mission is given  
    606606 * the ID and FD of a component that has registered to provide that service. Deregistration  
    607  * is okay until this method is called without a reload, but if deregistration occurs after this 
    608  * method is called it needs to be called again even if other engines also provide the services 
     607 * is okay until this method is called without a reload, but ifderegistration occurs after this 
     608 * method is called it needs to be called again even ifother engines also provide the services 
    609609 */ 
    610610void  
     
    630630                miss[activeMission].services[i].name.compare("dowhile") && \ 
    631631                miss[activeMission].services[i].name.compare("shell")) { 
    632                 /* If it is a service, search the database of registered services to find  
     632                /* ifit is a service, search the database of registered services to find  
    633633                 * the ID of the component that registered it */ 
    634634                _services_DB->command="select "; 
     
    644644                        -1, &pStatement, NULL); 
    645645                if(rc == SQLITE_OK) {  
    646                     if (sqlite3_step(pStatement) == SQLITE_ROW) 
     646                    if(sqlite3_step(pStatement) == SQLITE_ROW) 
    647647                        miss[activeMission].services[i].componentID = sqlite3_column_int(pStatement, 0);  
    648648                    else { 
     
    736736   }  
    737737 
    738     /* If this is a service command and not a shell command... */ 
     738    /* ifthis is a service command and not a shell command... */ 
    739739    /* Transmission starting messages */ 
    740740    SendMessage(miss[activeMission].services[sourceID].socketFD, "request_optimization_service"); 
     
    758758 * -All ordering constraints have been relaxed in this version; all data is stored  
    759759 *  locally and only sent when requested 
    760  * -If and while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot) 
     760 * -ifand while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot) 
    761761 * -For dowhiles, assumes loop condition determined on last line 
    762762 * 
     
    844844                             data = (const char *) sqlite3_column_text(pStatement, 1);  
    845845                        else { 
    846                             LOG("1 data_DB:: Data not yet in DB.\n"); 
     846                            WARNING("1 data_DB:: Data not yet in DB.\n"); 
    847847                            rc=31337; 
    848848                        } 
    849849                    } else { 
    850                         LOG("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     850                        WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
    851851                                rc,_data_DB->command.c_str()); 
    852852                    } 
     
    879879                         data2 = (const char *) sqlite3_column_text(pStatement, 1);  
    880880                    else { 
    881                         LOG("2 data_DB:: Data not yet in DB.\n"); 
     881                        WARNING("2 data_DB:: Data not yet in DB.\n"); 
    882882                        rc = 31337; 
    883883                    } 
    884884                } else { 
    885                     LOG("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     885                    WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
    886886                            rc, _data_DB->command.c_str()); 
    887887                } 
     
    921921                                         data = (const char *) sqlite3_column_text(pStatement, 1);  
    922922                                    else { 
    923                                         LOG("3 data_DB:: Data not yet in DB.\n"); 
     923                                        WARNING("3 data_DB:: Data not yet in DB.\n"); 
    924924                                        rc = 31337; 
    925925                                    } 
    926926                                } else { 
    927                                     LOG("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     927                                    WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
    928928                                            rc,_data_DB->command.c_str()); 
    929929                                } 
     
    947947                            _data_DB->command.append(miss[activeMission].services[k].output[t].erase(0, 1)); 
    948948                            _data_DB->command.append("';"); 
    949                             sqlite3_stmt * pStatement; 
    950                             rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
    951                             if (rc == SQLITE_OK){  
    952                             if (sqlite3_step(pStatement) == SQLITE_ROW) 
    953                                  data2 = (const char *) sqlite3_column_text(pStatement, 1);  
    954                             else { 
    955                                 printf("4 data_DB:: Data not yet in DB.\n"); 
    956                                 rc=31337; 
     949 
     950                            sqlite3_stmt *pStatement; 
     951                            rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), \ 
     952                                    -1, &pStatement, NULL); 
     953                            if(rc == SQLITE_OK) {  
     954                                if(sqlite3_step(pStatement) == SQLITE_ROW) 
     955                                     data2 = (const char *) sqlite3_column_text(pStatement, 1);  
     956                                else { 
     957                                    WARNING("4 data_DB:: Data not yet in DB.\n"); 
     958                                    rc = 31337; 
     959                                } 
     960                            } else { 
     961                                WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     962                                        rc, _data_DB->command.c_str()); 
    957963                            } 
    958                             } else { 
    959                             printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str()); 
    960                             } 
    961                                 sqlite3_finalize(pStatement); 
    962                             int pos = data2.find_last_of("@", data2.length()-2); 
    963                             token2 = data2.substr(pos+1); 
    964                             token2.erase(token2.length()-1); 
    965                                 //printf("token=%s token2=%s\n", token.c_str(), token2.c_str()); 
    966                                 if(atof(token.c_str()) > atof(token2.c_str())) 
    967                                 doit=true; 
     964 
     965                            sqlite3_finalize(pStatement); 
     966                            int32_t pos = data2.find_last_of("@", data2.length() - 2); 
     967                            token2 = data2.substr(pos + 1); 
     968                            token2.erase(token2.length() - 1); 
     969                            if(atof(token.c_str()) > atof(token2.c_str())) 
     970                                doit = true; 
    968971                        } 
    969                         else if (miss[activeMission].services[k].output[t].find(token) != string::npos) 
    970                         doit=true; 
    971                         if(doit){ 
    972                         //printf("Level 1:if taken\n"); 
    973                         for(uint16_t j = k+1; j <= k+miss[activeMission].services[k].num_conds; j++){  
    974                             if(miss[activeMission].services[j].name.compare("if")==0){ 
    975                             //printf("Level 2:if detected\n"); 
    976                                 input.clear(); 
    977                                 check.clear(); 
    978                                 for(t = 0; t < 10; t++){ 
    979                                 if(!miss[activeMission].services[j].output[t].empty()){ 
    980                                     input=miss[activeMission].services[j-numstatements[2]-1].output[t]; 
    981                                            _data_DB->command="SELECT "; 
    982                                         _data_DB->command.append(_data_DB->tablename); 
    983                                        _data_DB->command.append(".* from "); 
    984                                        _data_DB->command.append(_data_DB->tablename); 
    985                                       _data_DB->command.append(" where Tag=='"); 
    986                                      _data_DB->command.append(input); 
    987                                     _data_DB->command.append("';"); 
    988                                     sqlite3_stmt * pStatement; 
    989                                     rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
    990                                     if (rc == SQLITE_OK){  
    991                                     if (sqlite3_step(pStatement) == SQLITE_ROW) 
    992                                          data = (const char *) sqlite3_column_text(pStatement, 1);  
    993                                     else { 
    994                                         printf("5 data_DB:: Data not yet in DB.\n"); 
    995                                         rc=31337; 
    996                                     } 
    997                                     } else { 
    998                                     printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str()); 
    999                                     } 
    1000                                         sqlite3_finalize(pStatement); 
    1001                                     //printf("data=%s\n", data.c_str()); 
    1002                                     int pos = data.find_last_of("@", data.length()-2); 
    1003                                     token = data.substr(pos+1); 
    1004                                     token.erase(token.length()-1); 
    1005                                     //printf("token=%s\n", token.c_str()); 
    1006                                     data.clear(); 
    1007                                     break; 
    1008                                 } 
    1009                                 } 
    1010                                 bool doit = false; 
    1011                                 if(miss[activeMission].services[j].output[t].find(">") != string::npos){ 
    1012                                     _data_DB->command="SELECT "; 
    1013                                     _data_DB->command.append(_data_DB->tablename); 
    1014                                     _data_DB->command.append(".* from "); 
    1015                                    _data_DB->command.append(_data_DB->tablename); 
    1016                                     _data_DB->command.append(" where Tag=='"); 
    1017                                     _data_DB->command.append(miss[activeMission].services[j].output[t].erase(0, 1)); 
    1018                                     _data_DB->command.append("';"); 
    1019                                     sqlite3_stmt * pStatement; 
    1020                                     rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
    1021                                     if (rc == SQLITE_OK){  
    1022                                     if (sqlite3_step(pStatement) == SQLITE_ROW) 
    1023                                          data2 = (const char *) sqlite3_column_text(pStatement, 1);  
    1024                                     else { 
    1025                                         printf("6 data_DB:: Data not yet in DB.\n"); 
    1026                                         rc=31337; 
    1027                                     } 
    1028                                     } else { 
    1029                                     printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str()); 
    1030                                     } 
    1031                                         sqlite3_finalize(pStatement); 
    1032  
    1033                                 int pos = data2.find_last_of("@", data2.length()-2); 
    1034                                 token2 = data2.substr(pos+1); 
    1035                                 token2.erase(token2.length()-1); 
    1036                                     if(atof(token.c_str()) > atof(token2.c_str())) 
    1037                                     doit=true; 
    1038                                 data.clear(); 
    1039                                 } 
    1040                                 else if (miss[activeMission].services[j].output[t].find(token) != string::npos) 
    1041                                 doit=true; 
    1042                                 if(doit){ 
    1043                                 //printf("Level 1:if taken\n"); 
    1044                                 for(uint16_t l = j+1; l <= j+miss[activeMission].services[j].num_conds; l++){  
    1045                                     TransactData(l); 
    1046                                 } 
    1047                                 } 
    1048                                 else 
    1049                                 //printf("Level 2:if not taken\n"); 
    1050                                 numstatements[2] +=miss[activeMission].services[j].num_conds+1; 
    1051                                 j+=miss[activeMission].services[j].num_conds; 
    1052                                 //printf("Level 2:doneif %d, %d, %d\n", numstatements, miss[activeMission].services[i].num_conds, i); 
    1053                             }else if(miss[activeMission].services[j].name.compare("dowhile")==0){ 
    1054                                 numstatements[0]=0; 
    1055                                 //printf("Level 2:while detected\n"); 
    1056                                 while(true){ 
    1057                                     uint16_t l; 
    1058                                     for(l = j+1; l <= j+miss[activeMission].services[j].num_conds; l++){  
    1059                                     TransactData(l); 
    1060                                     } 
    1061                                     data.clear(); 
     972                        else if(miss[activeMission].services[k].output[t].find(token) != string::npos) 
     973                            doit=true; 
     974 
     975                        if(doit) { 
     976                            for(size_t j = k + 1; j <= k+miss[activeMission].services[k].num_conds; j++) {  
     977                                if(miss[activeMission].services[j].name.compare("if") == 0) { 
    1062978                                    input.clear(); 
    1063979                                    check.clear(); 
    1064                                     int t; 
    1065                                     for(t = 0; t < 10; t++){ 
    1066                                     if(!miss[activeMission].services[j].output[t].empty()){ 
    1067                                         input=miss[activeMission].services[l-2].output[t]; 
    1068                                         //printf("%s\n",input.c_str()); 
     980                                    for(t = 0; t < 10; t++) { 
     981                                        if(!miss[activeMission].services[j].output[t].empty()) { 
     982                                            input = miss[activeMission].services[j - numstatements[2] - 1].output[t]; 
     983 
     984                                            _data_DB->command="SELECT "; 
     985                                            _data_DB->command.append(_data_DB->tablename); 
     986                                            _data_DB->command.append(".* from "); 
     987                                            _data_DB->command.append(_data_DB->tablename); 
     988                                            _data_DB->command.append(" where Tag=='"); 
     989                                            _data_DB->command.append(input); 
     990                                            _data_DB->command.append("';"); 
     991 
     992                                            sqlite3_stmt *pStatement; 
     993 
     994                                            rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
     995                                            if(rc == SQLITE_OK) {  
     996                                                if(sqlite3_step(pStatement) == SQLITE_ROW) 
     997                                                     data = (const char *) sqlite3_column_text(pStatement, 1);  
     998                                                else { 
     999                                                    WARNING("5 data_DB:: Data not yet in DB.\n"); 
     1000                                                    rc = 31337; 
     1001                                                } 
     1002                                            } else { 
     1003                                                WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     1004                                                        rc, _data_DB->command.c_str()); 
     1005                                            } 
     1006 
     1007                                            sqlite3_finalize(pStatement); 
     1008                                            int32_t pos = data.find_last_of("@", data.length()-2); 
     1009                                            token = data.substr(pos+1); 
     1010                                            token.erase(token.length()-1); 
     1011                                            data.clear(); 
     1012                                            break; 
     1013                                        } 
     1014                                    } 
     1015 
     1016                                    bool doit = false; 
     1017                                    if(miss[activeMission].services[j].output[t].find(">") != string::npos) { 
    10691018                                        _data_DB->command="SELECT "; 
    10701019                                        _data_DB->command.append(_data_DB->tablename); 
     
    10721021                                        _data_DB->command.append(_data_DB->tablename); 
    10731022                                        _data_DB->command.append(" where Tag=='"); 
    1074                                         _data_DB->command.append(input); 
     1023                                        _data_DB->command.append(miss[activeMission].services[j].output[t].erase(0, 1)); 
    10751024                                        _data_DB->command.append("';"); 
    1076                                         sqlite3_stmt * pStatement; 
    1077  
     1025 
     1026                                        sqlite3_stmt *pStatement; 
    10781027                                        rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
    1079                                         if (rc == SQLITE_OK){  
    1080                                         if (sqlite3_step(pStatement) == SQLITE_ROW) 
    1081                                              data = (const char *) sqlite3_column_text(pStatement, 1);  
    1082                                         else { 
    1083                                             printf("7 data_DB:: Data not yet in DB.: %s\n", _data_DB->command.c_str()); 
    1084                                             rc=31337; 
     1028                                        if(rc == SQLITE_OK) {  
     1029                                            if(sqlite3_step(pStatement) == SQLITE_ROW) 
     1030                                                 data2 = (const char *) sqlite3_column_text(pStatement, 1);  
     1031                                            else { 
     1032                                                WARNING("6 data_DB:: Data not yet in DB.\n"); 
     1033                                                rc=31337; 
     1034                                            } 
     1035                                        } else { 
     1036                                            WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     1037                                                    rc, _data_DB->command.c_str()); 
    10851038                                        } 
    1086                                         } else { 
    1087                                           printf("data_DB:: SQL statement error. rc = %i\n%s\n",rc,_data_DB->command.c_str()); 
     1039 
     1040                                        sqlite3_finalize(pStatement); 
     1041 
     1042                                        int32_t pos = data2.find_last_of("@", data2.length()-2); 
     1043                                        token2 = data2.substr(pos + 1); 
     1044                                        token2.erase(token2.length()-1); 
     1045 
     1046                                        if(atof(token.c_str()) > atof(token2.c_str())) 
     1047                                            doit=true; 
     1048 
     1049                                        data.clear(); 
     1050                                    } 
     1051 
     1052                                    else if(miss[activeMission].services[j].output[t].find(token) != string::npos) 
     1053                                        doit = true; 
     1054 
     1055                                    if(doit) { 
     1056                                        for(size_t l = j + 1; l <= j + miss[activeMission].services[j].num_conds; l++) {  
     1057                                            TransactData(l); 
    10881058                                        } 
    1089                                             sqlite3_finalize(pStatement); 
    1090                                         //printf("Level 2:data=%s\n", data.c_str()); 
    1091                                             int pos = data.find_last_of("@", data.length()-2); 
    1092                                             token = data.substr(pos+1); 
    1093                                             token.erase(token.length()-1); 
    1094                                         //printf("Level 2:token=%s\n", token); 
    1095                                         break; 
    10961059                                    } 
     1060 
     1061                                    numstatements[2] += miss[activeMission].services[j].num_conds + 1; 
     1062                                    j += miss[activeMission].services[j].num_conds; 
     1063                                } else if(miss[activeMission].services[j].name.compare("dowhile") == 0) { 
     1064                                    numstatements[0]=0; 
     1065 
     1066                                    while(true) { 
     1067                                        uint32_t l; 
     1068                                        for(l = j + 1; l <= j+miss[activeMission].services[j].num_conds; l++) {  
     1069                                            TransactData(l); 
     1070                                        } 
     1071 
     1072                                        data.clear(); 
     1073                                        input.clear(); 
     1074                                        check.clear(); 
     1075 
     1076                                        int32_t t; 
     1077                                        for(t = 0; t < 10; t++) { 
     1078                                            if(!miss[activeMission].services[j].output[t].empty()){ 
     1079                                                input=miss[activeMission].services[l-2].output[t]; 
     1080                                                _data_DB->command="SELECT "; 
     1081                                                _data_DB->command.append(_data_DB->tablename); 
     1082                                                _data_DB->command.append(".* from "); 
     1083                                                _data_DB->command.append(_data_DB->tablename); 
     1084                                                _data_DB->command.append(" where Tag=='"); 
     1085                                                _data_DB->command.append(input); 
     1086                                                _data_DB->command.append("';"); 
     1087                                                sqlite3_stmt *pStatement; 
     1088 
     1089                                                rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
     1090                                                if(rc == SQLITE_OK){  
     1091                                                    if(sqlite3_step(pStatement) == SQLITE_ROW) 
     1092                                                         data = (const char *) sqlite3_column_text(pStatement, 1);  
     1093                                                    else { 
     1094                                                        WARNING("7 data_DB:: Data not yet in DB.: %s\n", _data_DB->command.c_str()); 
     1095                                                        rc = 31337; 
     1096                                                    } 
     1097                                                } else { 
     1098                                                    WARNING("data_DB:: SQL statement error. rc = %i\n%s\n", \ 
     1099                                                            rc, _data_DB->command.c_str()); 
     1100                                                } 
     1101 
     1102                                                sqlite3_finalize(pStatement); 
     1103                                                int32_t pos = data.find_last_of("@", data.length() - 2); 
     1104                                                token = data.substr(pos + 1); 
     1105                                                token.erase(token.length() - 1); 
     1106                                                break; 
     1107                                            } 
     1108                                        } 
     1109 
     1110                                        if(miss[activeMission].services[j].output[t].find(token) == string::npos) { 
     1111                                            break; 
     1112                                        } 
    10971113                                    } 
    1098                                     //printf("Level 2:--- %s  %s---\n", miss[activeMission].services[j].output[t].c_str(), token); 
    1099                                     if(miss[activeMission].services[j].output[t].find(token) != string::npos){ 
    1100                                     //printf("Level 2:while taken again!\n"); 
    1101                                     } 
    1102                                     else { 
    1103                                     //printf("Level 2:no more while\n"); 
    1104                                     break;} 
     1114 
     1115                                    j += miss[activeMission].services[j].num_conds; 
     1116                                } else { 
     1117                                    numstatements[2] = 0; 
     1118                                    TransactData(j); 
    11051119                                } 
    1106                                 j+=miss[activeMission].services[j].num_conds; 
    1107                             } 
    1108                             else{ 
    1109                                 //printf("Level 2: no conditional\n"); 
    1110                                 numstatements[2]=0; 
    1111                                     TransactData(j); 
    11121120                            } 
    11131121                        } 
    1114                         } 
    1115                         else{ 
    1116                         //printf("Level 1: if not taken\n"); 
    1117                         } 
    1118                             numstatements[1] +=miss[activeMission].services[k].num_conds+1; 
    1119                             k+=miss[activeMission].services[k].num_conds; 
    1120                         //printf("doneif %d, %d, %d\n", numstatements, miss[activeMission].services[i].num_conds, i); 
    1121                     }else if(miss[activeMission].services[k].name.compare("dowhile")==0){ 
    1122                         numstatements[0]=0; 
    1123                         //printf("Level 1: while detected\n"); 
    1124                         while(true){ 
    1125                         uint16_t j; 
    1126                             for(j = k+1; j <= k+miss[activeMission].services[k].num_conds; j++){  
    1127                             TransactData(j); 
     1122 
     1123                        numstatements[1] += miss[activeMission].services[k].num_conds + 1; 
     1124                        k += miss[activeMission].services[k].num_conds; 
     1125                    } else if(miss[activeMission].services[k].name.compare("dowhile") == 0) { 
     1126                        numstatements[0] = 0; 
     1127                        while(true) { 
     1128                            int32_t j; 
     1129                            for(j = k + 1; j <= k + miss[activeMission].services[k].num_conds; j++) { 
     1130                                TransactData(j); 
    11281131                            } 
     1132 
    11291133                            data.clear(); 
    11301134                            input.clear(); 
    11311135                            check.clear(); 
    1132                             int t; 
    1133                             for(t = 0; t < 10; t++){ 
    1134                             if(!miss[activeMission].services[k].output[t].empty()){ 
    1135                                 input=miss[activeMission].services[j-1].output[t]; 
    1136                                 _data_DB->command="SELECT "; 
    1137                                 _data_DB->command.append(_data_DB->tablename); 
    1138                                 _data_DB->command.append(".* from "); 
    1139                                 _data_DB->command.append(_data_DB->tablename); 
    1140                                 _data_DB->command.append(" where Tag=='"); 
    1141                                 _data_DB->command.append(input); 
    1142                                 _data_DB->command.append("';"); 
    1143                                 sqlite3_stmt * pStatement; 
    1144                                 rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
    1145                                 if (rc == SQLITE_OK){  
    1146                                 if (sqlite3_step(pStatement) == SQLITE_ROW) 
    1147                                      data = (const char *) sqlite3_column_text(pStatement, 1);  
    1148                                 else { 
    1149                                     printf("8 data_DB:: Data not yet in DB.\n"); 
    1150                                     rc=31337; 
     1136                            int32_t t; 
     1137                            for(t = 0; t < 10; t++) { 
     1138                                if(!miss[activeMission].services[k].output[t].empty()) { 
     1139                                    input = miss[activeMission].services[j - 1].output[t]; 
     1140                                    _data_DB->command="SELECT "; 
     1141                                    _data_DB->command.append(_data_DB->tablename); 
     1142                                    _data_DB->command.append(".* from "); 
     1143                                    _data_DB->command.append(_data_DB->tablename); 
     1144                                    _data_DB->command.append(" where Tag=='"); 
     1145                                    _data_DB->command.append(input); 
     1146                                    _data_DB->command.append("';"); 
     1147 
     1148                                    sqlite3_stmt *pStatement; 
     1149                                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
     1150                                    if(rc == SQLITE_OK) {  
     1151                                        if(sqlite3_step(pStatement) == SQLITE_ROW) 
     1152                                             data = (const char *) sqlite3_column_text(pStatement, 1);  
     1153                                        else { 
     1154                                            WARNING("8 data_DB:: Data not yet in DB.\n"); 
     1155                                            rc = 31337; 
     1156                                        } 
     1157                                    } else { 
     1158                                        WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     1159                                                rc, _data_DB->command.c_str()); 
     1160                                    } 
     1161 
     1162                                    sqlite3_finalize(pStatement); 
     1163                                    int32_t pos = data.find_last_of("@", data.length() - 2); 
     1164                                    token = data.substr(pos + 1); 
     1165                                    token.erase(token.length() - 1); 
     1166                                    break; 
    11511167                                } 
    1152                                 } else { 
    1153                                 printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str()); 
    1154                                 } 
    1155                                     sqlite3_finalize(pStatement); 
    1156                                 //printf("Level 1:data=%s\n", data.c_str()); 
    1157                                 int pos = data.find_last_of("@", data.length()-2); 
    1158                                 token = data.substr(pos+1); 
    1159                                 token.erase(token.length()-1); 
    1160                                 //printf("Level 1:token=%s\n", token); 
     1168                            } 
     1169 
     1170                            if(miss[activeMission].services[k].output[t].find(token) == string::npos) { 
    11611171                                break; 
    11621172                            } 
    1163                             } 
    1164                             //printf("Level 1:--- %s  %s---\n", miss[activeMission].services[k].output[t].c_str(), token); 
    1165                             if(miss[activeMission].services[k].output[t].find(token) != string::npos){ 
    1166                             //printf("Level 1:while taken again!\n"); 
    1167                             } 
    1168                             else { 
    1169                             //printf("Level 1:While finished\n"); 
    1170                             break;} 
    11711173                        } 
    1172                         k+=miss[activeMission].services[k].num_conds; 
    1173                     } 
    1174                     else{ 
    1175                         //printf("Level1:No conditional\n"); 
    1176                         numstatements[1]=0; 
    1177                             TransactData(k); 
     1174 
     1175                        k += miss[activeMission].services[k].num_conds; 
     1176                    } else{ 
     1177                        numstatements[1] = 0; 
     1178                        TransactData(k); 
    11781179                    } 
    11791180                } 
    11801181            } 
    1181                 numstatements[0] +=miss[activeMission].services[i].num_conds+1; 
    1182             i+=miss[activeMission].services[i].num_conds; 
    1183         } 
    1184         else if(miss[activeMission].services[i].name.compare("dowhile")==0) 
    1185         { 
    1186             numstatements[0]=0; 
    1187             //printf("Level 0: while detected\n"); 
    1188             while(true){ 
    1189             uint16_t k; 
    1190                 for(k = i+1; k <= i+miss[activeMission].services[i].num_conds; k++){  
    1191                 TransactData(k); 
     1182 
     1183            numstatements[0] += miss[activeMission].services[i].num_conds + 1; 
     1184            i += miss[activeMission].services[i].num_conds; 
     1185        } else if(miss[activeMission].services[i].name.compare("dowhile") == 0) { 
     1186            numstatements[0] = 0; 
     1187            while(true) { 
     1188                uint32_t k; 
     1189                for(k = i + 1; k <= i + miss[activeMission].services[i].num_conds; k++){  
     1190                    TransactData(k); 
    11921191                } 
     1192 
    11931193                data.clear(); 
    11941194                input.clear(); 
    11951195                check.clear(); 
    1196                 int t; 
     1196                int32_t t; 
    11971197                for(t = 0; t < 10; t++){ 
    1198                 if(!miss[activeMission].services[i].output[t].empty()){ 
    1199                     input=miss[activeMission].services[k-1].output[t]; 
    1200                     _data_DB->command="SELECT "; 
    1201                     _data_DB->command.append(_data_DB->tablename); 
    1202                     _data_DB->command.append(".* from "); 
    1203                     _data_DB->command.append(_data_DB->tablename); 
    1204                     _data_DB->command.append(" where Tag=='"); 
    1205                     _data_DB->command.append(input); 
    1206                     _data_DB->command.append("';"); 
    1207                     sqlite3_stmt * pStatement; 
    1208                     rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
    1209                     if (rc == SQLITE_OK){  
    1210                     if (sqlite3_step(pStatement) == SQLITE_ROW) 
    1211                          data = (const char *) sqlite3_column_text(pStatement, 1);  
    1212                     else { 
    1213                         printf("10data_DB:: Data not yet in DB.\n"); 
    1214                         rc=31337; 
     1198                    if(!miss[activeMission].services[i].output[t].empty()) { 
     1199                        input = miss[activeMission].services[k - 1].output[t]; 
     1200                        _data_DB->command="SELECT "; 
     1201                        _data_DB->command.append(_data_DB->tablename); 
     1202                        _data_DB->command.append(".* from "); 
     1203                        _data_DB->command.append(_data_DB->tablename); 
     1204                        _data_DB->command.append(" where Tag=='"); 
     1205                        _data_DB->command.append(input); 
     1206                        _data_DB->command.append("';"); 
     1207 
     1208                        sqlite3_stmt *pStatement; 
     1209                        rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), -1, &pStatement, NULL); 
     1210                        if(rc == SQLITE_OK) {  
     1211                            if(sqlite3_step(pStatement) == SQLITE_ROW) 
     1212                                 data = (const char *) sqlite3_column_text(pStatement, 1);  
     1213                            else { 
     1214                                WARNING("10data_DB:: Data not yet in DB.\n"); 
     1215                                rc = 31337; 
     1216                            } 
     1217                        } else { 
     1218                            WARNING("data_DB:: Error executing SQL statement. rc = %i\n%s\n", \ 
     1219                                    rc, _data_DB->command.c_str()); 
     1220                        } 
     1221 
     1222                        sqlite3_finalize(pStatement); 
     1223                        int32_t pos = data.find_last_of("@", data.length()-2); 
     1224                        token = data.substr(pos + 1); 
     1225                        token.erase(token.length() - 1); 
     1226                        break; 
    12151227                    } 
    1216                     } else { 
    1217                     printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command.c_str()); 
    1218                     } 
    1219                         sqlite3_finalize(pStatement); 
    1220                     int pos = data.find_last_of("@", data.length()-2); 
    1221                     token = data.substr(pos+1); 
    1222                     token.erase(token.length()-1); 
     1228                } 
     1229 
     1230                if(miss[activeMission].services[i].output[t].find(token) == string::npos) { 
    12231231                    break; 
    12241232                } 
    1225                 } 
    1226                 //printf("Level 0:--- %s  %s---\n", miss[activeMission].services[i].output[t].c_str(), token); 
    1227                 if(miss[activeMission].services[i].output[t].find(token) != string::npos){ 
    1228                 //printf("Level 0:while taken again!\n"); 
    1229                 } 
    1230                 else { 
    1231                 //printf("Level 0:no more while\n"); 
    1232                 break;} 
    12331233            } 
    1234             i+=miss[activeMission].services[i].num_conds; 
    1235         } 
    1236         else{ 
    1237             numstatements[0]=0; 
    1238             //printf("Level 0: No conditional\n"); 
     1234 
     1235            i += miss[activeMission].services[i].num_conds; 
     1236        } else{ 
     1237            numstatements[0] = 0; 
    12391238            TransactData(i); 
    12401239        } 
     
    12441243    data.clear(); 
    12451244 
    1246     if(!shellFound) 
    1247     { 
    1248     int k = 0; 
    1249     while(k<10 && !miss[activeMission].input[k].empty()){ 
    1250         k++; 
    1251     } 
    1252     sprintf(buffer, "%d", k); 
    1253     SendMessage(shellSocketFD, buffer); 
    1254     for(int t = 0; t < k; t++){ 
    1255         SendMessage(shellSocketFD, miss[activeMission].input[t].c_str());  
    1256         SendMessage(shellSocketFD, "0"); 
    1257     } 
    1258     } 
    1259  
     1245    if(!shellFound) { 
     1246        int k = 0; 
     1247        while(k < 10 && !miss[activeMission].input[k].empty()) { 
     1248            k++; 
     1249        } 
     1250 
     1251        sprintf(buffer, "%d", k); 
     1252        SendMessage(shellSocketFD, buffer); 
     1253 
     1254        for(size_t t = 0; t < k; t++) { 
     1255            SendMessage(shellSocketFD, miss[activeMission].input[t].c_str());  
     1256            SendMessage(shellSocketFD, "0"); 
     1257        } 
     1258    } 
    12601259 
    12611260    LOG("ServiceManagementLayer:: Done performing active mission.\n"); 
    1262     /* 
    1263     strcpy(_data_DB->command, "select "); 
    1264     strcat(_data_DB->command, _data_DB->tablename); 
    1265     strcat(_data_DB->command, ".* from "); 
    1266     strcat(_data_DB->command, _data_DB->tablename); 
    1267     strcat(_data_DB->command, ";"); 
    1268  
    1269     // execute print (select all)  command   
    1270     rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg); 
    1271     if( rc!=SQLITE_OK && rc!=101 ) 
    1272         fprintf(stderr, "SQL error: %s\n", errorMsg); 
    1273     printf("database %s, table %s:\n", _data_DB->filename, _data_DB->tablename); 
    1274     printf("\n\n\n");*/ 
    12751261} 
    12761262 
     
    12911277    _services_DB->command.append(";"); 
    12921278 
    1293     // execute print (select all)  command     
     1279    // Execute print (select all) command 
    12941280    char *errorMsg; 
    1295     int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 
    1296     if( rc!=SQLITE_OK && rc!=101 ) 
    1297         fprintf(stderr, "SQL error: %s\n", errorMsg); 
    1298     printf("database %s, table %s:\n", _services_DB->filename.c_str(), _services_DB->tablename.c_str()); 
     1281    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 
     1282    if((rc != SQLITE_OK) && (rc != 101)) 
     1283        WARNING("SQL error: %s\n", errorMsg); 
     1284 
     1285    LOG("database %s, table %s:\n", _services_DB->filename.c_str(), _services_DB->tablename.c_str()); 
    12991286} 
    13001287 
     
    13091296{ 
    13101297    LOG("ServiceManagementLayer:: Reloading Configuration.\n"); 
     1298 
    13111299    free(miss); 
     1300 
    13121301    miss = new Mission[10]; 
    1313     for(int i = 0; i < 10; i++) 
     1302    for(size_t i = 0; i < 10; i++) 
    13141303        miss[i].services = new Service[30]; 
     1304 
    13151305    LoadConfiguration(_SML_Config.c_str(), miss); 
    13161306} 
     
    13361326    TiXmlElement *pChild0, *pChild1, *pChild2, *pChild3, *pChild4; 
    13371327    TiXmlHandle hRoot(0); 
    1338     printf("ServiceManagementLayer:: Loading Configuration.\n"); 
     1328 
     1329    LOG("ServiceManagementLayer:: Loading Configuration.\n"); 
     1330 
    13391331    TiXmlDocument doc("."); 
    13401332    doc.LoadFile(SML_Config); 
    13411333    bool loadOkay = doc.LoadFile(); 
    13421334    if(!loadOkay) 
    1343         printf("Loading SML configuration failed: %s\n", SML_Config); 
     1335        WARNING("Loading SML configuration failed: %s\n", SML_Config); 
    13441336 
    13451337    TiXmlHandle hDoc(&doc); 
     
    13481340 
    13491341    if(!pMission)  
    1350         printf("No valid root!"); 
     1342        WARNING("No valid root!"); 
    13511343 
    13521344    hRoot = TiXmlHandle(pMission); 
    13531345    pService = pMission->FirstChildElement(); 
     1346 
    13541347    int32_t mission_num = 0; 
    1355     //Iterate through the missions 
    1356     for(pChild0 = pMission->FirstChildElement(); pChild0 ; \ 
    1357         pChild0 = pChild0->NextSiblingElement())  
    1358     { 
    1359     int32_t service_num = 0; 
    1360     uint16_t cond_array[] = {0, 0, 0}; 
     1348 
     1349    /* Iterate through the missions */ 
     1350    for(pChild0 = pMission->FirstChildElement(); pChild0 ; pChild0 = pChild0->NextSiblingElement())  { 
     1351        int32_t service_num = 0; 
     1352        uint16_t cond_array[] = {0, 0, 0}; 
    13611353     
    13621354        for(pChild1  = (pChild0->FirstChildElement())->FirstChildElement(); pChild1; \ 
    1363               pChild1  = pChild1->NextSiblingElement())  
    1364         { 
    1365         int32_t conditional_0 = service_num; 
    1366         for(pChild2 = pChild1->FirstChildElement(); \ 
    1367         pChild2; pChild2 = pChild2->NextSiblingElement()) 
    1368         { 
    1369         service_num++; 
    1370         int32_t conditional_1 = service_num; 
    1371         for(pChild3 = pChild2->FirstChildElement(); \ 
    1372             pChild3; pChild3 = pChild3->NextSiblingElement()) 
    1373         { 
    1374             service_num++; 
    1375             int32_t conditional_2 = service_num; 
    1376             for(pChild4 = pChild3->FirstChildElement(); \ 
    1377                 pChild4; pChild4 = pChild4->NextSiblingElement()) 
    1378             { 
    1379                    service_num++; 
    1380                 if(pChild4->Attribute("name")) 
    1381                     mList[mission_num].services[service_num].name = pChild4->Attribute("name"); 
    1382                 else 
    1383                     mList[mission_num].services[service_num].name = pChild4->Value(); 
     1355                pChild1  = pChild1->NextSiblingElement()) { 
     1356 
     1357            int32_t conditional_0 = service_num; 
     1358            for(pChild2 = pChild1->FirstChildElement(); pChild2; pChild2 = pChild2->NextSiblingElement()) { 
     1359                service_num++; 
     1360 
     1361                int32_t conditional_1 = service_num; 
     1362                for(pChild3 = pChild2->FirstChildElement(); pChild3; pChild3 = pChild3->NextSiblingElement()) { 
     1363                    service_num++; 
     1364                    int32_t conditional_2 = service_num; 
     1365                    for(pChild4 = pChild3->FirstChildElement(); pChild4; pChild4 = pChild4->NextSiblingElement()) { 
     1366                        service_num++; 
     1367                        if(pChild4->Attribute("name")) 
     1368                            mList[mission_num].services[service_num].name = pChild4->Attribute("name"); 
     1369                        else 
     1370                            mList[mission_num].services[service_num].name = pChild4->Value(); 
     1371 
     1372                        for(size_t i = 1; i <= 10; i++) { 
     1373                            char buffer[9]="input"; 
     1374                            sprintf(buffer, "%s%d", buffer, i);  
     1375                            if(pChild4->Attribute(buffer)) 
     1376                                mList[mission_num].services[service_num].input[i - 1] = pChild4->Attribute(buffer); 
     1377 
     1378                            char buffer2[9]="output"; 
     1379                            sprintf(buffer2, "%s%d", buffer2, i);  
     1380                            if(pChild4->Attribute(buffer2)) 
     1381                                mList[mission_num].services[service_num].output[i - 1] = pChild4->Attribute(buffer2); 
     1382                        } 
     1383 
     1384                        if(pChild4->Attribute("parameter")) 
     1385                            mList[mission_num].services[service_num].parameter = pChild4->Attribute("parameter"); 
     1386 
     1387                        cond_array[2]++; 
     1388                    } 
     1389 
     1390                    if(!strcmp(pChild3->Value(), "shell") || conditional_2 != service_num) { 
     1391                        mList[mission_num].services[conditional_2].name = pChild3->Value(); 
     1392                    } else { 
     1393                        mList[mission_num].services[service_num].name = pChild3->Attribute("name"); 
     1394                    } 
     1395 
     1396                    for(size_t i = 1; i <= 10; i++) { 
     1397                        char buffer[9]="input"; 
     1398                        sprintf(buffer, "%s%d", buffer, i);  
     1399                        if(pChild3->Attribute(buffer)) 
     1400                            mList[mission_num].services[conditional_2].input[i - 1] = pChild3->Attribute(buffer); 
     1401 
     1402                        char buffer2[9]="output"; 
     1403                        sprintf(buffer2, "%s%d", buffer2, i);  
     1404                        if(pChild3->Attribute(buffer2)) 
     1405                            mList[mission_num].services[conditional_2].output[i - 1] = pChild3->Attribute(buffer2); 
     1406                    } 
     1407 
     1408                    if(pChild3->Attribute("parameter")) 
     1409                        mList[mission_num].services[conditional_2].parameter = pChild3->Attribute("parameter"); 
     1410 
     1411                    mList[mission_num].services[conditional_2].num_conds = cond_array[2]; 
     1412                    cond_array[1] += cond_array[2] + 1; 
     1413                    cond_array[2] = 0; 
     1414                } 
     1415 
     1416                if(!strcmp(pChild2->Value(), "shell") || (conditional_1 != service_num)) { 
     1417                    mList[mission_num].services[conditional_1].name = pChild2->Value(); 
     1418                } else{ 
     1419                    mList[mission_num].services[service_num].name = pChild2->Attribute("name"); 
     1420                } 
     1421 
    13841422                for(int i = 1; i <= 10; i++) { 
    13851423                    char buffer[9]="input"; 
    13861424                    sprintf(buffer, "%s%d", buffer, i);  
    1387                     //printf("buffer=%s\n", buffer); 
    1388                     if(pChild4->Attribute(buffer)) 
    1389                         mList[mission_num].services[service_num].input[i-1] = pChild4->Attribute(buffer); 
     1425                    if(pChild2->Attribute(buffer)) 
     1426                        mList[mission_num].services[conditional_1].input[i - 1] = pChild2->Attribute(buffer); 
     1427 
    13901428                    char buffer2[9]="output"; 
    13911429                    sprintf(buffer2, "%s%d", buffer2, i);  
    1392                     if(pChild4->Attribute(buffer2)) 
    1393                     mList[mission_num].services[service_num].output[i-1] = pChild4->Attribute(buffer2); 
     1430                    if(pChild2->Attribute(buffer2)) 
     1431                        mList[mission_num].services[conditional_1].output[i - 1] = pChild2->Attribute(buffer2); 
    13941432                } 
    1395                 if(pChild4->Attribute("parameter")) 
    1396                 mList[mission_num].services[service_num].parameter = pChild4->Attribute("parameter"); 
    1397                 cond_array[2]++; 
     1433 
     1434                if(pChild2->Attribute("parameter")) 
     1435                    mList[mission_num].services[conditional_1].parameter = pChild2->Attribute("parameter"); 
     1436 
     1437                mList[mission_num].services[conditional_1].num_conds = cond_array[1]; 
     1438                cond_array[0] += cond_array[1] + 1; 
     1439                cond_array[1] = 0; 
    13981440            } 
    1399             if(!strcmp(pChild3->Value(), "shell") || conditional_2 != service_num) { 
    1400                 mList[mission_num].services[conditional_2].name = pChild3->Value(); 
     1441         
     1442            if(!strcmp(pChild1->Value(), "shell") || conditional_0 != service_num) { 
     1443                mList[mission_num].services[conditional_0].name = pChild1->Value(); 
     1444            } else{ 
     1445                mList[mission_num].services[conditional_0].name = pChild1->Attribute("name"); 
    14011446            } 
    1402             else{ 
    1403                 mList[mission_num].services[service_num].name = pChild3->Attribute("name"); 
    1404             } 
    1405             for(int i = 1; i <= 10; i++) { 
     1447 
     1448            for(size_t i = 1; i <= 10; i++) { 
    14061449                char buffer[9]="input"; 
    14071450                sprintf(buffer, "%s%d", buffer, i);  
    1408                 if(pChild3->Attribute(buffer)) 
    1409                 mList[mission_num].services[conditional_2].input[i-1] = pChild3->Attribute(buffer); 
     1451                if(pChild1->Attribute(buffer)) 
     1452                    mList[mission_num].services[conditional_0].input[i-1] = pChild1->Attribute(buffer); 
     1453 
    14101454                char buffer2[9]="output"; 
    14111455                sprintf(buffer2, "%s%d", buffer2, i);  
    1412                 if(pChild3->Attribute(buffer2)) 
    1413                 mList[mission_num].services[conditional_2].output[i-1] = pChild3->Attribute(buffer2); 
     1456                if(pChild1->Attribute(buffer2)) 
     1457                    mList[mission_num].services[conditional_0].output[i-1] = pChild1->Attribute(buffer2); 
    14141458            } 
    1415                 if(pChild3->Attribute("parameter")) 
    1416                 mList[mission_num].services[conditional_2].parameter = pChild3->Attribute("parameter"); 
    1417             mList[mission_num].services[conditional_2].num_conds = cond_array[2]; 
    1418             cond_array[1]+=cond_array[2]+1; 
    1419             cond_array[2] = 0; 
    1420  
    1421  
     1459 
     1460            if(pChild1->Attribute("parameter")) 
     1461                mList[mission_num].services[conditional_0].parameter = pChild1->Attribute("parameter"); 
     1462            mList[mission_num].services[conditional_0].num_conds = cond_array[0]; 
     1463                cond_array[0] = 0; 
     1464 
     1465            service_num++; 
    14221466        } 
    1423         if(!strcmp(pChild2->Value(), "shell") || conditional_1 != service_num) { 
    1424             mList[mission_num].services[conditional_1].name = pChild2->Value(); 
     1467     
     1468        mList[mission_num].numServices = service_num; 
     1469        mList[mission_num].name = pChild0->Attribute("name"); 
     1470        mList[mission_num].missionID = atoi(pChild0->Attribute("id")); 
     1471 
     1472        for(size_t i = 1; i <= 10; i++) { 
     1473            char buffer[9]="param"; 
     1474            sprintf(buffer, "%s%d", buffer, i);  
     1475            if(pChild0->Attribute(buffer)){ 
     1476                mList[mission_num].input[i-1] = pChild0->Attribute(buffer); 
     1477            } 
    14251478        } 
    1426         else{ 
    1427             mList[mission_num].services[service_num].name = pChild2->Attribute("name"); 
    1428         } 
    1429            for(int i = 1; i <= 10; i++) { 
    1430             char buffer[9]="input"; 
    1431             sprintf(buffer, "%s%d", buffer, i);  
    1432             if(pChild2->Attribute(buffer)) 
    1433                 mList[mission_num].services[conditional_1].input[i-1] = pChild2->Attribute(buffer); 
    1434             char buffer2[9]="output"; 
    1435             sprintf(buffer2, "%s%d", buffer2, i);  
    1436             if(pChild2->Attribute(buffer2)) 
    1437             mList[mission_num].services[conditional_1].output[i-1] = pChild2->Attribute(buffer2); 
    1438         } 
    1439             if(pChild2->Attribute("parameter")) 
    1440             mList[mission_num].services[conditional_1].parameter = pChild2->Attribute("parameter"); 
    1441  
    1442         mList[mission_num].services[conditional_1].num_conds = cond_array[1]; 
    1443         cond_array[0]+=cond_array[1]+1; 
    1444         cond_array[1] = 0; 
    1445         } 
    1446          
    1447         if(!strcmp(pChild1->Value(), "shell") || conditional_0 != service_num) { 
    1448             mList[mission_num].services[conditional_0].name = pChild1->Value(); 
    1449         } 
    1450         else{ 
    1451         mList[mission_num].services[conditional_0].name = pChild1->Attribute("name"); 
    1452         } 
    1453         for(int i = 1; i <= 10; i++) { 
    1454             char buffer[9]="input"; 
    1455             sprintf(buffer, "%s%d", buffer, i);  
    1456             if(pChild1->Attribute(buffer)) 
    1457                 mList[mission_num].services[conditional_0].input[i-1] = pChild1->Attribute(buffer); 
    1458             char buffer2[9]="output"; 
    1459             sprintf(buffer2, "%s%d", buffer2, i);  
    1460             if(pChild1->Attribute(buffer2)) 
    1461             mList[mission_num].services[conditional_0].output[i-1] = pChild1->Attribute(buffer2); 
    1462         } 
    1463         if(pChild1->Attribute("parameter")) 
    1464             mList[mission_num].services[conditional_0].parameter = pChild1->Attribute("parameter"); 
    1465         mList[mission_num].services[conditional_0].num_conds = cond_array[0]; 
    1466             cond_array[0] = 0; 
    1467         service_num++; 
    1468     } 
    1469      
    1470     mList[mission_num].numServices = service_num; 
    1471     mList[mission_num].name = pChild0->Attribute("name"); 
    1472         mList[mission_num].missionID = atoi(pChild0->Attribute("id")); 
    1473     for(int i = 1; i <= 10; i++) { 
    1474         char buffer[9]="param"; 
    1475         sprintf(buffer, "%s%d", buffer, i);  
    1476         if(pChild0->Attribute(buffer)){ 
    1477             mList[mission_num].input[i-1] = pChild0->Attribute(buffer); 
    1478         } 
    1479     } 
    1480     mission_num++; 
    1481     } 
     1479 
     1480        mission_num++; 
     1481    } 
     1482 
    14821483    LOG("ServiceManagementLayer:: Done Loading Configuration\n"); 
    14831484} 
     
    15131514 * 
    15141515 * DESCRIPTION: Deletes individual services from the DB 
    1515  * NOTE THAT this function only needs to be called if service deregistration is going 
     1516 * NOTE THAT this function only needs to be called ifservice deregistration is going 
    15161517 * to be done at a different time than component deregistration; it is handled 
    15171518 * more efficiently and directly during that deregistration process. 
     
    15261527    _services_DB->command.append(_services_DB->tablename); 
    15271528    _services_DB->command.append(" WHERE ID_Num IN (SELECT "); 
     1529 
    15281530    char tmp[3]; 
    15291531    memset(tmp,0,3); 
     
    15361538    _services_DB->command.append(buffer); 
    15371539    _services_DB->command.append("');"); 
     1540 
    15381541    char *errorMsg; 
    1539     int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 
    1540     if( rc!=SQLITE_OK && rc!=101 ) 
    1541         fprintf(stderr, "SQL error: %s\n", errorMsg); 
     1542    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 
     1543    if((rc != SQLITE_OK) && (rc != 101)) 
     1544        WARNING("SQL error: %s\n", errorMsg); 
    15421545} 
    15431546 
     
    15641567    SendMessage(CE_List[ID].FD, buffer); 
    15651568    if(strcmp("deregister_ack", buffer) != 0) { 
    1566     ERROR(1, "SML:: Failed to close CE socket\n"); 
     1569        ERROR(1, "SML:: Failed to close CE socket\n"); 
    15671570    } 
    15681571 
     
    15731576    _services_DB->command.append("ID_Num"); 
    15741577    _services_DB->command.append("=="); 
     1578 
    15751579    char tmp[3]; 
    15761580    memset(tmp,0,3); 
     
    15781582    _services_DB->command.append(tmp); 
    15791583    _services_DB->command.append(";"); 
     1584 
    15801585    char *errorMsg; 
    1581     int rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 
    1582     if( rc!=SQLITE_OK && rc!=101 ) 
    1583         fprintf(stderr, "SQL error: %s\n", errorMsg); 
    1584  
     1586    int32_t rc = sqlite3_exec(_services_DB->db, _services_DB->command.c_str(), callback, 0, &errorMsg); 
     1587    if((rc != SQLITE_OK) && (rc != 101)) 
     1588        WARNING("SQL error: %s\n", errorMsg); 
    15851589 
    15861590    CE_List[ID].FD = -1; 
     
    16001604ServiceManagementLayer::StartSMLServer() 
    16011605{ 
    1602     //printf("Ready for CE Signal! (registration done)\n"); 
    16031606    struct timeval selTimeout; 
    16041607    int32_t running = 1; 
    16051608    int32_t port, rc, new_sd = 1; 
    16061609    int32_t desc_ready = 1; 
    1607         //If there is, call the MessageHandler with the Shell_Msg code of -1 
    16081610    fd_set sockSet, shellSet; 
    16091611 
     
    16141616        ERROR(1,"Error initializing primary port\n"); 
    16151617 
    1616      
    16171618    while (running) { 
    16181619        /* Zero socket descriptor vector and set for server sockets */ 
     
    16221623         
    16231624        for(uint16_t k = 0; k < Current_ID; k++){ 
    1624         if(CE_List[k].ID_num != -1) 
    1625             FD_SET(CE_List[k].FD, &sockSet); 
    1626     } 
    1627         //printf("k=%d, CID=%d\n", k, CE_List[k].FD); 
     1625            if(CE_List[k].ID_num != -1) 
     1626                FD_SET(CE_List[k].FD, &sockSet); 
     1627        } 
    16281628 
    16291629        /* Timeout specification */ 
    16301630        /* This must be reset every time select() is called */ 
    1631         selTimeout.tv_sec = 0;       /* timeout (secs.) */ 
    1632         selTimeout.tv_usec = 0;            /* 0 microseconds */ 
    1633     //Changed both to zero so that select will check messages from the shell instead of blocking 
    1634     //when there is no command from the CE's to be processed 
    1635  
    1636         //Check if there is a message on the socket waiting to be read 
    1637     rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout);  
    1638         //printf("rc=%d\n", rc); 
    1639         if(rc == 0){ 
    1640             //LOG("No echo requests for %i secs...Server still alive\n", 10); 
    1641      
     1631        selTimeout.tv_sec = 0;      /* timeout (secs.) */ 
     1632        selTimeout.tv_usec = 0;     /* 0 microseconds */ 
     1633 
     1634        /* Changed both to zero so that select will check messages from the shell 
     1635         * instead of blocking when there is no command from the CE's to be processed */ 
     1636 
     1637        /* Check ifthere is a message on the socket waiting to be read */ 
     1638        rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout);  
     1639        if(rc == 0) { 
    16421640            FD_ZERO(&shellSet); 
    16431641            FD_SET(shellSocketFD, &shellSet); 
    16441642            selTimeout.tv_sec = 0; 
    16451643            selTimeout.tv_usec = 0; 
    1646             //Check if there is a message on the shell socket ready to be processed 
     1644            /* Check ifthere is a message on the shell socket ready to be processed */ 
    16471645            select(shellSocketFD + 1, &shellSet, NULL, NULL, &selTimeout); 
    1648             //printf("rc2=%d\n", rc2); 
    1649         //If there is, call the MessageHandler with the Shell_Msg code of -1 
    1650         if(FD_ISSET(shellSocketFD, &shellSet)){ 
    1651         //printf("shell_msg, %d\n", rc2); 
    1652             MessageHandler(-1);} 
    1653     } 
    1654         else {  
     1646            if(FD_ISSET(shellSocketFD, &shellSet)){ 
     1647                MessageHandler(-1);} 
     1648        } else {  
    16551649            desc_ready = rc; 
    16561650            for(port = 0; port <= maxDescriptor && desc_ready > 0; port++) { 
     
    16581652                    desc_ready -= 1; 
    16591653 
    1660                     //Check if request is new or on an existing open descriptor 
     1654                    /* Check ifrequest is new or on an existing open descriptor */ 
    16611655                    if(port == cogEngSrv) {  
    1662             //If new, assign it a descriptor and give it an ID 
     1656                        /* If new, assign it a descriptor and give it an ID */ 
    16631657                        new_sd = AcceptTCPConnection(port); 
    16641658              
     
    16671661 
    16681662                        CE_List[Current_ID].FD = new_sd; 
    1669             CE_List[Current_ID].ID_num = Current_ID; 
     1663                        CE_List[Current_ID].ID_num = Current_ID; 
    16701664                        MessageHandler(Current_ID); 
    1671             Current_ID++; 
     1665                        Current_ID++; 
    16721666     
    1673             FD_SET(new_sd,&sockSet); 
     1667                        FD_SET(new_sd,&sockSet); 
    16741668                        if(new_sd > maxDescriptor)  
    16751669                           maxDescriptor = new_sd; 
    1676                     }  
    1677                     else { 
    1678             //If old, figure out which ID it coresponds to and handle it accordingly 
    1679             for(uint16_t z = 0; z < Current_ID; z++) 
    1680             { 
    1681                 if(CE_List[z].FD == port){ 
    1682                     MessageHandler(z);} 
    1683             } 
     1670                    } else { 
     1671                        /* If old, figure out which ID it coresponds to and handle it accordingly */ 
     1672                        for(size_t z = 0; z < Current_ID; z++) { 
     1673                            if(CE_List[z].FD == port) { 
     1674                                MessageHandler(z); 
     1675                            } 
     1676                        } 
    16841677                    } 
    16851678                } 
    16861679            } 
    1687     } 
     1680        } 
    16881681    }         
    16891682 
     
    16911684    close(cogEngSrv); 
    16921685 
    1693     //delete &cogEngSrv; 
    16941686    return; 
    16951687} 
     1688