Exemplo n.º 1
0
void Modex::
initModex(const std::string& configFile,
          MediaId lang)
{
    TimeUtils::updateCurrentTime();
    MODEXLOGINIT;
    LINFO << "InformationExtraction resources initialization" << LENDL;

    XMLConfigurationFileParser configParser(configFile);

    // first, add resources and processors to common resources and processors

    try {
        ModuleConfigurationStructure& resources=LinguisticResources::changeable().getModuleConfiguration(lang);
        ModuleConfigurationStructure& modexResourcesModule=configParser.getModuleConfiguration("Resources");
        // get resources for this language
        map<string,string>& resourcesByLanguage=modexResourcesModule.
                                                getMapAtKeyOfGroupNamed("resourcesByLanguage","resourceList");

        map<string,string>::iterator it=resourcesByLanguage.find(LinguisticData::single().getMediaId(m_language));
        if (it == resourcesByLanguage.end()) {
            LERROR << "no resources for language '"
                   << LinguisticData::single().getMediaId(m_language)
                   << "' in Resources for Modex" << LENDL;
            throw InvalidConfiguration();
        }

        std::string resourcesModule=(*it).second;
        ModuleConfigurationStructure& modexResources=configParser.getModuleConfiguration(resourcesModule);
        addConfiguration(modexResources,resources);
    }
    catch (NoSuchGroup& e) {
        LERROR << "missing param 'resourceList' in Resources for Modex in " << configFile << LENDL;
        throw InvalidConfiguration();
    }
    catch (NoSuchParam& ) {
        LERROR << "missing param 'resourcesByLanguage' in Resources for Modex in " << configFile << LENDL;
        throw InvalidConfiguration();
    }
    catch (NoSuchModule &) {
        LDEBUG << "no module 'Resources' for Modex in " << configFile << LENDL;
        // not mandatory
    }

    try {
        ModuleConfigurationStructure& processors=LinguisticResources::changeable().getModuleConfiguration(lang);
        ModuleConfigurationStructure& modexProcessors=configParser.getModuleConfiguration("Processors");
        addConfiguration(modexProcessors,processors);
    }
    catch (NoSuchModule &) {
        LERROR << "no module 'Processors' for Modex in " << configFile << LENDL;
        throw InvalidConfiguration();
    }

    // init modex
    initModexConfig(configParser);

    LINFO << "Modex initialization finished" << LENDL;
    TimeUtils::logElapsedTime("ModexInit");
}
Exemplo n.º 2
0
Window::Window( QWidget * parent )
	: QGLWidget( parent )
{
	timer = new QTimer( this );
	connect( timer, SIGNAL(timeout()), this, SLOT(update()) );
	timer->start( 0 );
	time = new QTime();
	setFocusPolicy( Qt::StrongFocus );
	Configuration config;
	ConfigParser configParser( config );
	configParser.readSettings();
	controller = config.buildController( &quitFunc );
}
void TrackingSystemIGSTKService::configure()
{
	if (mConfigurationFilePath.isEmpty() || !QFile::exists(mConfigurationFilePath))
	{
		reportWarning(QString("Configuration file [%1] is not valid, could not configure the toolmanager.").arg(mConfigurationFilePath));
		return;
	}

	//parse
	ConfigurationFileParser configParser(mConfigurationFilePath, mLoggingFolder);

	std::vector<IgstkTracker::InternalStructure> trackers = configParser.getTrackers();

	if (trackers.empty())
	{
		reportWarning("Failed to configure tracking.");
		return;
	}

	IgstkTracker::InternalStructure trackerStructure = trackers[0]; //we only support one tracker atm

	IgstkTool::InternalStructure referenceToolStructure;
	std::vector<IgstkTool::InternalStructure> toolStructures;
	QString referenceToolFile = configParser.getAbsoluteReferenceFilePath();
	std::vector<QString> toolfiles = configParser.getAbsoluteToolFilePaths();
	for (std::vector<QString>::iterator it = toolfiles.begin(); it != toolfiles.end(); ++it)
	{
		ToolFileParser toolParser(*it, mLoggingFolder);
		IgstkTool::InternalStructure internalTool = toolParser.getTool();
		if ((*it) == referenceToolFile)
			referenceToolStructure = internalTool;
		else
			toolStructures.push_back(internalTool);
	}

	//new thread
	mTrackerThread.reset(new IgstkTrackerThread(trackerStructure, toolStructures, referenceToolStructure));

	connect(mTrackerThread.get(), SIGNAL(configured(bool)), this, SLOT(trackerConfiguredSlot(bool)));
	connect(mTrackerThread.get(), SIGNAL(initialized(bool)), this, SLOT(initializedSlot(bool)));
	connect(mTrackerThread.get(), SIGNAL(tracking(bool)), this, SLOT(trackerTrackingSlot(bool)));
	connect(mTrackerThread.get(), SIGNAL(error()), this, SLOT(uninitialize()));

	//start threads
	if (mTrackerThread)
		mTrackerThread->start();
}
Exemplo n.º 4
0
ConfigurationManager* ConfigurationManager::LoadFromFile(string filePath) {
		// create the first singleton instance

		Config configParser(filePath);

		ConfigurationManager::m_ConfigurationManagerInstance = new ConfigurationManager();
		ConfigurationManager::m_ConfigurationManagerInstance->m_PngMapPath = configParser.mapLocation;
		ConfigurationManager::m_ConfigurationManagerInstance->m_StartLocation.m_X = configParser.startLocation[0];
		ConfigurationManager::m_ConfigurationManagerInstance->m_StartLocation.m_Y = configParser.startLocation[1];
		ConfigurationManager::m_ConfigurationManagerInstance->m_StartLocation.m_Yaw = configParser.startLocation[2];
		ConfigurationManager::m_ConfigurationManagerInstance->m_EndLocation.m_X = configParser.goal[0];
		ConfigurationManager::m_ConfigurationManagerInstance->m_EndLocation.m_Y = configParser.goal[1];
		ConfigurationManager::m_ConfigurationManagerInstance->m_PpCM = configParser.mapResolutionCm;
		ConfigurationManager::m_ConfigurationManagerInstance->m_PngGridResolution = configParser.gridResolutionCm;
		ConfigurationManager::m_ConfigurationManagerInstance->m_RobotSize.m_Width = configParser.robotSize[0];
		ConfigurationManager::m_ConfigurationManagerInstance->m_RobotSize.m_Height = configParser.robotSize[1];
		return ConfigurationManager::m_ConfigurationManagerInstance;
	}
