void VoxelEditor::drawBrush(){//if brush is blocked by a voxel it will just skip over it vector <int> chunks; bool chunkCheck = 0; int x, y, z; _currentIntersect -= _step * _clickDirection;//takes one step back since findIntersect will be outside the grid or in a block if (_currentIntersect.x + _currentBrush->width >= _voxelGrid->getWidth()){ return; } if (_currentIntersect.y + _currentBrush->height >= _voxelGrid->getHeight()){ return; } if (_currentIntersect.z + _currentBrush->length >= _voxelGrid->getLength()){ return; } //for (int i = 0; i < _brushVoxelCoords.size(); i++){//checks if the brush can be drawn in the given dimensions // if ((int)_currentIntersect.x + _brushVoxelCoords[i].x >= _voxelGrid->getWidth()) // return; // if ((int)_currentIntersect.y + _brushVoxelCoords[i].y >= _voxelGrid->getHeight()) // return; // if ((int)_currentIntersect.z + _brushVoxelCoords[i].z >= _voxelGrid->getHeight()) // return; // if (_voxelGrid->getVoxel((int)_currentIntersect.x + _brushVoxelCoords[i].x, (int)_currentIntersect.y + _brushVoxelCoords[i].y, (int)_currentIntersect.z + _brushVoxelCoords[i].z)->type != 0){ // printf("Brush blocked\n"); // return; // } //} vector <Command*> tempComList; for (int i = 0; i < (int)_currentBrush->voxels.size(); i++){ z = i / (_currentBrush->height * _currentBrush->width); y = i % (_currentBrush->height * _currentBrush->width) / _currentBrush->width; x = i % (_currentBrush->height * _currentBrush->width) % _currentBrush->width; if (_voxelGrid->addVoxel(_currentBrush->voxels[i] , x + (int)_currentIntersect.x, y + (int)_currentIntersect.y, z + (int)_currentIntersect.z)){ Command* c = new Command; c->type = 'i'; c->coord = glm::vec3(x + (int)_currentIntersect.x, y + (int)_currentIntersect.y, z + (int)_currentIntersect.z); c->v = new Voxel; *c->v = _currentBrush->voxels[i]; int cChunk = ((int)c->coord.z / 32)*_cWidth * _cHeight + ((int)c->coord.y / 32)*_cWidth + ((int)c->coord.x / 32); for (int j = 0; j < (int)chunks.size(); j++){ if (chunks[j] == cChunk){ chunkCheck = 1; break; } } if (!chunkCheck){ chunks.push_back(cChunk); } chunkCheck = 0; tempComList.push_back(c); } } _voxelGrid->remesh(chunks); if (tempComList.size() > 0) newCommand(tempComList); }
void CMobileCAI::ExecuteLoadUnits(Command &c) { CUnit* unit = uh->GetUnit(c.params[0]); CTransportUnit* tran = dynamic_cast<CTransportUnit*>(unit); if (!tran) { FinishCommand(); return; } if (!inCommand) { inCommand = true; Command newCommand(CMD_LOAD_UNITS, INTERNAL_ORDER | SHIFT_KEY, owner->id); tran->commandAI->GiveCommandReal(newCommand); } if (owner->GetTransporter() != NULL) { if (!commandQue.empty()) FinishCommand(); return; } if (!unit) { return; } float3 pos = unit->pos; if ((pos - goalPos).SqLength2D() > cancelDistance) { SetGoal(pos, owner->pos); } if ((owner->pos - goalPos).SqLength2D() < cancelDistance) { StopMove(); } return; }
/* ---------------------------------------------------------------------- * Author: Julian * Date: 27 January 2014 * Description: Submits a command * ---------------------------------------------------------------------- */ void Console::submitCommand() { // Adds the text to the console! log("> " + consoleTextList[0].getString()); // Adds the command to the commandList commandList.push_back(consoleTextList[0]); iCommand = commandList.end(); // Check for commands (and maybe a values) std::string inputLine = consoleTextList[0].getString(); size_t pos = inputLine.find(' ', 0); // The two strings, one for the command and one for the value std::string command = inputLine.substr(0, pos); std::string values = inputLine.substr(pos + 1); // Searches for the right command and triggers it newCommand(command, values); // Clears the text ;) consoleTextList[0].setString(""); // Sets the scrollbar down again ;) scrollBar[0].setPosition(scrollBar[0].getPosition().x, line[0].position.y - scrollBar[0].getGlobalBounds().height); updateScroll(); }
/* * Reconnect to the current GTM master -------------------------------------------------- * * When failed over, the current Master must have been updated. * Remember to update gtm_proxy configuration file so that it * connects to the new master at the next start. * Please note that we assume GTM has already been failed over. * First argument is gtm_proxy nodename */ static cmd_t * prepare_reconnectGtmProxy(char *nodeName) { cmd_t *cmdGtmCtl, *cmdGtmProxyConf; int idx; FILE *f; char date[MAXTOKEN+1]; if ((idx = gtmProxyIdx(nodeName)) < 0) { elog(ERROR, "ERROR: Specified name %s is not GTM Proxy\n", nodeName); return(NULL); } /* gtm_ctl reconnect */ cmdGtmCtl = initCmd(aval(VAR_gtmProxyServers)[idx]); snprintf(newCommand(cmdGtmCtl), MAXLINE, "gtm_ctl reconnect -Z gtm_proxy -D %s -o \\\"-s %s -t %s\\\"", aval(VAR_gtmProxyDirs)[idx], sval(VAR_gtmMasterServer), sval(VAR_gtmMasterPort)); /* gtm_proxy.conf */ appendCmdEl(cmdGtmCtl, (cmdGtmProxyConf = initCmd(aval(VAR_gtmProxyServers)[idx]))); if ((f = prepareLocalStdin(newFilename(cmdGtmProxyConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdGtmCtl); return(NULL); } fprintf(f, "#===================================================\n" "# Updated due to GTM Proxy reconnect\n" "# %s\n" "gtm_host = '%s'\n" "gtm_port = %s\n" "#----End of reconfiguration -------------------------\n", timeStampString(date, MAXTOKEN), sval(VAR_gtmMasterServer), sval(VAR_gtmMasterPort)); fclose(f); snprintf(newCommand(cmdGtmProxyConf), MAXLINE, "cat >> %s/gtm_proxy.conf", aval(VAR_gtmProxyDirs)[idx]); return(cmdGtmCtl); }
/* * Stop gtm master --------------------------------------------------------- */ static cmd_t * prepare_stopGtmMaster(void) { cmd_t *cmdGtmCtl; cmdGtmCtl = initCmd(sval(VAR_gtmMasterServer)); snprintf(newCommand(cmdGtmCtl), MAXLINE, "gtm_ctl stop -Z gtm -D %s", sval(VAR_gtmMasterDir)); return(cmdGtmCtl); }
/* * Kill gtm master ----------------------------------------------------- * * You should not kill gtm master in this way. This may discard the latest * gtm status. This is just in case. You must try to stop gtm master * gracefully. */ static cmd_t * prepare_killGtmMaster(void) { cmd_t *cmdKill; pid_t gtmPid; if (is_none(sval(VAR_gtmMasterServer))) return(NULL); cmdKill = initCmd(sval(VAR_gtmMasterServer)); gtmPid = get_gtm_pid(sval(VAR_gtmMasterServer), sval(VAR_gtmMasterDir)); if (gtmPid > 0) snprintf(newCommand(cmdKill), MAXLINE, "kill -9 %d; rm -rf /tmp/.s.'*'%d'*' %s/gtm.pid", gtmPid, atoi(sval(VAR_gtmMasterPort)), sval(VAR_gtmMasterDir)); else snprintf(newCommand(cmdKill), MAXLINE, "killall -u %s -9 gtm; rm -rf /tmp/.s.'*'%d'*' %s/gtm.pid", sval(VAR_pgxcUser), atoi(sval(VAR_gtmMasterPort)), sval(VAR_gtmMasterDir)); return(cmdKill); }
/* * Clean gtm master resources -- directory and socket -------------------------- */ cmd_t * prepare_cleanGtmMaster(void) { cmd_t *cmd; /* Remote work dir and clean the socket */ cmd = initCmd(sval(VAR_gtmMasterServer)); snprintf(newCommand(cmd), MAXLINE, "rm -rf %s; mkdir -p %s; chmod 0700 %s;rm -f /tmp/.s.*%d*", sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), atoi(VAR_gtmMasterPort)); return cmd; }
/* * Start gtm master ----------------------------------------------------- */ static cmd_t * prepare_startGtmMaster(void) { cmd_t *cmdGtmCtl; cmdGtmCtl = initCmd(sval(VAR_gtmMasterServer)); snprintf(newCommand(cmdGtmCtl), MAXLINE, "gtm_ctl stop -Z gtm -D %s;" "rm -f %s/register.node;" "gtm_ctl start -Z gtm -D %s", sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir)); return cmdGtmCtl; }
/* * Kill gtm slave -------------------------------------------------------- * * GTM slave has no significant informaion to carry over. But it is a good * habit to stop gtm slave gracefully with stop command. */ static cmd_t * prepare_killGtmSlave(void) { cmd_t *cmdKill; pid_t gtmPid; if (!isVarYes(VAR_gtmSlave) || (sval(VAR_gtmSlaveServer) == NULL) || is_none(sval(VAR_gtmSlaveServer))) { elog(ERROR, "ERROR: GTM slave is not configured.\n"); return(NULL); } cmdKill = initCmd(sval(VAR_gtmSlaveServer)); gtmPid = get_gtm_pid(sval(VAR_gtmSlaveServer), sval(VAR_gtmSlaveDir)); if (gtmPid > 0) snprintf(newCommand(cmdKill), MAXLINE, "kill -9 %d; rm -rf /tmp/.s.'*'%d'*' %s/gtm.pid", gtmPid, atoi(sval(VAR_gtmSlavePort)), sval(VAR_gtmSlaveDir)); else snprintf(newCommand(cmdKill), MAXLINE, "killall -u %s -9 gtm; rm -rf /tmp/.s.'*'%d'*' %s/gtm.pid", sval(VAR_pgxcUser), atoi(sval(VAR_gtmSlavePort)), sval(VAR_gtmSlaveDir)); return(cmdKill); }
int optionAddCommand(struct conf *config, struct command_def *cmd_def, char **argv){ static unsigned int cmdlist_cnt; array_grow((void **) &config->cmdlist.data,&config->cmdlist.arr,sizeof(struct command_exec *)); if(cmd_def==NULL){ config->cmdlist.data[cmdlist_cnt]=NULL; } else{ config->cmdlist.data[cmdlist_cnt]=newCommand(cmd_def); config->cmdlist.data[cmdlist_cnt]->data=argv; } cmdlist_cnt++; return 0; }
/* * Null will be retruend if gtm slave is not configured. * Be careful. If you configure gtm slave and gtm master on a same server, * bott slave amd master process will be killed. */ cmd_t * prepare_cleanGtmSlave(void) { cmd_t *cmd; if (!isVarYes(VAR_gtmSlave) || is_none(VAR_gtmSlaveServer)) return(NULL); cmd = initCmd(sval(VAR_gtmSlaveServer)); snprintf(newCommand(cmd), MAXLINE, "rm -rf %s; mkdir -p %s; chmod 0700 %s;rm -f /tmp/.s.*%d*", sval(VAR_gtmSlaveDir), sval(VAR_gtmSlaveDir), sval(VAR_gtmMasterDir), atoi(VAR_gtmSlavePort)); return cmd; }
void CmdProvider::enqueuePacket(QString pkt_str) { QJsonDocument jdoc = QJsonDocument::fromJson(pkt_str.toLocal8Bit()); qDebug()<<"pkt type:"<<jdoc.isArray()<<jdoc.isObject()<<jdoc.isEmpty(); if (jdoc.isEmpty()) { return; } QJsonObject jobj = jdoc.object(); assert(jobj.contains("id") && jobj.contains("cmd")); this->m_q_cmds.enqueue(jobj); emit newCommand(jobj); }
/* * Cleanup -- nodeName must be valid. Instead, NULL will bereturned. */ cmd_t * prepare_cleanGtmProxy(char *nodeName) { cmd_t *cmd; int idx; if ((idx = gtmProxyIdx(nodeName)) < 0) return NULL; cmd = initCmd(aval(VAR_gtmProxyServers)[idx]); snprintf(newCommand(cmd), MAXLINE, "rm -rf %s; mkdir -p %s; chmod 0700 %s;rm -f /tmp/.s.*%d*", aval(VAR_gtmProxyDirs)[idx], aval(VAR_gtmProxyDirs)[idx], aval(VAR_gtmProxyDirs)[idx], atoi(aval(VAR_gtmProxyPorts)[idx])); return cmd; }
/* * Kill gtm proxy ------------------------------------------------------------------- * * Although gtm proxy does not have significant resources to carry over to the next * run, it is a good habit to stop gtm proxy with stop command gracefully. */ static cmd_t * prepare_killGtmProxy(char *nodeName) { cmd_t *cmd; int idx; pid_t gtmPxyPid; if ((idx = gtmProxyIdx(nodeName)) < 0) { elog(ERROR, "ERROR: Specified name %s is not GTM Proxy\n", nodeName); return NULL; } cmd = initCmd(aval(VAR_gtmProxyServers)[idx]); gtmPxyPid = get_gtmProxy_pid(aval(VAR_gtmProxyServers)[idx], aval(VAR_gtmProxyDirs)[idx]); if (gtmPxyPid > 0) snprintf(newCommand(cmd), MAXLINE, "kill -9 %d; rm -rf /tmp/.s.'*'%d'*' %s/gtm_proxy.pid", gtmPxyPid, atoi(aval(VAR_gtmProxyPorts)[idx]), aval(VAR_gtmProxyDirs)[idx]); else snprintf(newCommand(cmd), MAXLINE, "killall -u %s -9 gtm; rm -rf /tmp/.s.'*'%d'*' %s/gtm_proxy.pid", sval(VAR_pgxcUser), atoi(aval(VAR_gtmProxyPorts)[idx]), aval(VAR_gtmProxyDirs)[idx]); return(cmd); }
/* * Stop gtm slave --------------------------------------------------------------- */ static cmd_t * prepare_stopGtmSlave(void) { cmd_t *cmdGtmCtl; if (!isVarYes(VAR_gtmSlave) || (sval(VAR_gtmSlaveServer) == NULL) || is_none(sval(VAR_gtmSlaveServer))) { elog(ERROR, "ERROR: GTM slave is not configured.\n"); return(NULL); } cmdGtmCtl = initCmd(sval(VAR_gtmSlaveServer)); snprintf(newCommand(cmdGtmCtl), MAXLINE, "gtm_ctl stop -Z gtm -D %s", sval(VAR_gtmSlaveDir)); return(cmdGtmCtl); }
/** *当tcp socket有新数据到达时运行此函数 */ void MapThread::newData() { while(true) { int r = mapSocket->read((char*)(cmd_buf + cmd_buf_fill), 4 - cmd_buf_fill); if(r <= 0) return; cmd_buf_fill += r; if(cmd_buf_fill == 4) { newCommand(); cmd_buf_fill = 0; } } }
/* * Stop gtm proxy ------------------------------------------------------------- */ static cmd_t * prepare_stopGtmProxy(char *nodeName) { cmd_t *cmd; int idx; if ((idx = gtmProxyIdx(nodeName)) < 0) { elog(ERROR, "ERROR: Specified name %s is not GTM Proxy\n", nodeName); return NULL; } cmd = initCmd(aval(VAR_gtmProxyServers)[idx]); snprintf(newCommand(cmd), MAXLINE, "gtm_ctl stop -Z gtm_proxy -D %s", aval(VAR_gtmProxyDirs)[idx]); return(cmd); }
void VoxelEditor::addVoxel(int x, int y, int z) { vector <int> chunk; if (_voxelGrid->addVoxel(*_currentVoxel, x, y, z)){ vector <Command*> tempComList; Command* c = new Command; c->type = 'i'; c->coord = glm::vec3(x, y, z); chunk.push_back((z / 32)*_cWidth*_cHeight + (y / 32)*_cHeight + (x / 32)); c->v = new Voxel; *c->v = *_currentVoxel; tempComList.push_back(c); newCommand(tempComList); _voxelGrid->remesh(chunk); } }
void Console::registerCommand(const std::string &name, Command command) { verifyRegistration(CON_Lang("Command registration"), name, !command); CommandRecord newCommand(name, command); // Zaradi novy prikaz tak, aby byly setridene podle abecedy size_t position = 0; for (const CommandRecord &cmd : cmds) { if (cmd.getName().compare(name) > 0) { break; } ++position; } cmds.insert(cmds.begin() + position, newCommand); if (hasFlag(RegInfoFlag)) { print(CON_Format(CON_Lang("Command registration: \"{0}\" has been successful\n")) << name); } }
void VoxelEditor::fillRange(int x1, int y1, int z1, int x2, int y2, int z2) { vector <int> chunks; bool chunkCheck = 0; vector <Command*> tempComList; int startX = x1 < x2 ? x1 : x2; int startY = y1 < y2 ? y1 : y2; int startZ = z1 < z2 ? z1 : z2; int endX = x2 <= x1 ? x1 : x2; int endY = y2 <= y1 ? y1 : y2; int endZ = z2 <= z1 ? z1 : z2; for(int i = startX; i <= endX; i++) { for(int j = startY; j <= endY; j++) { for(int k = startZ; k <= endZ; k++) { if(_voxelGrid->addVoxel(*_currentVoxel, i, j, k)) { Command* c = new Command; c->type = 'i'; c->coord = glm::vec3(i, j, k); c->v = new Voxel(); *c->v = *_currentVoxel; tempComList.push_back(c); for (int l = 0; l < (int)chunks.size(); l++){ if (chunks[l] == (k / 32)*_cWidth * _cHeight + (j / 32)*_cWidth + (i / 32)){ chunkCheck = 1; break; } } if (!chunkCheck){ chunks.push_back((k / 32)*_cWidth * _cHeight + (j / 32)*_cWidth + (i / 32)); } chunkCheck = 0; } } } } _voxelGrid->remesh(chunks); if(tempComList.size() > 0) { newCommand(tempComList); } }
std::vector<uint8_t> hw_monitor::send(command cmd) const { hwmon_cmd newCommand(cmd); auto opCodeXmit = static_cast<uint32_t>(newCommand.cmd); hwmon_cmd_details details; details.oneDirection = newCommand.oneDirection; details.timeOut = newCommand.timeOut; fill_usb_buffer(opCodeXmit, newCommand.param1, newCommand.param2, newCommand.param3, newCommand.param4, newCommand.data, newCommand.sizeOfSendCommandData, details.sendCommandData.data(), details.sizeOfSendCommandData); send_hw_monitor_command(details); // Error/exit conditions if (newCommand.oneDirection) return std::vector<uint8_t>(); librealsense::copy(newCommand.receivedOpcode, details.receivedOpcode.data(), 4); librealsense::copy(newCommand.receivedCommandData, details.receivedCommandData.data(), details.receivedCommandDataLength); newCommand.receivedCommandDataLength = details.receivedCommandDataLength; // endian? auto opCodeAsUint32 = pack(details.receivedOpcode[3], details.receivedOpcode[2], details.receivedOpcode[1], details.receivedOpcode[0]); if (opCodeAsUint32 != opCodeXmit) { throw invalid_value_exception(to_string() << "OpCodes do not match! Sent " << opCodeXmit << " but received " << static_cast<int>(opCodeAsUint32) << "!"); } return std::vector<uint8_t>(newCommand.receivedCommandData, newCommand.receivedCommandData + newCommand.receivedCommandDataLength); }
TikzCommandList TikzCommandInserter::getChildCommands() { TikzCommandList commandList; QList<TikzCommand> commands; commandList.title = tr(xml.attributes().value("title").toString().toLatin1().data()); QString name; QString description; QString insertion; QString highlightString; QString type; QRegExp newLineRegExp("([^\\\\])\\\\n"); // newlines are the "\n" not preceded by a backslash as in "\\node" QRegExp descriptionRegExp("<([^<>]*)>"); // descriptions are between < and > while (xml.readNextStartElement()) { if (xml.name() == "item") { name = tr(xml.attributes().value("name").toString().toLatin1().data()); description = xml.attributes().value("description").toString(); insertion = xml.attributes().value("insert").toString(); highlightString = xml.attributes().value("highlight").toString(); type = xml.attributes().value("type").toString(); if (description.contains(QLatin1String("\\n"))) // minimize the number of uses of QRegExp { description.replace(newLineRegExp, QLatin1String("\\1\n")); // replace newlines, these are the "\n" not preceded by a backslash as in "\\node" description.replace(newLineRegExp, QLatin1String("\\1\n")); // do this twice to replace all newlines } description.replace(QLatin1String("\\\\"), QLatin1String("\\")); // translate options in the description: QString tempDescription; for (int pos = 0, oldPos = 0; pos >= 0;) { oldPos = pos; pos = descriptionRegExp.indexIn(description, pos); tempDescription += description.midRef(oldPos, pos - oldPos + 1); if (pos >= 0) { tempDescription += tr(descriptionRegExp.cap(1).toLatin1().data()); pos += descriptionRegExp.matchedLength() - 1; } } if (!tempDescription.isEmpty()) description = tempDescription; if (insertion.contains(QLatin1String("\\n"))) // minimize the number of uses of QRegExp { insertion.replace(newLineRegExp, QLatin1String("\\1\n")); // replace newlines, these are the "\n" not preceded by a backslash as in "\\node" insertion.replace(newLineRegExp, QLatin1String("\\1\n")); // do this twice to replace all newlines } insertion.replace(QLatin1String("\\\\"), QLatin1String("\\")); if (name.isEmpty()) { name = description; description.remove('&'); // we assume that if name.isEmpty() then an accelerator is defined in description if (name.isEmpty()) name = insertion; } if (description.isEmpty()) description = insertion; if (type.isEmpty()) type = '0'; commands << newCommand(name, description, insertion, highlightString, xml.attributes().value("dx").toString().toInt(), xml.attributes().value("dy").toString().toInt(), type.toInt()); xml.skipCurrentElement(); // allow to read the next start element on the same level: this skips reading the current end element which would cause xml.readNextStartElement() to evaluate to false } else if (xml.name() == "separator") { commands << newCommand("", "", "", "", 0, 0, 0); xml.skipCurrentElement(); // same as above } else if (xml.name() == "section") { commands << newCommand("", "", "", "", 0, 0, -1); // the i-th command with type == -1 corresponds to the i-th submenu (assumed in getMenu()) commandList.children << getChildCommands(); } else xml.skipCurrentElement(); } commandList.commands = commands; return commandList; }
TikzCommand TikzCommandInserter::newCommand(const QString &name, const QString &command, int dx, int dy, int type) { return newCommand(name, "", command, "", dx, dy, type); }
void ConfigEndpoint::receive(Command_ptr command){ if(command->getCommand()=="exit" || command->getCommand()=="logout" || command->getCommand()=="close"){ ConfigEndpoint_ptr this_ptr = this->shared_from_this(); close(); command->answer("closed config "+configname+"\n", this_ptr); } else if(command->getCommand()=="has_commands"){ { boost::mutex::scoped_lock lock(commandsMutex); for (std::list<Command_ptr>::const_iterator tmp_command = commands.begin(), end = commands.end(); tmp_command != end; ++tmp_command) { std::string receiver = (*tmp_command)->getReceiver(); boost::replace_all(receiver, "*", "(.*)"); boost::regex reg("^"+receiver+"$"); boost::cmatch matches; CommandEndpoint_ptr sender = boost::dynamic_pointer_cast<CommandEndpoint>(command->getSender()); if(sender){ if(boost::regex_search(sender->getId().c_str(), matches, reg)){ sender->receive((*tmp_command)); } } } } } else if(command->getCommand()=="add_command"){ try { Command_ptr newCommand(new Command(command->getArguments(), this->shared_from_this())); { boost::mutex::scoped_lock lock(commandsMutex); commands.push_back(newCommand); } deliver(newCommand); } catch (const std::invalid_argument& ia) { command->answer(Answer::UNKNOWN_CMD, "Command might not be conform with command format "+command->getArguments()+"\n", this->shared_from_this()); } command->answer("added command "+command->getArguments()+"\n", this->shared_from_this()); } else if(command->getCommand()=="save"){ if(command->getArguments().length()>0){ save(command->getArguments()); command->answer("saved config to "+command->getArguments()+"\n", this->shared_from_this()); } else{ save(configname); command->answer("saved config to "+configname+"\n", this->shared_from_this()); } } else if(command->getCommand()=="list"){ std::ostringstream ss; { boost::mutex::scoped_lock lock(commandsMutex); ss << "Currently " << commands.size() << " commands in config" << std::endl << "---------------------------------------" << std::endl; for (std::list<Command_ptr>::const_iterator commandi = commands.begin(), end = commands.end(); commandi != end; ++commandi) { ss << (*commandi)->to_str() << '\n'; } } command->answer(ss.str(), this->shared_from_this()); } else{ CommandEndpoint::receive(command); } }
int main(int argc, char **argv) { if(argc < 2) goto invalidArgNum; char* command = argv[1]; if(argc == 3) { char* path = argv[2]; if (strcasecmp(command, "allnotexist") == 0) { if(!allCaseNotExists(path)) fprintf(stdout, "%s:exists\n", path); } else goto invalidArgCommand; } else if(argc == 4) { char* path = argv[2]; char* fileName = strstr(path, basename(path)); int max = getArgMax(argv[3], fileName); if(strcasecmp(command, "getinos") == 0) { long* inos = getInos(path, max); outputWhenFailed(inos != NULL, strerror(errno)); for(int i = 0; i < max; i++) fprintf(stdout, "%ld\n", inos[i]); } else if (strcasecmp(command, "genaliases") == 0) outputWhenFailed(genInos(path, max), "fail to generate alias"); else goto invalidArgCommand; } else if(argc > 4) { if(strcasecmp(command, "concurrent") == 0) { // alias concurrent getinos /path1 getinos /path2 if(argc % 2 == 1) goto invalidArgSubCmdNum; InvokerPtr invoker = newConcurrentInvoker(); CommandExecutorPtr commandExecutor; char* subCommand; char* subComaandPath; for(int i = 2; i < argc; i += 2) { subCommand = argv[i]; subComaandPath = argv[i + 1]; if(strcasecmp(subCommand, "genalias") == 0) commandExecutor = newCreateAllAliasExecutor(subComaandPath); else if (strcasecmp(subCommand, "casechange") == 0) commandExecutor = newFullCaseChangeExecutor(subComaandPath); else if (strcasecmp(subCommand, "createremove") == 0) commandExecutor = newCreateFileAliasAndRemoveRepeatExecutor(subComaandPath); else goto invalidArgSubCmd; outputWhenFailed(invoker->addCommand(invoker, newCommand(commandExecutor)), "Error whe invoke add command"); } outputWhenFailed(invoker->execute(invoker), "Error whe invoke execute"); } else goto invalidArgCommand; } else goto invalidArgNum; //free all memory exit(EXIT_SUCCESS); invalidArgCommand: fprintf(stderr, "Invalid argument command\n"); goto error; invalidArgNum: fprintf(stdout, "Invalid arguments\n"); goto error; invalidArgSubCmdNum: fprintf(stdout, "Invalid arguments subcomannd number\n"); goto error; invalidArgSubCmd: fprintf(stdout, "Invalid arguments subcomannd\n"); error: exit(EXIT_FAILURE); return 0; }
virtual void MySendCommands() { ScopedLock lock(mutex); double dt = t - last_t; //advance limbs if(robotState.leftLimb.sendCommand) { if(robotState.leftLimb.controlMode == LimbState::POSITION || robotState.leftLimb.controlMode == LimbState::RAW_POSITION) robotState.leftLimb.sendCommand = false; else if(robotState.leftLimb.controlMode == LimbState::VELOCITY) robotState.leftLimb.commandedConfig.madd(robotState.leftLimb.commandedVelocity,dt); else //effort mode not supported robotState.leftLimb.sendCommand = false; //handle joint limits if(robotModel) { for(size_t i=0;i<leftKlamptIndices.size();i++) { if(robotState.leftLimb.commandedConfig[i] < robotModel->qMin[leftKlamptIndices[i]] || robotState.leftLimb.commandedConfig[i] > robotModel->qMax[leftKlamptIndices[i]]) { robotState.leftLimb.commandedConfig[i] = Clamp(robotState.leftLimb.commandedConfig[i],robotModel->qMin[leftKlamptIndices[i]],robotModel->qMax[leftKlamptIndices[i]]); robotState.leftLimb.commandedVelocity[i] = 0; } } } } if(robotState.rightLimb.sendCommand) { if(robotState.rightLimb.controlMode == LimbState::POSITION || robotState.rightLimb.controlMode == LimbState::RAW_POSITION) robotState.rightLimb.sendCommand = false; else if(robotState.rightLimb.controlMode == LimbState::VELOCITY) robotState.rightLimb.commandedConfig.madd(robotState.rightLimb.commandedVelocity,dt); else //effort mode not supported robotState.rightLimb.sendCommand = false; //handle joint limits if(robotModel) { for(size_t i=0;i<rightKlamptIndices.size();i++) { if(robotState.rightLimb.commandedConfig[i] < robotModel->qMin[rightKlamptIndices[i]] || robotState.rightLimb.commandedConfig[i] > robotModel->qMax[rightKlamptIndices[i]]) { robotState.rightLimb.commandedConfig[i] = Clamp(robotState.rightLimb.commandedConfig[i],robotModel->qMin[rightKlamptIndices[i]],robotModel->qMax[rightKlamptIndices[i]]); robotState.rightLimb.commandedVelocity[i] = 0; } } } } //advance grippers if(robotState.leftGripper.sendCommand) robotState.leftGripper.sendCommand = false; robotState.leftGripper.moving = false; for(int i=0;i<robotState.leftGripper.position.n;i++) { double pdes = Clamp(robotState.leftGripper.positionCommand[i],0.0,1.0); double v = Clamp(robotState.leftGripper.speedCommand[i],0.0,1.0); double old = robotState.leftGripper.position[i]; robotState.leftGripper.position[i] += dt*Sign(pdes-robotState.leftGripper.position[i])*v; if(Sign(old-pdes) != Sign(robotState.leftGripper.position[i]-pdes)) //stop robotState.leftGripper.position[i] = pdes; if(robotState.leftGripper.position[i] != pdes) robotState.leftGripper.moving=true; } if(robotState.rightGripper.sendCommand) robotState.rightGripper.sendCommand = false; robotState.rightGripper.moving = false; for(int i=0;i<robotState.leftGripper.position.n;i++) { double pdes = Clamp(robotState.rightGripper.positionCommand[i],0.0,1.0); double v = Clamp(robotState.leftGripper.speedCommand[i],0.0,1.0); double old = robotState.rightGripper.position[i]; robotState.rightGripper.position[i] += dt*Sign(pdes-robotState.rightGripper.position[i])*v; if(Sign(old-pdes) != Sign(robotState.rightGripper.position[i]-pdes)) //stop robotState.rightGripper.position[i] = pdes; if(robotState.rightGripper.position[i] != pdes) robotState.rightGripper.moving = true; } //process base commands if(robotState.base.sendCommand) { Assert(robotState.base.command.size()==3); if(robotState.base.controlMode == BaseState::NONE) { robotState.base.sendCommand = false; robotState.base.moving = false; robotState.base.velocity.set(0.0); } else if(robotState.base.controlMode == BaseState::RELATIVE_POSITION || robotState.base.controlMode == BaseState::ODOMETRY_POSITION) { if(robotState.base.controlMode == BaseState::RELATIVE_POSITION) { //first transform to global odometry robotState.base.controlMode = BaseState::ODOMETRY_POSITION; Vector newCommand(3); robotState.base.ToOdometry(robotState.base.command,newCommand); robotState.base.command = newCommand; } } else if(robotState.base.controlMode == BaseState::RELATIVE_VELOCITY) { //physical mode latches the command ... kinematic mode doesnt //robotState.base.sendCommand = false; if(robotState.base.command.norm() < 1e-3) { //done! robotState.base.sendCommand = false; robotState.base.moving = false; robotState.base.velocity.set(0.0); } } robotState.base.IntegrateCommand(baseCalibration,dt); //cout<<"Desired twist "<<robotState.base.commandedVelocity<<endl; if(robotState.base.controlMode == BaseState::RELATIVE_POSITION || robotState.base.controlMode == BaseState::ODOMETRY_POSITION) { if(robotState.base.commandedPosition.distance(robotState.base.command)<1e-3 && robotState.base.commandedVelocity.norm() < 1e-3) { printf("Arrived, setting sendCommand/moving = false\n"); robotState.base.sendCommand = false; robotState.base.moving = false; robotState.base.velocity.set(0.0); } } } //simulate base if(robotState.base.enabled && robotState.base.sendCommand) { //simulate friction Vector twist(3,0.0); robotState.base.DesiredToLowLevelCommand(baseCalibration,dt,twist); cout<<"Commanded twist "<<twist<<", dt "<<endl; if(Abs(twist(0)) < baseCalibration.xFriction) twist(0) = 0; else twist(0) -= Sign(twist(0))*baseCalibration.xFriction; if(Abs(twist(1)) < baseCalibration.yFriction) twist(1) = 0; else twist(1) -= Sign(twist(1))*baseCalibration.yFriction; if(Abs(twist(2)) < baseCalibration.angFriction) twist(2) = 0; else twist(2) -= Sign(twist(2))*baseCalibration.angFriction; cout<<"Friction changed twist to "<<twist<<endl; robotState.base.velocity = twist; Matrix2 R; R.setRotate(robotState.base.odometry(2)); Vector2 vworld = R*Vector2(twist(0),twist(1)); robotState.base.odometry(0) += vworld.x*dt; robotState.base.odometry(1) += vworld.y*dt; robotState.base.odometry(2) += twist(2)*dt; robotState.base.senseUpdateTime = t; assert(robotState.base.sendCommand == true); } }
tCmd * pC() { tCmd * cmd; simpleCmd * smpl = newCommand(); clearLexList(pSt.list); if (cur_l->type != LEX_WORD) { setParserError(PE_EXPECTED_WORD); delCommand(&smpl); return NULL; } addLex(pSt.list, pSt.l); for(;;) { if (gl()) { clearLexList(pSt.list); delCommand(&smpl); return NULL; } if (cur_l->type == LEX_WORD) addLex(pSt.list, pSt.l); else if (cur_l->type == LEX_REDIRECT_INPUT || cur_l->type == LEX_REDIRECT_OUTPUT || cur_l->type == LEX_REDIRECT_OUTPUT_APPEND) { int type = cur_l->type; if (glhard()) { clearLexList(pSt.list); delCommand(&smpl); return NULL; } if (cur_l->type != LEX_WORD) { setParserError(PE_EXPECTED_WORD); if(smpl->rdrInputFile != NULL) free(smpl->rdrInputFile); if(smpl->rdrOutputFile != NULL) free(smpl->rdrOutputFile); delCommand(&smpl); delLex(cur_l); clearLexList(pSt.list); return NULL; } if (type == LEX_REDIRECT_INPUT) { if(smpl->rdrInputFile != NULL) free(smpl->rdrInputFile); smpl->rdrInputFile = cur_l->str; } else if (type == LEX_REDIRECT_OUTPUT || type == LEX_REDIRECT_OUTPUT_APPEND) { if (type == LEX_REDIRECT_OUTPUT_APPEND) smpl->rdrOutputAppend = 1; else smpl->rdrOutputAppend = 0; if(smpl->rdrOutputFile != NULL) free(smpl->rdrOutputFile); smpl->rdrOutputFile = cur_l->str; } } else break; } genArgVector(smpl, pSt.list); smpl->file = smpl->argv[0]; cmd = genTCmd(smpl); cmd->cmdType = TCMD_SIMPLE; return cmd; }
/* * Does not check if node name is valid. */ static cmd_t * prepare_initGtmProxy(char *nodeName) { cmd_t *cmdInitGtm, *cmdGtmProxyConf; int idx; FILE *f; char timestamp[MAXTOKEN+1]; char **fileList = NULL; if ((idx = gtmProxyIdx(nodeName)) < 0) { elog(ERROR, "ERROR: Specified name %s is not GTM Proxy configuration.\n", nodeName); return NULL; } /* Build directory and run initgtm */ cmdInitGtm = initCmd(aval(VAR_gtmProxyServers)[idx]); snprintf(newCommand(cmdInitGtm), MAXLINE, "killall -u %s -9 gtm_proxy;" "rm -rf %s;" "mkdir -p %s;" "initgtm -Z gtm_proxy -D %s", sval(VAR_pgxcUser), aval(VAR_gtmProxyDirs)[idx], aval(VAR_gtmProxyDirs)[idx], aval(VAR_gtmProxyDirs)[idx]); /* Configure gtm_proxy.conf */ appendCmdEl(cmdInitGtm, (cmdGtmProxyConf = initCmd(aval(VAR_gtmProxyServers)[idx]))); if ((f = prepareLocalStdin(newFilename(cmdGtmProxyConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdInitGtm); return NULL; } fprintf(f, "#===========================\n" "# Added at initialization, %s\n" "listen_addresses = '*'\n" "worker_threads = 1\n" "gtm_connect_retry_interval = 1\n", timeStampString(timestamp, MAXTOKEN));; if (!is_none(sval(VAR_gtmPxyExtraConfig))) AddMember(fileList, sval(VAR_gtmPxyExtraConfig)); if (!is_none(aval(VAR_gtmPxySpecificExtraConfig)[idx])) AddMember(fileList, aval(VAR_gtmPxySpecificExtraConfig)[idx]); appendFiles(f, fileList); CleanArray(fileList); fprintf(f, "nodename = '%s'\n" "port = %s\n" "gtm_host = '%s'\n" "gtm_port = %s\n" "# End of addition\n", aval(VAR_gtmProxyNames)[idx], aval(VAR_gtmProxyPorts)[idx], sval(VAR_gtmMasterServer), sval(VAR_gtmMasterPort)); fclose(f); snprintf(newCommand(cmdGtmProxyConf), MAXLINE, "cat >> %s/gtm_proxy.conf", aval(VAR_gtmProxyDirs)[idx]); return(cmdInitGtm); }
void SerialConnector::done(){ this->command = ""; if( ui.monitorCheckBox->isChecked() ){ this->command.prepend("mon:"); } switch( ui.serialTypeComboBox->currentIndex() ){ case 0: if( ui.vcHeightSpinBox->value() > 0 && ui.vcWidthSpinBox-> value() > 0){ this->command.append("vc:"); if( ui.vcCheckBox->isChecked() ){ this->command.append(QString().sprintf("%dCx%dC",ui.vcWidthSpinBox->value(),ui.vcHeightSpinBox->value())); } else { this->command.append(QString().sprintf("%dx%d",ui.vcWidthSpinBox->value(),ui.vcHeightSpinBox->value())); } } else { this->command.append("vc"); } break; case 1: this->command.append("pty"); break; case 2: this->command.append("none"); break; case 3: this->command.append("null"); break; case 4: this->command.append(ui.ttyComboBox->currentText()); break; case 5: this->command.append(ui.parportComboBox->currentText()); break; case 6: this->command.append("file:"); this->command.append(ui.fileLineEdit->text()); break; case 7: this->command.append("stdio"); break; case 8: this->command.append("pipe:"); this->command.append(ui.pipeLineEdit->text()); break; case 9: this->command.append("udp:"); this->command.append( ui.udpDestinationLineEdit->text() ); this->command.append( ":" ); this->command.append( QString().sprintf("%d",ui.udpDestinationSpinBox->value()) ); this->command.append( "@" ); this->command.append( ui.udpSourceComboBox->itemData( ui.udpSourceComboBox->currentIndex(), Qt::UserRole ).toString()); this->command.append( ":" ); this->command.append( QString().sprintf("%d",ui.udpSourceSpinBox->value()) ); break; case 10: if( ui.tcpTelnetCheckBox->isChecked() ){ this->command.append("telnet:"); } else { this->command.append("tcp:"); } if( ui.tcpServerCheckBox->isChecked() ){ this->command.append( ui.tcpComboBox->itemData( ui.tcpComboBox->currentIndex(), Qt::UserRole ).toString()); this->command.append(":"); this->command.append( QString().sprintf("%d",ui.tcpSpinBox->value()) ); this->command.append(",server"); } else { this->command.append( ui.tcpLineEdit->text() ); this->command.append(":"); this->command.append( QString().sprintf("%d",ui.tcpSpinBox->value()) ); } if( ui.tcpNowaitCheckBox->isChecked() ){ this->command.append(",nowait"); } if( ui.tcpNodelayCheckBox->isChecked() ){ this->command.append(",nodelay"); } break; case 11: this->command.append("unix:"); this->command.append(ui.unixLineEdit->text()); if( ui.unixServerCheckBox->isChecked() ){ this->command.append(",server"); } if( ui.unixNowaitCheckBox->isChecked() ){ this->command.append(",nowait"); } break; case 12: this->command.append("braile"); break; case 13: this->command.append("msmouse"); break; default: break; } this->hide(); emit newCommand(command); }
void POP::parse() { Buffer *b = readBuffer(); while ( b->size() > 0 ) { if ( !d->reader ) { if ( d->reserved ) break; EString * s = b->removeLine( 255 ); if ( !s && b->size() < 255 ) return; if ( !s ) { log( "Connection closed due to overlong line (" + fn( b->size() ) + " bytes)", Log::Error ); err( "Line too long. Closing connection." ); Connection::setState( Closing ); return; } bool unknown = false; EStringList * args = EStringList::split( ' ', *s ); EString cmd = args->take( args->first() )->lower(); if ( d->sawUser && !( cmd == "quit" || cmd == "pass" ) ) { d->sawUser = false; unknown = true; } else if ( cmd == "quit" && args->isEmpty() ) { newCommand( d->commands, this, PopCommand::Quit ); } else if ( cmd == "capa" && args->isEmpty() ) { newCommand( d->commands, this, PopCommand::Capa ); } else if ( d->state == Authorization ) { if ( cmd == "stls" ) { if ( hasTls() ) err( "Nested STLS" ); else newCommand( d->commands, this, PopCommand::Stls ); } else if ( cmd == "auth" ) { newCommand( d->commands, this, PopCommand::Auth, args ); } else if ( cmd == "user" && args->count() == 1 ) { d->sawUser = true; newCommand( d->commands, this, PopCommand::User, args ); } else if ( d->sawUser && cmd == "pass" && args->count() >= 1 ) { d->sawUser = false; newCommand( d->commands, this, PopCommand::Pass, args ); } else if ( cmd == "apop" && args->count() == 2 ) { newCommand( d->commands, this, PopCommand::Apop, args ); } else { unknown = true; } } else if ( d->state == Transaction ) { if ( cmd == "stat" && args->isEmpty() ) { newCommand( d->commands, this, PopCommand::Stat ); } else if ( cmd == "list" && args->count() < 2 ) { newCommand( d->commands, this, PopCommand::List, args ); } else if ( cmd == "top" && args->count() == 2 ) { newCommand( d->commands, this, PopCommand::Top, args ); } else if ( cmd == "retr" && args->count() == 1 ) { newCommand( d->commands, this, PopCommand::Retr, args ); } else if ( cmd == "dele" && args->count() == 1 ) { newCommand( d->commands, this, PopCommand::Dele, args ); } else if ( cmd == "noop" && args->isEmpty() ) { newCommand( d->commands, this, PopCommand::Noop ); } else if ( cmd == "rset" && args->isEmpty() ) { newCommand( d->commands, this, PopCommand::Rset ); } else if ( cmd == "uidl" && args->count() < 2 ) { newCommand( d->commands, this, PopCommand::Uidl, args ); } else { unknown = true; } } else { unknown = true; } if ( unknown ) { err( "Bad command" ); recordSyntaxError(); } } else { d->reader->read(); } runCommands(); } }