void AgentThread::processCMDCLEAN_REQUEST(int socketHandle) { try { ConsoleServer::debugMsg(1,"Processing CMDCLEAN_REQUEST\n"); // read the serialized TestObject which we will stop TestObject test; test.readTestObject(socketHandle); // now send a signal indicating we are processing the request Utils::sendSignal(socketHandle,RESPONSE_PROCESSING); //clean the files now for (int i = 0; i < getProcessCount(); i++) { // check for any instance of test running with the same id TestObject *curr = getProcess(i)->getTestObject(); if (curr->getTestID().compare(test.getTestID())==0) { // clean up the trace files ConsoleServer::debugMsg(1, "Cleaning environment file :%s\n", curr->getEnvFileName().c_str()); if (Utils::delete_file(curr->getEnvFileName())!=0) ConsoleServer::debugMsg(1,"No environment file was found :%s\n", curr->getEnvFileName().c_str()); ConsoleServer::debugMsg(1,"Cleaning stdout file :%s\n", curr->getStdOutFileName().c_str()); if (Utils::delete_file(curr->getStdOutFileName())!=0) ConsoleServer::debugMsg(1,"No stdout file was found :%s\n", curr->getStdOutFileName().c_str()); ConsoleServer::debugMsg(1,"Cleaning stderr file :%s\n", curr->getStdErrFileName().c_str()); if (Utils::delete_file(curr->getStdErrFileName())!=0) ConsoleServer::debugMsg(1,"No stderr file was found :%s\n", curr->getStdErrFileName().c_str()); // remove from our list of test objects ConsoleServer::debugMsg(1,"Removing process from process pool\n"); delProcess(i); break; } } // now send a signal indicating we have finished Utils::sendSignal(socketHandle,RESPONSE_FINISHED_OK); } catch (char * message) { ConsoleServer::debugMsg(1,"Error processing CMDCLEAN_REQUEST request:%s\n",message); Utils::sendSignal(socketHandle,RESPONSE_FINISHED_ERROR); } };
void AgentThread::processCMDSTOP_REQUEST(int socketHandle) { try { ConsoleServer::debugMsg(1,"Processing CMDSTOP_REQUEST\n"); // read the serialized TestObject which we will stop TestObject test; test.readTestObject(socketHandle); // now send a signal indicating we are processing the request Utils::sendSignal(socketHandle,RESPONSE_PROCESSING); // find the exit code, blocking for requested timeout if neccesary int wasRunning = FALSE; int status; for (int i = 0; i < getProcessCount(); i++) { // check for any instance of test running with the same id TestObject *curr = getProcess(i)->getTestObject(); if (curr==NULL) { printf("Error: Null process found on process list"); return; } if (curr->getTestID().compare(test.getTestID())==0) { ConsoleServer::debugMsg(5,"Stopping process\n"); wasRunning = TRUE; status = getProcess(i)->checkExitValue(); // flush and close it's output streams getProcess(i)->interrupt(); Utils::sendSignal(socketHandle,status); break; } } if (!wasRunning) { // the process was never started, so assume it failed ConsoleServer::debugMsg(1,"Process was not running :%s\n",test.getTestID().c_str()); } else { // now send a signal indicating we have finished Utils::sendSignal(socketHandle,RESPONSE_FINISHED_OK); } } catch (char * message) { ConsoleServer::debugMsg(1,"Error processing CMDSTOP_REQUEST request:%s\n",message); Utils::sendSignal(socketHandle,RESPONSE_FINISHED_ERROR); } };
void AgentThread::processGETTRACEPATHS_REQUEST(int socketHandle) { try { ConsoleServer::debugMsg(1,"Processing GETTRACEPATHS_REQUEST\n"); // read the serialized TestObject which we want the exit code of TestObject test; test.readTestObject(socketHandle); // now send a signal indicating we are processing the request Utils::sendSignal(socketHandle,RESPONSE_PROCESSING); int wasRun = FALSE; for (int i = 0; i < getProcessCount(); i++) { // check for any instance of test running with the same id TestObject *curr = getProcess(i)->getTestObject(); if (curr->getTestID().compare(test.getTestID())==0) { wasRun = true; Utils::sendSignal(socketHandle,RESPONSE_FINISHED_OK); ConsoleServer::debugMsg(9,"Sending trace file paths\n"); ConsoleServer::debugMsg(9,"Env file :%s\n",curr->getEnvFileName().c_str()); ConsoleServer::debugMsg(9,"StdOut file :%s\n",curr->getStdOutFileName().c_str()); ConsoleServer::debugMsg(9,"StdErr file :%s\n",curr->getStdErrFileName().c_str()); // ---- send the env, stdout and stderr files -------------------- Utils::writeString(socketHandle,curr->getEnvFileName()); Utils::writeString(socketHandle,curr->getStdOutFileName()); Utils::writeString(socketHandle,curr->getStdErrFileName()); // ---------------------------------- break; } } if (!wasRun) { // the process was never started, so assume it failed ConsoleServer::debugMsg(1,"Process was never started :%s\n",test.getTestID().c_str()); Utils::writeInt(socketHandle,RESPONSE_FINISHED_ERROR); } else { // now send a signal indicating we have finished Utils::sendSignal(socketHandle,RESPONSE_FINISHED_OK); } } catch (char *message) { ConsoleServer::debugMsg(1,"Error processing GETTRACEPATHS_REQUEST request:%s\n",message); Utils::sendSignal(socketHandle,RESPONSE_FINISHED_ERROR); } }
void AgentThread::processCMDSTATUS_REQUEST(int socketHandle) { TestObject test; try { ConsoleServer::debugMsg(1,"Processing CMDSTATUS_REQUEST\n"); // read the serialized TestObject which we will stop test.readTestObject(socketHandle); // now send a signal indicating we are processing the request Utils::sendSignal(socketHandle,RESPONSE_PROCESSING); // find the exit code, blocking if neccesary int wasRunning = FALSE; for (int i = 0; i < getProcessCount(); i++) { // check for any instance of test running with the same id TestObject *curr = getProcess(i)->getTestObject(); if (curr->getTestID().compare(test.getTestID())==0) { ConsoleServer::debugMsg(8,"Found started process :%s\n",test.getTestID().c_str()); int status = getProcess(i)->getExitValue(); ConsoleServer::debugMsg(5,"Returning CMDSTATUS value :%d\n",status); Utils::writeInt(socketHandle,status); wasRunning = TRUE; break; } } if (!wasRunning) { // the process was never started, so assume it failed ConsoleServer::debugMsg(1,"Process was never started :%s\n",test.getTestID().c_str()); Utils::writeInt(socketHandle,FAILED); } else { // now send a signal indicating we have finished Utils::sendSignal(socketHandle,RESPONSE_FINISHED_OK); } } catch (char * message) { ConsoleServer::debugMsg(1,"Error processing CMDSTATUS_REQUEST request:%s\n",message); Utils::sendSignal(socketHandle,RESPONSE_FINISHED_ERROR); } }