Ejemplo n.º 1
0
int main(int argc, const char *argv[])
{
    void *context = zmq_ctx_new();

    assert(argc == 4);
    void *subWildcardSock = createSocket(context, argv[1], ZMQ_SUB);
    void *pubFilenamesSock = createSocket(context, argv[2], ZMQ_PUB);
    void *subDoneSock = createSocket(context, argv[3], ZMQ_SUB);

    std::cout << "Sockets connected" << std::endl;

    bool done = false;
    std::vector<void*> sockets;
    sockets.push_back(subWildcardSock);
    sockets.push_back(subDoneSock);
    while (!done)
    {
        switch (demultiplexSockets(sockets))
        {
        case 0:
            processWildcards(subWildcardSock, pubFilenamesSock);
            break;
        case 1:
            processDone(subDoneSock);
            done = true;
            break;
        };
    }

    zmq_close(subWildcardSock);
    zmq_close(pubFilenamesSock);
    zmq_close(subDoneSock);
}
void PictoreShrinkerController::processDone(void)
{
    PictureShrinker *shrinkedThread = qobject_cast<PictureShrinker *>(this->sender());
    Q_ASSERT (shrinkedThread);

    shrinkedThread->deleteLater();

    emit this->progress((float(this->_actualPicture) / float(this->_pictures)) * 100);

    if (this->_actualPicture < this->_pictures)
    {
        QFileInfo fileInfo =  this->_list.at(this->_actualPicture);

        PictureShrinker *shrinkThread = new PictureShrinker();
        Q_ASSERT (shrinkThread);
        shrinkThread->setPath(QDir::toNativeSeparators(this->_path + QDir::separator() + fileInfo.fileName()));
        shrinkThread->setSavePath(this->_savePath);
        shrinkThread->setScale(this->_widthPercent, this->_heightPercent);

        this->connect(shrinkThread, SIGNAL(finished()), this, SLOT(processDone()), Qt::QueuedConnection);

        this->_actualPicture++;
        shrinkThread->start();
    }
}
void PictoreShrinkerController::startProcessing(void)
{
    if (this->_path.isEmpty())
    {
        emit this->error(PictoreShrinkerController::tr("Missing path to file"));
        return;
    }

    if (this->_savePath.isEmpty())
    {
        emit this->error(PictoreShrinkerController::tr("Missing save path"));
        return;
    }

    if (this->_widthPercent < 0)
    {
        emit this->error(PictoreShrinkerController::tr("Bad width"));
        return;
    }

    if (this->_heightPercent < 0)
    {
        emit this->error(PictoreShrinkerController::tr("Bad height"));
        return;
    }

    this->_actualPicture = 0;
    QDir dir(this->_path);
    dir.setFilter(QDir::Files | QDir::NoSymLinks);

    this->_list = dir.entryInfoList();
    this->_pictures = this->_list.size();
    int startAmount = this->_pictures;
    int i = 0;
    if (this->_pictures > 10)
    {
        startAmount = 10;
    }

    for (i = 0; i < startAmount; ++i)
    {
        QFileInfo fileInfo =  this->_list.at(this->_actualPicture);

        PictureShrinker *shrinkThread = new PictureShrinker();
        Q_ASSERT (shrinkThread);
        shrinkThread->setPath(QDir::toNativeSeparators(this->_path + QDir::separator() + fileInfo.fileName()));
        shrinkThread->setSavePath(this->_savePath);
        shrinkThread->setScale(this->_widthPercent, this->_heightPercent);

        this->connect(shrinkThread, SIGNAL(finished()), this, SLOT(processDone()), Qt::QueuedConnection);

        this->_actualPicture++;
        shrinkThread->start();
    }
}
Ejemplo n.º 4
0
void ApplicationLauncher::stop()
{
    if (!isRunning())
        return;
    if (d->m_currentMode == Gui) {
        d->m_guiProcess.terminate();
        if (!d->m_guiProcess.waitForFinished(1000)) { // This is blocking, so be fast.
            d->m_guiProcess.kill();
            d->m_guiProcess.waitForFinished();
        }
    } else {
        d->m_consoleProcess.stop();
        processDone(0, QProcess::CrashExit);
    }
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ard = new QSerialPort();
    connect(ui->actionConnect_2,SIGNAL(triggered()),this,SLOT(ardConnect()));
    connect(ard,SIGNAL(readyRead()),this,SLOT(receivedLine()));
    connect(ui->actionRead_from_log,SIGNAL(triggered()),this,SLOT(readFile()));
    connect(this,SIGNAL(processDone()),this,SLOT(continueMath()));
    timesPerTic = new QList<int>;
    rpm = new QList<double>;
    angAcc = new QList<double>;
    timeStamp = new QList<double>;
    sortedAng = new QList<double>;
    sortedAngTimes = new QList<double>;
    sortedRpm = new QList<double>;
    sortedRpmTimes = new QList<double>;
}
void StemmedFileProcessingDialog::processFiles(const QString &inFile, const QString &outFile)
{
    ui->cbxReading->setText(ui->cbxReading->text() + " " + inFile);
    ui->cbxWriting->setText(ui->cbxWriting->text() + " " + outFile);
    this->in = inFile;
    this->out = outFile;

    QThread* t = new QThread(this);
    StemmedFileParserController* controller = new StemmedFileParserController(this);
    controller->moveToThread(t);
    t->start();
    QObject::connect(this, SIGNAL(read(QString)), controller, SLOT(onRead(QString)), Qt::QueuedConnection);
    QObject::connect(this, SIGNAL(process()), controller, SLOT(onProcess()), Qt::QueuedConnection);
    QObject::connect(this, SIGNAL(write(QString)), controller, SLOT(onWrite(QString)), Qt::QueuedConnection);
    QObject::connect(this, SIGNAL(generateHistograms(QString)), controller, SLOT(onGenerateHistograms(QString)), Qt::QueuedConnection);
    QObject::connect(controller, SIGNAL(readDone(bool)), this, SLOT(onReadDone(bool)), Qt::QueuedConnection);
    QObject::connect(controller, SIGNAL(processDone()), this, SLOT(onProcessDone()), Qt::QueuedConnection);
    QObject::connect(controller, SIGNAL(writeDone(bool)), this, SLOT(onWriteDone(bool)), Qt::QueuedConnection);
    QObject::connect(controller, SIGNAL(generateHistogramsDone(bool, QString)), this, SLOT(onGenerateHistogramsDone(bool, QString)), Qt::QueuedConnection);
    emit read(this->in);

    this->show();
}
Ejemplo n.º 7
0
void handleInvokeReply(RemoteOpHeader *h, Node srv, Stream str)
{
  State *state;

  anticipateGC(64 * 1024 + 2 * StreamLength(str));
  state = (State *)OIDFetch(h->ss);
  if (ISNIL(state) || !RESDNT(state->firstThing)) {
    /*
     * We probably gc'd this state because we couldn't find any references
     * to it.  Find it and send it this reply.
     */
    Stream newstr;
    RewindStream(str);
    newstr = StealStream(str);
    findAndSendTo(h->ss, newstr);
  } else {
    TRACE(rinvoke, 3, ("InvokeReply received"));

    assert(!ISNIL(state));
    assert(RESDNT(state->firstThing));
    assert(ISetMember(allProcesses, (int)state));

    TRACE(process, 5, ("Resetting nsoid in state %#x", state));
    state->nsoid = nooid;
    state->nstoid = nooid;
    if (h->status) {
      TRACE(rinvoke, 0, ("Obsolete remote invocation return code"));
      h->option1 = 2;
    }
    if (h->option1) {
      /*
       * We are supposed to propagate a failure.
       */
      TRACE(rinvoke, 1, ("Remote invocation raised %s",
			 h->option1 == 1 ? "failure" :
			 h->option1 == 2 ? "unavailable" :
			 "unknown"));
      if (!findHandler(state, h->option1 - 1, (Object)JNIL)) {
	if (!debugInteractively) {
	  state = processDone(state, h->option1);
	} else {
	  char buf[80];
	  sprintf(buf, "Remote invocation raised %s",
		  h->option1 == 1 ? "failure" :
		  h->option1 == 2 ? "unavailable" :
		  "unknown");
	  if (debug(state, buf)) {
	    /*
	     * debug returns 1 when we shouldn't run the state no more.
	     */
	    state = 0;
	  }
	}
      }
      if (state) makeReady(state);
    } else if (RESDNT(state->op->flags) &&
	       BROKEN(state->op->flags) && isBroken(state->op)) {
      if (returnToBrokenObject(state)) {
	/* nothing to do */
      } else {
	makeReady(state);
      }
    } else {
      extractNVars(str, -1, (int *)state->sp, &state->ep, &state->et, srv);
      makeReady(state);
    }
  }
  TRACE(rinvoke, 4, ("Invoke return handled"));
  inhibit_gc--;
}
void BatchProcessImagesDialog::slotFinished()
{
    if (m_convertStatus == PROCESS_DONE)
    {
        // processAborted() has already been called. No need to show the warning.
        return;
    }

    BatchProcessImagesItem *item = static_cast<BatchProcessImagesItem*>(**m_listFile2Process_iterator);
    m_listFiles->scrollToItem(m_listFiles->currentItem());

    if (m_ProcessusProc->exitStatus() == QProcess::CrashExit)
    {
        int code = KMessageBox::warningContinueCancel(this,
                   i18n("The 'convert' program from 'ImageMagick' package has been stopped abnormally"),
                   i18n("Error running 'convert'"));

        if (code == KMessageBox::Cancel)
        {
            processAborted(true);
        }
        else
        {
            item->changeResult(i18nc("batch process result", "Failed."));
            item->changeError(i18n("'convert' program from 'ImageMagick' package "
                                   "has been stopped abnormally."));
            ++*m_listFile2Process_iterator;
            ++m_progressStatus;
            m_ui->m_progress->setValue((int)((float) m_progressStatus * (float) 100 / (float) m_nbItem));

            if (**m_listFile2Process_iterator)
                startProcess();
            else
                endProcess();
        }
        return;
    }

    int ValRet = m_ProcessusProc->exitCode();
    kWarning() << "Convert exit (" << ValRet << ")";

    switch (ValRet)
    {
        case 0:
        { // Process finished successfully !
            item->changeResult(i18n("OK"));
            item->changeError(i18n("no processing error"));
            processDone();

            KUrl src;
            src.setPath(item->pathSrc());
            KUrl dest = m_ui->m_destinationUrl->url();
            dest.addPath(item->nameDest());
            QString errmsg;

            KUrl::List urlList;
            urlList.append(src);
            urlList.append(dest);
            iface()->refreshImages(urlList);

            if (!item->overWrote())
            {
                // Do not add an entry if there was an image at the location already.
                bool ok = iface()->addImage(dest, errmsg);

                if (!ok)
                {
                    int code = KMessageBox::warningContinueCancel(this, i18n(
                                  "<qt>Error adding image to application; error message was: "
                                  "<b>%1</b></qt>", errmsg),
                              i18n("Error Adding Image to Application"));

                    if (code == KMessageBox::Cancel)
                    {
                        slotProcessStop();
                        break;
                    }
                    else
                    {
                        item->changeResult(i18nc("batch process result", "Failed."));
                    }
                }
            }

            if (src != dest)
            {
                // Clone data in KIPI host application.
                KPImageInfo info(src);
                info.cloneData(dest);

                // Move XMP sidecar file.
                KPMetadata::moveSidecar(src, dest);
            }

            if (m_ui->m_removeOriginal->isChecked() && src != dest)
            {
                KUrl deleteImage(item->pathSrc());

                if (KIO::NetAccess::del(deleteImage, kapp->activeWindow()) == false)
                {
                    item->changeResult(i18nc("batch process result", "Warning:"));
                    item->changeError(i18n("cannot remove original image file."));
                }
                else
                {
                    iface()->delImage(item->pathSrc());
                }
            }
            break;
        }
        case 15:
        { //  process aborted !
            processAborted(true);
            break;
        }
        default :
        { // Processing error !
            item->changeResult(i18nc("batch process result", "Failed."));
            item->changeError(i18n("cannot process original image file."));
            break;
        }
    }

    ++*m_listFile2Process_iterator;
    ++m_progressStatus;
    m_ui->m_progress->setValue((int)((float)m_progressStatus *(float)100 / (float)m_nbItem));

    if (**m_listFile2Process_iterator)
        startProcess();
    else
        endProcess();
}