Changeset 294

Show
Ignore:
Timestamp:
06/23/09 15:22:35 (15 years ago)
Author:
wrodgers
Message:

Added nested conditionals, service paramaters, more dynamic conditional checking, and some minor reworks of the data storage backend

Files:
1 modified

Legend:

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

    r293 r294  
    1616 */ 
    1717 
    18 //TODO Add nested conditional support 
    19 //TODO Verify update functionality 
    20 //TODO Better shutdown 
    21 //TODO Verify Deregister services 
    22 //TODO printf's  
    2318 
    2419#include <stdlib.h> 
     
    145140    miss = new Mission[10]; 
    146141    for(int i = 0; i < 10; i++) 
    147         miss[i].services = new Service[20]; 
     142        miss[i].services = new Service[30]; 
    148143 
    149144    Current_ID = 0; 
     
    467462 
    468463//Modified to check the incoming message buffer rather than the outgoing message buffer to avoid a portion of the delay 
     464//May change this again to handle data more inteligently, taking advantage of it's properties. 
    469465void  
    470466ServiceManagementLayer::TransferRadioConfiguration(int32_t ID) 
     
    505501 
    506502//Modified to check the incoming message buffer rather than the outgoing message buffer to avoid a portion of the delay 
     503//May change this again to handle data more inteligently, taking advantage of it's properties. 
    507504void  
    508505ServiceManagementLayer::TransferExperience(int32_t ID) 
     
    653650    char* cols[] = {(char *)"Tag", (char *)"Data"}; 
    654651    int i = 0; 
    655     fd_set sockSet; 
    656652    char *token; 
    657     struct timeval selTimeout; 
    658653 
    659654   //Send a message directly to the shell 
     
    661656   if(miss[activeMission].services[sourceID].name.find("shell")!=string::npos) 
    662657   { 
    663         //printf("caught shell\n"); 
    664658        //If the name on the output doesn't start with "~", search the DB to find the output that should be returned 
    665659        if(miss[activeMission].services[sourceID].output[0].find("~") == string::npos){ 
     
    679673                else { 
    680674                    //TODO could do shell output here if not in DB 
    681                 data.append("1@"); 
    682                 data.append(miss[activeMission].services[sourceID].output[0]); 
    683                 data.append("@"); 
     675                data.append("1@output1@"); 
    684676                data.append(miss[activeMission].services[sourceID].output[0]); 
    685677                data.append("@"); 
    686678                //printf("data = %s\n", data.c_str()); 
    687679                 
    688                     printf("data_DB:: Data not yet in DB.\n"); 
     680                    //printf("2222data_DB:: Data not yet in DB.\n"); 
    689681                    rc=31337; 
    690682                } 
     
    707699   }  
    708700 
    709  
    710701    //If this is a service command and not a shell command... 
    711702    //Transmission starting messages 
    712703    SendMessage(miss[activeMission].services[sourceID].socketFD, "request_optimization_service"); 
    713704    SendMessage(miss[activeMission].services[sourceID].socketFD, miss[activeMission].services[sourceID].name.c_str()); 
    714     //Find and load the input data 
     705 
     706   //If the service takes a paramater, feed that paramater in 
     707   if(!miss[activeMission].services[sourceID].paramater.empty()){ 
     708        //printf("sending parameter!\n"); 
     709        SendMessage(miss[activeMission].services[sourceID].socketFD, "1"); 
     710        SendMessage(miss[activeMission].services[sourceID].socketFD, "parameter"); 
     711        SendMessage(miss[activeMission].services[sourceID].socketFD, miss[activeMission].services[sourceID].paramater.c_str()); 
     712    } 
     713 
     714 
     715    //Load and transmit the input data 
    715716    while(i < 5 && !miss[activeMission].services[sourceID].input[i].empty()){ 
    716         //printf("pulling input data out of DB for ID#=%d\n", sourceID); 
    717717        strcpy(_data_DB->command, "select "); 
    718718        strcat(_data_DB->command, _data_DB->tablename); 
     
    720720        strcat(_data_DB->command, _data_DB->tablename); 
    721721        strcat(_data_DB->command, " where Tag=="); 
    722         char temp[100]; 
    723         strcpy(temp, miss[activeMission].services[sourceID].input[i].c_str()); 
    724         char *temp2 = strtok(temp, "+"); 
    725         sprintf(_data_DB->command, "%s'%s';", _data_DB->command, temp2); 
     722        sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].services[sourceID].input[i].c_str()); 
    726723        sqlite3_stmt * pStatement; 
    727724        int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); 
     
    738735        } 
    739736        sqlite3_finalize(pStatement); 
    740         char *data_ch = (char *) data.c_str(); 
    741         int32_t numStatements = 0; 
    742         temp2 = strtok(NULL, "+"); 
    743         while(temp2){ 
    744             numStatements++; 
    745             temp2 = strtok(NULL, "+"); 
    746         } 
    747         //printf("here1%d\n", numStatements); 
    748         char temp4[10]; 
    749         memset(temp4, 0, 10); 
    750         sprintf(temp4, "%d", numStatements); 
    751         //Tokenize the data and pass it along 
    752         //printf("here2 %s\n", temp4); 
    753         if(strstr(miss[activeMission].services[sourceID].input[i].c_str(), "+")){ 
    754             SendMessage(miss[activeMission].services[sourceID].socketFD, temp4); 
    755             token = strtok(data_ch, "@"); 
    756         } 
    757         else{ 
    758             token = strtok(data_ch, "@"); 
     737 
     738            token = strtok((char *)data.c_str(), "@"); 
     739        while(token){ 
    759740            SendMessage(miss[activeMission].services[sourceID].socketFD, token); 
    760         } 
    761         token = strtok(NULL, "@"); 
    762  
    763  
    764         //Either have to send whole block of memory or just one piece 
    765         while(token){ 
    766             if(strstr(miss[activeMission].services[sourceID].input[i].c_str(), token)) 
    767             { 
    768                 //printf("1tokenizing %s %s!\n", miss[activeMission].services[sourceID].input[i].c_str(), token); 
    769                 SendMessage(miss[activeMission].services[sourceID].socketFD, token); 
    770                 token = strtok(NULL, "@"); 
    771                 SendMessage(miss[activeMission].services[sourceID].socketFD, token); 
    772             } 
    773             else if(!strstr(miss[activeMission].services[sourceID].input[i].c_str(), "+")) 
    774             { 
    775                 //printf("t not detected tokenizing %s %s!\n", miss[activeMission].services[sourceID].input[i].c_str(), token); 
    776                 SendMessage(miss[activeMission].services[sourceID].socketFD, token); 
    777                 token = strtok(NULL, "@"); 
    778                 SendMessage(miss[activeMission].services[sourceID].socketFD, token); 
    779             } 
    780             else{ 
    781                 //printf("3tokenizing %s %s!\n", miss[activeMission].services[sourceID].input[i].c_str(), token); 
    782                 token = strtok(NULL, "@");} 
    783741            token = strtok(NULL, "@"); 
    784742        } 
    785         //printf("done\n"); 
    786         //printf("done pulling input data out of DB for ID#=%d\n", sourceID); 
    787743        i++; 
    788744        data.clear(); 
    789745    } 
    790746    int32_t j = 0; 
    791     FD_ZERO(&sockSet); 
    792     FD_SET(miss[activeMission].services[sourceID].socketFD, &sockSet); 
    793     //TODO neccessary? 
    794     selTimeout.tv_sec = 5; 
    795     selTimeout.tv_usec = 0; 
    796     //Use select command to force wait for processing to finish 
    797     select(miss[activeMission].services[sourceID].socketFD + 1, &sockSet, NULL, NULL, &selTimeout); 
    798         //printf("done\n"); 
    799    //TODO rewrite part of data on output? 
    800    //TODO true false format? 
     747     
     748    //Receive and store the output data 
    801749    while(j < 5 && !miss[activeMission].services[sourceID].output[j].empty()){ 
    802750        int rc; 
    803751        memset(buffer, 0, 256); 
     752        //Read the number of datapairs for this output 
    804753        ReadMessage(miss[activeMission].services[sourceID].socketFD, buffer); 
    805        // printf("waiting\n");       
    806754        data.append(buffer); 
    807755        data.append("@"); 
    808756        int t = atoi(buffer); 
    809         //printf("%d\n", t); 
    810757        for(int k = 0; k < t; k++){ 
    811             //Read the data incrementally and deliminate it with the "@" symbol 
     758            //Read the datapairs incrementally and deliminate it with the "@" symbol 
    812759            memset(buffer, 0, 256); 
    813760            ReadMessage(miss[activeMission].services[sourceID].socketFD, buffer); 
    814             if(!strcmp(buffer, "TF")){ 
    815                 ReadMessage(miss[activeMission].services[sourceID].socketFD, buffer); 
    816                 data.append(buffer); 
    817                 data.append("@"); 
    818             } 
    819             else{ 
    820                 data.append(buffer); 
    821                 data.append("@"); 
    822                 memset(buffer, 0, 256); 
    823                 ReadMessage(miss[activeMission].services[sourceID].socketFD, buffer); 
    824                 data.append(buffer); 
    825                 data.append("@"); 
    826             } 
     761            data.append(buffer); 
     762            data.append("@"); 
     763            memset(buffer, 0, 256); 
     764            ReadMessage(miss[activeMission].services[sourceID].socketFD, buffer); 
     765            data.append(buffer); 
     766            data.append("@"); 
    827767        } 
    828         //printf("SML: putting output data into DB for ID#=%d\n", sourceID); 
    829768 
    830769        strcpy(_data_DB->command, "insert or replace into "); 
     
    884823 * -Five inputs/outputs per service and per mission 
    885824 * -All ordering constraints have been relaxed in this version; all data is stored locally and only sent when requested 
    886  * -If support fully implemented - up to three levels 
    887  * -While support still a work in progress 
     825 * -If and while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot) 
     826 * -For dowhiles, assumes loop condition determined on next to last line (last line is a shell statement to keep the application updated) 
    888827 * -IMPORTANT: DB uses '@' to seperate individual statements; using '@' in the data stream will result in incorrect behavior 
    889828 */ 
    890829 
    891 //IF-IF-IF 
    892830//WHILE 
    893831void 
     
    908846    ReadMessage(shellSocketFD, buffer); 
    909847    LOG("ServiceManagementLayer:: Received PerformActiveMission command.\n"); 
    910  
     848    //TODO this whole section needs to be reworked depending on how relevent data is actually transmitted from the app to the shell to the SML 
    911849    int32_t t = atoi(buffer); 
    912850    /* Receive Set of Observables */ 
     
    957895 
    958896 
    959  
     897    //Receive any other defined inputs 
    960898    while(i < 5 && !miss[activeMission].input[i].empty()){ 
    961899            //New data being added to DB 
     
    1054992                    token = strtok(NULL, "@"); 
    1055993                    //printf("data=%s\n", token); 
     994                data.clear(); 
    1056995                    break; 
    1057996                } 
     
    1059998            //printf("L0:--- %s  %s---\n", miss[activeMission].services[i].output[t].c_str(), token); 
    1060999            //TODO change to strstr 
    1061             if(strstr(miss[activeMission].services[i].output[t].c_str(), token)){ 
     1000 
     1001            bool doit = false; 
     1002            if(miss[activeMission].services[i].output[t].find(">") != string::npos){ 
     1003                //printf("foundit!\n"); 
     1004                    strcpy(_data_DB->command, "SELECT "); 
     1005                    strcat(_data_DB->command, _data_DB->tablename); 
     1006                    strcat(_data_DB->command, ".* from "); 
     1007                    strcat(_data_DB->command, _data_DB->tablename); 
     1008                strcat(_data_DB->command, " where Tag=="); 
     1009                    miss[activeMission].services[i].output[t].erase(0, 1); 
     1010            //printf("here! %s\n", miss[activeMission].services[i].output[t].c_str()); 
     1011                    sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].services[i].output[t].c_str()); 
     1012                    sqlite3_stmt * pStatement; 
     1013                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); 
     1014                    if (rc == SQLITE_OK){  
     1015                        if (sqlite3_step(pStatement) == SQLITE_ROW) 
     1016                             data = (const char *) sqlite3_column_text(pStatement, 1);  
     1017                        else { 
     1018                                printf("1 data_DB:: Data not yet in DB.\n"); 
     1019                                rc=31337; 
     1020                        } 
     1021                    } else { 
     1022                        printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); 
     1023                    } 
     1024                            sqlite3_finalize(pStatement); 
     1025                    token = strtok((char *)data.c_str(), "@"); 
     1026                    token = strtok(NULL, "@"); 
     1027                    token = strtok(NULL, "@"); 
     1028                    if(atof(buffer) > atof(token)) 
     1029                        doit=true; 
     1030                    //printf("%s %s\n", buffer, token); 
     1031                data.clear(); 
     1032            } 
     1033            else if (strstr(miss[activeMission].services[i].output[t].c_str(), token)) 
     1034                doit=true; 
     1035            if(doit){ 
     1036            //if(strstr(miss[activeMission].services[i].output[t].c_str(), token)){ 
    10621037                //printf("L0:if taken\n"); 
    10631038                for(uint16_t k = i+1; k <= i+miss[activeMission].services[i].num_conds; k++){  
     
    10961071                                    token = strtok(NULL, "@"); 
    10971072                                    //printf("data=%s\n", token); 
     1073                                    data.clear(); 
    10981074                                    break; 
    10991075                                } 
     
    11011077                            //printf("L1:--- %s  %s---\n", miss[activeMission].services[k].output[t].c_str(), token); 
    11021078                            //TODO change to strstr 
    1103                             if(strstr(miss[activeMission].services[k].output[t].c_str(), token)){ 
     1079                            bool doit = false; 
     1080                                //printf("here! %s\n", miss[activeMission].services[k].output[t].c_str()); 
     1081                            if(miss[activeMission].services[k].output[t].find(">") != string::npos){ 
     1082                                    strcpy(_data_DB->command, "SELECT "); 
     1083                                    strcat(_data_DB->command, _data_DB->tablename); 
     1084                                    strcat(_data_DB->command, ".* from "); 
     1085                                    strcat(_data_DB->command, _data_DB->tablename); 
     1086                                    strcat(_data_DB->command, " where Tag=="); 
     1087                                    miss[activeMission].services[k].output[t].erase(0, 1); 
     1088                                    sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].services[k].output[t].c_str()); 
     1089                                    sqlite3_stmt * pStatement; 
     1090                                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); 
     1091                                    if (rc == SQLITE_OK){  
     1092                                        if (sqlite3_step(pStatement) == SQLITE_ROW) 
     1093                                             data = (const char *) sqlite3_column_text(pStatement, 1);  
     1094                                        else { 
     1095                                                printf("1 data_DB:: Data not yet in DB.\n"); 
     1096                                                rc=31337; 
     1097                                        } 
     1098                                    } else { 
     1099                                        printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); 
     1100                                    } 
     1101                                    sqlite3_finalize(pStatement); 
     1102                                    token = strtok((char *)data.c_str(), "@"); 
     1103                                    token = strtok(NULL, "@"); 
     1104                                    token = strtok(NULL, "@"); 
     1105                                if(atof(buffer) > atof(token)) 
     1106                                    doit=true; 
     1107                                data.clear(); 
     1108                            } 
     1109                            else if (strstr(miss[activeMission].services[k].output[t].c_str(), token)) 
     1110                                doit=true; 
     1111                            if(doit){ 
    11041112                                //printf("L1:if taken\n"); 
    11051113                                for(uint16_t j = k+1; j <= k+miss[activeMission].services[k].num_conds; j++){  
     
    11381146                                                    token = strtok(NULL, "@"); 
    11391147                                                    //printf("data=%s\n", token); 
     1148                                                    data.clear(); 
    11401149                                                    break; 
    11411150                                                } 
     
    11431152                                            //printf("L2:--- %s  %s---\n", miss[activeMission].services[j].output[t].c_str(), token); 
    11441153                                            //TODO change to strstr 
    1145                                             if(strstr(miss[activeMission].services[j].output[t].c_str(), token)){ 
     1154                                            bool doit = false; 
     1155                                                //printf("here! %s\n", miss[activeMission].services[j].output[t].c_str()); 
     1156                                            if(miss[activeMission].services[j].output[t].find(">") != string::npos){ 
     1157                                                    strcpy(_data_DB->command, "SELECT "); 
     1158                                                    strcat(_data_DB->command, _data_DB->tablename); 
     1159                                                    strcat(_data_DB->command, ".* from "); 
     1160                                                    strcat(_data_DB->command, _data_DB->tablename); 
     1161                                                    strcat(_data_DB->command, " where Tag=="); 
     1162                                                    miss[activeMission].services[k].output[t].erase(0, 1); 
     1163                                        sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].services[j].output[t].c_str()); 
     1164                                                    sqlite3_stmt * pStatement; 
     1165                                                    rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); 
     1166                                                    if (rc == SQLITE_OK){  
     1167                                                        if (sqlite3_step(pStatement) == SQLITE_ROW) 
     1168                                                             data = (const char *) sqlite3_column_text(pStatement, 1);  
     1169                                                        else { 
     1170                                                                printf("1 data_DB:: Data not yet in DB.\n"); 
     1171                                                                rc=31337; 
     1172                                                        } 
     1173                                                    } else { 
     1174                                                        printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); 
     1175                                                    } 
     1176                                                    sqlite3_finalize(pStatement); 
     1177                                                    token = strtok((char *)data.c_str(), "@"); 
     1178                                                    token = strtok(NULL, "@"); 
     1179                                                    token = strtok(NULL, "@"); 
     1180                                                if(atof(buffer) > atof(token)) 
     1181                                                    doit=true; 
     1182                                                data.clear(); 
     1183                                            } 
     1184                                            else if (strstr(miss[activeMission].services[k].output[t].c_str(), token)) 
     1185                                                doit=true; 
     1186                                            if(doit){ 
    11461187                                                //printf("L1:if taken\n"); 
    11471188                                                for(uint16_t l = j+1; l <= j+miss[activeMission].services[j].num_conds; l++){  
     
    11551196                                                j+=miss[activeMission].services[j].num_conds; 
    11561197                                            //printf("doneif %d, %d, %d\n", numstatements, miss[activeMission].services[i].num_conds, i); 
     1198                                        }else if(miss[activeMission].services[j].name.compare("dowhile")==0){ 
     1199                                            numstatements[0]=0; 
     1200                                            printf("L2 while detected\n"); 
     1201                                            while(true){ 
     1202                                                uint16_t l; 
     1203                                                    for(l = j+1; l <= j+miss[activeMission].services[j].num_conds; l++){  
     1204                                                        TransactData(l); 
     1205                                                        printf("l=%d\n", l); 
     1206                                                    } 
     1207                                                    data.clear(); 
     1208                                                    //printf("L0:while detected %d, %d\n", k, miss[activeMission].services[i].num_conds); 
     1209                                                    input.clear(); 
     1210                                                    check.clear(); 
     1211                                                    int t; 
     1212                                                    for(t = 0; t < 5; t++){ 
     1213                                                        if(!miss[activeMission].services[j].output[t].empty()){ 
     1214                                                            input=miss[activeMission].services[l-2].output[t]; 
     1215                                                            //printf("input=%s\n", input.c_str()); 
     1216                                                            strcpy(_data_DB->command, "SELECT "); 
     1217                                                            strcat(_data_DB->command, _data_DB->tablename); 
     1218                                                            strcat(_data_DB->command, ".* from "); 
     1219                                                            strcat(_data_DB->command, _data_DB->tablename); 
     1220                                                            strcat(_data_DB->command, " where Tag=="); 
     1221                                                            sprintf(_data_DB->command, "%s'%s';", _data_DB->command, input.c_str()); 
     1222                                                            sqlite3_stmt * pStatement; 
     1223                                                            rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL); 
     1224                                                            if (rc == SQLITE_OK){  
     1225                                                                if (sqlite3_step(pStatement) == SQLITE_ROW) 
     1226                                                                     data = (const char *) sqlite3_column_text(pStatement, 1);  
     1227                                                                else { 
     1228                                                                        printf("1 data_DB:: Data not yet in DB.\n"); 
     1229                                                                        rc=31337; 
     1230                                                                } 
     1231                                                            } else { 
     1232                                                                printf("data_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command); 
     1233                                                            } 
     1234                                                            sqlite3_finalize(pStatement); 
     1235                                                            //printf("data=%s\n", data.c_str()); 
     1236                                                            token = strtok((char *)data.c_str(), "@"); 
     1237                                                            token = strtok(NULL, "@"); 
     1238                                                            token = strtok(NULL, "@"); 
     1239                                                            //printf("data=%s\n", token); 
     1240                                                            break; 
     1241                                                        } 
     1242                                                    } 
     1243                                                    //printf("L2:--- %s  %s---\n", miss[activeMission].services[j].output[t].c_str(), token); 
     1244                                                    if(strstr(miss[activeMission].services[j].output[t].c_str(), token)){ 
     1245                                                        //printf("L2:while taken again!\n"); 
     1246                                                    } 
     1247                                                    else { 
     1248                                                        //printf("no more while\n"); 
     1249                                                        break;} 
     1250                                            } 
     1251                                            j+=miss[activeMission].services[j].num_conds; 
     1252                                            //printf("doneif\n"); 
    11571253                                        } 
    11581254                                        else{ 
     
    11681264                                k+=miss[activeMission].services[k].num_conds; 
    11691265                            //printf("doneif %d, %d, %d\n", numstatements, miss[activeMission].services[i].num_conds, i); 
    1170                         } else if(miss[activeMission].services[k].name.compare("dowhile")==0){ 
    1171                             //printf("while detected\n"); 
     1266                        }else if(miss[activeMission].services[k].name.compare("dowhile")==0){ 
     1267                            numstatements[0]=0; 
     1268                            //printf("L1 while detected\n"); 
    11721269                            while(true){ 
    1173                                 uint16_t m; 
    1174                                 for(uint16_t m = k+1; m <= k+miss[activeMission].services[k].num_conds; m++){  
    1175                                     TransactData(m); 
    1176                                     printf("transact! %d\n", m); 
    1177                                 } 
     1270                                uint16_t j; 
     1271                                    for(j = k+1; j <= k+miss[activeMission].services[k].num_conds; j++){  
     1272                                        TransactData(j); 
     1273                                    } 
    11781274                                    data.clear(); 
    1179                                     printf("L1:while detected %d, %d\n", miss[activeMission].services[k].num_conds, k); 
     1275                                    //printf("L0:while detected %d, %d\n", k, miss[activeMission].services[i].num_conds); 
    11801276                                    input.clear(); 
    11811277                                    check.clear(); 
    11821278                                    int t; 
    11831279                                    for(t = 0; t < 5; t++){ 
    1184                                         if(!miss[activeMission].services[k-1].output[t].empty()){ 
    1185                                             input=miss[activeMission].services[m].output[t]; 
     1280                                        if(!miss[activeMission].services[k].output[t].empty()){ 
     1281                                            input=miss[activeMission].services[j-2].output[t]; 
     1282                                            //printf("input=%s\n", input.c_str()); 
    11861283                                            strcpy(_data_DB->command, "SELECT "); 
    11871284                                            strcat(_data_DB->command, _data_DB->tablename); 
     
    12031300                                            } 
    12041301                                            sqlite3_finalize(pStatement); 
    1205                                             //printf("data=%s\n", data.c_str()); 
     1302                                           // printf("data=%s\n", data.c_str()); 
    12061303                                            token = strtok((char *)data.c_str(), "@"); 
    12071304                                            token = strtok(NULL, "@"); 
     
    12111308                                        } 
    12121309                                    } 
    1213                                     printf("L1:--- %s  %s---\n", miss[activeMission].services[k].output[t].c_str(), token); 
     1310                                    //printf("L1:--- %s  %s---\n", miss[activeMission].services[k].output[t].c_str(), token); 
    12141311                                    if(strstr(miss[activeMission].services[k].output[t].c_str(), token)){ 
    1215                                         printf("L1:do it again!\n"); 
     1312                                        //printf("L1:while taken again!\n"); 
    12161313                                    } 
    1217                                     else 
    1218                                         break; 
     1314                                    else { 
     1315                                        //printf("no more while\n"); 
     1316                                        break;} 
    12191317                            } 
    12201318                            k+=miss[activeMission].services[k].num_conds; 
    1221                             //printf("donewhile\n"); 
     1319                            //printf("doneif\n"); 
    12221320                        } 
    12231321                        else{ 
     
    12411339        { 
    12421340            numstatements[0]=0; 
    1243             //printf("while detected\n"); 
     1341            //printf("L0 while detected\n"); 
    12441342            while(true){ 
    12451343                uint16_t k; 
     
    12541352                    for(t = 0; t < 5; t++){ 
    12551353                        if(!miss[activeMission].services[i].output[t].empty()){ 
    1256                             input=miss[activeMission].services[k-1].output[t]; 
     1354                            input=miss[activeMission].services[k-2].output[t]; 
    12571355                            //printf("input=%s\n", input.c_str()); 
    12581356                            strcpy(_data_DB->command, "SELECT "); 
     
    12871385                        //printf("L0:while taken again!\n"); 
    12881386                    } 
    1289                     else 
    1290                         break; 
     1387                    else { 
     1388                        //printf("no more while\n"); 
     1389                        break;} 
    12911390            } 
    12921391            i+=miss[activeMission].services[i].num_conds; 
     
    13171416                 data.append((const char*) sqlite3_column_text(pStatement, 1));  
    13181417            else { 
    1319                     printf("data_DB:: Data not yet in DB.\n"); 
     1418                    printf("1data_DB:: Data not yet in DB.\n"); 
    13201419                    rc=31337; 
    13211420            } 
     
    13411440        data.clear(); 
    13421441    } 
    1343     LOG("ServiceManagementLayer:: Done sending output data to shell from PerformActiveMission.\n"); 
    1344     /*strcpy(_data_DB->command, "select "); 
     1442    /*LOG("ServiceManagementLayer:: Done sending output data to shell from PerformActiveMission.\n"); 
     1443    strcpy(_data_DB->command, "select "); 
    13451444    strcat(_data_DB->command, _data_DB->tablename); 
    13461445    strcat(_data_DB->command, ".* from "); 
     
    13941493    miss = new Mission[10]; 
    13951494    for(int i = 0; i < 10; i++) 
    1396         miss[i].services = new Service[20]; 
     1495        miss[i].services = new Service[30]; 
    13971496    LoadConfiguration(_SML_Config, miss); 
    13981497} 
     
    14441543        //memset(cond_array, 0, 2); 
    14451544         
    1446         for(pChild1  = pChild0->FirstChildElement(); pChild1; \ 
     1545        for(pChild1  = (pChild0->FirstChildElement())->FirstChildElement(); pChild1; \ 
    14471546            pChild1  = pChild1->NextSiblingElement())  
    14481547        { 
     
    14871586                            if(pChild4->Attribute("output5")) 
    14881587                                mList[mission_num].services[service_num].output[4] = pChild4->Attribute("output5"); 
     1588                            if(pChild4->Attribute("parameter")) 
     1589                                mList[mission_num].services[service_num].paramater = pChild4->Attribute("parameter"); 
    14891590                            cond_array[2]++; 
    14901591                        } 
     
    15151616                            if(pChild3->Attribute("output5")) 
    15161617                                mList[mission_num].services[conditional_2].output[4] = pChild3->Attribute("output5"); 
     1618                            if(pChild3->Attribute("parameter")) 
     1619                                mList[mission_num].services[conditional_2].paramater = pChild3->Attribute("parameter"); 
    15171620                        mList[mission_num].services[conditional_2].num_conds = cond_array[2]; 
    15181621                        cond_array[1]+=cond_array[2]+1; 
     
    15481651                    if(pChild2->Attribute("output5")) 
    15491652                        mList[mission_num].services[conditional_1].output[4] = pChild2->Attribute("output5"); 
     1653                    if(pChild2->Attribute("parameter")) 
     1654                        mList[mission_num].services[conditional_1].paramater = pChild2->Attribute("parameter"); 
    15501655 
    15511656                mList[mission_num].services[conditional_1].num_conds = cond_array[1]; 
     
    15811686                    mList[mission_num].services[conditional_0].output[3] = pChild1->Attribute("output4"); 
    15821687                if(pChild1->Attribute("output5")) 
    1583                     mList[mission_num].services[service_num].output[4] = pChild1->Attribute("output4"); 
     1688                    mList[mission_num].services[conditional_0].output[4] = pChild1->Attribute("output5"); 
     1689                if(pChild1->Attribute("parameter")) 
     1690                    mList[mission_num].services[conditional_0].paramater = pChild1->Attribute("parameter"); 
    15841691            mList[mission_num].services[conditional_0].num_conds = cond_array[0]; 
    15851692            cond_array[0] = 0; 
     
    15871694        } 
    15881695        //for(int i = 0; i < service_num; i++) 
    1589          //printf("ttt%d\n", mList[mission_num].services[i].num_conds); 
     1696        // printf("ttt%s\n",mList[mission_num].services[i].name.c_str()); 
    15901697         
    15911698        mList[mission_num].numServices = service_num;