Exemplo n.º 1
0
Arquivo: gui.c Projeto: tuval10/Chess
/*	
*	initiallize mainGame + slots for the game
*	PRECONDITION: the game was allocated
*/
void initializeChess(int isGUI){
	loadDefaultSettings(mainGame->gameInfo);
	if(isGUI){
		loadDefaultSettings(mainGame->startingGameSettings);
		mainGame->clickedPieceCol=0;
		mainGame->pieceWasClicked = 0; /* no piece clicked */
		mainGame->isCheckMate = 0; /* game in initial stage */
		mainGame->isLoadingAIMove = mainGame->clickedPieceCol = mainGame->clickedPieceRow=mainGame->promoteTo = 0;
	}
}
Exemplo n.º 2
0
PhotoTexturingWidget::PhotoTexturingWidget(MeshEditInterface* plugin, PhotoTexturer* texturer,MeshModel &m,GLArea *gla): MeshlabEditDockWidget(gla) {
	
	lastDirectory = "";
	
	connect(this,SIGNAL(updateGLAreaTextures()),gla,SLOT(updateTexture()));
	connect(this,SIGNAL(setGLAreaTextureMode(vcg::GLW::TextureMode)),gla,SLOT(setTextureMode(vcg::GLW::TextureMode)));
	connect(this,SIGNAL(updateMainWindowMenus()),gla,SIGNAL(updateMainWindowMenus()));

	ptPlugin = plugin;
	photoTexturer = texturer;
	PhotoTexturingWidget::ui.setupUi(this);
	this->setWidget(ui.main_frame);
	//this->setFeatures(QDockWidget::AllDockWidgetFeatures);
	this->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetClosable);
	this->setAllowedAreas(Qt::NoDockWidgetArea);
	this->setFloating(true);
	mesh = &m;
	glarea = gla;

	//setting up the headers for the tblewidget
	//QStringList headers;
	//headers << "Camera" << "Image";
	//ui.cameraTableWidget->setHorizontalHeaderLabels(headers);

	connect(ui.configurationLoadPushButton, SIGNAL(clicked()),this,SLOT(loadConfigurationFile()));
	connect(ui.configurationSavePushButton, SIGNAL(clicked()),this,SLOT(saveConfigurationFile()));
	connect(ui.exportToMaxScriptPushButton, SIGNAL(clicked()),this,SLOT(exportCamerasToMaxScript()));
	connect(ui.convertToTsaiCameraPushButton, SIGNAL(clicked()),this,SLOT(convertToTsaiCamera()));

	connect(ui.addCameraPushButton, SIGNAL(clicked()),this,SLOT(addCamera()));
	connect(ui.removeCameraPushButton, SIGNAL(clicked()),this,SLOT(removeCamera()));

	connect(ui.assignImagePushButton, SIGNAL(clicked()),this,SLOT(assignImage()));
	connect(ui.calculateTexturesPushButton, SIGNAL(clicked()),this,SLOT(calculateTextures()));
	connect(ui.combineTexturesPushButton, SIGNAL(clicked()),this,SLOT(combineTextures()));
	connect(ui.unprojectTexturePushButton, SIGNAL(clicked()),this,SLOT(unprojectTextures()));
	connect(ui.bakeTexturePushButton, SIGNAL(clicked()),this,SLOT(bakeTextures()));

	connect(ui.textureListWidget, SIGNAL(itemClicked(QListWidgetItem* )),this,SLOT(selectCurrentTexture()));

	connect(ui.resetPushButton, SIGNAL(clicked()),this,SLOT(reset()));
	connect(ui.closePushButton, SIGNAL(clicked()),this,SLOT(close()));
	//connect(ui.cancelPushButton, SIGNAL(clicked()),this,SLOT(cancel()));

	photoTexturer->storeOriginalTextureCoordinates(mesh);
	loadDefaultSettings();
	update();

}
Exemplo n.º 3
0
EvaUserSetting::EvaUserSetting(const int id)
{
	qqNum = id;
	isUserDirExisted=false;
	pictureCacheDir = getEvaUserDir() + "/customCaches";
	customSmileyDir = getEvaUserDir() + "/CustomFace";
	userHeadDir = getEvaUserDir() + "/UserHead";
	loadDefaultSettings();
	SqlFileName = "user.sqlite3";
	buddyListFileName = "user.dat";
	qunListFileName = "qun.dat";
	chatMsgFileName = "chat.msg";
	qunMsgFileName = "qun.msg";
	userProfileFileName = "user.profile";
	userConfigFileName = "user.cfg";
	
	if(!createDefaultDirs())
		printf("error, cannot create user directory!\n");
	
	m_config = new TDEConfig(getEvaUserDir() + "/" + userConfigFileName);
	
	m_NeedRepaint = true;
}
Exemplo n.º 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    _marker_detector.setMinMaxSize(0.0001,0.5);

    ui->cameraResolutionComboBox->addItem("640x480");
    ui->cameraResolutionComboBox->addItem("1920x1080");

    _serial_port = new QSerialPort();
    refreshSerialPortOptions();
    connect(ui->serialConnectButton,SIGNAL(clicked()),SLOT(updateSerialPort()));
    connect(ui->serialDisconnectButton,SIGNAL(clicked()),SLOT(disconnectSerialPort()));
    connect(_serial_port,SIGNAL(readyRead()),SLOT(receiveData()));
    connect(ui->sendSerialDataButton,SIGNAL(clicked()),SLOT(sendTextEditSerialData()));
    connect(ui->sendSerialDataLineEdit,SIGNAL(returnPressed()),SLOT(sendTextEditSerialData()));
    connect(ui->refreshSerialOptionsButton,SIGNAL(clicked()),SLOT(refreshSerialPortOptions()));
    loadDefaultSettings();
    //applySettings();

    //Timer connects to the kcamera object to call grabFrame every 30 milliseconds
    _timer = new QTimer(this);
    connect(_timer,SIGNAL(timeout()),SLOT(update()));
    _timer->start(20);

    //Update video every 20ms
    QTimer* video_timer = new QTimer(this);
    connect(video_timer,SIGNAL(timeout()),SLOT(updateVideo()));
    video_timer->start(20);

    connect(ui->applySettingsButton,SIGNAL(clicked()),SLOT(applySettings()));

    QFileDialog* file_dialog = new QFileDialog();
    connect(file_dialog,SIGNAL(fileSelected(QString)),ui->calibrationFileLineEdit,SLOT(setText(QString)));
    connect(ui->browseCalibrationFileButton,SIGNAL(clicked()),file_dialog,SLOT(open()));

    //Connections for selecting view (image/2D trace)
    connect(ui->viewSelectComboBox,SIGNAL(currentIndexChanged(QString)),SLOT(selectView(QString)));

    connect(ui->saveSentDataButton,SIGNAL(clicked()),SLOT(saveSentData()));
    connect(ui->clearSentDataButton,SIGNAL(clicked()),SLOT(clearSentData()));

    ui->markerTracePlot->addGraph();
    ui->markerTracePlot->graph(0)->addData(1.5,1.5);

    ui->markerTracePlot->graph(0)->addData(1.9,1.9);
    ui->markerTracePlot->graph(0)->addData(1.5,1.9);
    ui->markerTracePlot->graph(0)->setScatterStyle(QCPScatterStyle::ssCross);
    ui->markerTracePlot->replot();

    _running = false;
    _frame_count = 0;
    connect(ui->startRunButton,SIGNAL(clicked()),this,SLOT(startRun()));
    connect(ui->stopRunButton,SIGNAL(clicked()),this,SLOT(stopRun()));

    _received_data_max_length = 1000;
    _sent_data_max_length = 1000;

    //Camera Sliders
    connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(updateBrightness(int)));
    connect(ui->sharpnessSlider, SIGNAL(valueChanged(int)), this, SLOT(updateSharpness(int)));
    connect(ui->autofocusCheckbox, SIGNAL(toggled(bool)), this, SLOT(updateAutoFocus(bool)));
    connect(ui->focusSlider, SIGNAL(valueChanged(int)), this, SLOT(updateFocus(int)));
}
Exemplo n.º 5
0
PtpClock *
ptpdStartup(int argc, char **argv, Integer16 * ret, RunTimeOpts * rtOpts)
{
    PtpClock * ptpClock;
    int i = 0;

    /*
     * Set the default mode for all newly created files - previously
     * this was not the case for log files. This adds consistency
     * and allows to use FILE* vs. fds everywhere
     */
    umask(~DEFAULT_FILE_PERMS);

    /**
     * If a required setting, such as interface name, or a setting
     * requiring a range check is to be set via getopts_long,
     * the respective currentConfig dictionary entry should be set,
     * instead of just setting the rtOpts field.
     *
     * Config parameter evaluation priority order:
     * 	1. Any dictionary keys set in the getopt_long loop
     * 	2. CLI long section:key type options
     * 	3. Config file (parsed last), merged with 2. and 3 - will be overwritten by CLI options
     * 	4. Defaults and any rtOpts fields set in the getopt_long loop
    **/

    /**
     * Load defaults. Any options set here and further inside loadCommandLineOptions()
     * by setting rtOpts fields, will be considered the defaults
     * for config file and section:key long options.
     */
    loadDefaultSettings(rtOpts);
    /* initialise the config dictionary */
    rtOpts->candidateConfig = dictionary_new(0);
    rtOpts->cliConfig = dictionary_new(0);
    /* parse all long section:key options and clean up argv for getopt */
    loadCommandLineKeys(rtOpts->cliConfig,argc,argv);
    /* parse the normal short and long option, exit on error */
    if (!loadCommandLineOptions(rtOpts, rtOpts->cliConfig, argc, argv, ret)) {
        goto fail;
    }

    /* Display startup info and argv if not called with -? or -H */
    NOTIFY("%s version %s starting\n",USER_DESCRIPTION, USER_VERSION);
    dump_command_line_parameters(argc, argv);
    /*
     * we try to catch as many error conditions as possible, but before we call daemon().
     * the exception is the lock file, as we get a new pid when we call daemon(),
     * so this is checked twice: once to read, second to read/write
     */
    if(geteuid() != 0)
    {
        printf("Error: "PTPD_PROGNAME" daemon can only be run as root\n");
        *ret = 1;
        goto fail;
    }

    /* Have we got a config file? */
    if(strlen(rtOpts->configFile) > 0) {
        /* config file settings overwrite all others, except for empty strings */
        INFO("Loading configuration file: %s\n",rtOpts->configFile);
        if(loadConfigFile(&rtOpts->candidateConfig, rtOpts)) {
            dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, "from command line");
        } else {
            *ret = 1;
            dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, "from command line");
            goto configcheck;
        }
    } else {
        dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, "from command line");
    }
    /**
     * This is where the final checking  of the candidate settings container happens.
     * A dictionary is returned with only the known options, explicitly set to defaults
     * if not present. NULL is returned on any config error - parameters missing, out of range,
     * etc. The getopt loop in loadCommandLineOptions() only sets keys verified here.
     */
    if( ( rtOpts->currentConfig = parseConfig(rtOpts->candidateConfig,rtOpts)) == NULL ) {
        *ret = 1;
        dictionary_del(rtOpts->candidateConfig);
        goto configcheck;
    }

    /* we've been told to print the lock file and exit cleanly */
    if(rtOpts->printLockFile) {
        printf("%s\n", rtOpts->lockFile);
        *ret = 0;
        goto fail;
    }

    /* we don't need the candidate config any more */
    dictionary_del(rtOpts->candidateConfig);

    /* Check network before going into background */
    if(!testInterface(rtOpts->ifaceName, rtOpts)) {
        ERROR("Error: Cannot use %s interface\n",rtOpts->ifaceName);
        *ret = 1;
        goto configcheck;
    }

