bool ActionStd::LoadFromXml(TiXmlElement *node)
{
    node = node->FirstChildElement();

    for (; node; node = node->NextSiblingElement())
    {
        if (node->ValueStr() == "calaos:output")
        {
            std::string id = "", val = "", val_var = "";

            if (node->Attribute("id")) id = node->Attribute("id");
            if (node->Attribute("val")) val = node->Attribute("val");
            if (node->Attribute("val_var")) val_var = node->Attribute("val_var");

            if (id == "OutTouchscreen" && ListeRule::Instance().size() > 0)
            {
                cInfoDom("rule.action.standard") <<  "Converting old OutTouchscreen to new ActionTouchscreen";
                Rule *rule = ListeRule::Instance().get_rule(ListeRule::Instance().size() - 1);
                ActionTouchscreen *action = new ActionTouchscreen(val);
                rule->AddAction(dynamic_cast<Action *>(action));
            }

            IOBase *out = ListeRoom::Instance().get_io(id);

            if (!out)
            {
                //for compatibility with old AudioPlayer and Camera, update ids if needed
                std::list<IOBase *> l = ListeRoom::Instance().getAudioList();
                for (IOBase *io: l)
                {
                    if (io->get_param("iid") == id ||
                        io->get_param("oid") == id)
                        out = io;
                }

                l = ListeRoom::Instance().getCameraList();
                for (IOBase *io: l)
                {
                    if (io->get_param("iid") == id ||
                        io->get_param("oid") == id)
                        out = io;
                }
            }

            if (out && out->isOutput())
            {
                Add(out);
                params.Add(id, val);
                if (val_var != "")
                    params_var.Add(id, val_var);
            }
            else
            {
                return false;
            }
        }
    }

    return true;
}
Esempio n. 2
0
Rule *Rule::duplicate()
{
    Rule *rule = new Rule(get_type(), get_name() + " (copy)", get_specialType());

    for (Condition *cond: conds)
    {
        Condition *newcond = cond->duplicate();
        rule->AddCondition(newcond);
    }

    for (Action *act: actions)
    {
        Action *newact = act->duplicate();
        rule->AddAction(newact);
    }

    return rule;
}
Esempio n. 3
0
bool ActionStd::LoadFromXml(TiXmlElement *node)
{
        node = node->FirstChildElement();

        for (; node; node = node->NextSiblingElement())
        {
                if (node->ValueStr() == "calaos:output")
                {
                        string id = "", val = "", val_var = "";

                        if (node->Attribute("id")) id = node->Attribute("id");
                        if (node->Attribute("val")) val = node->Attribute("val");
                        if (node->Attribute("val_var")) val_var = node->Attribute("val_var");

                        if (id == "OutTouchscreen" && ListeRule::Instance().size() > 0)
                        {
                                Utils::logger("rule.action.standard") << Priority::INFO << "ActionStd::LoadFromXml(): Converting old OutTouchscreen to new ActionTouchscreen" << log4cpp::eol;
                                Rule *rule = ListeRule::Instance().get_rule(ListeRule::Instance().size() - 1);
                                ActionTouchscreen *action = new ActionTouchscreen(val);
                                rule->AddAction(dynamic_cast<Action *>(action));
                        }

                        Output *out = ListeRoom::Instance().get_output(id);
                        if (out)
                        {
                                Add(out);
                                params.Add(id, val);
                                if (val_var != "")
                                        params_var.Add(id, val_var);
                        }
                        else
                        {
                                return false;
                        }
                }
        }

        return true;
}