Example #1
0
void BasicConfig::AddBasicConfig(const std::string& name, ConfigItem::ConfigItemType type, const std::string& value)
{
    ConfigItem *pConfigItem;


    pConfigItem = new xPL::ConfigItem(name, type);
	pConfigItem->AddValue(value);
	AddConfigItem(pConfigItem);
}
Example #2
0
bool BasicConfig::MsgAnswer(SchemaObject& msg)
{
    if(msg.GetMsgType() != SchemaObject::cmnd)
    {
        LOG_VERBOSE(m_Log) << "Not a command message.";
        LOG_EXIT_OK;
        return false;
    }

    if(msg.GetClass() != "config")
    {
        LOG_VERBOSE(m_Log) << "Not a config class.";
        LOG_EXIT_OK;
        return false;
    }

    if(msg.GetType() == "current")
    {
        LOG_VERBOSE(m_Log) << "current type...";
        if(msg.GetValue("command") != "request")
        {
            LOG_VERBOSE(m_Log) << "but not command request";
            LOG_EXIT_OK;
            return false;
        }
        LOG_VERBOSE(m_Log) << "send config.current message";
        SchemaConfigCurrent configCurrent;
        configCurrent = ToConfigCurrent();
        m_xPLDevice->SendMessage(&configCurrent, msg.GetSource());
        LOG_EXIT_OK;
        return true;
    }

    if(msg.GetType() == "list")
    {
        LOG_VERBOSE(m_Log) << "list type...";
        if(msg.GetValue("command") != "request")
        {
            LOG_VERBOSE(m_Log) << "but not command request";
            LOG_EXIT_OK;
            return false;
        }
        LOG_VERBOSE(m_Log) << "send config.list message";
        SchemaConfigList configList;
        configList = ToConfigList();
        m_xPLDevice->SendMessage(&configList, msg.GetSource());
        LOG_EXIT_OK;
        return true;
    }

    if(msg.GetType() == "response")
    {
        LOG_VERBOSE(m_Log) << "response type";
        size_t i;
        SchemaObject::SchemaItem* pSchemaItem;
        ConfigItem* pConfigItem;
        SchemaObject::SchemaItem::Iterator itValue;

        for(i=0; i<m_ConfigItems.size(); i++)
        {
            pConfigItem = m_ConfigItems[i];

            pSchemaItem = msg.GetItem(pConfigItem->GetName());
            if(pSchemaItem==nullptr) continue;

            pConfigItem->ClearValues();

            for(itValue=pSchemaItem->begin(); itValue!=pSchemaItem->end(); ++itValue)
                pConfigItem->AddValue(*itValue);
        }

        if(m_CallBackConfig != nullptr) m_CallBackConfig->Configure();
        m_xPLDevice->SaveConfig();
        LOG_EXIT_OK;
        return true;
    }

    LOG_VERBOSE(m_Log) << "Not a current|list|response type.";
    LOG_EXIT_OK;
    return false;
}