configcheck:
    /*
     * We've been told to check config only - clean exit before checking locks
     */
    if(rtOpts->checkConfigOnly) {
        if(*ret != 0) {
            printf("Configuration has errors\n");
            *ret = 1;
        }
        else
            printf("Configuration OK\n");
        return 0;
    }

    /* Previous errors - exit */
    if(*ret !=0)
        return 0;

    /* First lock check, just to be user-friendly to the operator */
    if(!rtOpts->ignore_daemon_lock) {
        if(!writeLockFile(rtOpts)) {
            /* check and create Lock */
            ERROR("Error: file lock failed (use -L or global:ignore_lock to ignore lock file)\n");
            *ret = 3;
            return 0;
        }
        /* check for potential conflicts when automatic lock files are used */
        if(!checkOtherLocks(rtOpts)) {
            *ret = 3;
            return 0;
        }
    }

    /* Manage log files: stats, log, status and quality file */
    restartLogging(rtOpts);

    /* Allocate memory after we're done with other checks but before going into daemon */
    ptpClock = (PtpClock *) calloc(1, sizeof(PtpClock));
    if (!ptpClock) {
        PERROR("Error: Failed to allocate memory for protocol engine data");
        *ret = 2;
        return 0;
    } else {
        DBG("allocated %d bytes for protocol engine data\n",
            (int)sizeof(PtpClock));
        ptpClock->foreign = (ForeignMasterRecord *)
                            calloc(rtOpts->max_foreign_records,
                                   sizeof(ForeignMasterRecord));
        if (!ptpClock->foreign) {
            PERROR("failed to allocate memory for foreign "
                   "master data");
            *ret = 2;
            free(ptpClock);
            return 0;
        } else {
            DBG("allocated %d bytes for foreign master data\n",
                (int)(rtOpts->max_foreign_records *
                      sizeof(ForeignMasterRecord)));
        }

        ptpClock->owd_filt = FilterCreate(FILTER_EXPONENTIAL_SMOOTH, "owd");
        ptpClock->ofm_filt = FilterCreate(FILTER_MOVING_AVERAGE, "ofm");
    }

    if(rtOpts->statisticsLog.logEnabled)
        ptpClock->resetStatisticsLog = TRUE;

    /* Init to 0 net buffer */
    memset(ptpClock->msgIbuf, 0, PACKET_SIZE);
    memset(ptpClock->msgObuf, 0, PACKET_SIZE);

    /* Init user_description */
    memset(ptpClock->user_description, 0, sizeof(ptpClock->user_description));
    memcpy(ptpClock->user_description, &USER_DESCRIPTION, sizeof(USER_DESCRIPTION));

    /* Init outgoing management message */
    ptpClock->outgoingManageTmp.tlv = NULL;


    /*  DAEMON */
