Index: vtcross/trunk/src/shell/CognitiveRadioShell.cpp
===================================================================
--- vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 285)
+++ vtcross/trunk/src/shell/CognitiveRadioShell.cpp	(revision 316)
@@ -123,5 +123,4 @@
     sprintf(counter, "%d", radio_info->numUtilities);
     SendMessage(socketFD, counter);
-    LOG("Cognitive Radio Shell:: Sending radio configuration to Cognitive Engine. %s\n",counter);
     for(size_t i = 0; i < radio_info->numUtilities; i++) {
         SendMessage(socketFD, utils[i].name.c_str());
@@ -536,5 +535,5 @@
         SendMessage(ceSocketFD,cp[i].name.c_str());
         sprintf(var,"%f",cp[i].value);
-        SendMessage(ceSocketFD,var);
+        SendMessage(ceSocketFD,var); 
     }
 
@@ -741,5 +740,6 @@
 
         /* Suspend program until descriptor is ready or timeout */
-        rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); 
+	//printf("Waiting for signal...\n");
+        rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, NULL); 
         if(rc == 0)
             LOG("No echo requests for %i secs...Server still alive\n", timeout);
@@ -763,5 +763,4 @@
                             if(port == servSock[policy])
                                 policySocketFD = new_sd;
- 			    //printf("%d %d %d :: %d\n", ceSocketFD, commandSocketFD, policySocketFD, new_sd);
 
                             HandleMessage(new_sd);
Index: vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp
===================================================================
--- vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 313)
+++ vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp	(revision 316)
@@ -74,4 +74,5 @@
 data_DB _data_DB;
 const char *_SML_Config;
+bool shellFound;
 
 //Callback function used internally by some of the SQLite3 commands
@@ -655,10 +656,14 @@
 
    //Send a message directly to the shell
-   //printf("name = %s\n", miss[activeMission].services[sourceID].name.c_str());
    if(miss[activeMission].services[sourceID].name.find("shell")!=string::npos)
-   {
-	//If the name on the output doesn't start with "~", search the DB to find the output that should be returned
-	if(miss[activeMission].services[sourceID].output[0].find("~") == string::npos){
-	   // printf("taken1\n");
+   { 
+	int k = 0;
+	shellFound=true;
+	while(k<10 && !miss[activeMission].input[k].empty()){
+	    k++;
+	}
+	sprintf(buffer, "%d", k);
+	SendMessage(shellSocketFD, buffer);
+	for(int t = 0; t < k; t++){
 	    memset(buffer, 0 , 256);
             strcpy(_data_DB->command, "select ");
@@ -667,17 +672,12 @@
     	    strcat(_data_DB->command, _data_DB->tablename);
     	    strcat(_data_DB->command, " where Tag==");
-	    sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].services[sourceID].output[0].c_str());
+	    sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].input[t].c_str());
             sqlite3_stmt * pStatement;
             int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL);
             if (rc == SQLITE_OK){ 
                 if (sqlite3_step(pStatement) == SQLITE_ROW)
-	            data.append((const char*) sqlite3_column_text(pStatement, 1)); 
+	            data=((const char*) sqlite3_column_text(pStatement, 1)); 
                 else {
-	    	data.append("1@output1@");
-	    	data.append(miss[activeMission].services[sourceID].output[0]);
-	    	data.append("@");
-		//printf("data = %s\n", data.c_str());
-	    	
-	            //printf("2222data_DB:: Data not yet in DB.\n");
+	            printf("data_DB:: Data not yet in DB.\n");
 		    rc=31337;
 	        }
@@ -688,13 +688,9 @@
             sqlite3_finalize(pStatement);
 	    token = strtok((char *)data.c_str(), "@");
+	    token = strtok(NULL, "@");
 	    SendMessage(shellSocketFD, token);
 	    token = strtok(NULL, "@");
-	    while(token){
-	        SendMessage(shellSocketFD, token);
-	        token = strtok(NULL, "@");
-	    }
+	    SendMessage(shellSocketFD, token);
 	}
