Пример #1
0
  void Pipeline::dumpSettings() {
    QList<Module*> modules;
    this->listModules(modules);
    foreach(Module *module, modules) {
      qDebug() << "---------------------------" << module->getModuleName() << ":" << module->getInstanceName();

      QHash<QString, Setting*> *settings = module->getSettings();
      QList<QString> keys = settings->keys();
      foreach(QString key, keys) {
        Setting *setting = module->setting(key);
        qDebug() << "   - setting: " << setting->getName() << ", type: " << setting->getType();

        switch(setting->getType()) {
        case Setting::NONE:
          qDebug() << "     - value: " << "none"; break;
        case Setting::BOOLEAN:
          qDebug() << "     - value: " << setting->asBool(); break;
        case Setting::STRING:
          qDebug() << "     - value: " << setting->asString(); break;
        case Setting::INTEGER:
          qDebug() << "     - value: " << setting->asInteger(); break;
        case Setting::DOUBLE:
          qDebug() << "     - value: " << setting->asDouble(); break;
        case Setting::POINTLIST:
          qDebug() << "     - value: " << "pointlist"; break;
        case Setting::FRAME:
          qDebug() << "     - value: " << setting->getFrameName();
          qDebug() << "     - module pointer: " << setting->getModule();
          break;
        }
      }
Пример #2
0
    std::string settingToString(Setting& setting, uint32_t maxElements)
    {
        Setting::Type t = setting.getType();
        switch (t)
        {
            case Setting::Type::TypeInt: {
                return stringFormat("%i", (int)setting);
            }

            case Setting::Type::TypeInt64: {
                return stringFormat("%ll", (long long)setting);
            }

            case Setting::Type::TypeString: {
                return stringFormat("\"%s\"", (const char*)setting);
            }

            case Setting::Type::TypeBoolean: {
                return stringFormat("%i", (bool)setting);
            }

            case Setting::Type::TypeArray:
            case Setting::Type::TypeList: {
                std::ostringstream value;
                value << ((t == Setting::Type::TypeArray) ? "[" : "(");

                if (setting.getLength() > 0) {
                    int i = 0;
                    while (true) {
                        value << settingToString(setting[i++]);

                        if (i == setting.getLength()) {
                            break;
                        }

                        if (i == maxElements) {
                            value << ",...";
                            break;
                        } else {
                            value << ",";
                        }
                    }
                } else {
                    value << "empty";
                }

                value << ((t == Setting::Type::TypeArray) ? "]" : ")");

                return value.str();
            }

            default: {
                return std::string("<unknown-type>");
            }
        }
    }
Пример #3
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;
            }
        }
    }