コード例 #1
0
ファイル: krunnerapp.cpp プロジェクト: fluxer/kde-workspace
void KRunnerApp::cleanUp()
{
    disconnect(KRunnerSettings::self(), SIGNAL(configChanged()), this, SLOT(reloadConfig()));
    kDebug() << "deleting interface";
    delete m_interface;
    m_interface = 0;
    delete m_runnerManager;
    m_runnerManager = 0;
    delete m_tasks;
    m_tasks = 0;
    KGlobal::config()->sync();
}
コード例 #2
0
ファイル: cap_gphoto2.cpp プロジェクト: Aspie96/opencv
/**
 * Connects to selected device.
 */
bool DigitalCameraCapture::open(int index)
{
    const char * model = 0, *path = 0;
    int m, p;
    GPPortInfo portInfo;

    if (isOpened()) {
        close();
    }

    try
    {
        CR(gp_camera_new(&camera));
        CR(gp_list_get_name(allDevices, index, &model));
        CR(gp_list_get_value(allDevices, index, &path));

        // Set model abilities.
        CR(m = gp_abilities_list_lookup_model(abilitiesList, model));
        CR(gp_abilities_list_get_abilities(abilitiesList, m, &cameraAbilities));
        CR(gp_camera_set_abilities(camera, cameraAbilities));

        // Set port
        CR(p = gp_port_info_list_lookup_path(capablePorts, path));
        CR(gp_port_info_list_get_info(capablePorts, p, &portInfo));
        CR(gp_camera_set_port_info(camera, portInfo));

        // Initialize connection to the camera.
        CR(gp_camera_init(camera, context));

        message(STATUS, "connected camera", model);
        message(STATUS, "connected using", path);

        // State initialization
        firstCapturedFrameTime = 0;
        capturedFrames = 0;
        preview = false;
        reloadOnChange = false;
        collectMsgs = false;

        reloadConfig();

        opened = true;
        return true;
    }
    catch (GPhoto2Exception & e)
    {
        message(WARNING, "opening device failed", e);
        return false;
    }
}
コード例 #3
0
ファイル: Collider.cpp プロジェクト: ilyaskurikhin/beesim
Collider::Collider(const Vec2d& position, double radius)
// affecte par défaut le rayon et la position
    :
    radius_(radius), position_(position)
{
    reloadConfig();
    // PRECODITIONS for constructor
    if (radius_ < 0) {
        throw std::runtime_error(
            "Collider with negative radius created. (Collider::Collider)");
    }

    // puts Collider into map
    clamping();
}
コード例 #4
0
ファイル: shellui.cpp プロジェクト: giucam/orbital
ShellUI::ShellUI(Client *client, QQmlEngine *engine, const QString &configFile)
       : QObject(client)
       , m_client(client)
       , m_configFile(configFile)
       , m_configMode(false)
       , m_cursorShape(-1)
       , m_engine(engine)
       , m_numWorkspaces(1)
       , m_style(nullptr)
{
    m_engine->rootContext()->setContextProperty(QStringLiteral("Ui"), this);

    client->addWorkspace(0);
    reloadConfigFile();
    reloadConfig();
}
コード例 #5
0
bool AsyncThriftForwarder::init()
{
	TLogger::configure();
	this->setApplicationName("asyncthrift-forwarder");

	try {
		QtArgCmdLine cmdline;

		QtArg config('c', "config", "Configuration directory override", false, true);
		QtArg daemonize('d', "daemonize", "Daemonize on start", false, false);
		QtArg user('u', "user", "Run as the given user", false, true);

		QtArgHelp help(&cmdline);
		help.printer()->setProgramDescription("Thrift asynchronous server forwarder.");
		help.printer()->setExecutableName(this->applicationName());

		cmdline.addArg(&config);
		cmdline.addArg(&daemonize);
		cmdline.addArg(&user);
		cmdline.addArg(help);
		cmdline.parse();

		if (config.isPresent())
			config_dir = QDir(config.value().toString());

		if (!config_dir.exists()) {
			TERROR("Invalid configuration directory: '%s'", qPrintable(config_dir.path()));
			return false;
		}

		config_dir.makeAbsolute();

		if (!TApplication::init(QList<int>() << SIGINT << SIGTERM << SIGHUP, daemonize.isPresent(), user.value().toString(), "asyncthrift/forwarder"))
			return false;
	} catch (const QtArgHelpHasPrintedEx& ex) {
		return false;
	} catch (const QtArgBaseException& ex) {
		TERROR("%s", ex.what());
		return false;
	}

	if (!reloadConfig())
		return false;

	return true;
}
コード例 #6
0
void ControlApplication::checkServicePasswords()
{
  Configurator::getInstance()->setServiceFlag(true);
  Configurator::getInstance()->load();
  ServerConfig *config = Configurator::getInstance()->getServerConfig();

  bool askToChangeRfbAuth = !config->isUsingAuthentication() || !config->hasPrimaryPassword();
  bool askToChangeAdmAuth = !config->isControlAuthEnabled() || !config->hasControlPassword();
  SetPasswordsDialog dialog(askToChangeRfbAuth, askToChangeAdmAuth);
  if (dialog.showModal() == IDOK) {
    UINT8 cryptedPass[8];
    bool useRfbAuth = dialog.getUseRfbPass();
    bool dontUseRfbAuth = dialog.getRfbPassForClear();
    // Note: The state !useRfbAuth && !dontUseRfbAuth is valid and means "do not change
    // the auth settings".
    if (useRfbAuth) {
      StringStorage pass;
      dialog.getRfbPass(&pass);
      getCryptedPassword(cryptedPass, pass.getString());
      config->setPrimaryPassword(cryptedPass);
      config->useAuthentication(true);
    } else if (dontUseRfbAuth) {
      config->deletePrimaryPassword();
      config->deleteReadOnlyPassword();
      config->useAuthentication(false);
    }
    bool useAdmAuth = dialog.getUseAdmPass();
    bool dontUseAdmAuth = dialog.getAdmPassForClear();
    if (useAdmAuth) {
      StringStorage pass;
      dialog.getAdmPass(&pass);
      getCryptedPassword(cryptedPass, pass.getString());
      config->setControlPassword(cryptedPass);
      config->useControlAuth(true);
    } else if (dontUseAdmAuth) {
      config->deleteControlPassword();
      config->useControlAuth(false);
    }
    Configurator::getInstance()->save();
    reloadConfig();
  }
}
コード例 #7
0
void DesktopThemeDetails::removeTheme()
{
    bool removeTheme = true;
    KConfigGroup cfg = KConfigGroup(KSharedConfig::openConfig("plasmarc"), "Theme");
    QString activeTheme = cfg.readEntry("name", "default");
    const QString theme = m_theme->currentIndex().data(ThemeModel::PackageNameRole).toString();
    const QString themeName = m_theme->currentIndex().data(Qt::DisplayRole).toString();


    if (m_themeCustomized) {
        if(KMessageBox::questionYesNo(this, i18n("Theme items have been changed.  Do you still wish remove the \"%1\" theme?", themeName), i18n("Remove Desktop Theme")) == KMessageBox::No) {
            removeTheme = false;
        }
    } else {
        if (theme == "default") {
            KMessageBox::information(this, i18n("Removal of the default desktop theme is not allowed."), i18n("Remove Desktop Theme"));
            removeTheme = false;
        } else {
            if(KMessageBox::questionYesNo(this, i18n("Are you sure you wish remove the \"%1\" theme?", themeName), i18n("Remove Desktop Theme")) == KMessageBox::No) {
                removeTheme = false;
            }
        }

    }
    KStandardDirs dirs;
    if (removeTheme) {
        if (theme == activeTheme) {
            setDesktopTheme("default");
            activeTheme = "default";
        }
        if (QDir(dirs.locateLocal("data", "desktoptheme/" + theme, false)).exists()) {
            KIO::DeleteJob *deleteTheme = KIO::del(QUrl::fromLocalFile(dirs.locateLocal("data", "desktoptheme/" + theme, false)), KIO::HideProgressInfo);
            KIO::NetAccess::synchronousRun(deleteTheme, this);
        }
    }
    m_themeModel->reload();
    reloadConfig();
    m_theme->setCurrentIndex(m_themeModel->indexOf(activeTheme));
}
コード例 #8
0
DesktopThemeDetails::DesktopThemeDetails(QWidget* parent)
    : QWidget(parent),
      m_themeModel(0)