-	//printf("done shell\n");
-       // LOG("ServiceManagementLayer:: Finished with data transaction.\n");
 	return;
    } 
@@ -825,5 +821,5 @@
  * -All ordering constraints have been relaxed in this version; all data is stored locally and only sent when requested
  * -If and while support fully implemented - up to three levels (if's can be nested, but dowhiles cannot)
- * -For dowhiles, assumes loop condition determined on next to last line (last line is a shell statement to keep the application updated)
+ * -For dowhiles, assumes loop condition determined on last line
  * -IMPORTANT: DB uses '@' to seperate individual statements; using '@' in the data stream will result in incorrect behavior
  */
@@ -834,5 +830,6 @@
 {
     //printf("start PAM\n");
-    uint16_t i = 0;
+    uint16_t i = 0, t;
+    shellFound = false;
     std::string data_param, data_obsv, data;
     std::string input;
@@ -845,30 +842,12 @@
     char *errorMsg;
     char* cols[] = {(char *)"Tag", (char *)"Data"};
+
+    LOG("ServiceManagementLayer:: Received PerformActiveMission command.\n");
+
     //Get the inputs
     memset(buffer, 0, 256);
+    //Needed to read the zero passed in by GOP as the number of observables
     ReadMessage(shellSocketFD, buffer);
-    LOG("ServiceManagementLayer:: Received PerformActiveMission command.\n");
-    //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
-    int32_t t = atoi(buffer);
-    /* Receive Set of Observables */
-    for(int32_t m = 0; m < t; m++) {
-	//printf("data=%s\n", data_obsv.c_str());
-        memset(buffer1, 0, 256);
-        ReadMessage(shellSocketFD, buffer1);
-	strcpy(_data_DB->command, "insert into ");
-    	strcat(_data_DB->command, _data_DB->tablename); 
-      	strcat(_data_DB->command, " (");
-    	strcat(_data_DB->command, cols[0]);
-    	strcat(_data_DB->command, ", ");
-	strcat(_data_DB->command, cols[1]);
-	strcat(_data_DB->command, ") ");
-        memset(buffer, 0, 256);
-        ReadMessage(shellSocketFD, buffer);
-	sprintf(_data_DB->command, "%s values('%s', '1@%s@%s", _data_DB->command, buffer1, buffer1, buffer);
-	strcat(_data_DB->command, "');");
-   	rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg);
-   	if( rc!=SQLITE_OK && rc!=101 )
-   	    fprintf(stderr, "SQL error: %s\n", errorMsg);
-    }
+
 
     /* Receive Set of Parameters */
@@ -895,46 +874,4 @@
     }
 
