Changeset 446
- Timestamp:
- 08/31/09 17:30:09 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
r445 r446 211 211 _services_DB->tablename="Services"; 212 212 213 /* Ifprogram execution ends in anything other than a ordered shutdown, DB's will still213 /* ifprogram execution ends in anything other than a ordered shutdown, DB's will still 214 214 * be there for next run. Need to get rid of it so that old data isn't inadvertantly 215 215 * used in the next execution cycle. */ 216 _services_DB->command = "DROP TABLE IFEXISTS Services;";216 _services_DB->command = "DROP TABLE ifEXISTS Services;"; 217 217 218 218 rc = sqlite3_prepare_v2(_services_DB->db, _services_DB->command.c_str(), 128, &ppStmt, &pzTail); … … 266 266 267 267 _data_DB->tablename = "Data"; 268 _data_DB->command = "DROP TABLE IFEXISTS Data;";268 _data_DB->command = "DROP TABLE ifEXISTS Data;"; 269 269 270 270 rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command.c_str(), 128, &ppStmt, &pzTail); … … 354 354 //printf("********* %s **********\n", buffer); 355 355 // TODO 356 // Ifwe send integer op codes rather than strings, this process will be356 // ifwe send integer op codes rather than strings, this process will be 357 357 // MUCH faster since instead of donig string compares we can simply 358 358 // switch on the integer value... … … 507 507 selTimeout.tv_usec = 5000; 508 508 509 /* Check if 509 /* Check ifthere is a message on the shell ready to be processed */ 510 510 rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); 511 511 } … … 548 548 selTimeout.tv_usec = 5000; 549 549 550 /* Check if 550 /* Check ifthere is a message on the shell ready to be processed */ 551 551 rc = select(shellSocketFD + 1, &sockSet, NULL, NULL, &selTimeout); 552 552 } … … 605 605 * services that are requested in the mission. Each service in the mission is given 606 606 * 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 608 * method is called it needs to be called again even if 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 609 609 */ 610 610 void … … 630 630 miss[activeMission].services[i].name.compare("dowhile") && \ 631 631 miss[activeMission].services[i].name.compare("shell")) { 632 /* Ifit is a service, search the database of registered services to find632 /* ifit is a service, search the database of registered services to find 633 633 * the ID of the component that registered it */ 634 634 _services_DB->command="select "; … … 644 644 -1, &pStatement, NULL); 645 645 if(rc == SQLITE_OK) { 646 if 646 if(sqlite3_step(pStatement) == SQLITE_ROW) 647 647 miss[activeMission].services[i].componentID = sqlite3_column_int(pStatement, 0); 648 648 else { … … 736 736 } 737 737 738 /* Ifthis is a service command and not a shell command... */738 /* ifthis is a service command and not a shell command... */ 739 739 /* Transmission starting messages */ 740 740 SendMessage(miss[activeMission].services[sourceID].socketFD, "request_optimization_service"); … … 758 758 * -All ordering constraints have been relaxed in this version; all data is stored 759 759 * locally and only sent when requested 760 * - Ifand 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) 761 761 * -For dowhiles, assumes loop condition determined on last line 762 762 * … … 844 844 data = (const char *) sqlite3_column_text(pStatement, 1); 845 845 else { 846 LOG("1 data_DB:: Data not yet in DB.\n");846 WARNING("1 data_DB:: Data not yet in DB.\n"); 847 847 rc=31337; 848 848 } 849 849 } 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", \ 851 851 rc,_data_DB->command.c_str()); 852 852 } … … 879 879 data2 = (const char *) sqlite3_column_text(pStatement, 1); 880 880 else { 881 LOG("2 data_DB:: Data not yet in DB.\n");881 WARNING("2 data_DB:: Data not yet in DB.\n"); 882 882 rc = 31337; 883 883 } 884 884 } 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", \ 886 886 rc, _data_DB->command.c_str()); 887 887 } … … 921 921 data = (const char *) sqlite3_column_text(pStatement, 1); 922 922 else { 923 LOG("3 data_DB:: Data not yet in DB.\n");923 WARNING("3 data_DB:: Data not yet in DB.\n"); 924 924 rc = 31337; 925 925 } 926 926 } 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", \ 928 928 rc,_data_DB->command.c_str()); 929 929 } … … 947 947 _data_DB->command.append(miss[activeMission].services[k].output[t].erase(0, 1)); 948 948 _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()); 957 963 } 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; 968 971 } 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) { 1062 978 input.clear(); 1063 979 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) { 1069 1018 _data_DB->command="SELECT "; 1070 1019 _data_DB->command.append(_data_DB->tablename); … … 1072 1021 _data_DB->command.append(_data_DB->tablename); 1073 1022 _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)); 1075 1024 _data_DB->command.append("';"); 1076 sqlite3_stmt * pStatement; 1077 1025 1026 sqlite3_stmt *pStatement; 1078 1027 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()); 1085 1038 } 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); 1088 1058 } 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;1096 1059 } 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 } 1097 1113 } 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); 1105 1119 } 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);1112 1120 } 1113 1121 } 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); 1128 1131 } 1132 1129 1133 data.clear(); 1130 1134 input.clear(); 1131 1135 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; 1151 1167 } 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) { 1161 1171 break; 1162 1172 } 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;}1171 1173 } 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); 1178 1179 } 1179 1180 } 1180 1181 } 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); 1192 1191 } 1192 1193 1193 data.clear(); 1194 1194 input.clear(); 1195 1195 check.clear(); 1196 int t;1196 int32_t t; 1197 1197 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; 1215 1227 } 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) { 1223 1231 break; 1224 1232 } 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;}1233 1233 } 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; 1239 1238 TransactData(i); 1240 1239 } … … 1244 1243 data.clear(); 1245 1244 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 } 1260 1259 1261 1260 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) command1270 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");*/1275 1261 } 1276 1262 … … 1291 1277 _services_DB->command.append(";"); 1292 1278 1293 // execute print (select all) command1279 // Execute print (select all) command 1294 1280 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()); 1299 1286 } 1300 1287 … … 1309 1296 { 1310 1297 LOG("ServiceManagementLayer:: Reloading Configuration.\n"); 1298 1311 1299 free(miss); 1300 1312 1301 miss = new Mission[10]; 1313 for( int i = 0; i < 10; i++)1302 for(size_t i = 0; i < 10; i++) 1314 1303 miss[i].services = new Service[30]; 1304 1315 1305 LoadConfiguration(_SML_Config.c_str(), miss); 1316 1306 } … … 1336 1326 TiXmlElement *pChild0, *pChild1, *pChild2, *pChild3, *pChild4; 1337 1327 TiXmlHandle hRoot(0); 1338 printf("ServiceManagementLayer:: Loading Configuration.\n"); 1328 1329 LOG("ServiceManagementLayer:: Loading Configuration.\n"); 1330 1339 1331 TiXmlDocument doc("."); 1340 1332 doc.LoadFile(SML_Config); 1341 1333 bool loadOkay = doc.LoadFile(); 1342 1334 if(!loadOkay) 1343 printf("Loading SML configuration failed: %s\n", SML_Config);1335 WARNING("Loading SML configuration failed: %s\n", SML_Config); 1344 1336 1345 1337 TiXmlHandle hDoc(&doc); … … 1348 1340 1349 1341 if(!pMission) 1350 printf("No valid root!");1342 WARNING("No valid root!"); 1351 1343 1352 1344 hRoot = TiXmlHandle(pMission); 1353 1345 pService = pMission->FirstChildElement(); 1346 1354 1347 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}; 1361 1353 1362 1354 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 1384 1422 for(int i = 1; i <= 10; i++) { 1385 1423 char buffer[9]="input"; 1386 1424 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 1390 1428 char buffer2[9]="output"; 1391 1429 sprintf(buffer2, "%s%d", buffer2, i); 1392 if(pChild 4->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); 1394 1432 } 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; 1398 1440 } 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"); 1401 1446 } 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++) { 1406 1449 char buffer[9]="input"; 1407 1450 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 1410 1454 char buffer2[9]="output"; 1411 1455 sprintf(buffer2, "%s%d", buffer2, i); 1412 if(pChild 3->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); 1414 1458 } 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++; 1422 1466 } 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 } 1425 1478 } 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 1482 1483 LOG("ServiceManagementLayer:: Done Loading Configuration\n"); 1483 1484 } … … 1513 1514 * 1514 1515 * DESCRIPTION: Deletes individual services from the DB 1515 * NOTE THAT this function only needs to be called if 1516 * NOTE THAT this function only needs to be called ifservice deregistration is going 1516 1517 * to be done at a different time than component deregistration; it is handled 1517 1518 * more efficiently and directly during that deregistration process. … … 1526 1527 _services_DB->command.append(_services_DB->tablename); 1527 1528 _services_DB->command.append(" WHERE ID_Num IN (SELECT "); 1529 1528 1530 char tmp[3]; 1529 1531 memset(tmp,0,3); … … 1536 1538 _services_DB->command.append(buffer); 1537 1539 _services_DB->command.append("');"); 1540 1538 1541 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); 1542 1545 } 1543 1546 … … 1564 1567 SendMessage(CE_List[ID].FD, buffer); 1565 1568 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"); 1567 1570 } 1568 1571 … … 1573 1576 _services_DB->command.append("ID_Num"); 1574 1577 _services_DB->command.append("=="); 1578 1575 1579 char tmp[3]; 1576 1580 memset(tmp,0,3); … … 1578 1582 _services_DB->command.append(tmp); 1579 1583 _services_DB->command.append(";"); 1584 1580 1585 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); 1585 1589 1586 1590 CE_List[ID].FD = -1; … … 1600 1604 ServiceManagementLayer::StartSMLServer() 1601 1605 { 1602 //printf("Ready for CE Signal! (registration done)\n");1603 1606 struct timeval selTimeout; 1604 1607 int32_t running = 1; 1605 1608 int32_t port, rc, new_sd = 1; 1606 1609 int32_t desc_ready = 1; 1607 //If there is, call the MessageHandler with the Shell_Msg code of -11608 1610 fd_set sockSet, shellSet; 1609 1611 … … 1614 1616 ERROR(1,"Error initializing primary port\n"); 1615 1617 1616 1617 1618 while (running) { 1618 1619 /* Zero socket descriptor vector and set for server sockets */ … … 1622 1623 1623 1624 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 } 1628 1628 1629 1629 /* Timeout specification */ 1630 1630 /* 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) { 1642 1640 FD_ZERO(&shellSet); 1643 1641 FD_SET(shellSocketFD, &shellSet); 1644 1642 selTimeout.tv_sec = 0; 1645 1643 selTimeout.tv_usec = 0; 1646 / /Check if there is a message on the shell socket ready to be processed1644 /* Check ifthere is a message on the shell socket ready to be processed */ 1647 1645 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 { 1655 1649 desc_ready = rc; 1656 1650 for(port = 0; port <= maxDescriptor && desc_ready > 0; port++) { … … 1658 1652 desc_ready -= 1; 1659 1653 1660 / /Check if request is new or on an existing open descriptor1654 /* Check ifrequest is new or on an existing open descriptor */ 1661 1655 if(port == cogEngSrv) { 1662 //If new, assign it a descriptor and give it an ID1656 /* If new, assign it a descriptor and give it an ID */ 1663 1657 new_sd = AcceptTCPConnection(port); 1664 1658 … … 1667 1661 1668 1662 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; 1670 1664 MessageHandler(Current_ID); 1671 Current_ID++;1665 Current_ID++; 1672 1666 1673 FD_SET(new_sd,&sockSet);1667 FD_SET(new_sd,&sockSet); 1674 1668 if(new_sd > maxDescriptor) 1675 1669 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 } 1684 1677 } 1685 1678 } 1686 1679 } 1687 }1680 } 1688 1681 } 1689 1682 … … 1691 1684 close(cogEngSrv); 1692 1685 1693 //delete &cogEngSrv;1694 1686 return; 1695 1687 } 1688