#ifdef PTPD_NO_DAEMON
    if(!rtOpts->nonDaemon) {
        rtOpts->nonDaemon=TRUE;
    }
#endif

    if(!rtOpts->nonDaemon) {
        /*
         * fork to daemon - nochdir non-zero to preserve the working directory:
         * allows relative paths to be used for log files, config files etc.
         * Always redirect stdout/err to /dev/null
         */
        if (daemon(1,0) == -1) {
            PERROR("Failed to start as daemon");
            *ret = 3;
            return 0;
        }
        INFO("  Info:    Now running as a daemon\n");
        /*
         * Wait for the parent process to terminate, but not forever.
         * On some systems this happened after we tried re-acquiring
         * the lock, so the lock would fail. Hence, we wait.
         */
        for (i = 0; i < 1000000; i++) {
            /* Once we've been reaped by init, parent PID will be 1 */
            if(getppid() == 1)
                break;
            usleep(1);
        }
    }

    /* Second lock check, to replace the contents with our own new PID and re-acquire the advisory lock */
    if(!rtOpts->nonDaemon && !rtOpts->ignore_daemon_lock) {
        /* check and create Lock */
        if(!writeLockFile(rtOpts)) {
            ERROR("Error: file lock failed (use -L or global:ignore_lock to ignore lock file)\n");
            *ret = 3;
            return 0;
        }
    }

