CCmd::CCmd() { resetCmd(_cmd); registerCmd(HELP_CMDID,"HELP",&helpCmd); //registerCmd(NOLOG_CMDID,"NOLOG",&noLogCmd); registerCmd(EXIT_CMDID,"EXIT",&exitCmd); #if CMD_DEBUG printf("(C)Copyright ASUSTEK Hunter_Chen 2009.\n"); #endif }
static int cmdDestructor(MprCmd *cmd) { MprCmdService *cs; resetCmd(cmd); #if VXWORKS vxCmdDestructor(cmd); #endif cs = mprGetMpr(cmd)->cmdService; mprLock(cs->mutex); mprRemoveItem(cs->cmds, cmd); mprUnlock(cs->mutex); return 0; }
void Graphical_UI::createProcessingMenu() { QMenu* pm = menuBar()->addMenu(tr("&Processing")); newMenuItem(pm, "&Reset", SLOT(resetCmd()), "Reset the graph, clear all data collected", "Ctrl+R", QIcon::fromTheme("edit-delete")); newMenuItem(pm, "&Process", this, SLOT(pause(bool)), "Start/stop processing of frames", !ParameterServer::instance()->get<bool>("start_paused"), " ", QIcon::fromTheme("media-playback-start")); newMenuItem(pm, "Capture One& Frame", SLOT(getOneFrameCmd()), "Process one frame only", QKeySequence::InsertParagraphSeparator); /* Crashes newMenuItem(pm, "&Delete Last Node", SLOT(deleteLastFrameCmd()), "Remove last node from graph", "Backspace", QIcon::fromTheme("edit-undo")); */ pm->addSeparator(); newMenuItem(pm, "Clear Cloud Storage", SIGNAL(clearClouds()), "Remove Point Clouds from Memory", "", QIcon::fromTheme("edit-delete")); newMenuItem(pm, "Optimize Trajectory &Estimate", SLOT(optimizeGraphTrig()), "Compute optimized pose graph with g2o", "O"); pm->addSeparator(); newMenuItem(pm, "E&xit", SLOT(close()), "Exit the application", "Ctrl+Q", QIcon::fromTheme("application-exit"));//doesn't work for gnome }
void GetCmd(){ char input; resetCmd(); while ((input != '\n') && (buffSize < INPUT_MAX_LENGTH)) { buffer[buffSize++] = input; input = getc(); } buffer[buffSize] = '\0'; char* bufferTemp; // bufferTemp = strtok(buffer, " "); while (bufferTemp != NULL) { cmdArgv[cmdArgc] = bufferTemp; //On stock les arguments bufferTemp = strtok(NULL, " "); cmdArgc++; } }
static void manageCmd(MprCmd *cmd, int flags) { int i; if (flags & MPR_MANAGE_MARK) { mprMark(cmd->program); mprMark(cmd->makeArgv); mprMark(cmd->defaultEnv); mprMark(cmd->dir); mprMark(cmd->env); for (i = 0; i < MPR_CMD_MAX_PIPE; i++) { mprMark(cmd->files[i].name); } for (i = 0; i < MPR_CMD_MAX_PIPE; i++) { mprMark(cmd->handlers[i]); } mprMark(cmd->dispatcher); mprMark(cmd->callbackData); mprMark(cmd->signal); mprMark(cmd->forkData); mprMark(cmd->stdoutBuf); mprMark(cmd->stderrBuf); mprMark(cmd->userData); mprMark(cmd->mutex); mprMark(cmd->searchPath); #if ME_WIN_LIKE mprMark(cmd->command); #endif mprMark(cmd->argv); for (i = 0; cmd->argv && i < cmd->argc; i++) { mprMark(cmd->argv[i]); } } else if (flags & MPR_MANAGE_FREE) { resetCmd(cmd, 1); #if VXWORKS if (cmd->startCond) { semDelete(cmd->startCond); } if (cmd->exitCond) { semDelete(cmd->exitCond); } #endif } }
/* Start the command to run (stdIn and stdOut are named from the client's perspective). This is the lower-level way to run a command. The caller needs to do code like mprRunCmd() themselves to wait for completion and to send/receive data. The routine does not wait. Callers must call mprWaitForCmd to wait for the command to complete. */ PUBLIC int mprStartCmd(MprCmd *cmd, int argc, cchar **argv, cchar **envp, int flags) { MprPath info; cchar *pair; int rc, next, i; assert(cmd); assert(argv); if (argc <= 0 || argv == NULL || argv[0] == NULL) { return MPR_ERR_BAD_ARGS; } resetCmd(cmd, 0); cmd->flags = flags; cmd->argc = argc; cmd->argv = mprAlloc((argc + 1) * sizeof(char*)); for (i = 0; i < argc; i++) { cmd->argv[i] = sclone(argv[i]); } cmd->argv[i] = 0; prepWinProgram(cmd); if ((cmd->program = mprSearchPath(cmd->argv[0], MPR_SEARCH_EXE, cmd->searchPath, NULL)) == 0) { mprLog("error mpr cmd", 0, "Cannot access %s, errno %d", cmd->argv[0], mprGetOsError()); return MPR_ERR_CANT_ACCESS; } if (mprGetPathInfo(cmd->program, &info) == 0 && info.isDir) { mprLog("error mpr cmd", 0, "Program \"%s\", is a directory", cmd->program); return MPR_ERR_CANT_ACCESS; } mprLog("info mpr cmd", 6, "Program: %s", cmd->program); cmd->argv[0] = cmd->program; prepWinCommand(cmd); if (envp == 0) { envp = cmd->defaultEnv; } if (blendEnv(cmd, envp, flags) < 0) { return MPR_ERR_MEMORY; } for (i = 0; i < cmd->argc; i++) { mprLog("info mpr cmd", 6, " arg[%d]: %s", i, cmd->argv[i]); } for (ITERATE_ITEMS(cmd->env, pair, next)) { mprLog("info mpr cmd", 6, " env[%d]: %s", next, pair); } slock(cmd); if (makeCmdIO(cmd) < 0) { sunlock(cmd); return MPR_ERR_CANT_OPEN; } /* Determine how many end-of-files will be seen when the child dies */ cmd->requiredEof = 0; if (cmd->flags & MPR_CMD_OUT) { cmd->requiredEof++; } if (cmd->flags & MPR_CMD_ERR) { cmd->requiredEof++; } if (addCmdHandlers(cmd) < 0) { mprLog("error mpr cmd", 0, "Cannot open command handlers - insufficient I/O handles"); return MPR_ERR_CANT_OPEN; } rc = startProcess(cmd); cmd->originalPid = cmd->pid; mprAddItem(MPR->cmdService->cmds, cmd); sunlock(cmd); #if ME_WIN_LIKE if (!rc) { mprCreateTimerEvent(cmd->dispatcher, "pollWinTimer", 10, pollWinTimer, cmd, 0); } #endif return rc; }
PUBLIC void mprDestroyCmd(MprCmd *cmd) { assert(cmd); resetCmd(cmd, 0); mprRemoveItem(MPR->cmdService->cmds, cmd); }
static int syncOVS(EVMod *mod) { HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data; resetCmd(mod); resetExtras(mod); char line[SFVS_MAX_LINELEN]; myDebug(1, "==== ovs-vsctl version ===="); char *version_cmd[] = { SFVS_OVS_CMD, "--version", NULL}; // don't abort if this fails: readVersion returns NO as an easy way // to only see the first line. (Line number should really be supplied to // callback from myExec) mdata->ovs10 = NO; // assume newer version mdata->usingAtVar = NO; myExec((void *)mod, version_cmd, readVersion, line, SFVS_MAX_LINELEN, NULL); // adapt if OVS is upgraded under our feet if(mdata->ovs10 == NO) mdata->useAtVar = YES; if(mdata->config.error || mdata->config.num_collectors == 0 || (mdata->config.sampling_n == 0 && mdata->config.polling_secs == 0)) { // no config or no targets or no sampling/polling - clear everything myDebug(1, "no config found: clearing all OVS sFlow config"); setStr(&mdata->sflowUUID, "[]"); setState(mod, SFVSSTATE_SYNC_DESTROY); } else { // got config - assume here that we're going to create a new // sflow object, but if we find one we'll adopt it setStr(&mdata->sflowUUID, SFVS_NEW_SFLOW_ID); setState(mod, SFVSSTATE_SYNC_SEARCH); } myDebug(1, "==== list sflow ===="); char *list_sflow_cmd[] = { SFVS_OVS_CMD, "list", "sflow", NULL }; if(myExec((void *)mod, list_sflow_cmd, sFlowList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; if(mdata->useAtVar) { // we can add the create at the end } else { // create new sFlow object if there were none found (i.e. if // the sflowUUID has not changed from the initial setting we // gave it. if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) { addCreateSFlow(mod); logCmd(mod); strArrayAdd(mdata->cmd, NULL); // for execve(2) if(myExec((void *)mod, strArray(mdata->cmd), submitCreate, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; resetCmd(mod); } } // make sure every bridge is using this sFlow entry myDebug(1, "==== list bridge ===="); char *list_bridge_cmd[] = { SFVS_OVS_CMD, "list", "bridge", NULL}; if(myExec((void *)mod, list_bridge_cmd, bridgeList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; // now it's safe to delete any extras that we found for(int ex = strArrayN(mdata->extras); --ex >= 0; ) { addDestroySFlow(mod, strArrayAt(mdata->extras, ex)); } if(mdata->useAtVar) { // create new sFlow object if there were none found (i.e. if // the sflowUUID has not changed from the initial setting we // gave it. if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) { addCreateSFlow(mod); } } // if we decided to make any changes, submit them now mdata->cmdFailed = NO; if(strArrayN(mdata->cmd) > 1) { logCmd(mod); strArrayAdd(mdata->cmd, NULL); // for execve(2) if(myExec((void *)mod, strArray(mdata->cmd), submitChanges, line, SFVS_MAX_LINELEN, NULL) == NO) return NO; if(mdata->usingAtVar && mdata->cmdFailed == NO) { // remember that it worked at least once mdata->usedAtVarOK = YES; } } return mdata->cmdFailed ? NO : YES; }
/* * Start the command to run (stdIn and stdOut are named from the client's perspective). This is the lower-level way to * run a command. The caller needs to do code like mprRunCmd() themselves to wait for completion and to send/receive data. * The routine does not wait. Callers must call mprWaitForCmd to wait for the command to complete. */ int mprStartCmd(MprCmd *cmd, int argc, char **argv, char **envp, int flags) { MprPath info; char *program; int rc; mprAssert(argv); mprAssert(argc > 0); if (argc <= 0 || argv == NULL || argv[0] == NULL) { return MPR_ERR_BAD_STATE; } resetCmd(cmd); program = argv[0]; cmd->program = program; cmd->flags = flags; if (sanitizeArgs(cmd, argc, argv, envp) < 0) { return MPR_ERR_NO_MEMORY; } if (access(program, X_OK) < 0) { program = mprJoinPathExt(cmd, program, BLD_EXE); if (access(program, X_OK) < 0) { mprLog(cmd, 1, "cmd: can't access %s, errno %d", program, mprGetOsError()); return MPR_ERR_CANT_ACCESS; } } if (mprGetPathInfo(cmd, program, &info) == 0 && info.isDir) { mprLog(cmd, 1, "cmd: program \"%s\", is a directory", program); return MPR_ERR_CANT_ACCESS; } #if CYGWIN mprGlobalLock(cmd); #endif if (mprMakeCmdIO(cmd) < 0) { #if CYGWIN mprGlobalUnlock(cmd); #endif return MPR_ERR_CANT_OPEN; } /* * Determine how many end-of-files will be seen when the child dies */ cmd->requiredEof = 0; if (cmd->flags & MPR_CMD_OUT) { cmd->requiredEof++; } if (cmd->flags & MPR_CMD_ERR) { cmd->requiredEof++; } #if UNUSED && KEEP && NON_BLOCKING #if BLD_UNIX_LIKE || VXWORKS { int stdinFd, stdoutFd, stderrFd, nonBlock; stdinFd = cmd->files[MPR_CMD_STDIN].fd; stdoutFd = cmd->files[MPR_CMD_STDOUT].fd; stderrFd = cmd->files[MPR_CMD_STDERR].fd; nonBlock = 1; /* * Put the stdout and stderr into non-blocking mode. Windows can't do this because both ends of the pipe * share the same blocking mode (Ugh!). */ #if VXWORKS if (stdoutFd >= 0) { ioctl(stdoutFd, FIONBIO, (int) &nonBlock); } if (stderrFd >= 0) { ioctl(stderrFd, FIONBIO, (int) &nonBlock); } #else if (stdoutFd >= 0) { fcntl(stdoutFd, F_SETFL, fcntl(stdoutFd, F_GETFL) | O_NONBLOCK); } if (stderrFd >= 0) { fcntl(stderrFd, F_SETFL, fcntl(stderrFd, F_GETFL) | O_NONBLOCK); } #endif if (stdoutFd >= 0) { cmd->handlers[MPR_CMD_STDOUT] = mprCreateWaitHandler(cmd, stdoutFd, MPR_READABLE, (MprWaitProc) stdoutCallback, cmd, MPR_NORMAL_PRIORITY, MPR_WAIT_THREAD); } if (stderrFd >= 0) { cmd->handlers[MPR_CMD_STDERR] = mprCreateWaitHandler(cmd, stderrFd, MPR_READABLE, (MprWaitProc) stderrCallback, cmd, MPR_NORMAL_PRIORITY, MPR_WAIT_THREAD); if (stdoutFd >= 0) { /* * Delay enabling stderr events until stdout is complete */ mprDisableWaitEvents(cmd->handlers[MPR_CMD_STDERR]); } } } #endif #endif rc = startProcess(cmd); #if CYGWIN mprGlobalUnlock(cmd); #endif return rc; }
void SerialThreadObject::serialCommand(const ThreadCmd& incomingCommand) { // check for avaiable data: if(incomingCommand != noCmd) { boost::mutex::scoped_lock looplock(threadMutex); // act on the command. switch (incomingCommand) { case resetArduino: { // reset the arduino. //flush out the commands. commandsToArd.clear(); commandsToArd.push_back(resetCmd()); //add the reset command: ; } break; case resetSerial: { if(textStatusData != NULL) { textStatusData->appendText(std::string("Attempting to reset Arduino Serial Connection")); } //reset the serial bus. std::vector<std::string> ports; ss->getAvailablePorts(ports); if (!ports.size()) { if(textStatusData != NULL) { textStatusData->appendText(std::string("No Serial Ports found.")); } } else { if (ports.size() == 1) { ss->setPort(ports[0]); if(textStatusData != NULL) { textStatusData->appendText(std::string("Connecting to Port: ")+ports[0]); } } else { // have user select the correct port for (int i = 0; i < ports.size(); i++) { wxMessageBox(wxString::Format("Found Serial Port: %s (%d/%d)", wxString(ports[i]), i + 1, ports.size())); } int which_port(wxGetNumberFromUser(wxEmptyString, wxT("Select Serial Port Number"), wxEmptyString, 0, 1, ports.size()) - 1); wxMessageBox(wxString::Format("Selected Serial Port: %s", wxString(ports[which_port]))); ss->setPort(ports[which_port]); if(textStatusData != NULL) { textStatusData->appendText(std::string("Connecting to Port: ")+ports[which_port]); } } connected = ss->start(); if(textStatusData != NULL) { textStatusData->appendText(std::string("Connected!!")); } } } break; case connect: //connect to the arduino break; case disconnect: //disconnect from the arduino break; case poll: commandsToArd.clear(); commandsToArd.push_back(pollCmd()); break; default: if(textStatusData != NULL) { textStatusData->appendText(std::string("Command not recognized")); } } looplock.unlock(); } // return currentStatus; }