--- /dev/null
+
+
+#ifndef _TANK_H_
+#define _TANK_H_
+
+#include "source.h"
+#include "drain.h"
+
+namespace PlaQui {
+
+namespace Model {
+
+class Tank:public Source, public Drain {
+public:
+ Tank(const std::string &_name);
+ virtual ~Tank();
+
+ virtual bool get_output();
+
+ virtual void recieve_msg(int msg, IConector *who, void *data);
+ virtual void update();
+ virtual void simulate();
+protected:
+ float litros;
+ float actual_in_flow;
+ float actual_out_flow;
+private:
+ Tank():Drain("null"),Source("null"),Control("null") {}
+ Tank &operator = (const Tank &) { return *this; }
+};
+
+}
+}
+
+#endif // _TANK_H_
--- /dev/null
+
+#include "tank.h"
+#include <iostream>
+
+using namespace PlaQui::Model;
+
+Tank::Tank(const std::string &_name):Source(_name),Drain(_name),Control(_name)
+{
+ litros = 0.0f;
+}
+
+Tank::~Tank()
+{
+}
+
+bool Tank::get_output()
+{
+ return litros > 0;
+}
+
+void Tank::update()
+{
+ updated = true;
+}
+
+void Tank::simulate()
+{
+ if (!updated) return;
+
+ // le resto lo que entrego
+ litros -= actual_out_flow;
+ // le sumo lo que recibo
+ litros += actual_in_flow;
+
+ std::cout << name << "Capacidad: " << capacity;
+ std::cout << " Litros : " << litros << std::endl;
+ updated = false;
+}
+
+void Tank::recieve_msg(int msg, IConector *who, void *data)
+{
+ int pos = OUT;
+
+ // Verifico si esta conectado a mi entrada
+ std::list<IConector *>::iterator i;
+ for(i=in_list.begin(); i!=in_list.end(); i++) {
+ if ((*i) == who) pos = IN;
+ }
+
+ switch (msg) {
+ case MSG_QUERY_MAX_FLOW_OUT:
+ actual_in_flow = capacity - litros;
+ if (*((float *)data) < actual_in_flow)
+ actual_in_flow = *((float *)data);
+ actual_out_flow = litros;
+ send_msg(OUT, MSG_QUERY_MAX_FLOW_OUT, &actual_out_flow);
+
+ who->recieve_msg(MSG_RESPONSE_MAX_FLOW, this, &actual_in_flow);
+ updated = true;
+ break;
+ case MSG_RESPONSE_MAX_FLOW:
+ if (pos == OUT) {
+ if (*((float *)data) < actual_out_flow)
+ actual_out_flow = *((float *)data);
+ }
+ }
+}
+