#if defined(linux) && defined(HAVE_SCHED_H)
    /* Try binding to a single CPU core if configured to do so */

    if(rtOpts->cpuNumber > -1) {

        cpu_set_t mask;
        CPU_ZERO(&mask);
        CPU_SET(rtOpts->cpuNumber,&mask);
        if(sched_setaffinity(0, sizeof(mask), &mask) < 0) {
            PERROR("Could not bind to CPU core %d", rtOpts->cpuNumber);
        } else {
            INFO("Successfully bound "PTPD_PROGNAME" to CPU core %d\n", rtOpts->cpuNumber);
        }
    }
#endif /* linux && HAVE_SCHED_H */

#ifdef HAVE_SYS_CPUSET_H

    /* Try binding to a single CPU core if configured to do so */

    if(rtOpts->cpuNumber > -1) {
        cpuset_t mask;
        CPU_ZERO(&mask);
        CPU_SET(rtOpts->cpuNumber,&mask);
        if(cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
                              -1, sizeof(mask), &mask) < 0) {
            PERROR("Could not bind to CPU core %d",
                   rtOpts->cpuNumber);
        } else {
            INFO("Successfully bound "PTPD_PROGNAME" to CPU core %d\n",
                 rtOpts->cpuNumber);
        }
    }
#endif /* HAVE_SYS_CPUSET_H */

    /* use new synchronous signal handlers */
    signal(SIGINT,  catchSignals);
    signal(SIGTERM, catchSignals);
    signal(SIGHUP,  catchSignals);

    signal(SIGUSR1, catchSignals);
    signal(SIGUSR2, catchSignals);

