bool ActionStd::Execute() { std::string tmp; bool ret = true; std::string sval; bool bval = false; double dval = 0; for (uint i = 0;i < outputs.size();i++) { bool ovar = false; switch (outputs[i]->get_type()) { case TBOOL: { if (params_var[outputs[i]->get_param("id")] != "") { std::string var_id = params_var[outputs[i]->get_param("id")]; IOBase *out = ListeRoom::Instance().get_io(var_id); if (out && out->get_type() == TBOOL) { bval = out->get_value_bool(); ovar = true; } } if (ovar) { if (!outputs[i]->set_value(bval)) ret = false; } else if (params[outputs[i]->get_param("id")] == "true") { if (!outputs[i]->set_value(true)) ret = false; } else if (params[outputs[i]->get_param("id")] == "false") { if (!outputs[i]->set_value(false)) ret = false; } else { if (!outputs[i]->set_value(params[outputs[i]->get_param("id")])) ret = false; } break; } case TINT: { if (params_var[outputs[i]->get_param("id")] != "") { std::string var_id = params_var[outputs[i]->get_param("id")]; IOBase *out = ListeRoom::Instance().get_io(var_id); if (out && out->get_type() == TINT) { dval = out->get_value_double(); ovar = true; } } tmp = params[outputs[i]->get_param("id")]; if (ovar) { if (!outputs[i]->set_value(dval)) ret = false; } else if (is_of_type<double>(tmp)) { if (!outputs[i]->set_value(atof(tmp.c_str()))) ret = false; } else { if (!outputs[i]->set_value(tmp)) ret = false; } break; } case TSTRING: { if (params_var[outputs[i]->get_param("id")] != "") { std::string var_id = params_var[outputs[i]->get_param("id")]; IOBase *out = ListeRoom::Instance().get_io(var_id); if (out && out->get_type() == TSTRING) { sval = out->get_command_string(); ovar = true; } } tmp = params[outputs[i]->get_param("id")]; if (ovar) { if (!outputs[i]->set_value(sval)) ret = false; } else if (tmp != "") { if (!outputs[i]->set_value(tmp)) ret = false; } break; } default: break; } } if (ret) cDebugDom("rule.action.standard") << "Ok"; else cErrorDom("rule.action.standard") << "Failed !"; return ret; }
bool ConditionOutput::Evaluate() { string sval, oper; bool bval; double dval; bool ret = false; bool ovar = false; bool changed = false; switch (output->get_type()) { case TBOOL: if (params_var != "") { IOBase *out = ListeRoom::Instance().get_io(params_var); if (out && out->get_type() == TBOOL) { bval = out->get_value_bool(); ovar = true; } } if (!ovar) { if (params == "true") bval = true; else if (params == "false") bval = false; else if (params == "changed") changed = true; else { cWarningDom("rule.condition.output") << "get_value(bool) not bool !"; ret = false; break; } } if (!changed) { ret = eval(output->get_value_bool(), ops, bval); } else { ret = true; } break; case TINT: if (params_var != "") { IOBase *out = ListeRoom::Instance().get_io(params_var); if (out && out->get_type() == TINT) { dval = out->get_value_double(); sval = "ovar"; ovar = true; } } if (!ovar) sval = params; if (sval != "") { if (!ovar) { if (sval == "changed") changed = true; else from_string(sval, dval); } if (!changed) { ret = eval(output->get_value_double(), ops, dval); } else { ret = true; } } else cWarningDom("rule.condition.output") << "get_value(int) not int !"; break; case TSTRING: if (params_var != "") { IOBase *out = ListeRoom::Instance().get_io(params_var); if (out && out->get_type() == TSTRING) { sval = out->get_value_string(); ovar = true; } } if (!ovar) { sval = url_decode2(params); if (sval == "changed") changed = true; } if (!changed) { ret = eval(output, ops, sval); } else { ret = true; } break; default: break; } if (ret) cDebugDom("rule.condition.output") << "Ok"; else cDebugDom("rule.condition.output") << "Failed !"; return ret; }