/****************************************************************************** * * Title : commandFunc_runChildCommandList.c * Version 0.0 * * Description: Runs "child" command list (included into the main command list). * Related files: * * Author: Lukas Tomasek, tomasekl@fzu.cz * ******************************************************************************/ /****************************************************************************** * Header files * ******************************************************************************/ #include #include #include "commandListDefinitions.h" #include "commandFunc_runChildCommandList.h" #include "uirUtility.h" #include "globalDefinitions.h" #include "commandParamsUir.h" #include "hostUtility.h" #include "mainUir.h" #include "threadUtility.h" #include "commandStatusMessage.h" #include "RWlists.h" /****************************************************************************** * Global functions * ******************************************************************************/ /*============================================================================= * commandFunction_runChildCommandList() *============================================================================= * * * */ ERROR_ID commandFunction_runChildCommandList(COMMAND_FUNC_OPTION funcOption, struct COMMAND *command, UINT8 slotNumber, FILE *file){ struct HOST *host; const int panel=global.panel.commandEdit[RUN_CHILD_COMMAND_LIST_ID]; struct COMMAND_LIST *cmdList; struct COMMAND *commandChild; struct RUN_CHILD_COMMAND_LIST_PARAMS *runChCmdList=&command->params.runChildCmdList; int status; ERROR_ID errorId=SUCCESS; unsigned int fileSize; char text[300]; UINT32 tempVar; int count, index; int ifError; int repCount; char inputText[500]; switch(funcOption){ case COMMAND_TO_LIST: GetCtrlVal(panel, RUN_CLIST_FILE, runChCmdList->fileName); if(runChCmdList->fileName[0]==0) { status = MessagePopup ("WARNING", "No list selected!"); UIR_STATUS_CHECK(status, MessagePopup()); return(PROGRAM_WARNING); } break; case LIST_TO_COMMAND: SetCtrlVal(panel, RUN_CLIST_FILE, runChCmdList->fileName); break; case COMMAND_EXECUTION: host=global.host[HOST_INDEX(slotNumber)]; cmdList=calloc(sizeof(struct COMMAND_LIST), sizeof(UINT8)); if(cmdList==NULL){ ERROR_CHECK(PROGRAM_ERROR, calloc()); break; } errorId=readCmdListFile(runChCmdList->fileName, cmdList); ERROR_CHECK(errorId, readCmdListFile()); if(errorId!=SUCCESS){ free(cmdList); break; } /* execute child command list */ for(index=0; indexcommandCount; ++index){ if(host->cmdListExecState==CMDLISTEXEC_ABORT) break; commandChild=&cmdList->command[index]; GetCtrlVal(host->panel.commandListStatus, CLISTP_IF_ERROR, &ifError); /* overload continueIfError */ switch(ifError){ case IF_ERROR_DEFAULT: /* default */ /* do nothing - hold value defined in the list */ break; case IF_ERROR_STOP: /* stop */ command->continueIfError=0; break; case IF_ERROR_CONTINUE: /* continue */ command->continueIfError=1; break; } /* execute command */ for(repCount=0; repCount<=commandChild->numRepetitions; ++repCount){ if(host->cmdListExecState==CMDLISTEXEC_ABORT) break; switch(commandChild->id){ case SEND_PRIM_LIST_COMMAND_ID: /* no break */ case COMPARE_FILES_COMMAND_ID: /* no break */ case RUN_CHILD_COMMAND_LIST_ID: /* no break */ case RUN_EXTERNAL_PROGRAM_ID: /* no break */ case DELAY_COMMAND_ID: /* no break */ errorId=(*global.commandFunction[commandChild->id])(COMMAND_EXECUTION, commandChild, host->slotNumber, 0); HOST_ERROR_CHECK(errorId, host, commandFunction()); if(errorId!=SUCCESS){ sprintf(inputText,"##CHILD COMMAND ERROR (CmdList:%s - ChildIndex:%d; cmdRepCount:%d); Date:%s, Time:%s\n", runChCmdList->fileName, index, repCount, DateStr(), TimeStr()); errorId=commandStatusMessage(host, host->commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); if(command->continueIfError){ continue; }else{ host->cmdListExecState=CMDLISTEXEC_IDLE; SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 1); errorId=suspendThread(GetCurrentThread()); ERROR_CHECK(errorId, suspendThread()); SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 0); } } if(commandChild->id!=SEND_PRIM_LIST_COMMAND_ID){ break; } /* else no break */ default: if(commandChild->id!=SEND_PRIM_LIST_COMMAND_ID){ /* command is executed in communicationLoop */ host->command=commandChild; host->commandReady=1; } /* wait for reply */ errorId=waitForEvent(host->commandDone_event); ERROR_CHECK(errorId, waitForEvent()); if(errorId!=SUCCESS){ sprintf(inputText,"##CHILD COMMAND ERROR (CmdList:%s - ChildIndex:%d; cmdRepCount:%d); Date:%s, Time:%s\n", runChCmdList->fileName, index, repCount, DateStr(), TimeStr()); errorId=commandStatusMessage(host, host->commandStatusFile, inputText); HOST_ERROR_CHECK(errorId, host, commandStatusMessage()); if(command->continueIfError){ continue; }else{ host->cmdListExecState=CMDLISTEXEC_IDLE; SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 1); errorId=suspendThread(GetCurrentThread()); ERROR_CHECK(errorId, suspendThread()); SetCtrlVal(host->panel.commandListStatus, CLISTP_STOPPED, 0); } } break; } if(command->id==SEND_PRIM_LIST_COMMAND_ID) break; /* repeated in primList building or listHandler */ } } free(cmdList); break; case SAVE_CMD_TO_FILE: fprintf(file, "fileName[]= %s\n", runChCmdList->fileName); break; case LOAD_CMD_FROM_FILE: status=readLineFromIndex(file, strlen("fileName[]= "), PATHNAME_LENGTH, runChCmdList->fileName); if(status!=0) {ERROR_CHECK(FATAL_ERROR, Read from cmd file error!); return(FATAL_ERROR);} break; default: ; } return(errorId); } /******************************************************************************/