{
    setWindowIcon(QIcon::fromTheme("preferences-desktop"));
    setupUi(this);

    QFont font = QFont();
    //font.setBold(true);
    font.setPointSize(1.2*font.pointSize());
    m_themeInfoName->setFont(font);

    m_enableAdvanced->setChecked(false);
    toggleAdvancedVisible();


    m_themeModel = new ThemeModel(this);
    m_theme->setModel(m_themeModel);
    m_theme->setItemDelegate(new ThemeDelegate(m_theme));

    reloadConfig();

    connect(m_theme->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(themeSelectionChanged(QItemSelection,QItemSelection)));

    connect(m_enableAdvanced, &QCheckBox::toggled, this, &DesktopThemeDetails::toggleAdvancedVisible);
    connect(m_removeThemeButton, &QPushButton::clicked, this, &DesktopThemeDetails::removeTheme);
    connect(m_exportThemeButton, &QPushButton::clicked, this, &DesktopThemeDetails::exportTheme);

    connect(m_newThemeName, &KLineEdit::editingFinished, this, &DesktopThemeDetails::newThemeInfoChanged);

    m_baseTheme = "default";
    m_themeCustomized = false;
    resetThemeDetails();
    adjustSize();
}
コード例 #9
0
ファイル: view.cpp プロジェクト: cmacq2/plasma-workspace
View::View(QWindow *)
    : PlasmaQuick::Dialog(),
      m_offset(.5),
      m_floating(false)
{
    setClearBeforeRendering(true);
    setColor(QColor(Qt::transparent));
    setFlags(Qt::FramelessWindowHint);

    KCrash::setFlags(KCrash::AutoRestart);

    m_config = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("krunnerrc")), "General");

    setFreeFloating(m_config.readEntry("FreeFloating", false));
    reloadConfig();

    new AppAdaptor(this);
    QDBusConnection::sessionBus().registerObject(QStringLiteral("/App"), this);

    if (KAuthorized::authorize(QStringLiteral("run_command"))) {
        QAction *a = new QAction(0);
        QObject::connect(a, &QAction::triggered, this, &View::displayOrHide);
        a->setText(i18n("Run Command"));
        a->setObjectName(QStringLiteral("run command"));
        KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << QKeySequence(Qt::ALT + Qt::Key_Space), KGlobalAccel::NoAutoloading);
        KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << QKeySequence(Qt::ALT + Qt::Key_Space) << QKeySequence(Qt::ALT + Qt::Key_F2) << Qt::Key_Search);

        a = new QAction(0);
        QObject::connect(a, &QAction::triggered, this, &View::displayWithClipboardContents);
        a->setText(i18n("Run Command on clipboard contents"));
        a->setObjectName(QStringLiteral("run command on clipboard contents"));
        KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2));
        KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2));
    }

    m_qmlObj = new KDeclarative::QmlObject(this);
    m_qmlObj->setInitializationDelayed(true);
    connect(m_qmlObj, &KDeclarative::QmlObject::finished, this, &View::objectIncubated);

    KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
    KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE");
    const QString packageName = cg.readEntry("LookAndFeelPackage", QString());
    if (!packageName.isEmpty()) {
        package.setPath(packageName);
    }

    m_qmlObj->setSource(QUrl::fromLocalFile(package.filePath("runcommandmainscript")));
    m_qmlObj->engine()->rootContext()->setContextProperty(QStringLiteral("runnerWindow"), this);
    m_qmlObj->completeInitialization();

    auto screenRemoved = [=](QScreen* screen) {
        if (screen == this->screen()) {
            setScreen(qGuiApp->primaryScreen());
            hide();
        }
    };

    auto screenAdded = [=](QScreen* screen) {
        connect(screen, &QScreen::geometryChanged, this, &View::screenGeometryChanged);
        screenGeometryChanged();
    };

    foreach(QScreen* s, QGuiApplication::screens())
        screenAdded(s);
    connect(qApp, &QGuiApplication::screenAdded, this, screenAdded);
    connect(qApp, &QGuiApplication::screenRemoved, this, screenRemoved);

    connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos);

    connect(this, &View::visibleChanged, this, &View::resetScreenPos);

    KDirWatch::self()->addFile(m_config.name());

    // Catch both, direct changes to the config file ...
    connect(KDirWatch::self(), &KDirWatch::dirty, this, &View::reloadConfig);
    connect(KDirWatch::self(), &KDirWatch::created, this, &View::reloadConfig);

    if (m_qmlObj->rootObject()) {
        connect(m_qmlObj->rootObject(), SIGNAL(widthChanged()), this, SLOT(resetScreenPos()));
    }

    if (m_floating) {
        setLocation(Plasma::Types::Floating);
    } else {
        setLocation(Plasma::Types::TopEdge);
    }

    connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &View::slotFocusWindowChanged);
}
コード例 #10
0
ファイル: cap_gphoto2.cpp プロジェクト: Aspie96/opencv
/**
 * Set property.
 * @see DigitalCameraCapture for more information about value, double typed, argument.
 */