-
-
-
-    //Receive any other defined inputs
-    /*while(i < 10 && !miss[activeMission].input[i].empty()){
-	    //New data being added to DB
-	//printf("inserting data from shell\n");
-	memset(buffer1, 0, 256);
-	ReadMessage(shellSocketFD, buffer1);
-        t=atoi(buffer1);
-	//printf("t=%d\n", t);
-        for(int m = 0; m < t; m++) {
-	    data.append("@");
-	    memset(buffer, 0, 256);
-	    ReadMessage(shellSocketFD, buffer);
-	    data.append(buffer);
-	    data.append("@");
-	    memset(buffer, 0, 256);
-	    ReadMessage(shellSocketFD, buffer);
-	    data.append(buffer);
-	}
-	//printf("here %s\n", data.c_str());
-	strcpy(_data_DB->command, "insert into ");
-    	strcat(_data_DB->command, _data_DB->tablename); 
-      	strcat(_data_DB->command, " (");
-    	strcat(_data_DB->command, cols[0]);
-    	strcat(_data_DB->command, ", ");
-	strcat(_data_DB->command, cols[1]);
-	strcat(_data_DB->command, ") ");
-	strcat(_data_DB->command, " values('");
-	strcat(_data_DB->command, miss[activeMission].input[i].c_str());
-	sprintf(_data_DB->command, "%s', '%s%s');", _data_DB->command, buffer1, data.c_str());
-    	char *errorMsg;
-   	rc = sqlite3_exec(_data_DB->db, _data_DB->command, callback, 0, &errorMsg);
-   	if( rc!=SQLITE_OK && rc!=101 )
-   	    fprintf(stderr, "SQL error: %s\n", errorMsg);
-        //printf("SML: finished adding data from shell on input %d\n", i);
-        i++;
-	data.clear();
-    }*/
-
-
     //Useful for spotchecking what's in the database
     /*printf("\n\n\n");
@@ -954,7 +891,4 @@
 
 
-
-
-   // printf("done\n");
     i=0; 
     int32_t numstatements[3] = {0,0,0};
@@ -967,5 +901,5 @@
 	    check.clear();
 	    int t;
-	    for(t = 0; t < 5; t++){
+	    for(t = 0; t < 10; t++){
 		if(!miss[activeMission].services[i].output[t].empty()){
 		    //printf("i-numstmts-1 = %d\n", i-numstatements[0]-1);
@@ -1002,5 +936,4 @@
 	    bool doit = false;
 	    if(miss[activeMission].services[i].output[t].find(">") != string::npos){
-		//printf("foundit!\n");
 		    std::string data2;
 		    strcpy(_data_DB->command, "SELECT ");
@@ -1044,5 +977,5 @@
 			    input.clear();
 			    check.clear();
-			    for(t = 0; t < 5; t++){
+			    for(t = 0; t < 10; t++){
 				if(!miss[activeMission].services[k].output[t].empty()){
 				    //printf("i-numstmts = %d\n", i-numstatements-1);
@@ -1076,5 +1009,4 @@
 			    }
 			    //printf("L1:--- %s  %s---\n", miss[activeMission].services[k].output[t].c_str(), token);
-			    //TODO change to strstr
 			    bool doit = false;
 				//printf("here! %s\n", miss[activeMission].services[k].output[t].c_str());
@@ -1120,5 +1052,5 @@
 					    input.clear();
 					    check.clear();
-					    for(t = 0; t < 5; t++){
+					    for(t = 0; t < 10; t++){
 						if(!miss[activeMission].services[j].output[t].empty()){
 						    //printf("i-numstmts = %d\n", i-numstatements-1);
@@ -1153,5 +1085,4 @@
 					    }
 					    //printf("L2:---%s||%s---\n", miss[activeMission].services[j].output[t].c_str(), token);
-					    //TODO change to strstr
 					    bool doit = false;
 						//printf("here! %s\n", miss[activeMission].services[j].output[t].c_str());
@@ -1208,12 +1139,11 @@
 						    }
 						    data.clear();
-						    //printf("L0:while detected %d, %d\n", k, miss[activeMission].services[i].num_conds);
+						    //printf("L2:while detected %d, %d\n", k, miss[activeMission].services[i].num_conds);
 						    input.clear();
 						    check.clear();
 						    int t;
-						    for(t = 0; t < 5; t++){
+						    for(t = 0; t < 10; t++){
 							if(!miss[activeMission].services[j].output[t].empty()){
-							    input=miss[activeMission].services[l-2].output[t];
-							    //printf("input=%s\n", input.c_str());
+							    input=miss[activeMission].services[l-1].output[t];
 							    strcpy(_data_DB->command, "SELECT ");
 							    strcat(_data_DB->command, _data_DB->tablename);
@@ -1276,11 +1206,11 @@
 				    }
 				    data.clear();
-				    //printf("L0:while detected %d, %d\n", k, miss[activeMission].services[i].num_conds);
+				    //printf("L1:while detected %d, %d\n", k, miss[activeMission].services[i].num_conds);
 				    input.clear();
 				    check.clear();
 				    int t;
-				    for(t = 0; t < 5; t++){
+				    for(t = 0; t < 10; t++){
 					if(!miss[activeMission].services[k].output[t].empty()){
-					    input=miss[activeMission].services[j-2].output[t];
+					    input=miss[activeMission].services[j-1].output[t];
 					    //printf("input=%s\n", input.c_str());
 					    strcpy(_data_DB->command, "SELECT ");
@@ -1303,5 +1233,5 @@
 					    }
 				    	    sqlite3_finalize(pStatement);
-					   // printf("data=%s\n", data.c_str());
+					    //printf("data=%s\n", data.c_str());
 					    token = strtok((char *)data.c_str(), "@");
 					    token = strtok(NULL, "@");
@@ -1352,7 +1282,7 @@
 		    check.clear();
 		    int t;
-		    for(t = 0; t < 5; t++){
+		    for(t = 0; t < 10; t++){
 			if(!miss[activeMission].services[i].output[t].empty()){
-			    input=miss[activeMission].services[k-2].output[t];
+			    input=miss[activeMission].services[k-1].output[t];
 			    //printf("input=%s\n", input.c_str());
 			    strcpy(_data_DB->command, "SELECT ");
@@ -1400,47 +1330,25 @@
     i=0;
     data.clear();
-    //get the ouptuts
-    while(i < 10 && !miss[activeMission].output[i].empty()){
-	//printf("sending output data to shell\n");
-        strcpy(_data_DB->command, "select ");
-   	strcat(_data_DB->command, _data_DB->tablename);
-    	strcat(_data_DB->command, ".* from ");
-    	strcat(_data_DB->command, _data_DB->tablename);
-    	strcat(_data_DB->command, " where Tag==");
-	sprintf(_data_DB->command, "%s'%s';", _data_DB->command, miss[activeMission].output[i].c_str());
-        sqlite3_stmt * pStatement;
-        int rc = sqlite3_prepare_v2(_data_DB->db, _data_DB->command, -1, &pStatement, NULL);
-        if (rc == SQLITE_OK){ 
-            if (sqlite3_step(pStatement) == SQLITE_ROW) 
-	         data.append((const char*) sqlite3_column_text(pStatement, 1)); 
-            else {
-	            printf("1data_DB:: Data not yet in DB.\n");
-		    rc=31337;
-	    }
-        } 
-	else {
-	    printf("services_DB:: Error executing SQL statement. rc = %i\n%s\n",rc,_data_DB->command);
-        } 
-        //printf("here %s\n", data.c_str());
-        sqlite3_finalize(pStatement);
-	char *data_ch = (char *) data.c_str();
-	char *token = strtok(data_ch, "@");
-	SendMessage(shellSocketFD, token);
-	token = strtok(NULL, "@");
-	while(token){
-	    SendMessage(shellSocketFD, token);
-	    //printf("token1 = %s\n", token);
-	    token = strtok(NULL, "@");
-	    SendMessage(shellSocketFD, token);
-	    //printf("token2 = %s\n", token);
-	    token = strtok(NULL, "@");
+
+
+
+    if(!shellFound)
+    {
+	int k = 0;
+	while(k<10 && !miss[activeMission].input[k].empty()){
+	    k++;
 	}
-	i++;
-        data.clear();
+	sprintf(buffer, "%d", k);
+	SendMessage(shellSocketFD, buffer);
+	for(int t = 0; t < k; t++){
+	    //printf("---%s---\n", miss[activeMission].input[t].c_str());
+	    SendMessage(shellSocketFD, miss[activeMission].input[t].c_str()); 
+	    SendMessage(shellSocketFD, "0");
+	}
     }
 
 
     LOG("ServiceManagementLayer:: Done performing active mission.\n");
-    /*LOG("ServiceManagementLayer:: Done sending output data to shell from PerformActiveMission.\n");
+    /*
     strcpy(_data_DB->command, "select ");
     strcat(_data_DB->command, _data_DB->tablename);
@@ -1467,5 +1375,4 @@
 ServiceManagementLayer::ListServices()
 {
-    // generate commandi
     strcpy(_services_DB->command, "select ");
     strcat(_services_DB->command, _services_DB->tablename);
@@ -1542,11 +1449,8 @@
 	int32_t service_num = 0;
 	uint16_t cond_array[] = {0, 0, 0};
-	//printf("mission_num = %d\n", mission_num);
-	//memset(cond_array, 0, 2);
 	
     	for(pChild1  = (pChild0->FirstChildElement())->FirstChildElement(); pChild1; \
       	    pChild1  = pChild1->NextSiblingElement()) 
     	{
-	    //printf("here1\n");
 	    int32_t conditional_0 = service_num;
 	    for(pChild2 = pChild1->FirstChildElement(); \
@@ -1578,5 +1482,4 @@
 			        if(pChild4->Attribute(buffer2))
 				    mList[mission_num].services[service_num].output[i-1] = pChild4->Attribute(buffer2);
-			        //printf("i1=%s\n", mList[mission_num].services[conditional_0].input[i].c_str());
 			    }
 			    if(pChild4->Attribute("parameter"))
@@ -1648,5 +1551,4 @@
 			mList[mission_num].services[conditional_0].output[i-1] = pChild1->Attribute(buffer2);
 		}
-		   // printf("i1=%s\n", mList[mission_num].services[conditional_0].input[0].c_str());
 		if(pChild1->Attribute("parameter"))
 		    mList[mission_num].services[conditional_0].parameter = pChild1->Attribute("parameter");
@@ -1655,6 +1557,4 @@
 	    service_num++;
 	}
-	//for(int i = 0; i < service_num; i++)
-	 //printf("ttt%s\n",mList[mission_num].services[i].input[0].c_str());
 	
 	mList[mission_num].numServices = service_num;
@@ -1662,19 +1562,13 @@
         mList[mission_num].missionID = atoi(pChild0->Attribute("id"));
 	for(int i = 1; i <= 10; i++) {
-	    char buffer[9]="input";
+	    char buffer[9]="param";
 	    sprintf(buffer, "%s%d", buffer, i); 
-	    if(pChild0->Attribute(buffer))
+	    if(pChild0->Attribute(buffer)){
 	        mList[mission_num].input[i-1] = pChild0->Attribute(buffer);
-	    char buffer2[9]="output";
-	    sprintf(buffer2, "%s%d", buffer2, i); 
-	    if(pChild0->Attribute(buffer2))
-		mList[mission_num].output[i-1] = pChild0->Attribute(buffer2);
+	    }
 	}
-	//printf("mis, input1=%s, output1=%s\n", mList[mission_num].input[0].c_str(), mList[mission_num].output[0].c_str());
-	//printf("NUMSERVICES = %d\n", mList[mission_num].numServices);
 	mission_num++;
-	//printf("here\n");
-    }
-    //LOG("ServiceManagementLayer:: Done Loading Configuration");
+    }
+    LOG("ServiceManagementLayer:: Done Loading Configuration\n");
 }
 
@@ -1688,23 +1582,18 @@
 ServiceManagementLayer::RegisterCognitiveEngine(int32_t ID)
 {
-    //LOG("SML::regcogeng");
     SendMessage(shellSocketFD, "register_engine_cognitive");
 
-   // printf("SSFD = %d\n", shellSocketFD);
     LOG("ServiceManagementLayer:: CE registration message forwarded to shell.\n");
     char buffer[256];
     memset(buffer, 0, 256);
     ReadMessage(shellSocketFD, buffer);
-    //printf("ServiceManagementLayer::buffer = %s\n", buffer);
     SendMessage(CE_List[ID].FD, buffer);
 
     TransferRadioConfiguration(ID);
     memset(buffer, 0, 256);
-    //printf("start trans exp\n");
     TransferExperience(ID);
     memset(buffer, 0, 256);
     numberOfCognitiveEngines++;
     CE_Present = true;
-    //printf("done registering CE!\n");
 }
 
@@ -1807,7 +1696,5 @@
         ERROR(1,"Error initializing primary port\n");
 
-    int i = 10000000;  //TODO change to "running" if endpoint can be reached
     while (running) {
-        i--;
         /* Zero socket descriptor vector and set for server sockets */
         /* This must be reset every time select() is called */