Exemplo n.º 5
0
bool readConfigFile() {
    FileHandle* file = file_open(INI_PATH, "r");
    char line[100];
    void (*configParser)(char*) = generalParseConfig;

    if (file == NULL)
        goto end;

    while (file_tell(file) < file_getSize(file)) {
        file_gets(line, 100, file);
        char c=0;
        while (*line != '\0' && ((c = line[strlen(line)-1]) == ' ' || c == '\n' || c == '\r'))
            line[strlen(line)-1] = '\0';
        if (line[0] == '[') {
            char* endBrace;
            if ((endBrace = strrchr(line, ']')) != 0) {
                *endBrace = '\0';
                const char* section = line+1;
                if (strcasecmp(section, "general") == 0) {
                    configParser = generalParseConfig;
                }
                else if (strcasecmp(section, "console") == 0) {
                    configParser = menuParseConfig;
                }
                else if (strcasecmp(section, "controls") == 0) {
                    configParser = controlsParseConfig;
                }
            }
        }
        else
            configParser(line);
    }
    file_close(file);
end:
    controlsCheckConfig();

    return file != NULL;
}
Exemplo n.º 6
0
void threadHandler(char driveLtr)
{
    /* Lock the mutex so we don't try and access the database at the same time */
    gMutex.lock();

    bool authorized = false;

    /* Lock the USB drive */
    UsbOps ops;
    ops.lockUSB(driveLtr);

    /* Query authorized devices */
    Sql sql;
    if (!sql.dbConnect((char*)Paths::getDatabasePath().c_str(), false))
    {
        ErrorLog::logErrorToFile("*CRITICAL*", "Unable to open authorized drives database!");
        ops.ejectUSB();
        gMutex.unlock();
        return;
    }
    std::vector<authedDrive> drvs;
    sql.queryAuthedDrives(&drvs);

    /* Get the serial key of the device */
    UsbKey usbKey;
    UsbKeyhdr hdr;

    ops.unlockUSB();
    usbKey.getUsbKeyHdr(&hdr, driveLtr);
    ops.lockUSB(driveLtr);

    /* Check if the serial exists in the database */
    for (std::vector<authedDrive>::iterator it = drvs.begin(); it != drvs.end(); it++)
    {
        std::cout << it->serial.c_str() << " " << hdr.serialkey.c_str() << std::endl;
        if (it->serial.compare(hdr.serialkey) == 0)
        {
            authorized = true;
            break;
        }
    }

    ops.unlockUSB();

    /* Log media insertion event */

    AccessLog *log = new AccessLog();
    log->createLogStruct(&log->logUSBStruct, driveLtr, (char*)hdr.serialkey.c_str());
    log->logUSBStruct.accepted = authorized;


    /* Get config settings, check if remote SQL is enabled */
    ConfigParser configParser((char*)Paths::getConfigPath().c_str());
    if (configParser.getValue("SQLenabled") == "1")
    {
        /* SQL enabled = true */
        log->logUsbDrive(log->logUSBStruct, true);
    }
    else
        log->logUsbDrive(log->logUSBStruct, false);

    /* If not authorized, eject it! */
    if (!authorized)
    {
        ops.lockUSB(driveLtr);
        ops.ejectUSB();
    }

    /* Check for viruses here... */

    gMutex.unlock();
    delete log;
}