X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/a8803d96a8a33195ae9234b5e6ea84d7eefa0fd9..3b0c56cf70eaac383f3cff2b3c76d1ec04595b92:/Model/src/conduct.cpp?ds=sidebyside diff --git a/Model/src/conduct.cpp b/Model/src/conduct.cpp index 02fe3a6..a0e40fe 100644 --- a/Model/src/conduct.cpp +++ b/Model/src/conduct.cpp @@ -5,12 +5,13 @@ using namespace PlaQui::Model; Conduct::Conduct(const std::string &_name):Transport(_name) { - max_flow = actual_flow = 0.0f; + max_flow = 0.0f; // Inicio los parametros de conectores in_slots = 1; out_slots = 1; - actual_flow = 9999; + actual_flow = INFINITO; + updated = false; } Conduct::~Conduct() @@ -21,18 +22,19 @@ void Conduct::recieve_msg(int msg, IConector *who, void *data) { switch (msg) { case MSG_QUERY_MAX_FLOW_OUT: { + if (updated) { + who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow); + } + // Me preguntan por el flujo máximo. // Primero me actualizo, y luego respondo + updated = true; float tmp = *((float *)data); - // update(); actual_flow = (actual_flow>max_flow)?max_flow:actual_flow; actual_flow = (actual_flowrecieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_flow); - updated = true; } break; case MSG_RESPONSE_MAX_FLOW: { @@ -51,34 +53,29 @@ void Conduct::recieve_msg(int msg, IConector *who, void *data) void Conduct::update(int dir) { // Si ya me actualice, no lo tengo que hacer de nuevo - if (updated) return; + if (updated) { + return; + } // Seteo mi actualizar en true para evitar entrar de nuevo - actual_flow = 99999; updated = true; - switch (dir) { - case IN: - send_msg(IN, MSG_QUERY_MAX_FLOW_IN, (void *)&max_flow); - break; - case OUT: - send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, (void *)&max_flow); - } + actual_flow = max_flow; + send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, (void *)&actual_flow); } void Conduct::simulate() { if (!updated) { +#ifdef DEBUG std::cout << name << "::sin actualizar!" << std::endl; +#endif return; } - std::cout << name << "::Flujo actual = " << actual_flow << std::endl; +#ifdef DEBUG + std::cout << name << "::Flujo actual = " << actual_flow << " de " << max_flow << std::endl; +#endif updated = false; + color_updated = false; } -void Conduct::get_state_as_xml(std::stringstream &out) -{ - out << "\t" << std::endl; - out << "\t\t" << actual_flow << "" << std::endl; - out << "\t" << std::endl; -}