#if defined PTPD_SNMP
    /* Start SNMP subsystem */
    if (rtOpts->snmp_enabled)
        snmpInit(rtOpts, ptpClock);
#endif



    NOTICE(USER_DESCRIPTION" started successfully on %s using \"%s\" preset (PID %d)\n",
           rtOpts->ifaceName,
           (getPtpPreset(rtOpts->selectedPreset,rtOpts)).presetName,
           getpid());
    ptpClock->resetStatisticsLog = TRUE;

#ifdef PTPD_STATISTICS
    if (rtOpts->delayMSOutlierFilterEnabled) {
        ptpClock->delayMSRawStats = createDoubleMovingStdDev(rtOpts->delayMSOutlierFilterCapacity);
        strncpy(ptpClock->delayMSRawStats->identifier, "delayMS", 10);
        ptpClock->delayMSFiltered = createDoubleMovingMean(rtOpts->delayMSOutlierFilterCapacity);
    } else {
        ptpClock->delayMSRawStats = NULL;
        ptpClock->delayMSFiltered = NULL;
    }

    if (rtOpts->delaySMOutlierFilterEnabled) {
        ptpClock->delaySMRawStats = createDoubleMovingStdDev(rtOpts->delaySMOutlierFilterCapacity);
        strncpy(ptpClock->delaySMRawStats->identifier, "delaySM", 10);
        ptpClock->delaySMFiltered = createDoubleMovingMean(rtOpts->delaySMOutlierFilterCapacity);
    } else {
        ptpClock->delaySMRawStats = NULL;
        ptpClock->delaySMFiltered = NULL;
    }
#endif

    *ret = 0;
    return ptpClock;

fail:
    dictionary_del(rtOpts->candidateConfig);
    return 0;
}
Exemplo n.º 6
0
/**
 * Signal handler for HUP which tells us to swap the log file
 * and reload configuration file if specified
 *
 * @param sig
 */
