Exemple #1
0
    SimulatorProcessParallel(utils::ContextPtr context)
      : m_jobs(nullptr)
    {
        long block_size = 8;
        {
            context->get_setting("vle.simulation.block-size", &block_size);

            if (block_size <= 0)
                m_block_size = 8;
            else
                m_block_size = block_size;
        }

        long workers_count = 1;
        {
            context->get_setting("vle.simulation.thread", &workers_count);

            if (workers_count <= 0)
                workers_count = 0l;
        }

        vInfo(context,
              _("Simulation kernel: thread:%ld block-size:%ld\n"),
              workers_count,
              m_block_size);

        m_block_id.store(-1, std::memory_order_relaxed);
        m_block_count.store(-1, std::memory_order_relaxed);
        m_running_flag.store(true, std::memory_order_relaxed);

        try {
            m_workers.reserve(workers_count);
            for (long i = 0; i != workers_count; ++i)
                m_workers.emplace_back(&SimulatorProcessParallel::run, this);
        } catch (...) {
            m_running_flag.store(false, std::memory_order_relaxed);
            throw;
        }
    }
Exemple #2
0
void
UpdateProcess::readStandardError()
{
  int idx;
  bool ok;
  QString line, type;
  QHash<QString,QString> args;

  setReadChannel(QProcess::StandardError);
  while (canReadLine()) {
    line = readLine().trimmed();
    vInfo("updater (stderr): %1").arg(line);

    idx = line.indexOf(" ");
    if (idx < 0 || idx == line.length()-1)
      continue;
    type = line.mid(0, idx);
    line = line.mid(idx + 1);

    args = string_parse_keyvals(line, &ok);
    if (! ok)
      continue;
    else if (line.startsWith("thandy.InstallFailed: ", Qt::CaseInsensitive)) {
      /** XXX: This is a f*****g kludge. If installation fails, Thandy just
       *       dumps a Python traceback that (for obvious reasons) doesn't
       *       follow the expected format. There isn't a defined control
       *       message type for this yet we'd really like the error, so treat
       *       this one specially.
       */
      emit installUpdatesFailed(line);
      continue;
    }

    if (! type.compare("CAN_INSTALL", Qt::CaseInsensitive)) {
      QString package = args.value("PKG");
      if (! package.isEmpty()) {
        PackageInfo pkgInfo = packageInfo(package);
        if (pkgInfo.isValid())
          _packageList << pkgInfo;
      }
    } else if (_currentCommand == CheckForUpdates
                 && ! type.compare("DEBUG")
                 && args.value("msg").startsWith("Got ")) {
      /* XXX: This is an even worse f*****g kludge. Thandy only reports
       *      download progress in a not-so-parser-friendly log message,
       *      though, so we must kludge again.
       *
       *      Here's an example of what we're parsing:
       *        "Got 1666048/1666560 bytes from http://updates.torproject.org/thandy/data/win32/tor-0.2.1.9-alpha.msi"
       *
       *      (Note that the kludge above would even match on "Got milk?".)
       */
      QStringList parts = args.value("msg").split(" ");
      if (parts.size() == 5) {
        QStringList progress = parts.at(1).split("/");
        if (progress.size() == 2) {
          int bytesReceived = progress.at(0).toUInt();
          int bytesTotal = progress.at(1).toUInt();
          vInfo("updater: Downloaded %1 of %2 bytes of file %3").arg(bytesReceived)
                                                                .arg(bytesTotal)
                                                                .arg(parts.at(4));
          emit downloadProgress(parts.at(4), bytesReceived, bytesTotal);
        }
      }
    }
  }
}
Exemple #3
0
/** Main application entry point. */
int
main(int argc, char *argv[])
{
  Q_INIT_RESOURCE(vidalia);
  QStringList args = char_array_to_stringlist(argv+1, argc-1);

  /* Construct the application object. Qt strips any command-line arguments
   * that it recognizes in argv, so we'll pass a stringlist of the original
   * list of command-line arguments too. */
  Vidalia vidalia(args, argc, argv);
  vNotice("Vidalia %1 using Qt %2").arg(Vidalia::version())
                                   .arg(QT_VERSION_STR);

#if defined(USE_BREAKPAD)
  /* Set up the crash reporting application and exception handlers. */
  setup_crash_reporter();
#endif
#if defined(USE_MARBLE) && defined(Q_OS_WIN32)
  vApp->addLibraryPath(vApp->applicationDirPath() + "/plugins/qt");
#endif

  /* Install a signal handler to clean up properly after a catching a
   * SIGINT or SIGTERM. */
  install_signal_handler();

  /* Validate any command-line arguments, or show usage message box, if
   * necessary. */
  QString errmsg;
  if (vidalia.showUsage()) {
    Vidalia::showUsageMessageBox();
    return 0;
  } else if (!vidalia.validateArguments(errmsg)) {
    vError("Unable to apply command-line arguments: %1").arg(errmsg);
    VMessageBox::critical(0,
      vApp->translate("Vidalia",
        QT_TRANSLATE_NOOP("Vidalia", "Invalid Argument")), errmsg,
      VMessageBox::Ok);
    return 1;
  }

  /* Check if Vidalia is already running. */
  QString pidfile = vidalia.pidFile();
  if (is_vidalia_running(pidfile)) {
    vWarn("Detected another process with pid %1. Is Vidalia already running?")
                                                               .arg(get_pid());
    /* Let the user know another Vidalia is running and we are going to exit
     * now. */
    int ret = VMessageBox::critical(0,
                vApp->translate("Vidalia",
                  QT_TRANSLATE_NOOP("Vidalia", "Vidalia is already running")),
                vApp->translate("Vidalia",
                  QT_TRANSLATE_NOOP("Vidalia",
                    "Another Vidalia process is possibly already running. "
                    "If there really is not another Vidalia process running, "
                    "you can choose to continue anyway.\n\n"
                    "Would you like to continue starting Vidalia?")),
                VMessageBox::Continue, VMessageBox::Quit|VMessageBox::Default);
    if (ret != VMessageBox::Continue) {
      /* Don't start a second instance of Vidalia */
      vError("Exiting duplicate Vidalia process.");
      return 1;
    }
  }
  write_pidfile(pidfile);

  /* Since we don't have a visible main window, if we were to display a
   * QMessageBox (for example, to display an error when starting or stopping
   * Tor) then the application would exit when that message box was closed.
   * Setting quitOnLastWindowClosed to false fixes this behavior. */
  Vidalia::setQuitOnLastWindowClosed(false);

  /* Create an instance of the main window  */
  MainWindow mainWin;

  /* Run Vidalia */
  int ret = vidalia.run();

  /* Vidalia exited, so cleanup our pidfile and return */
  QFile::remove(pidfile);
  vNotice("Vidalia is exiting cleanly (return code %1).").arg(ret);

#if defined(USE_BREAKPAD)
  vInfo("Removing Breakpad exception handler.");
  CrashReporter::remove_exception_handler();
#endif

  return ret;
}