bool DigitalCameraCapture::setProperty(int propertyId, double value)
{
    CameraWidget * widget = NULL;
    bool output = false;
    if (propertyId < 0)
    {
        widget = getWidget(-propertyId);
    }
    else
    {
        switch (propertyId)
        {
            // gphoto2 cap featured
            case CV_CAP_PROP_GPHOTO2_PREVIEW:
                preview = value != 0;
                return true;
            case CV_CAP_PROP_GPHOTO2_WIDGET_ENUMERATE:
                return false;
            case CV_CAP_PROP_GPHOTO2_RELOAD_CONFIG:
                reloadConfig();
                return true;
            case CV_CAP_PROP_GPHOTO2_RELOAD_ON_CHANGE:
                reloadOnChange = value != 0;
                return true;
            case CV_CAP_PROP_GPHOTO2_COLLECT_MSGS:
                collectMsgs = value != 0;
                return true;
            case CV_CAP_PROP_GPHOTO2_FLUSH_MSGS:
                return false;
            default:
                widget = setGenericProperty(propertyId, value, output);
                /* no break */
        }
    }
    if (widget == NULL)
        return output;
    try
    {
        CameraWidgetType type;
        CR(gp_widget_get_type(widget, &type));
        switch (type)
        {
            case GP_WIDGET_RADIO:
            case GP_WIDGET_MENU:
            {
                int i = static_cast<int>(value);
                char *choice;
                CR(gp_widget_get_choice(widget, i, (const char**)&choice));
                CR(gp_widget_set_value(widget, choice));
                break;
            }
            case GP_WIDGET_TOGGLE:
            {
                int i = static_cast<int>(value);
                CR(gp_widget_set_value(widget, &i));
                break;
            }
            case GP_WIDGET_RANGE:
            {
                float v = static_cast<float>(value);
                CR(gp_widget_set_value(widget, &v));
                break;
            }
            default:
            {
                CR(gp_widget_set_value(widget, (void* )(intptr_t )&value));
                break;
            }
        }
        if (!reloadOnChange)
        {
            // force widget change
            CR(gp_widget_set_changed(widget, 1));
        }

        // Use the same locale setting as while getting rootWidget.
        char * localeTmp = setlocale(LC_ALL, "C");
        CR(gp_camera_set_config(camera, rootWidget, context));
        setlocale(LC_ALL, localeTmp);

        if (reloadOnChange)
        {
            reloadConfig();
        } else {
            CR(gp_widget_set_changed(widget, 0));
        }
    }
    catch (GPhoto2Exception & e)
    {
        char buf[128] = "";
        sprintf(buf, "cannot set property: %d to %f", propertyId, value);
        message(WARNING, (const char *) buf, e);
        return false;
    }
    return true;
}
コード例 #11
0
ファイル: krunnerapp.cpp プロジェクト: fluxer/kde-workspace
void KRunnerApp::initialize()
{
    setWindowIcon(KIcon(QLatin1String("system-run")));

    setQuitOnLastWindowClosed(false);
    KCrash::setFlags(KCrash::AutoRestart);
    initializeStartupNotification();

    connect(KRunnerSettings::self(), SIGNAL(configChanged()), this, SLOT(reloadConfig()));

    m_runnerManager = new Plasma::RunnerManager;

    new AppAdaptor(this);
    QDBusConnection::sessionBus().registerObject(QLatin1String("/App"), this);

    // Global keys
    m_actionCollection = new KActionCollection(this);
    KAction* a = 0;

    a = m_actionCollection->addAction(QLatin1String("Run Command"));
    a->setText(i18n("Run Command"));
    a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::Key_F2));
    connect(a, SIGNAL(triggered(bool)), SLOT(displayOrHide()));

    a = m_actionCollection->addAction(QLatin1String("Run Command on clipboard contents"));
    a->setText(i18n("Run Command on clipboard contents"));
    a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::SHIFT+Qt::Key_F2));
    connect(a, SIGNAL(triggered(bool)), SLOT(displayWithClipboardContents()));

    a = m_actionCollection->addAction(QLatin1String("Show System Activity"));
    a->setText(i18n("Show System Activity"));
    a->setGlobalShortcut(KShortcut(Qt::CTRL+Qt::Key_Escape));
    connect(a, SIGNAL(triggered(bool)), SLOT(showTaskManager()));

    if (KAuthorized::authorize(QLatin1String("switch_user"))) {
        a = m_actionCollection->addAction(QLatin1String("Switch User"));
        a->setText(i18n("Switch User"));
        a->setGlobalShortcut(KShortcut(Qt::ALT+Qt::CTRL+Qt::Key_Insert));
        connect(a, SIGNAL(triggered(bool)), SLOT(switchUser()));
    }

    //Setup the interface after we have set up the actions
    switch (KRunnerSettings::interface()) {
        default:
        case KRunnerSettings::EnumInterface::CommandOriented:
            m_interface = new Interface(m_runnerManager);
            break;
        case KRunnerSettings::EnumInterface::TaskOriented:
            m_interface = new QsDialog(m_runnerManager);
            break;
    }