void
do_signal_sighup(RunTimeOpts * rtOpts, PtpClock * ptpClock)
{

    NOTIFY("SIGHUP received\n");

#ifdef RUNTIME_DEBUG
    if(rtOpts->transport == UDP_IPV4 && rtOpts->ip_mode != IPMODE_UNICAST) {
        DBG("SIGHUP - running an ipv4 multicast based mode, re-sending IGMP joins\n");
        netRefreshIGMP(&ptpClock->netPath, rtOpts, ptpClock);
    }
#endif /* RUNTIME_DEBUG */


    /* if we don't have a config file specified, we're done - just reopen log files*/
    if(strlen(rtOpts->configFile) ==  0)
        goto end;

    dictionary* tmpConfig = dictionary_new(0);
    /* Try reloading the config file */
    NOTIFY("Reloading configuration file: %s\n",rtOpts->configFile);
    if(!loadConfigFile(&tmpConfig, rtOpts)) {
        dictionary_del(tmpConfig);
        goto end;
    }
    dictionary_merge(rtOpts->cliConfig, tmpConfig, 1, "from command line");
    /* Load default config to fill in the blanks in the config file */
    RunTimeOpts tmpOpts;
    loadDefaultSettings(&tmpOpts);

    /* Check the new configuration for errors, fill in the blanks from defaults */
    if( ( rtOpts->candidateConfig = parseConfig(tmpConfig,&tmpOpts)) == NULL ) {
        WARNING("Configuration file has errors, reload aborted\n");
        dictionary_del(tmpConfig);
        goto end;
    }

    /* Check for changes between old and new configuration */
    if(compareConfig(rtOpts->candidateConfig,rtOpts->currentConfig)) {
        INFO("Configuration unchanged\n");
        goto cleanup;
    }

    /*
     * Mark which subsystems have to be restarted. Most of this will be picked up by doState()
     * If there are errors past config correctness (such as non-existent NIC,
     * or lock file clashes if automatic lock files used - abort the mission
     */

    rtOpts->restartSubsystems =
        checkSubsystemRestart(rtOpts->candidateConfig, rtOpts->currentConfig);

    /* If we're told to re-check lock files, do it: tmpOpts already has what rtOpts should */
    if( (rtOpts->restartSubsystems & PTPD_CHECK_LOCKS) &&
            tmpOpts.autoLockFile && !checkOtherLocks(&tmpOpts)) {
        rtOpts->restartSubsystems = -1;
    }

    /* If the network configuration has changed, check if the interface is OK */
    if(rtOpts->restartSubsystems & PTPD_RESTART_NETWORK) {
        INFO("Network configuration changed - checking interface\n");
        if(!testInterface(tmpOpts.ifaceName, &tmpOpts)) {
            rtOpts->restartSubsystems = -1;
            ERROR("Error: Cannot use %s interface\n",tmpOpts.ifaceName);
        }

    }


#if defined(linux) && defined(HAVE_SCHED_H)
    /* Changing the CPU affinity mask */
    if(rtOpts->restartSubsystems & PTPD_CHANGE_CPUAFFINITY) {
        NOTIFY("Applying CPU binding configuration: changing selected CPU core\n");
        cpu_set_t mask;
        CPU_ZERO(&mask);
        if(tmpOpts.cpuNumber > -1) {
            CPU_SET(tmpOpts.cpuNumber,&mask);
        } else {
            int i;
            for(i = 0;  i < CPU_SETSIZE; i++) {
                CPU_SET(i, &mask);
            }
        }
        if(sched_setaffinity(0, sizeof(mask), &mask) < 0) {
            if(tmpOpts.cpuNumber == -1) {
                PERROR("Could not unbind from CPU core %d", rtOpts->cpuNumber);
            } else {
                PERROR("Could bind to CPU core %d", tmpOpts.cpuNumber);
            }
            rtOpts->restartSubsystems = -1;
        } else {
            if(tmpOpts.cpuNumber > -1)
                INFO("Successfully bound "PTPD_PROGNAME" to CPU core %d\n", tmpOpts.cpuNumber);
            else
                INFO("Successfully unbound "PTPD_PROGNAME" from cpu core CPU core %d\n", rtOpts->cpuNumber);
        }
    }
#endif /* linux && HAVE_SCHED_H */

#ifdef HAVE_SYS_CPUSET_H
    /* Changing the CPU affinity mask */
    if (rtOpts->restartSubsystems & PTPD_CHANGE_CPUAFFINITY) {
        NOTIFY("Applying CPU binding configuration:"
               "changing selected CPU core\n");
        cpuset_t mask;
        CPU_ZERO(&mask);
        if (tmpOpts.cpuNumber < 0) {
            if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_CPUSET, 1,
                                   sizeof(mask), &mask) < 0)
                PERROR("Could not get affinity.");
            if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
                                   -1, sizeof(mask), &mask) < 0)
                PERROR("Could not unbind from CPU core %d",
                       rtOpts->cpuNumber);
            else
                INFO("Successfully unbound "
                     PTPD_PROGNAME" from cpu core CPU core %d\n",
                     rtOpts->cpuNumber);
        } else {
            CPU_SET(tmpOpts.cpuNumber,&mask);
            if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID,
                                   -1, sizeof(mask), &mask) < 0)  {
                PERROR("Could not bind to CPU core %d",
                       tmpOpts.cpuNumber);
                rtOpts->restartSubsystems = -1;
            } else {
                INFO("Successfully bound "
                     PTPD_PROGNAME" to CPU core %d\n",
                     tmpOpts.cpuNumber);
            }
        }
    }
#endif

    if(rtOpts->restartSubsystems == -1) {
        ERROR("New configuration cannot be applied - aborting reload\n");
        rtOpts->restartSubsystems = 0;
        goto cleanup;
    }


    /* Tell parseConfig to shut up - it's had its chance already */
    dictionary_set(rtOpts->candidateConfig,"%quiet%:%quiet%","Y");

    /**
     * Commit changes to rtOpts and currentConfig
     * (this should never fail as the config has already been checked if we're here)
     * However if this DOES fail, some default has been specified out of range -
     * this is the only situation where parse will succeed but commit not:
     * disable quiet mode to show what went wrong, then die.
     */
    if (rtOpts->currentConfig) {
        dictionary_del(rtOpts->currentConfig);
    }
    if ( (rtOpts->currentConfig = parseConfig(rtOpts->candidateConfig,rtOpts)) == NULL) {
        CRITICAL("************ "PTPD_PROGNAME": parseConfig returned NULL during config commit"
                 "  - this is a BUG - report the following: \n");

        dictionary_unset(rtOpts->candidateConfig,"%quiet%:%quiet%");

        if ((rtOpts->currentConfig = parseConfig(rtOpts->candidateConfig,rtOpts)) == NULL)
            CRITICAL("*****************" PTPD_PROGNAME" shutting down **********************\n");
        /*
         * Could be assert(), but this should be done any time this happens regardless of
         * compile options. Anyhow, if we're here, the daemon will no doubt segfault soon anyway
         */
        abort();
    }

    /* clean up */
