// ---------------------------------------------------------------------------- void LocalEvaluator::createProcess() { process = new QProcess(this); process->setProcessChannelMode(QProcess::MergedChannels); connect( process, SIGNAL( error(QProcess::ProcessError) ), SLOT( onProcessError(QProcess::ProcessError) ) ); connect( process, SIGNAL( readyRead() ), SLOT( onProcessOutput() ) ); connect( process, SIGNAL( finished(int) ), SLOT( exit(int) ) ); }
// ---------------------------------------------------------------------------- void LocalEvaluator::reset() { //setWorkingDir( "" ); disconnect( process, SIGNAL( error(QProcess::ProcessError) ), this, SLOT( onProcessError(QProcess::ProcessError) ) ); disconnect( process, SIGNAL( readyRead() ), this, SLOT( onProcessOutput() ) ); disconnect( process, SIGNAL( finished(int) ), this, SLOT( exit(int) ) ); kill(); process->deleteLater(); createProcess(); startJulia(); }
void HITLWidget::startButtonClicked() { QThread *mainThread = QThread::currentThread(); qDebug() << "Main Thread: " << mainThread; // Allow only one instance per simulator if (Simulator::Instances().indexOf(settings.simulatorId) != -1) { widget->textBrowser->append(settings.simulatorId + " alreary started!"); return; } if (!HITLPlugin::typeSimulators.size()) { qxtLog->info("There is no registered simulators, add through HITLPlugin::addSimulator"); return; } // Stop running process if one is active if (simulator) { QMetaObject::invokeMethod(simulator, "onDeleteSimulator", Qt::QueuedConnection); simulator = NULL; } if (settings.hostAddress == "" || settings.inPort == 0) { widget->textBrowser->append("Before start, set UDP parameters in options page!"); return; } SimulatorCreator *creator = HITLPlugin::getSimulatorCreator(settings.simulatorId); simulator = creator->createSimulator(settings); // move to thread <--[BCH] simulator->setName(creator->Description()); simulator->setSimulatorId(creator->ClassId()); connect(simulator, SIGNAL(processOutput(QString)), this, SLOT(onProcessOutput(QString))); // Setup process widget->textBrowser->append(QString("[%1] Starting %2... ").arg(QTime::currentTime().toString("hh:mm:ss")).arg(creator->Description())); qxtLog->info("HITL: Starting " + creator->Description()); // Start bridge bool ret = QMetaObject::invokeMethod(simulator, "setupProcess", Qt::QueuedConnection); if (ret) { Simulator::setInstance(settings.simulatorId); connect(this, SIGNAL(deleteSimulator()), simulator, SLOT(onDeleteSimulator()), Qt::QueuedConnection); widget->startButton->setEnabled(false); widget->stopButton->setEnabled(true); qxtLog->info("HITL: Starting bridge, initializing flight simulator and Autopilot connections"); connect(simulator, SIGNAL(autopilotConnected()), this, SLOT(onAutopilotConnect()), Qt::QueuedConnection); connect(simulator, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect()), Qt::QueuedConnection); connect(simulator, SIGNAL(simulatorConnected()), this, SLOT(onSimulatorConnect()), Qt::QueuedConnection); connect(simulator, SIGNAL(simulatorDisconnected()), this, SLOT(onSimulatorDisconnect()), Qt::QueuedConnection); // Initialize connection status if (simulator->isAutopilotConnected()) { onAutopilotConnect(); } else { onAutopilotDisconnect(); } if (simulator->isSimulatorConnected()) { onSimulatorConnect(); } else { onSimulatorDisconnect(); } } }
void DataInput::start() { QNetworkRequest nr; QString url; //qDebug() << "DataInput:start:"<<type<<":"<<input->arg1(); if( type == "ifttt" ) { // url = "http://api.thingm.com/blink1/eventsall/" + iftttKey; url = "http://feed.thingm.com/blink1/eventsall/" + iftttKey; //url = "http://localhost:3232/blink1/eventsall/" + iftttKey; nr.setUrl(QUrl(url)); reply = networkManager->get(nr); connect(reply, SIGNAL(finished()), this, SLOT(onFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError())); } else if( type == "url" ) { url = input->arg1(); //qDebug() << "datainput:start url: "<<url; if(!url.startsWith("http://") && !url.startsWith("https://")) url="http://"+url; QUrl correctUrl(url); if(correctUrl.isValid()) { nr.setUrl(QUrl(url)); reply = networkManager->get(nr); connect(reply, SIGNAL(finished()), this, SLOT(onFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError())); } else { input->setArg2("Bad URL"); input->setDate(-1); // FIXME: don't like -1 here emit toDelete(this); } } else if( type == "file" ) { QFileInfo fileInfo; fileInfo.setFile(input->arg1()); if( !fileInfo.exists() ) { qDebug() << "datainput:start: no file"; input->setArg2("Not Found"); input->setDate(-1); } else { int lastModTime = fileInfo.lastModified().toTime_t(); // why was cast to uint? if( lastModTime > input->date()) { qDebug() << "datainput:start: file newer"; QFile f(input->arg1()); if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) { input->setArg2("Couldn't Open"); input->setDate(-1); // FIXME: why -1? what does it mean? emit toDelete(this); return; } input->setDate( lastModTime); //fileInfo.lastModified().toTime_t()); QString txt = ""; QTextStream in(&f); txt.append(in.readAll()); bool good = parsePatternOrColor( txt, type, lastModTime ); if( !good ) { input->setArg2("Bad Parse"); } } // last modified else { //input->setArg2("Old File"); // FIXME: should do something to indicate older file //input->setDate(-1); } } emit toDelete(this); } else if( type == "script" ) { //QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, input->arg1()); QFileInfo fileInfo; fileInfo.setFile( input->arg1() ); if( !fileInfo.exists() ) { input->setArg2("Not Found"); input->setDate(-1); emit toDelete(this); } else if( !fileInfo.isExecutable() ) { input->setArg2("Not Executable"); input->setDate(-1); emit toDelete(this); } else { // FIXME: should check new value compare to lastVal // (and FIXME: need to refactor to properly use lastVal for all monitor types) //if(fileInfo.lastModified().toTime_t() != (uint)input->date()){ // no, don't do lastModTime check on exec file, jeez input->setDate(fileInfo.lastModified().toTime_t()); process = new QProcess; connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput())); connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError())); connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError())); connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinished())); // start process running process->start( fileInfo.canonicalFilePath() ); } }
void DataInput::startQml() { QNetworkRequest nr; QString url; int typeNumber = typeToInt(type); switch(typeNumber) { case 0: { url = "http://api.thingm.com/blink1/events/" + iftttKey; // url = "http://api.thingm.com/blink1/events/04CE5FA11A002B8E"; nr.setUrl(QUrl(url)); reply = networkManager->get(nr); connect(reply, SIGNAL(finished()), this, SLOT(onFinishedQml())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError())); } break; case 1: { url = rule; QUrl correctUrl(url); if(correctUrl.isValid()) { nr.setUrl(QUrl(url)); reply = networkManager->get(nr); connect(reply, SIGNAL(finished()), this, SLOT(onFinishedQml())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError())); } else { emit setValueRet("NOT FOUND"); emit toDelete(this); } } break; case 2: { QFile f(rule); if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) { //qDebug() << "File error:"; //qDebug() << "File not found."; emit setValueRet("NOT FOUND"); emit toDelete(this); return; } QString txt = ""; QTextStream in(&f); txt.append(in.readAll()); int idx=txt.indexOf(QRegExp("#([0-9a-fA-F]{6})")); QColor c=QColor("#000000"); f.close(); if(idx!=-1) { c=QColor(txt.mid(idx,7)); emit setColor(c); emit setValueRet(c.name().toUpper()); } else { emit setColor(c); emit setValueRet("NO VALUE"); } emit toDelete(this); } break; case 3: { process = new QProcess; connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput())); connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError())); connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError())); connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinishedQml())); QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, rule); QFile f(path); if(f.exists()) process->start(path); else { //qDebug() << "Script error:"; //qDebug() << "Script doesn't' exist!"; emit setValueRet("NOT FOUND"); emit toDelete(this); } } break; default: { emit toDelete(this); } break; } }
void DataInput::start() { QNetworkRequest nr; QString url; int typeNumber = typeToInt(type); switch(typeNumber) { case 0: { url = "http://api.thingm.com/blink1/eventsall/" + iftttKey; // url = "http://api.thingm.com/blink1/events/04CE5FA11A002B8E"; nr.setUrl(QUrl(url)); reply = networkManager->get(nr); connect(reply, SIGNAL(finished()), this, SLOT(onFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError())); } break; case 1: { url = input->arg1(); if(!url.startsWith("http://") && !url.startsWith("https://")) url="http://"+url; QUrl correctUrl(url); if(correctUrl.isValid()) { nr.setUrl(QUrl(url)); reply = networkManager->get(nr); connect(reply, SIGNAL(finished()), this, SLOT(onFinished())); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError())); } else { emit setValueRet("NOT FOUND"); input->setArg2("NOT FOUND"); input->setDate(-1); emit toDelete(this); } } break; case 2: { QFileInfo fileInfo; fileInfo.setFile(input->arg1()); if(!fileInfo.exists()){ input->setArg2("NOT FOUND"); input->setDate(-1); } if(fileInfo.lastModified().toTime_t() != (uint)input->date()) { QFile f(input->arg1()); if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) { //qDebug() << "File error:"; //qDebug() << "File not found."; emit setValueRet("NOT FOUND"); input->setArg2("NOT FOUND"); input->setDate(-1); emit toDelete(this); return; } input->setDate(fileInfo.lastModified().toTime_t()); QString txt = ""; QTextStream in(&f); txt.append(in.readAll()); int idx=txt.indexOf(QRegExp("#([0-9a-fA-F]{6})")); QColor c=QColor("#000000"); f.close(); if(idx!=-1) { c=QColor(txt.mid(idx,7)); emit setColor(c); emit addReceiveEvent(fileInfo.lastModified().toTime_t(), c.name().toUpper(), "FILE"); input->setArg2(c.name()); } else { QStringList list; list.append("pattern:"); list.append("\"pattern\":"); QString patternName; int index=-1; for(int i=0; i<list.count(); i++) { index = txt.indexOf(list.at(i),0); if(index != -1) break; } if(index != -1) { index = txt.indexOf(":", index); int idx1, idx2; idx1 = txt.indexOf("\"", index); idx2 = txt.indexOf("\"", idx1+1); patternName = txt.mid(idx1+1, idx2-idx1-1); for(int i=0; i<patternList.count(); i++) { if(patternList[i] == patternName) { emit runPattern(patternName, false); emit addReceiveEvent(fileInfo.lastModified().toTime_t(), patternName, "FILE"); input->setArg2(patternName); break; } } }else{ input->setArg2("NO VALUE"); } } } emit toDelete(this); } break; case 3: { process = new QProcess; connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput())); connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError())); connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError())); connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinished())); // QString path = QStandardPaths::displayName(QStandardPaths::DocumentsLocation); QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, input->arg1()); QFile f(path); QFileInfo fileInfo; fileInfo.setFile(path); if(f.exists()){ if(fileInfo.lastModified().toTime_t() != (uint)input->date()){ input->setDate(fileInfo.lastModified().toTime_t()); process->start(path); }else{ emit toDelete(this); } }else { //qDebug() << "Script error:"; //qDebug() << "Script doesn't' exist!"; emit setValueRet("NOT FOUND"); input->setArg2("NOT FOUND"); input->setDate(-1); emit toDelete(this); } } break; default: { emit toDelete(this); } break; } }
void MoCapWidget::startButtonClicked() { QThread* mainThread = QThread::currentThread(); qDebug() << "Main Thread: "<< mainThread; //Allow only one instance per exporter if(Exporter::Instances().indexOf(settings.exporterId) != -1) { widget->textBrowser->append(settings.exporterId + " alreary started!"); return; } if(!MoCapPlugin::typeMocaps.size()) { qxtLog->info("There is no registered exporters, add through MoCapPlugin::addExporter"); return; } // Stop running process if one is active if(exporter) { QMetaObject::invokeMethod(exporter, "onDeleteExporter",Qt::QueuedConnection); exporter = NULL; } if(settings.hostAddress == "" || settings.inPort == 0) { widget->textBrowser->append("Before start, set UDP parameters in options page!"); return; } MocapCreator* creator = MoCapPlugin::getMocapCreator(settings.exporterId); exporter = creator->createExporter(settings, widget); // move to thread <--[BCH] exporter->setName(creator->Description()); exporter->setExporterId(creator->ClassId()); connect(exporter, SIGNAL(processOutput(QString)), this, SLOT(onProcessOutput(QString))); // Setup process widget->textBrowser->append(QString("[%1] Starting %2... ").arg(QTime::currentTime().toString("hh:mm:ss")).arg(creator->Description())); qxtLog->info("MoCap: Starting " + creator->Description()); // Start bridge bool ret = QMetaObject::invokeMethod(exporter, "setupProcess",Qt::QueuedConnection); if(ret) { Exporter::setInstance(settings.exporterId); connect(this,SIGNAL(deleteExporter()),exporter, SLOT(onDeleteExporter()),Qt::QueuedConnection); widget->startButton->setEnabled(false); widget->stopButton->setEnabled(true); qxtLog->info("MoCap: Starting bridge, initializing flight exporter and Autopilot connections"); connect(exporter, SIGNAL(autopilotConnected()), this, SLOT(onAutopilotConnect()),Qt::QueuedConnection); connect(exporter, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect()),Qt::QueuedConnection); connect(exporter, SIGNAL(exporterConnected()), this, SLOT(onExporterConnect()),Qt::QueuedConnection); connect(exporter, SIGNAL(exporterDisconnected()), this, SLOT(onExporterDisconnect()),Qt::QueuedConnection); connect(widget->trackablesComboBox, SIGNAL( currentIndexChanged(int)), this, SLOT(ontrackablesComboBox_changed())); // Initialize connection status if ( exporter->isAutopilotConnected() ) { onAutopilotConnect(); } else { onAutopilotDisconnect(); } if ( exporter->isExporterConnected() ) { onExporterConnect(); } else { onExporterDisconnect(); } } }