HINSTANCE Command::run(HWND hWnd) { const int argsIntermediateLen = MAX_PATH*2; const int args2ExecLen = CURRENTWORD_MAXLENGTH+MAX_PATH*2; TCHAR cmdPure[MAX_PATH]; TCHAR cmdIntermediate[MAX_PATH]; TCHAR cmd2Exec[MAX_PATH]; TCHAR args[MAX_PATH]; TCHAR argsIntermediate[argsIntermediateLen]; TCHAR args2Exec[args2ExecLen]; extractArgs(cmdPure, args, _cmdLine.c_str()); int nbTchar = ::ExpandEnvironmentStrings(cmdPure, cmdIntermediate, MAX_PATH); if (!nbTchar) lstrcpy(cmdIntermediate, cmdPure); else if (nbTchar >= MAX_PATH) cmdIntermediate[MAX_PATH-1] = '\0'; nbTchar = ::ExpandEnvironmentStrings(args, argsIntermediate, argsIntermediateLen); if (!nbTchar) lstrcpy(argsIntermediate, args); else if (nbTchar >= argsIntermediateLen) argsIntermediate[argsIntermediateLen-1] = '\0'; expandNppEnvironmentStrs(cmdIntermediate, cmd2Exec, MAX_PATH, hWnd); expandNppEnvironmentStrs(argsIntermediate, args2Exec, args2ExecLen, hWnd); HINSTANCE res = ::ShellExecute(hWnd, TEXT("open"), cmd2Exec, args2Exec, TEXT("."), SW_SHOW); return res; }
void TFarmExecutor::onReceive(int socket, const QString &data) { QString reply; try { std::vector<QString> argv; extractArgs(data, argv); reply = execute(argv); } catch (...) { } sendReply(socket, reply); }
int main(int argc, char *argv[]) { // initiates some variables that are used in the computation float h = VMAX/(ALPHA*FC); float dt = h/(BETA*VMAX); float fat = (dt*dt)/(h*h*12.0f); float tf = ((2.0*sqrt(M_PI))/FC); extractArgs(argc, argv); // allocate memory for values needed on host side as well float *seismicPulseVector = NULL; float *npf; CHECK_NULL((float*) malloc(sizeof(float) * xDim * yDim), npf); float *vel; CHECK_NULL((float*) malloc(sizeof(float) * xDim * yDim), vel); // init vel array int i; for( i=0; i < xDim * yDim; i++) { vel[i] = VEL_VALUE * VEL_VALUE * fat; } // allocates memory for the seismic pulse vector CHECK_NULL((float *) malloc(sizeof(float) *timeSteps), seismicPulseVector); // based on the previous calculated parameters, generates the seismic pulse vector generate_seismic_pulse_vector(seismicPulseVector, timeSteps, dt, tf, FC); // initialises the OpenCL environment #ifdef _CPU_ oclSetup(xDim, yDim, spPosX, spPosY, vel, kernelSource); #elif _GPU_ oclSetup(xDim, yDim, spPosX, spPosY, vel, wgXDim, wgYDim, seismicPulseVector[0], kernelSource); #endif // executes the kernel on device GET_TIME_ELAPSED(seismic_exec_ocl(npf, seismicPulseVector, timeSteps)); // writes the image to a binary file #ifdef _OUTFILE write_result_ocl(npf, xDim, yDim, outputFile); #endif // free all allocated memory free(npf); free(vel); free(seismicPulseVector); return 0; }
/*! * Load a JSON object with an args array and kwargs object parsed from the args string */ static void loadArgs( const CodeLine &codeLine, Poco::JSON::Object &obj, const std::string &argsStr, const std::string &argsKey = "args", const std::string &kwargsKey = "kwargs") { Poco::JSON::Array::Ptr args(new Poco::JSON::Array()); Poco::JSON::Object::Ptr kwargs(new Poco::JSON::Object()); try {extractArgs(argsStr, args, kwargs);} catch (const Pothos::Exception &ex) { throw Pothos::SyntaxException(codeLine.toString(), ex); } if (args->size() > 0) obj.set(argsKey, args); if (kwargs->size() > 0) obj.set(kwargsKey, kwargs); }
int main() { char *args[20]; char *input = NULL; //to be filled by getcmd int cnt, bg, status; int histCount = 0; //keeps track of which history item we're on struct hist histArray[10]; //stores history items while(1) { if ((cnt = getcmd("\n>> ", args, &bg, &input)) == 0) { printf("\nPlease enter a command.\n"); continue; } printf("\n"); //if a number is entered as first argument, execute the command with that index in the history array if (isdigit(*args[0])) { if (getCmdFromHistory(args, &input, &histArray[0], histCount) == 0) continue; extractArgs(args, input, &bg); } //add the command to history addToHist(&histArray[0], &histCount, input); if (builtInCmd(args, &histArray[0], histCount) == 1) continue; //run command if issued with '&' at the end else if (bg) { backgroundExec(args, cnt, input); } else { foregroundExec(args, cnt, &histArray[0], histCount); } free(input); } }
// // routine: receive and send on incoming messages // // Notes: // No analysis of the message is performed - that is left // to the command processor task. Instead, the local copy // of the header // is demarshalled to determined whether or not there // is associated data; if there is, space is allocated to // contain it. void * SseInputTask::routine() { extractArgs(); Timer timer; if (cmdArgs->noSSE()) { processIpFromFile(); while (1) timer.sleep(3000); }; // run forever, waiting for messages from the SSE bool stopIssued = false; bool done = false; uint32_t lastCode = MESSAGE_CODE_UNINIT; int32_t lastLen = 0; uint32_t lastTime = 0; while (!done) { // if there's no connection, request that it be // established, then wait for that to happen if (!sse->isConnected()) { requestConnection(); while (!sse->isConnected()) timer.sleep(3000); } stopIssued = false; // got a connection - wait for data to come in SseInterfaceHeader hdr; Error err = sse->recv((void *) &hdr, sizeof(hdr)); if (err) { switch (err) { case EAGAIN: case EINTR: case ENOTCONN: case ECONNRESET: stopAllActivities(stopIssued); continue; default: Fatal(err); break; } } // demarshall the header hdr.demarshall(); if (cmdArgs->logSseMessages()) { LogWarning(ERR_NE, hdr.activityId, "bad msg from Sse, code = %d, len = %d", hdr.code, hdr.dataLength); } // allocate a message to hold the incoming message Msg *msg = msgList->alloc(); msg->setHeader(hdr); msg->setUnit((sonata_lib::Unit) UnitSse); // if there's data associated with the message, // allocate space and retrieve it, demarshall it // based on the message type, // then send it on to the command processor void *data = 0; int32_t len = hdr.dataLength; timeval tv; gettimeofday(&tv, NULL); if (len > 10000) { LogWarning(ERR_NE, hdr.activityId, "msg code = %d, len = %d, t = %u, last msg = %d, last len = %d, last t = %u", hdr.code, len, tv.tv_sec, lastCode, lastLen, lastTime); Timer t; t.sleep(100); } else { lastCode = hdr.code; lastLen = len; lastTime = tv.tv_sec; } if (len) { MemBlk *blk = partitionSet->alloc(len); Assert(blk); if (!blk) Fatal(ERR_MAF); data = blk->getData(); err = sse->recv(data, len); if (err) { switch (err) { case EAGAIN: case EINTR: case ENOTCONN: case ECONNRESET: blk->free(); Assert(msgList->free(msg)); stopAllActivities(stopIssued); continue; default: Fatal(err); break; } } msg->setData(data, len, blk); } // demarshall the data of the message depending on // the message type switch (hdr.code) { case REQUEST_INTRINSICS: break; case CONFIGURE_DX: (static_cast<DxConfiguration *> (data))->demarshall(); break; case PERM_RFI_MASK: case BIRDIE_MASK: case RCVR_BIRDIE_MASK: case TEST_SIGNAL_MASK: demarshallFrequencyMask(data); break; case RECENT_RFI_MASK: demarshallRecentRFIMask(data); break; case REQUEST_DX_STATUS: break; case SEND_DX_ACTIVITY_PARAMETERS: (static_cast<DxActivityParameters *> (data))->demarshall(); break; case DX_SCIENCE_DATA_REQUEST: (static_cast<DxScienceDataRequest *> (data))->demarshall(); break; #ifdef notdef case SEND_DOPPLER_PARAMETERS: (static_cast<DopplerParameters *> (data))->demarshall(); break; #endif case BEGIN_SENDING_FOLLOW_UP_SIGNALS: (static_cast<Count *> (data))->demarshall(); break; case SEND_FOLLOW_UP_CW_SIGNAL: (static_cast<FollowUpCwSignal *> (data))->demarshall(); break; case SEND_FOLLOW_UP_PULSE_SIGNAL: (static_cast<FollowUpPulseSignal *> (data))->demarshall(); break; case DONE_SENDING_FOLLOW_UP_SIGNALS: break; case START_TIME: (static_cast<StartActivity *> (data))->demarshall(); break; case BEGIN_SENDING_CANDIDATES: (static_cast<Count *> (data))->demarshall(); break; case SEND_CANDIDATE_CW_POWER_SIGNAL: (static_cast<CwPowerSignal *> (data))->demarshall(); break; case SEND_CANDIDATE_PULSE_SIGNAL: demarshallPulseSignal(data); break; case DONE_SENDING_CANDIDATES: break; case BEGIN_SENDING_CW_COHERENT_SIGNALS: break; case SEND_CW_COHERENT_SIGNAL: (static_cast<CwCoherentSignal *> (data))->demarshall(); break; case DONE_SENDING_CW_COHERENT_SIGNALS: break; case REQUEST_ARCHIVE_DATA: (static_cast<ArchiveRequest *> (data))->demarshall(); break; case DISCARD_ARCHIVE_DATA: (static_cast<ArchiveRequest *> (data))->demarshall(); break; // the following commands arrive with no data case STOP_DX_ACTIVITY: case SHUTDOWN_DX: case RESTART_DX: Debug(DEBUG_CONTROL, hdr.activityId, "STOP_DX_ACTIVITY, act"); break; default: LogError(ERR_IMT, hdr.activityId, "activity %d, type %d", hdr.activityId, hdr.code); Err(ERR_IMT); ErrStr(hdr.code, "msg code"); Assert(msgList->free(msg)); continue; } // at this point, the entire marshalled message is in // a generic Msg; send the message on for processing, // then go back to waiting cmdQ->send(msg); } return (0); }