#ifdef Q_WS_X11
    //FIXME: if argb visuals enabled Qt will always set WM_CLASS as "qt-subapplication" no matter what
    //the application name is we set the proper XClassHint here, hopefully won't be necessary anymore when
    //qapplication will manage apps with argvisuals in a better way
    XClassHint classHint;
    classHint.res_name = const_cast<char*>("krunner");
    classHint.res_class = const_cast<char*>("krunner");
    XSetClassHint(QX11Info::display(), m_interface->winId(), &classHint);
#endif


    m_actionCollection->readSettings();
    //m_runnerManager->setAllowedRunners(QStringList() << "shell");
    m_runnerManager->reloadConfiguration(); // pre-load the runners

    // Single runner mode actions shortcuts

    foreach (const QString &runnerId, m_runnerManager->singleModeAdvertisedRunnerIds()) {
        a = m_actionCollection->addAction(runnerId);
        a->setText(i18nc("Run krunner restricting the search only to runner %1", "Run Command (runner \"%1\" only)",
                    m_runnerManager->runnerName(runnerId)));
        a->setGlobalShortcut(KShortcut());
        connect(a, SIGNAL(triggered(bool)), SLOT(singleRunnerModeActionTriggered()));
    }
}
コード例 #12
0
ファイル: ninjamsrv.cpp プロジェクト: tzhuan/wahjam
int main(int argc, char **argv)
{
  QCoreApplication app(argc, argv);

  if (argc < 2)
  {
    usage(argv[0]);
  }

  g_server = new Server(myCreateUserLookup);

  printf("%s", startupmessage);

  if (!reloadConfig(argc, argv, true)) {
    printf("Error loading config file!\n");
    exit(1);
  }

#ifdef _WIN32
  DWORD v=GetTickCount();
  WDL_RNG_addentropy(&v,sizeof(v));
  v=(DWORD)time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
#else
  time_t v=time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
  int pid=getpid();
  WDL_RNG_addentropy(&pid,sizeof(pid));

  if (g_config.setuid != -1) setuid(g_config.setuid);

  if (g_config.pidFilename.Get()[0])
  {
    FILE *fp=fopen(g_config.pidFilename.Get(),"w");
    if (fp)
    {
      fprintf(fp,"%d\n",pid);
      fclose(fp);
    }
    else printf("Error opening PID file '%s'\n", g_config.pidFilename.Get());
  }
#endif

  if (g_config.logFilename.Get()[0])
  {
    g_logfp=fopen(g_config.logFilename.Get(),"at");
    if (!g_logfp)
      printf("Error opening log file '%s'\n",g_config.logFilename.Get());
    else
      logText("Opened log. Wahjam Server %s built on %s at %s\n",VERSION,__DATE__,__TIME__);

  }

  logText("Server starting up...\n");

#ifndef _WIN32
  SignalHandler *sigHandler = new SignalHandler(argc, argv);
#endif

  app.exec();

#ifndef _WIN32
  delete sigHandler;
#endif

  logText("Shutting down server\n");

  /* Explicitly delete before closing log */
  delete g_server;

  if (g_logfp)
  {
    fclose(g_logfp);
    g_logfp=0;
  }

	return 0;
}
コード例 #13
0
ファイル: qt_gui.cpp プロジェクト: SHFB/rgbdslam
                feature_image_label,
                SLOT(setVisible(bool)),
                "Show/Hide image with keypoints.",
                false);

    newMenuItem(v2, "Show Visual Flow Image",
                feature_flow_image_label,
                SLOT(setVisible(bool)),
                "Show/Hide image with sparse feature flow (arrows).",
                true);

    //Settings Menu
    QMenu *st = menuBar()->addMenu(tr("&Settings"));

    newMenuItem(st, "&Reload Config",
                SLOT(reloadConfig()),
                "Reload Configuration from Parameter Server.",
                "",
                QIcon::fromTheme("reload"));

    newMenuItem(st, "&View Current Settings",
                SLOT(showOptions()),
                "Display the currently active options",
                "?");
                
    newMenuItem(st, "Set internal &Parameter",
                SLOT(setParam()),
                "Change a parameter (This will also change the value on the ROS Parameter server)");
                
    newMenuItem(st, "Set Ma&ximum Edge Error",
                SLOT(pruneEdgesWithHighError()),
コード例 #14
0
ファイル: ninjamsrv.cpp プロジェクト: ycros/wahjam
int main(int argc, char **argv)
{
  QCoreApplication app(argc, argv);

  if (argc < 2)
  {
    usage(argv[0]);
  }

  g_server = new Server(myCreateUserLookup);

  printf("%s", startupmessage);

  if (!reloadConfig(argc, argv, true)) {
    printf("Error loading config file!\n");
    exit(1);
  }

#ifdef _WIN32
  DWORD v=GetTickCount();
  WDL_RNG_addentropy(&v,sizeof(v));
  v=(DWORD)time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
#else
  time_t v=time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
  int pid=getpid();
  WDL_RNG_addentropy(&pid,sizeof(pid));

  if (g_config.setuid != -1) setuid(g_config.setuid);

  if (g_config.pidFilename.Get()[0])
  {
    FILE *fp=fopen(g_config.pidFilename.Get(),"w");
    if (fp)
    {
      fprintf(fp,"%d\n",pid);
      fclose(fp);
    }
    else qWarning("Error opening PID file '%s'", g_config.pidFilename.Get());
  }
#endif

  logInit(g_config.logFilename.Get());

  qDebug("Server starting up...");

#ifndef _WIN32
  SignalHandler *sigHandler = new SignalHandler(argc, argv);
#endif

  app.exec();

#ifndef _WIN32
  delete sigHandler;
#endif

  qDebug("Shutting down server");

  /* Explicitly delete before closing log */
  delete g_server;

	return 0;
}
コード例 #15
0
int main(int argc, char **argv)
{
	char *dev;
	int oldMonitor, newMonitor;
	u_char packet[4096];
	int pktlen;
	wiviz_cfg cfg;
	int i;
	int defaultHopSeq[] = { 1, 3, 6, 8, 11 };
	int s, one;
	memset(&cfg, 0, sizeof(cfg));
#ifdef HAVE_RT2880
	wl_dev = "ra0";
#elif HAVE_MADWIFI
	wl_dev = nvram_safe_get("wifi_display");
#else
	char tmp[32];
	sprintf(tmp, "%s_ifname", nvram_safe_get("wifi_display"));
	wl_dev = nvram_safe_get(tmp);
#endif
	if (argc > 1)
		if (!strcmp(argv[1], "terminate")) {
#ifdef HAVE_MADWIFI
			// return to original channel
#ifdef HAVE_ATH9K
			if (!is_ath9k(wl_dev))
#endif
			{
				sysprintf("iwconfig %s channel %sM", get_monitor(), nvram_nget("%s_channel", nvram_safe_get("wifi_display")));
				sleep(1);
				sysprintf("ifconfig %s down", get_monitor());
				if (is_ar5008(nvram_safe_get("wifi_display"))) {
					sysprintf("80211n_wlanconfig %s destroy", get_monitor());
				} else {
					sysprintf("wlanconfig %s destroy", get_monitor());
				}
			}
#elif HAVE_RT2880
			nvram_set("wl0_mode", nvram_safe_get("wl0_oldmode"));
			sysprintf("startservice configurewifi");
			if (nvram_match("wl0_mode", "sta") || nvram_match("wl0_mode", "apsta")) {
				sysprintf("startstop wan");
			}
#else
			oldMonitor = 0;
			wl_ioctl(wl_dev, WLC_SET_MONITOR, &oldMonitor, 4);
#endif
			return 0;
		}

	global_cfg = &cfg;
	signal(SIGUSR1, &signal_handler);
	signal(SIGUSR2, &signal_handler);

	printf("Wi-Viz 2 infogathering daemon by Nathan True\n");
	printf("http://wiviz.natetrue.com\n");

	memset(&cfg, 0, sizeof(wiviz_cfg));
	cfg.numHosts = 0;
	cfg.lastKeepAlive = time(NULL);
	cfg.channelHopping = 0;
	cfg.channelDwellTime = 1000;
	cfg.channelHopSeqLen = 5;
	memcpy(cfg.channelHopSeq, defaultHopSeq, sizeof(defaultHopSeq));

#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
	wl_ioctl(wl_dev, WLC_GET_MAGIC, &i, 4);
	if (i != WLC_IOCTL_MAGIC) {
		printf("Wireless magic not correct, not querying wl for info %X!=%X\n", i, WLC_IOCTL_MAGIC);
		cfg.readFromWl = 0;
	} else {
		cfg.readFromWl = 1;
		wl_ioctl(wl_dev, WLC_GET_MONITOR, &oldMonitor, 4);
		newMonitor = 1;
		wl_ioctl(wl_dev, WLC_SET_MONITOR, &newMonitor, 4);
	}

#elif HAVE_RT2880
	nvram_set("wl0_oldmode", nvram_safe_get("wl0_mode"));
	nvram_set("wl0_mode", "sta");
	if (!nvram_match("wl0_oldmode", "sta"))
		sysprintf("startservice configurewifi");
	sysprintf("iwconfig ra0 mode monitor");
	cfg.readFromWl = 1;
#else
#ifdef HAVE_ATH9K
	if (!is_ath9k(nvram_safe_get("wifi_display")))
#endif
	{
		if (is_ar5008(nvram_safe_get("wifi_display"))) {
			sysprintf("80211n_wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display")));
		} else {
			sysprintf("wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display")));
		}
		sysprintf("ifconfig %s up", get_monitor());
	}
	cfg.readFromWl = 1;
