Ejemplo n.º 1
0
void Settings::ParseInitConfig() {
    QFile launcherFile(DirectoryManager::GetInstance()->GetConfigDir() + InitFile);
    if (!launcherFile.open(QFile::ReadOnly)) {
        Logger::GetInstance()->AddLog(tr("Error read launcher config"));
        return;
    }
    YAML::Parser launcherParser;
    std::istringstream launcherStream(launcherFile.readAll().data());
    launcherParser.Load(launcherStream);
    launcherFile.close();

    YAML::Node launcherSettings;
    if (!launcherParser.GetNextDocument(launcherSettings)) {
        Logger::GetInstance()->AddLog(tr("Error parse launcher settings."));
        return;
    }

    AppsConfig newConfig;
    const YAML::Node* pTimer = launcherSettings.FindValue(CONFIG_UPDATE_INTERVAL);
    if (pTimer) {
        QString interval;
        setString(interval, pTimer);
        m_nUpdateTimer = interval.toInt() * 60 * 1000;
    }
    const YAML::Node* Launcher = launcherSettings.FindValue(LAUNCHER);
    if (Launcher) {
        const YAML::Node* LauncherVer = Launcher->FindValue(LAUNCHER_VER);
        if (LauncherVer)
            setString(newConfig.m_Launcher.m_Version, LauncherVer);
        const YAML::Node* LauncherUrl = Launcher->FindValue(LAUNCHER_UPDATE_URL);
        if (LauncherUrl)
            setString(newConfig.m_Launcher.m_Url, LauncherUrl);
    }

    QFile docFile(DirectoryManager::GetInstance()->GetDocumentsDirectory() + InitFile);
    if(docFile.open(QFile::ReadOnly)) {
        YAML::Parser docParser;
        std::istringstream docStream(docFile.readAll().data());
        docParser.Load(docStream);
        docFile.close();

        YAML::Node docSettings;
        docParser.GetNextDocument(docSettings);

        ParseAppConfig(&docSettings, STABLE, newConfig.m_Stable);
        ParseAppConfig(&docSettings, QA, newConfig.m_Test);
        ParseAppConfig(&docSettings, DEVELOPMENT, newConfig.m_Development);
        ParseAppConfig(&docSettings, DEPENDENCIES, newConfig.m_Dependencies);
    }


    m_Config = newConfig;

}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------------
bool g3d::VoxelSpace_c::load(const std::string &FileName,YAML::Node &user_doc)
{
	bool Res = true;
	
	mcv::MixedFileManager_c FManager;
	std::stringstream YamlHeader = FManager.Parse(FileName);
	if(YamlHeader.str().empty())
	{
		std::cout << "VoxelSpace_c::load() Couldn't load File: " << FileName << std::endl;
		return false;
	}
	YAML::Parser parser;
	parser.Load(YamlHeader);
	parser.GetNextDocument(user_doc);
	YAML::Node doc;
	parser.GetNextDocument(doc);
	
	doc["VoxelSize"] >> VoxelSize;
	int TotalVoxels,vXv,vYv,vZv;
	doc["Xv"] >> vXv;
	doc["Yv"] >> vYv;
	doc["Zv"] >> vZv;
	doc["TotalVoxels"] >> TotalVoxels;
	int vNbFill;
	doc["NbFill"] >> vNbFill;
	EigenBox3D vBox;
	doc["VoxBox"] >> vBox;

	//This is the load SetUp as the data is the master with its Xv,Yv,Zv
	//and the <float> is not guarantied through text save and load
	//whether use double if more precision is needed but won't correct the text conversion issue
	//or save the critical information on data, but it becomes no more editable by the user
	//the remaining issue is the float -> text -> float conversion !!! ??? is this safe ?
	Reset(vBox.Low,vXv,vYv,vZv,VoxelSize);//will get Xv = vXv ....

	doc["TypeName"] >> TypeName;
	doc["ColorTable"] >> ColorTable;

	if(doc.FindValue("ClassesNames"))
	{
		doc["ClassesNames"] >> ClassesNames;
	}
Ejemplo n.º 3
0
YamlConfigurationNode *
YamlConfiguration::read_yaml_file(std::string filename, bool ignore_missing,
				  std::queue<LoadQueueEntry> &load_queue,
                                  std::string &host_file)
{
  if (access(filename.c_str(), R_OK) == -1) {
    if (ignore_missing) {
      return NULL;
    }
    throw Exception(errno, "YamlConfig: cannot access file %s", filename.c_str());
  }

#ifdef HAVE_YAMLCPP_0_5
  std::vector<YAML::Node> docs;
#else
  std::ifstream fin(filename.c_str());
  YAML::Parser parser;
  YAML::Node doc1, doc2;
#endif
  bool have_doc1 = false, have_doc2 = false;

  try {
#ifdef HAVE_YAMLCPP_0_5
    docs = YAML::LoadAllFromFile(filename);
    have_doc1 = docs.size() > 0;
    have_doc2 = docs.size() > 1;
#else
    parser.Load(fin);
    have_doc1 = parser.GetNextDocument(doc1);
    have_doc2 = parser.GetNextDocument(doc2);
#endif
  } catch (YAML::ParserException &e) {
    throw CouldNotOpenConfigException("Failed to parse %s line %i column %i: %s",
				      filename.c_str(), e.mark.line, e.mark.column,
				      e.msg.c_str());
  }

  YamlConfigurationNode *sub_root = NULL;

  if (! have_doc1) {
    //throw Exception("YamlConfig: file %s contains no document", filename.c_str());
    // empty -> ignore
  } else if (have_doc1 && have_doc2) {
    // we have a meta info and a config document
#ifdef HAVE_YAMLCPP_0_5
    read_meta_doc(docs[0], load_queue, host_file);
    read_config_doc(docs[1], sub_root);
#else
    read_meta_doc(doc1, load_queue, host_file);
    read_config_doc(doc2, sub_root);
#endif

  } else {
    // only one, assume this to be the config document
#ifdef HAVE_YAMLCPP_0_5
    read_config_doc(docs[0], sub_root);
#else
    read_config_doc(doc1, sub_root);
#endif
  }

  return sub_root;
}
Ejemplo n.º 4
0
int ConfigManager::readConfigFile(int fd, std::istream* stream)
{
    YAML::Parser p;
    YAML::Node doc;
    int ret = 0;
    std::vector<v4l2_ext_control> controls;

    try
    {
        p.Load(*stream);
    }
    catch(YAML::Exception& e)
    {
        ROS_FATAL("Could not parse config file: %s", e.what());
        return -1;
    }

    if(!p.GetNextDocument(doc))
    {
        ROS_FATAL("Could not get YAML document");
        return -1;
    }

    for(YAML::Iterator it = doc.begin(); it != doc.end(); ++it)
    {
        std::string key, value;

        try
        {
            (*it).begin().first() >> key;
            (*it).begin().second() >> value;
        }
        catch(YAML::Exception& e)
        {
            ROS_FATAL("Invalid parameter specification: %s", e.what());
            return -1;
        }

        int ivalue = -1;
        calibration::CameraParam* info = getParamInfo(key);
        if(!info)
        {
            ROS_FATAL("Unknown parameter '%s' in config file, ignoring...", key.c_str());
            continue;
        }

        ivalue = atoi(value.c_str());

        info->value = ivalue;
        v4l2_ext_control control;
        memset(&control, 0, sizeof(control));
        control.id = info->id;
        control.value = ivalue;

        controls.push_back(control);
    }

    v4l2_ext_controls request;
    memset(&request, 0, sizeof(request));
    request.controls = &controls[0];
    request.count = controls.size();
    request.ctrl_class = V4L2_CTRL_CLASS_USER;

    if(ioctl(fd, VIDIOC_S_EXT_CTRLS, &request) != 0)
    {
        ROS_FATAL("Control setting failed. This may have happened at control 0x%X with value %d",
                  controls[request.error_idx].id,
                  controls[request.error_idx].value
                 );
        return -1;
    }
    ROS_INFO("Controls set successfully from config file");

    return ret;
}