cleanup:

    dictionary_del(tmpConfig);
    dictionary_del(rtOpts->candidateConfig);

end:

    if(rtOpts->recordLog.logEnabled ||
            rtOpts->eventLog.logEnabled ||
            (rtOpts->statisticsLog.logEnabled))
        INFO("Reopening log files\n");

    restartLogging(rtOpts);

    if(rtOpts->statisticsLog.logEnabled)
        ptpClock->resetStatisticsLog = TRUE;


}
Exemplo n.º 7
0
void
applyConfig(dictionary *baseConfig, RunTimeOpts *rtOpts, PtpClock *ptpClock)
{

	Boolean reloadSuccessful = TRUE;


	/* Load default config to fill in the blanks in the config file */
	RunTimeOpts tmpOpts;
	loadDefaultSettings(&tmpOpts);

	/* Check the new configuration for errors, fill in the blanks from defaults */
	if( ( rtOpts->candidateConfig = parseConfig(CFGOP_PARSE, NULL, baseConfig, &tmpOpts)) == NULL ) {
	    WARNING("Configuration has errors, reload aborted\n");
	    return;
	}

	/* Check for changes between old and new configuration */
	if(compareConfig(rtOpts->candidateConfig,rtOpts->currentConfig)) {
	    INFO("Configuration unchanged\n");
	    goto cleanup;
	}

	/*
	 * Mark which subsystems have to be restarted. Most of this will be picked up by doState()
	 * If there are errors past config correctness (such as non-existent NIC,
	 * or lock file clashes if automatic lock files used - abort the mission
	 */

	rtOpts->restartSubsystems =
	    checkSubsystemRestart(rtOpts->candidateConfig, rtOpts->currentConfig, rtOpts);

	/* If we're told to re-check lock files, do it: tmpOpts already has what rtOpts should */
	if( (rtOpts->restartSubsystems & PTPD_CHECK_LOCKS) &&
	    tmpOpts.autoLockFile && !checkOtherLocks(&tmpOpts)) {
		reloadSuccessful = FALSE;
	}

	/* If the network configuration has changed, check if the interface is OK */
	if(rtOpts->restartSubsystems & PTPD_RESTART_NETWORK) {
		INFO("Network configuration changed - checking interface(s)\n");
		if(!testInterface(tmpOpts.primaryIfaceName, &tmpOpts)) {
		    reloadSuccessful = FALSE;
		    ERROR("Error: Cannot use %s interface\n",tmpOpts.primaryIfaceName);
		}
		if(rtOpts->backupIfaceEnabled && !testInterface(tmpOpts.backupIfaceName, &tmpOpts)) {
		    rtOpts->restartSubsystems = -1;
		    ERROR("Error: Cannot use %s interface as backup\n",tmpOpts.backupIfaceName);
		}
	}
#if (defined(linux) && defined(HAVE_SCHED_H)) || defined(HAVE_SYS_CPUSET_H) || defined(__QNXNTO__)
        /* Changing the CPU affinity mask */
        if(rtOpts->restartSubsystems & PTPD_CHANGE_CPUAFFINITY) {
                NOTIFY("Applying CPU binding configuration: changing selected CPU core\n");

                if(setCpuAffinity(tmpOpts.cpuNumber) < 0) {
                        if(tmpOpts.cpuNumber == -1) {
                                ERROR("Could not unbind from CPU core %d\n", rtOpts->cpuNumber);
                        } else {
                                ERROR("Could bind to CPU core %d\n", tmpOpts.cpuNumber);
                        }
			reloadSuccessful = FALSE;
                } else {
                        if(tmpOpts.cpuNumber > -1)
                                INFO("Successfully bound "PTPD_PROGNAME" to CPU core %d\n", tmpOpts.cpuNumber);
                        else
                                INFO("Successfully unbound "PTPD_PROGNAME" from cpu core CPU core %d\n", rtOpts->cpuNumber);
                }
         }
#endif

	if(!reloadSuccessful) {
		ERROR("New configuration cannot be applied - aborting reload\n");
		rtOpts->restartSubsystems = 0;
		goto cleanup;
	}


		/**
		 * Commit changes to rtOpts and currentConfig
		 * (this should never fail as the config has already been checked if we're here)
		 * However if this DOES fail, some default has been specified out of range -
		 * this is the only situation where parse will succeed but commit not:
		 * disable quiet mode to show what went wrong, then die.
		 */
		if (rtOpts->currentConfig) {
			dictionary_del(&rtOpts->currentConfig);
		}
		if ( (rtOpts->currentConfig = parseConfig(CFGOP_PARSE_QUIET, NULL, rtOpts->candidateConfig,rtOpts)) == NULL) {
			CRITICAL("************ "PTPD_PROGNAME": parseConfig returned NULL during config commit"
				 "  - this is a BUG - report the following: \n");

			if ((rtOpts->currentConfig = parseConfig(CFGOP_PARSE, NULL, rtOpts->candidateConfig,rtOpts)) == NULL)
			    CRITICAL("*****************" PTPD_PROGNAME" shutting down **********************\n");
			/*
			 * Could be assert(), but this should be done any time this happens regardless of
			 * compile options. Anyhow, if we're here, the daemon will no doubt segfault soon anyway
			 */
			abort();
		}

	/* clean up */
	cleanup:

		dictionary_del(&rtOpts->candidateConfig);
}
Exemplo n.º 8
0
void ServiceManager::start()
{
    VitaMTP_Init();

    loadDefaultSettings();

    if(QSettings().value("useMemoryStorage", true).toBool()) {
        m_db = new QListDB();
    } else {
        m_db = new SQLiteDB();
    }

    // initializing database for the first use
    refreshDatabase();

    // send a signal when the update is finished
    connect(m_db, SIGNAL(updated(int)), this, SIGNAL(databaseUpdated(int)));

    thread_count = 0;
    qDebug("Starting cma threads");
    CmaClient *client;
    QSettings settings;

    if(!settings.value("disableUSB", false).toBool()) {

        usb_thread = new QThread();
        client = new CmaClient(m_db);
        usb_thread->setObjectName("usb_thread");
        connect(usb_thread, SIGNAL(started()), client, SLOT(connectUsb()));
        connect(client, SIGNAL(finished()), usb_thread, SLOT(quit()), Qt::DirectConnection);
        connect(usb_thread, SIGNAL(finished()), usb_thread, SLOT(deleteLater()));
        connect(usb_thread, SIGNAL(finished()), this, SLOT(threadStopped()));
        connect(usb_thread, SIGNAL(finished()), client, SLOT(deleteLater()));

        connect(client, SIGNAL(refreshDatabase()), this, SLOT(refreshDatabase()));

        client->moveToThread(usb_thread);
        usb_thread->start();
        thread_count++;
    }

    if(!settings.value("disableWireless", false).toBool()) {
        CmaBroadcast *broadcast = new CmaBroadcast(this);
        wireless_thread = new QThread();
        client = new CmaClient(m_db, broadcast);
        wireless_thread->setObjectName("wireless_thread");
        connect(wireless_thread, SIGNAL(started()), client, SLOT(connectWireless()));
        connect(client, SIGNAL(finished()), wireless_thread, SLOT(quit()), Qt::DirectConnection);
        connect(wireless_thread, SIGNAL(finished()), wireless_thread, SLOT(deleteLater()));
        connect(wireless_thread, SIGNAL(finished()), this, SLOT(threadStopped()));
        connect(wireless_thread, SIGNAL(finished()), client, SLOT(deleteLater()));

        connect(client, SIGNAL(refreshDatabase()), this, SLOT(refreshDatabase()));

        client->moveToThread(wireless_thread);
        wireless_thread->start();
        thread_count++;
    }

    if(thread_count == 0) {
        qCritical("You must enable at least USB or Wireless monitoring");
    }
}
void DifficultySettingsManager::loadSettings() {
    loadDefaultSettings();
    loadMapSettings();
    loadDifficultyNames();
}