#endif
	reloadConfig();

#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
	s = openMonitorSocket(get_monitor());	// for testing we use ath0
#else

	if (nvram_match("wifi_display", "wl1"))
		s = openMonitorSocket("prism1");
	else
		s = openMonitorSocket("prism0");
#endif
	if (s == -1)
		return;
	one = 1;
	ioctl(s, FIONBIO, (char *)&one);

	if (cfg.readFromWl) {
		readWL(&cfg);
	}
#ifdef WIVIZ_GPS
	gps_init(&cfg);
#endif

	while (!stop) {
#ifdef WIVIZ_GPS
		gps_tick();
#else
		if (time(NULL) - cfg.lastKeepAlive > 30)
			stop = 1;
#endif
		pktlen = recv(s, packet, 4096, 0);
		if (pktlen <= 0)
			continue;
		dealWithPacket(&cfg, pktlen, packet);
	}

	signal_handler(SIGUSR1);

	if (cfg.channelHopperPID)
		kill(cfg.channelHopperPID, SIGKILL);

#ifndef WIVIZ_GPS
	for (i = 0; i < MAX_HOSTS; i++) {
		print_host(stderr, cfg.hosts + i);
		if (cfg.hosts[i].occupied)
			printf("\n");
		if (cfg.hosts[i].apInfo)
			free(cfg.hosts[i].apInfo);
		if (cfg.hosts[i].staInfo)
			free(cfg.hosts[i].staInfo);
	}
#endif
	close(s);
	return 0;
}
コード例 #16
0
HiveManager::HiveManager(Game* game, Env* env)
: game_(game), env_(env)
{
	reloadConfig();
}