int processStart(Proc_NAME process, Proc_ID *id, int waitTimeSecs, int *exitCode) { int iReturnCode = DIAGLIB_OK; if(process.empty() || id == NULL) { return RETURN_LOG_BAD_FUNCTION_CALL; } LOG_TIME(L"Ask for start process named '%ls' --> ",process.c_str()); STARTUPINFO siStartupInfo; PROCESS_INFORMATION piProcessInfo; ZeroMemory(&siStartupInfo, sizeof(siStartupInfo)); ZeroMemory(&piProcessInfo, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); if (!CreateProcess(NULL,(LPWSTR)process.c_str(),0,0,false,0,NULL,NULL, &siStartupInfo, &piProcessInfo)) { LOG_LASTERROR(L"CreateProcess failed"); iReturnCode = DIAGLIB_ERR_PROCESS_START_FAILED; } else { *id=piProcessInfo.dwProcessId; Sleep(100); LOG(L"STARTED with pid=%ld\n",*id); if(waitTimeSecs>0) { iReturnCode=processWait(*id, exitCode, waitTimeSecs); } } return iReturnCode; }
void processCommand(std::vector< std::string > &args) { /* printf("PROCESS: "); for(int i = 0; i < args.size(); i ++) { printf("[%s] ", args[i].c_str()); } printf("\n");*/ if(args.empty()) { *mAction = BNBActions::ERASE; } else if(args[0] == "forward") { *mAction = BNBActions::FORWARD | BNBActions::ERASE; eraseCommand(); } else if(args[0] == "drop") { *mAction = BNBActions::DROP | BNBActions::ERASE; eraseCommand(); } else if(args[0] == "var") { BNB_ASSERT(args.size() == 2); processVar(args[1]); } else if(args[0] == "set") { BNB_ASSERT(args.size() == 3); processAssign(args[1], args[2]); } else if(args[0] == "inc") { BNB_ASSERT(args.size() == 3); processInc(args[1], args[2]); } else if(args[0] == "cat") { BNB_ASSERT(args.size() == 3); processCat(args[1], args[2]); } else if(args[0] == "wait") { BNB_ASSERT(args.size() == 4); processWait(args[1], args[2], args[3]); } else if(args[0] == "echo") { processEcho(args); } else if(args[0] == "erase") { *mAction = BNBActions::ERASE; eraseCommand(); } else if(args[0] == "save") { processSave(args[1], args[2]); } else if(args[0] == "append") { processAppend(args[1], args[2]); } else if(args[0] == "load") { processLoad(args[1], args[2]); } else if(args[0] == "mkdir") { processMkdir(args[1]); } else if(args[0] == "skip") { eraseCommand(); } else if(args[0] == "exec") { processExec(args[1]); } else if(args[0] == "exit") { *mAction = BNBActions::EXIT; eraseCommand(); } else { printf("%s\n", args[0].c_str()); BNB_ERROR_REPORT("Unrecognized command"); } }
/* * ======== UNIVERSAL_processWait ======== */ XDAS_Int32 UNIVERSAL_processWait(UNIVERSAL_Handle handle, XDM1_BufDesc *inBufs, XDM1_BufDesc *outBufs, XDM1_BufDesc *inOutBufs, IUNIVERSAL_InArgs *inArgs, IUNIVERSAL_OutArgs *outArgs, UInt timeout) { XDAS_Int32 retVal = UNIVERSAL_EFAIL; UNIVERSAL_InArgs refInArgs; /* * Note, we assign "VISA_isChecked()" results to a local variable * rather than repeatedly query it throughout this fxn because * someday we may allow dynamically changing the global * 'VISA_isChecked()' value on the fly. If we allow that, we need * to ensure the value stays consistent in the context of this * call. */ Bool checked = VISA_isChecked(); Log_print6(Diags_ENTRY, "[+E] UNIVERSAL_processWait> " "Enter (handle=0x%x, inBufs=0x%x, outBufs=0x%x, inOutBufs=0x%x, " "inArgs=0x%x, outArgs=0x%x)", (IArg)handle, (IArg)inBufs, (IArg)outBufs, (IArg)inOutBufs, (IArg)inArgs, (IArg)outArgs); if (handle) { IUNIVERSAL_Handle alg = VISA_getAlgHandle((VISA_Handle)handle); if (alg != NULL) { if (checked) { /* * Make a reference copy of inArgs so we can check that * the codec didn't modify them during process(). */ refInArgs = *inArgs; } retVal = processWait(alg, inBufs, outBufs, inOutBufs, inArgs, outArgs, timeout); if (checked) { /* ensure the codec didn't modify the read-only inArgs */ if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) { Log_print1(Diags_USER7, "[+7] ERROR> codec (0x%x) modified read-only inArgs " "struct!", (IArg)handle); } } } } Log_print2(Diags_EXIT, "[+X] UNIVERSAL_processWait> " "Exit (handle=0x%x, retVal=0x%x)", (IArg)handle, (IArg)retVal); return (retVal); }
/* * ======== VIDDEC2_processWait ======== */ XDAS_Int32 VIDDEC2_processWait(VIDDEC2_Handle handle, XDM1_BufDesc *inBufs, XDM_BufDesc *outBufs, VIDDEC2_InArgs *inArgs, VIDDEC2_OutArgs *outArgs, UInt timeout) { XDAS_Int32 retVal = VIDDEC2_EFAIL; VIDDEC2_InArgs refInArgs; /* * Note, we do this because someday we may allow dynamically changing * the global 'VISA_isChecked()' value on the fly. If we allow that, * we need to ensure the value stays consistent in the context of this call. */ Bool checked = VISA_isChecked(); Log_print5(Diags_ENTRY, "[+E] VIDDEC2_processWait> " "Enter (handle=0x%x, inBufs=0x%x, outBufs=0x%x, inArgs=0x%x, " "outArgs=0x%x)", (IArg)handle, (IArg)inBufs, (IArg)outBufs, (IArg)inArgs, (IArg)outArgs); if (handle) { IVIDDEC2_Handle alg = VISA_getAlgHandle((VISA_Handle)handle); if (alg != NULL) { if (checked) { /* * Make a reference copy of inArgs so we can check that * the codec didn't modify them during process(). */ refInArgs = *inArgs; } retVal = processWait(alg, inBufs, outBufs, inArgs, outArgs, timeout); if (checked) { /* ensure the codec didn't modify the read-only inArgs */ if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) { Log_print1(Diags_USER7, "[+7] ERROR> codec (0x%x) modified read-only inArgs " "struct!", (IArg)handle); } } } } Log_print2(Diags_EXIT, "[+X] VIDDEC2_processWait> " "Exit (handle=0x%x, retVal=0x%x)", (IArg)handle, (IArg)retVal); return (retVal); }
/* * ======== IMGENC1_processWait ======== */ XDAS_Int32 IMGENC1_processWait(IMGENC1_Handle handle, XDM1_BufDesc *inBufs, XDM1_BufDesc *outBufs, IIMGENC1_InArgs *inArgs, IIMGENC1_OutArgs *outArgs, UInt timeout) { XDAS_Int32 retVal = IMGENC1_EFAIL; IMGENC1_InArgs refInArgs; /* * Note, we do this because someday we may allow dynamically changing * the global 'VISA_isChecked()' value on the fly. If we allow that, * we need to ensure the value stays consistent in the context of this call. */ Bool checked = VISA_isChecked(); GT_5trace(CURTRACE, GT_ENTER, "IMGENC1_processWait> " "Enter (handle=0x%x, inBufs=0x%x, outBufs=0x%x, inArgs=0x%x, " "outArgs=0x%x)\n", handle, inBufs, outBufs, inArgs, outArgs); if (handle) { IIMGENC1_Handle alg = VISA_getAlgHandle((VISA_Handle)handle); if (alg != NULL) { if (checked) { /* * Make a reference copy of inArgs so we can check that * the codec didn't modify them during process(). */ refInArgs = *inArgs; } retVal = processWait(alg, inBufs, outBufs, inArgs, outArgs, timeout); if (checked) { /* ensure the codec didn't modify the read-only inArgs */ if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) { GT_1trace(CURTRACE, GT_7CLASS, "ERROR> codec (0x%x) modified read-only inArgs " "struct!\n", handle); } } } } GT_2trace(CURTRACE, GT_ENTER, "IMGENC1_processWait> " "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal); return retVal; }
/* * ======== VIDDEC2_processWait ======== */ XDAS_Int32 VIDDEC2BACK_processWait(VIDDEC2BACK_Handle handle, XDM_Context *context, VIDDEC2_OutArgs *outArgs, UInt timeout) { XDAS_Int32 retVal = VIDDEC2_EFAIL; /* * Note, we do this because someday we may allow dynamically changing * the global 'VISA_isChecked()' value on the fly. If we allow that, * we need to ensure the value stays consistent in the context of this call. */ Bool checked = VISA_isChecked(); Log_print4(Diags_ENTRY, "[+E] VIDDEC2BACK_processWait> " "Enter (handle=0x%x, context=0x%x, outArgs=0x%x (size=0x%x))", (IArg)handle, (IArg)context, (IArg)outArgs, (IArg)(outArgs->size)); if (handle) { IVIDDEC2BACK_Handle alg = VISA_getAlgHandle((VISA_Handle)handle); if (alg != NULL) { if (checked) { /* TBD */ } retVal = processWait(alg, context, outArgs, timeout); if (checked) { /* TBD */ } } } Log_print2(Diags_EXIT, "[+X] VIDDEC2BACK_processWait> " "Exit (handle=0x%x, retVal=0x%x)", (IArg)handle, (IArg)retVal); return (retVal); }
//======================================================================================= //inline void sendMachine_3(){ enum { DATAMAXLEN = 64, DATAMARKERPOSITION = 0, DATAMARKER = '?', DATACODELENPOSITION = 1, DATACODEPOSION = 2 }; #define ASKDATALEN 3 char ASKDATA[ASKDATALEN] = "***"; #define ANSWERDATALEN 3 char ANSWERDATA[ANSWERDATALEN] = "+++"; static char data[DATAMAXLEN]; #define REPCOUNTER 3 static char repeat_counter = REPCOUNTER; enum {WAITNEWCODE, WAITCODEDONE, WAITBOX, SENDTOBOX, WAITDELAY}; static char state = WAITNEWCODE; switch (state){ //======================== case WAITNEWCODE: //======================== if (getFlag(FLAG_NEW_NOCK) == TRUE) state = WAITCODEDONE; break; //======================== case WAITCODEDONE: //======================== if (getFlag(FLAG_NEW_NOCK) == FALSE){ //state = WAITBOX; //DEBUG state = SENDTOBOX; } break; //======================== case WAITBOX:{ //======================== char len = Receive_Packet(data, DATAMAXLEN); if (len > 0){ #ifdef LOGG loggerWriteToMarker((LogMesT)" WAITBOX get data: *", '*'); loggerWrite((LogMesT)data, len); #endif for (char i = 0; i < ANSWERDATALEN; i++) if (data[i] != ANSWERDATA[i]) return; state = SENDTOBOX; break; } SwitchToTxMode(); Send_Packet(W_TX_PAYLOAD_NOACK_CMD, (unsigned char *)ASKDATA, ASKDATALEN); //Send_Packet(0, ASKDATA, ASKDATALEN); SwitchToRxMode(); state = WAITDELAY; }break; //======================== case WAITDELAY: //======================== if (processWait() == TRUE) #ifdef LOGG loggerWriteToMarker((LogMesT)" goto WAITBOX\r*", '*'); #endif state = WAITBOX; break; //======================== case SENDTOBOX:{ //======================== #ifdef LOGG loggerWriteToMarker((LogMesT)" SENDTOBOX\r*", '*'); #endif SwitchToTxMode(); Nock * nock = getNock(NOCK_PATTERN); data[DATAMARKERPOSITION] = DATAMARKER; data[DATACODELENPOSITION] = nock->count; unsigned char i; for (i = 0; i < nock->count; i++){ int time = nock->nock[i]; char * p = &time; data[DATACODEPOSION + i*2] = *p; p++; data[DATACODEPOSION + i*2 + 1] = *p; } data[DATACODEPOSION + i * 2] = DATAMARKER; Send_Packet(W_TX_PAYLOAD_NOACK_CMD, (unsigned char *)data, DATACODEPOSION + nock->count * 2 + 1); //Send_Packet(0, (unsigned char *)data, DATACODEPOSION + nock->count + 1); #ifdef LOGG loggerWriteToMarker((LogMesT)" nock count: *", '*'); char ch = nock->count + 48; loggerWrite(&ch, 1); #endif if (repeat_counter-- <= 0){ repeat_counter = REPCOUNTER; state = WAITNEWCODE; } }break; //======================== default: break; //======================== } }
int connectionHandler() { requests = 0; logTest("connectionHandler", "Going to create a new dispatcher"); dispatcher = new Dispatcher(); dispatcher -> start(); logTest("connectionHandler", "Going to create a new listener"); listener = new TcpListener(); listener -> setPort(6001); listener -> setBacklog(32); // // Not needed for the early tests. // // listener -> setAccept("127.0.0.1"); // listener -> start(); logTest("connectionHandler", "Going to add the listener to the set"); dispatcher -> addReadFd(listener -> getFd()); logTest("connectionHandler", "Going to enter the main loop"); T_timestamp start = getTimestamp(); T_timestamp now = getTimestamp(); int result; int fd; T_timestamp timeout; while (diffTimestamp(start, now) < 1000000000) { logTest("connectionHandler", "Going to wait for new events"); timeout = nullTimestamp(); result = dispatcher -> waitEvent(timeout); logTest("connectionHandler", "Dispatcher returned %d", result); while ((fd = dispatcher -> nextReadEvent()) != -1) { if ((fd = listener -> accept()) != -1) { requests++; logTest("connectionHandler", "Going to handle request %d", requests); processHandler(fd); } } processCheck(); now = getTimestamp(); } logTest("connectionHandler", "Exiting with %ld seconds elapsed since start", diffTimestamp(start, now) / 1000); dispatcher -> removeReadFd(listener -> getFd()); dispatcher -> end(); delete dispatcher; logTest("connectionHandler", "Deleted the dispatcher"); listener -> end(); delete listener; logTest("connectionHandler", "Deleted the listener"); processWait(); return requests; }