Exemple #1
0
    bool _isLocked(Setting& setting, bool exists, LockList* lockList)
    {
        // Compare the path of the current setting with the lock list and
        // prevent changes if the path is found.
        if (lockList != nullptr) {
            std::string path = setting.getPath();

            for (int i = 0; i < lockList->size(); ++i) {
                ConfigurationLock& lock = (*lockList)[i];

                if ((path.compare(lock.path) == 0) &&
                    ((lock.type == ConfigurationLock::Type::ClkAlways) ||
                     ((lock.type == ConfigurationLock::Type::ClkIfExists) && exists))) {

                    return true;
                }
            }
        }

        return false;
    }
Exemple #2
0
    void _apply(Setting& root, Setting& source, LockList* lockList)
    {
        Setting* s = nullptr;

        if (!source.isRoot()) {
            const char* name = source.getName();
            if (name != nullptr) {
                if (root.exists(name)) {
                    s = &root[name];

                    if (_isLocked(*s, true, lockList)) {
                        LogWarn("Ignored updating configuration '%s' to value "
                                "'%s'. Setting locked to value '%s'.",
                                s->getPath().c_str(),
                                settingToString(source).c_str(),
                                settingToString(*s).c_str());

                        return;
                    }

                    if (!s->isGroup()) {
                        root.remove(s->getIndex());
                        s = &root.add(name, source.getType());
                    }
                } else {
                    s = &root.add(name, source.getType());

                    if (_isLocked(*s, false, lockList)) {
                        LogWarn("Ignored creating configuration '%s' with "
                                "value '%s'. Setting locked.",
                                s->getPath().c_str(),
                                settingToString(*s).c_str());

                        root.remove(s->getIndex());
                        return;
                    }
                }
            } else {
                // List or array elements
                s = &root.add(source.getType());
            }
        } else {
            s = &root;
        }

        switch (source.getType())
        {
            case Setting::Type::TypeInt: {
                *s = (int)source;
                break;
            }

            case Setting::Type::TypeInt64: {
                *s = (long long)source;
                break;
            }

            case Setting::Type::TypeString: {
                *s = (const char*)source;
                break;
            }

            case Setting::Type::TypeBoolean: {
                *s = (bool)source;
                break;
            }

            case Setting::Type::TypeArray:
            case Setting::Type::TypeList:
            case Setting::Type::TypeGroup: {
                for (int i = 0; i < source.getLength(); ++i) {
                    _apply(*s, source[i], lockList);
                }
                break;
            }

            default: {
                assert(false);
                break;
            }
        }
    }