Example #1
0
bool
Configuration::saveFile(std::string name)
{
    int idx = findFileName(name);
    if(idx >= 0) {
        ConfigFile *c = m_ConfigFiles.at(idx);
        switch(c->getMode()) {
        case eFM_ReadOnly:
            debugOutput(DEBUG_LEVEL_VERBOSE, "Not saving readonly config file: %s\n", c->getName().c_str());
            break;
        case eFM_Temporary:
            debugOutput(DEBUG_LEVEL_VERBOSE, "Not saving temporary config file: %s\n", c->getName().c_str());
            break;
        case eFM_ReadWrite:
            debugOutput(DEBUG_LEVEL_VERBOSE, "Saving config file: %s\n", c->getName().c_str());
            try {
                c->writeFile();
            } catch (...) {
                debugError("Could not write file: %s\n", c->getName().c_str());
                return false;
            }
        default:
            debugOutput(DEBUG_LEVEL_VERBOSE, "bad mode for file: %s\n", c->getName().c_str());
        }
    }
    return true;
}
Example #2
0
libconfig::Setting *
Configuration::getDeviceSetting( unsigned int vendor_id, unsigned model_id )
{
    for ( std::vector<ConfigFile *>::iterator it = m_ConfigFiles.begin();
      it != m_ConfigFiles.end();
      ++it )
    {
        ConfigFile *c = *it;
        try {
            Setting &list = c->lookup("device_definitions");
            unsigned int children = list.getLength();
            for(unsigned int i = 0; i < children; i++) {
                Setting &s = list[i];
                try {
                    Setting &vendorid = s["vendorid"];
                    Setting &modelid = s["modelid"];
                    uint32_t vid = vendorid;
                    uint32_t mid = modelid;
                    if (vendor_id == vid && model_id == mid) {
                        debugOutput(DEBUG_LEVEL_VERBOSE,
                                    "  device VME for %X:%x found in %s\n",
                                    vendor_id, model_id, c->getName().c_str());
                        c->showSetting(s);
                        return &s;
                    }
                } catch (...) {
                    debugWarning("Bogus format\n");
                }
            }
        } catch (...) {
            debugOutput(DEBUG_LEVEL_VERBOSE, "  %s has no device definitions\n", c->getName().c_str());
        }
    }
    return NULL;
}
Example #3
0
bool
Configuration::save()
{
    bool retval = true;
    for (unsigned int idx = 0; idx < m_ConfigFiles.size(); idx++) {
        ConfigFile *c = m_ConfigFiles.at(idx);
        switch(c->getMode()) {
        case eFM_ReadOnly:
            debugOutput(DEBUG_LEVEL_VERBOSE, "Not saving readonly config file: %s\n", c->getName().c_str());
            break;
        case eFM_Temporary:
            debugOutput(DEBUG_LEVEL_VERBOSE, "Not saving temporary config file: %s\n", c->getName().c_str());
            break;
        case eFM_ReadWrite:
            debugOutput(DEBUG_LEVEL_VERBOSE, "Saving config file: %s\n", c->getName().c_str());
            try {
                c->writeFile();
            } catch (...) {
                debugError("Could not write file: %s\n", c->getName().c_str());
                retval = false;
            }
        default:
            debugOutput(DEBUG_LEVEL_VERBOSE, "bad mode for file: %s\n", c->getName().c_str());
        }
    }
    return retval;
}
Example #4
0
libconfig::Setting *
Configuration::getSetting( std::string path )
{
    for ( std::vector<ConfigFile *>::iterator it = m_ConfigFiles.begin();
      it != m_ConfigFiles.end();
      ++it )
    {
        ConfigFile *c = *it;
        try {
            Setting &s = c->lookup(path);
            return &s;
        } catch (...) {
            debugOutput(DEBUG_LEVEL_VERY_VERBOSE, "  %s has no setting %s\n",
                        c->getName().c_str(), path.c_str());
        }
    }
    return NULL;
}