#define PLAQUI_PLANT_H
#include "plaqui/server/runnable.h"
+#include "plaqui/server/transmitter.h"
+#include "simulator.h"
#include <sigc++/signal.h>
namespace PlaQui {
// Tipos.
+ private:
+
+ /// Lista de conexiones de control.
+ typedef std::list<Transmitter*> TransmitterList;
+
public:
/// Tipo de señal para indicar que se actualizó la planta.
- typedef SigC::Signal0<void> SignalUpdated;
+ //typedef SigC::Signal0<void> SignalUpdated;
// Atributos.
private:
+ /// Transmisiones del estado de las plantas.
+ TransmitterList transmissions;
+
+ /// Mutex para las transmisiones.
+ Glib::Mutex transmissions_mutex;
+
+ /// Simulador usado para calcular el estado de la planta.
+ Model::Simulator simulator;
+
/// Señal para indicar que se actualizó la planta.
- SignalUpdated updated;
+ //SignalUpdated updated;
+
+ /// Nombre de la planta.
+ //std::string name;
// Métodos.
/**
* Constructor desde un archivo.
*
+ * \param name Nombre de la planta.
* \param filename Nombre del archivo de donde obtener la planta.
*/
Plant(const std::string& filename);
+ /**
+ * Comienza una transmisión del estado de la planta.
+ *
+ * \return true si comenzó la transmisión, false si hubo problemas.
+ */
+ bool transmission_start(const string& host,
+ const Connection::Port& port);
+
+ /**
+ * Comienza una transmisión del estado de la planta.
+ *
+ * \return true si detuvo la transmisión, false si no existía.
+ */
+ bool transmission_stop(const string& host,
+ const Connection::Port& port);
+
/**
* Obtiene la señal para indicar que se actualizó la planta.
*/
- SignalUpdated& signal_updated(void);
+ //SignalUpdated& signal_updated(void);
};
#include "plaqui/server/command.h"
#include <socket++/sockinet.h>
#include <string>
-#include <list>
+#include <map>
namespace PlaQui {
private:
- /// Lista de conexiones de control.
- typedef std::list<Transmitter*> TransmitterList;
-
/// Lista de plantas químicas.
- typedef std::list<Plant*> PlantList;
+ typedef std::map<std::string, Plant*> PlantList;
// Atributos.
private:
- /// Transmisiones del estado de las plantas.
- TransmitterList transmissions;
-
- /// Mutex para las transmisiones.
- Glib::Mutex transmissions_mutex;
-
// Plantas disponibles en el servidor.
PlantList plants;
*/
HTTPResponse* cmd_connection_stop(const Command& command);
+ /**
+ * Maneja el comando transmission/list.
+ */
+ HTTPResponse* cmd_transmission_list(void);
+
+ /**
+ * Maneja el comando transmission/start.
+ */
+ HTTPResponse* cmd_transmission_start(const Command& command);
+
+ /**
+ * Maneja el comando transmission/stop.
+ */
+ HTTPResponse* cmd_transmission_stop(const Command& command);
+
+ /**
+ * Maneja el comando plant/list.
+ */
+ HTTPResponse* cmd_plant_list(void);
+
+ /**
+ * Maneja el comando plant/stop.
+ */
+ HTTPResponse* cmd_plant_stop(const Command& command);
+
public:
/**
Server(int port = 7522);
/**
- * Comienza la transimisión del estado de una planta.
- *
- * \param host Host al cual se quiere transmitir.
- * \param port Puerto al cual transmitir.
- *
- * \return true si se pudo empezar a transmitir, false si no.
- *
- * \todo Ver si es necesario que devuelva algo y si devuelve ver si
- * no sería mejor que dé más información (si no se pudo abrir
- * o si ya estaba abierto por ejemplo.
+ * Maneja los comandos recibidos por las conexiones.
*/
- bool start_transmission(std::string host = "localhost",
- int port = 7528);
+ void on_control_command_received(const Command& command,
+ ControlServer* controlserver);
/**
- * Finaliza la transimisión del estado de una planta.
- *
- * \param host Host al cual se quiere dejar de transmitir.
- * \param port Puerto al cual dejar de transmitir.
+ * Se encarga de borrar una planta de la lista cuando finaliza.
*
- * \return true si se pudo empezar a transmitir, false si no.
- *
- * \todo Ver de hacer un TransmissionManager.
+ * \param connection Conexión a eliminar.
*/
- bool stop_transmission(std::string host, int port);
+ void on_plant_finished(const char* plant);
/**
- * Maneja los comandos recibidos por las conexiones.
+ * Envia el estado de una planta cuando esta se actualiza.
+ *
+ * \param plant Planta actualizada.
*/
- void on_control_command_received(const Command& command,
- ControlServer* controlserver);
+ void on_plant_updated(const Plant* const);
};
#define PLAQUI_TRANSMITTER_H
#include "plaqui/server/connection.h"
+//#include "plaqui/server/plant.h"
#include <string>
namespace PlaQui {
/// Conexión para transmitir el estado de una planta.
class Transmitter: public Connection {
+ // Métodos.
+
private:
/**
* \param host Host al cual transmitir.
* \param port Puerto al cual transmitir.
*/
- Transmitter(std::string host = "localhost", int port = 7528);
+ Transmitter(const std::string& _host = "localhost",
+ const Connection::Port& _port = 7528);
+
+ /**
+ * Envia datos.
+ */
+ void send(const std::string& data);
};
# Directorio con los .h
INCLUDE_BASE_DIR=../include
INCLUDE_DIR=$(INCLUDE_BASE_DIR)/plaqui/server
+MODEL_DIR=../../Model
# Opciones para el compilador.
-CXXFLAGS=-ansi -pedantic -Wall -I$(INCLUDE_BASE_DIR) \
- `pkg-config --cflags glibmm-2.0 gthread-2.0`
+CXXFLAGS=-ansi -pedantic -Wall -I$(INCLUDE_BASE_DIR) -I$(MODEL_DIR)/include \
+ `pkg-config --cflags glibmm-2.0 gthread-2.0` `xml2-config --cflags`
CXXFLAGS+=-g -DDEBUG
#CXXFLAGS+=-g
#CXXFLAGS+=-O2
objects+=httpmessage.o
httpmessage.o: $(httpmessage_h) httpmessage.cpp
+httpresponse_h=$(string_h) $(httperror_h) $(httpmessage_h) $(INCLUDE_DIR)/httprequest.h
+objects+=httpresponse.o
+httpresponse.o: $(httpresponse_h) httpresponse.cpp
+
httprequest_h=$(string_h) $(httpmessage_h) $(INCLUDE_DIR)/httprequest.h
objects+=httprequest.o
httprequest.o: $(httprequest_h) httprequest.cpp
objects+=command.o
command.o: $(command_h) command.cpp
-httpresponse_h=$(string_h) $(httperror_h) $(httpmessage_h) $(INCLUDE_DIR)/httprequest.h
-objects+=httpresponse.o
-httpresponse.o: $(httpresponse_h) httpresponse.cpp
+plant_h=$(INCLUDE_DIR)/plant.h
+objects+=plant.o
+plant.o: $(plant_h) plant.cpp
runnable_h=$(INCLUDE_DIR)/runnable.h
objects+=runnable.o
}
void Command::build(void) {
- uri = string("/") + target + '/' + command + String::join(args, "/");
+ uri = string("/") + target;
+ if (command.length()) {
+ uri += '/' + command;
+ if (args.size()) {
+ uri += '/' + String::join(args, "/");
+ }
+ }
#ifdef DEBUG
cerr << __FILE__ << ": build() = " << uri << endl;
#endif // DEBUG
--- /dev/null
+// vim: set noexpandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// PlaQui
+//----------------------------------------------------------------------------
+// This file is part of PlaQui.
+//
+// PlaQui is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: dom nov 16 13:03:33 ART 2003
+// Autores: Leandro Lucarella <llucare@fi.uba.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#include "plaqui/server/plant.h"
+#include <glibmm/timer.h>
+#include <sigc++/slot.h>
+#ifdef DEBUG
+# include <iostream>
+#endif // DEBUG
+
+using namespace std;
+
+namespace PlaQui {
+
+namespace Server {
+
+Plant::~Plant(void) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": destructor." << endl;
+#endif // DEBUG
+ // Termino transmisiones.
+ Glib::Mutex::Lock lock(transmissions_mutex);
+ for (TransmitterList::iterator trans = transmissions.end();
+ trans != transmissions.end(); trans++) {
+ (*trans)->finish(true);
+ }
+}
+
+Plant::Plant(const string& filename): simulator(filename) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": constructor. filename = " << filename << endl;
+#endif // DEBUG
+ // TODO plant
+ simulator.add_pump("bomba1");
+ simulator.add_conduct("c");
+ simulator.add_conduct("c1");
+ simulator.add_drainage("d");
+ simulator.add_tank("tanque");
+
+ simulator.connect("bomba1", "c", Model::IConector::OUT);
+ simulator.connect("c", "tanque", Model::IConector::OUT);
+ simulator.connect("tanque", "c1", Model::IConector::OUT);
+ simulator.connect("c1", "d", Model::IConector::OUT);
+
+}
+
+void Plant::real_run(void) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": real_run." << endl;
+#endif // DEBUG
+ while (!stop) {
+ simulator.simulate();
+ Glib::Mutex::Lock lock(transmissions_mutex);
+ for (TransmitterList::iterator i = transmissions.begin();
+ i != transmissions.end(); i++) {
+ (*i)->send(simulator.get_state_as_xml());
+ }
+ Glib::usleep(1000000);
+ }
+}
+
+bool Plant::transmission_start(const string& host,
+ const Connection::Port& port) {
+ Glib::Mutex::Lock lock(transmissions_mutex);
+ for (TransmitterList::iterator i = transmissions.begin();
+ i != transmissions.end(); i++) {
+ if (((*i)->get_host() == host) && ((*i)->get_port() == port)) {
+ return false;
+ }
+ }
+ Transmitter* trans;
+ try {
+ trans = new Transmitter(host, port);
+ } catch (...) { // TODO - Hace mas selectivo el catch?
+ delete trans;
+ return false;
+ }
+ transmissions.push_back(trans);
+ trans->run();
+ return true;
+}
+
+bool Plant::transmission_stop(const string& host,
+ const Connection::Port& port) {
+ Glib::Mutex::Lock lock(transmissions_mutex);
+ for (TransmitterList::iterator i = transmissions.begin();
+ i != transmissions.end(); i++) {
+ if (((*i)->get_host() == host) && ((*i)->get_port() == port)) {
+ (*i)->finish();
+ return true;
+ }
+ }
+ return false; // No la encontró.
+}
+
+/*
+bool Plant::transmission_exists(const string& host,
+ const Connection::Port& port) {
+ Glib::Mutex::Lock lock(transmissions_mutex);
+ for (TransmitterList::const_iterator i = transmissions.begin();
+ i != transmissions.end(); i++) {
+ if (((*i)->get_host() == host) && ((*i)->get_oprt() == port)) {
+ return true;
+ }
+ }
+ return false; // No la encontró.
+}
+*/
+
+//const std::string& Plant::get_name(void) const {
+// return name;
+//}
+
+/// \todo FIXME esto deberia estar protegido por un mutex.
+//Plant::SignalUpdated& Plant::signal_updated(void) {
+// return updated;
+//}
+
+} // namespace Server
+
+} // namespace PlaQui
+
//
#include "plaqui/server/runnable.h"
-#include <sigc++/class_slot.h>
+#include <sigc++/slot.h>
#include <glibmm/thread.h>
#ifdef DEBUG
# include <iostream>
#ifdef DEBUG
cerr << __FILE__ << ": destructor." << endl;
#endif // DEBUG
+ // Termino plantas.
+ Glib::Mutex::Lock lock(plants_mutex);
+ for (PlantList::iterator i = plants.end(); i != plants.end(); i++) {
+ i->second->finish(true);
+ }
}
-Server::Server(int port):
- TCPServer(port) {
+Server::Server(int port): TCPServer(port) {
#ifdef DEBUG
cerr << __FILE__ << ": port = " << port << endl;
#endif // DEBUG
+ // FIXME
+ Glib::Mutex::Lock lock(plants_mutex);
+ plants["prueba"] = new Plant("prueba.xml");
+ plants["prueba"]->signal_finished().connect(
+ SigC::bind<const char*>(
+ SigC::slot_class(*this, &Server::on_plant_finished),
+ "prueba"));
+ plants["prueba"]->run();
}
-/// \todo Implementar.
-bool Server::start_transmission(string host, int port) {
-#ifdef DEBUG
- cerr << __FILE__ << ": start_transmission(host = " << host
- << " | port = " << port << ")" << endl;
-#endif // DEBUG
- // TODO
- return false;
-}
-
Connection* Server::new_connection(
const sockbuf::sockdesc& sd) {
#ifdef DEBUG
return connection;
}
-/// \todo Implementar.
-bool Server::stop_transmission(string host, int port) {
+void Server::on_plant_updated(const Plant* plant) {
#ifdef DEBUG
- cerr << __FILE__ << ": stop_transmission(host = " << host
- << " | port = " << port << ")" << endl;
+ cerr << __FILE__ << ": on_plant_updated(plant = " << plant << ")." << endl;
#endif // DEBUG
- // TODO
- return false;
}
-/// \todo Implementar.
+void Server::on_plant_finished(const char* plant) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": on_plant_finished(plant_name = " << plant << endl;
+#endif // DEBUG
+ Glib::Mutex::Lock lock(plants_mutex);
+ plants.erase(plant);
+}
+
+/// \todo Terminar de implementar.
void Server::on_control_command_received(const Command& command,
ControlServer* controlserver) {
#ifdef DEBUG
"Invalid command for 'connection' taget!");
}
} else if (command.get_target() == "transmission") {
- response = new HTTPResponse(HTTPMessage::NOT_FOUND,
- "Invalid command for 'transmission' taget!");
+ if (command.get_command() == "list") {
+ response = cmd_transmission_list();
+ } else if (command.get_command() == "start") {
+ response = cmd_transmission_start(command);
+ } else if (command.get_command() == "stop") {
+ response = cmd_transmission_stop(command);
+ } else {
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND,
+ "Invalid command for 'transmission' taget!");
+ }
} else if (command.get_target() == "plant") {
- response = new HTTPResponse(HTTPMessage::NOT_FOUND,
- "Invalid command for 'plant' taget!");
+ if (command.get_command() == "list") {
+ response = cmd_plant_list();
+ } else if (command.get_command() == "stop") {
+ response = cmd_plant_stop(command);
+ } else {
+ response = new HTTPResponse(HTTPMessage::NOT_FOUND,
+ "Invalid command for 'plant' taget!");
+ }
} else {
response = new HTTPResponse(HTTPMessage::NOT_FOUND, "Invalid taget!");
}
stringstream response_xml;
response_xml << "<html>" << endl;
response_xml << " <head>" << endl;
- response_xml << " <title>PlaQui v0.7</title>" << endl;
+ response_xml << " <title>PlaQui v0.8</title>" << endl;
response_xml << " </head>" << endl;
response_xml << " <body>" << endl;
response_xml << " <h1>PlaQui</h1>" << endl;
- response_xml << " <p>versión 0.7</p>" << endl;
+ response_xml << " <p>versión 0.8</p>" << endl;
/* response_xml << " <h2>Comando</h2>" << endl;
response_xml << " <ul>" << endl;
response_xml << " <li><b>Target:</b> " << command.get_target() << endl;
response_xml << " <li>" << *i << "</li>" << endl;
}
response_xml << " </ol>" << endl;
- response_xml << " </ul>" << endl;
-*/ response_xml << " <h2>Desarrollado por</h2>" << endl;
+ response_xml << " </ul>" << endl;*/
+ response_xml << " <h2>Desarrollado por</h2>" << endl;
response_xml << " <ul>" << endl;
response_xml << " <li>Nicolás Dimov.</li>" << endl;
response_xml << " <li>Leandro Lucarella.</li>" << endl;
stringstream response_xml;
response_xml << "<html>" << endl;
response_xml << " <head>" << endl;
- response_xml << " <title>PlaQui v0.7</title>" << endl;
+ response_xml << " <title>PlaQui v0.8</title>" << endl;
response_xml << " </head>" << endl;
response_xml << " <body>" << endl;
response_xml << " <h1>PlaQui</h1>" << endl;
- response_xml << " <p>versión 0.7</p>" << endl;
+ response_xml << " <p>versión 0.8</p>" << endl;
response_xml << " <h2>Lista de conexiones:</h2>" << endl;
response_xml << " <ul>" << endl;
for (TCPServer::ConnectionInfoList::const_iterator i = cil.begin();
}
}
+HTTPResponse* Server::cmd_transmission_list(void) {
+ // FIXME
+ stringstream response_xml;
+ response_xml << "<html>" << endl;
+ response_xml << " <head>" << endl;
+ response_xml << " <title>PlaQui v0.8</title>" << endl;
+ response_xml << " </head>" << endl;
+ response_xml << " <body>" << endl;
+ response_xml << " <h1>PlaQui</h1>" << endl;
+ response_xml << " <p>versión 0.8</p>" << endl;
+ response_xml << " <h2>Lista de transmisiones:</h2>" << endl;
+ response_xml << " <ul>" << endl;
+ // TODO - recorrer todas las plantas y sus transmisiones.
+/* transmissions_mutex.lock();
+ for (TransmitterList::const_iterator i = transmissions.begin();
+ i != transmissions.end(); i++) {
+ response_xml << " <li>" << (*i)->get_host() << ":"
+ << (*i)->get_port() << " [<a href=\"/transmission/stop/"
+ << (*i)->get_host() << "/" << (*i)->get_port()
+ << "\">desconectar</a>]</li>" << endl;
+ }
+ transmissions_mutex.unlock();*/
+ response_xml << " </ul>" << endl;
+ response_xml << " <address>" << endl;
+ response_xml << " Copyleft 2003 - bajo los " << endl;
+ response_xml << " términos de la licencia GPL" << endl;
+ response_xml << " </address>" << endl;
+ response_xml << " </body>" << endl;
+ response_xml << "</html>" << endl;
+ return new HTTPResponse(HTTPMessage::OK, response_xml.str());
+}
+
+HTTPResponse* Server::cmd_transmission_start(const Command& command) {
+ const Command::Arguments& args = command.get_args();
+ if (args.size() < 3) {
+ return new HTTPResponse(HTTPMessage::CONFLICT,
+ "Faltan argumentos.");
+ } else {
+ const string& plant = args[0];
+ const string& host = args[1];
+ Connection::Port port = String(args[2]).to(port);
+ Glib::Mutex::Lock lock(plants_mutex);
+ PlantList::iterator p = plants.find(plant);
+ if (p == plants.end()) {
+ return new HTTPResponse(HTTPMessage::NOT_FOUND,
+ string("No existe la planta '") + plant + "'.");
+ // TODO - agregar chequeo de que la transmision a ese host:port no
+ // exista para otra planta?
+ } else if (plants[plant]->transmission_start(host, port)) {
+ return new HTTPResponse(HTTPMessage::OK,
+ string("Se empieza a transmitir la planta '") + plant
+ + "' a " + host + ":" + args[1] + ".");
+ } else {
+ return new HTTPResponse(HTTPMessage::INTERNAL_SERVER_ERROR,
+ string("Error al crear la transmisión a de la planta '")
+ + plant + "' a " + host + ":" + args[2] + ".");
+ }
+ }
+}
+
+HTTPResponse* Server::cmd_transmission_stop(const Command& command) {
+ const Command::Arguments& args = command.get_args();
+ if (args.size() < 2) {
+ return new HTTPResponse(HTTPMessage::CONFLICT,
+ "Faltan argumentos.");
+ } else {
+ const string& host = args[0];
+ Connection::Port port = String(args[1]).to(port);
+ for (PlantList::iterator i = plants.begin(); i != plants.end(); i++) {
+ // TODO - agregar chequeo para saber si existe una conexion (para
+ // tirar error de que no hay conexion o de que no se pudo
+ // desconectar.
+ if (i->second->transmission_stop(host, port)) {
+ return new HTTPResponse(HTTPMessage::OK,
+ string("Se finaliza la transmisión de la planta '")
+ + i->first + "' a " + host + ":" + args[1] + ".");
+ }
+ }
+ return new HTTPResponse(HTTPMessage::NOT_FOUND,
+ string("No se puede finalizar la transmisión a ")
+ + host + ":" + args[1] + ".");
+ }
+}
+
+HTTPResponse* Server::cmd_plant_list(void) {
+ // FIXME
+ stringstream response_xml;
+ response_xml << "<html>" << endl;
+ response_xml << " <head>" << endl;
+ response_xml << " <title>PlaQui v0.8</title>" << endl;
+ response_xml << " </head>" << endl;
+ response_xml << " <body>" << endl;
+ response_xml << " <h1>PlaQui</h1>" << endl;
+ response_xml << " <p>versión 0.8</p>" << endl;
+ response_xml << " <h2>Lista de plantas:</h2>" << endl;
+ response_xml << " <ul>" << endl;
+ plants_mutex.lock();
+ for (PlantList::const_iterator i = plants.begin();
+ i != plants.end(); i++) {
+ response_xml << " <li>" << i->first
+ << " [<a href=\"/plant/stop/" << i->first << "\">parar</a>]</li>"
+ << endl;
+ }
+ plants_mutex.unlock();
+ response_xml << " </ul>" << endl;
+ response_xml << " <address>" << endl;
+ response_xml << " Copyleft 2003 - bajo los " << endl;
+ response_xml << " términos de la licencia GPL" << endl;
+ response_xml << " </address>" << endl;
+ response_xml << " </body>" << endl;
+ response_xml << "</html>" << endl;
+ return new HTTPResponse(HTTPMessage::OK, response_xml.str());
+}
+
+HTTPResponse* Server::cmd_plant_stop(const Command& command) {
+ if (!command.get_args().size()) {
+ return new HTTPResponse(HTTPMessage::CONFLICT,
+ "Faltan argumentos.");
+ }
+ Glib::Mutex::Lock lock(plants_mutex);
+ const string name = command.get_args()[0];
+ if (plants.find(name) == plants.end()) {
+ return new HTTPResponse(HTTPMessage::NOT_FOUND,
+ string("No existe la planta ") + name);
+ }
+ // TODO Ver si al frenar la planta se destruye (no deberia!!!)
+ plants[name]->finish();
+ return new HTTPResponse(HTTPMessage::OK,
+ string("La planta '") + name + "' se cerrará en instantes...");
+}
+
} // namespace Server
} // namespace PlaQui
#ifdef DEBUG
cerr << __FILE__ << ": destructor." << endl;
#endif // DEBUG
+ Glib::Mutex::Lock lock(connections_mutex);
+ for (ConnectionList::iterator con = connections.begin();
+ con != connections.end(); con++) {
+ (*con)->finish(true);
+ }
}
TCPServer::TCPServer(const Connection::Port& port): socket(sockbuf::sock_stream) {
//
#include "plaqui/server/transmitter.h"
+#include <glibmm/timer.h>
#include <socket++/sockinet.h>
#include <string>
#ifdef DEBUG
#endif // DEBUG
}
-/// \todo debría conectarse en real_run() (?)
-Transmitter::Transmitter(string host, int port):
+Transmitter::Transmitter(const string& _host, const Connection::Port& _port):
Connection(sockbuf::sock_dgram) {
#ifdef DEBUG
- cerr << __FILE__ << ": host = " << host
- << " | port = " << port << endl;
+ cerr << __FILE__ << ": host = " << _host
+ << " | port = " << _port << endl;
#endif // DEBUG
- // FIXME - deberia ir en run().
- socket->connect(host.c_str(), port);
+ socket->connect(_host.c_str(), _port);
+ host = socket->peerhost();
+ port = socket->peerport();
}
/// \todo debría dar una excepción (?)
void Transmitter::real_run(void) {
#ifdef DEBUG
- // FIXME - debería tirar una excepción?
- if (!socket->is_open()) {
- cerr << "No se pudo conectar a " << socket->peerhost() <<
- ":" << socket->peerport() << "." << endl;
- } else {
- cerr << "Conectado a " << socket->peerhost() <<
- ":" << socket->peerport() << "." << endl;
+ cerr << __FILE__ << ": real_run()." << endl;
+#endif // DEBUG
+ // No hace nada, porque solo actua cuando se manda algo con send().
+ while (!stop) {
+ Glib::usleep(1000);
}
+}
+
+void Transmitter::send(const string& data) {
+#ifdef DEBUG
+ cerr << __FILE__ << ": send(data = " << data << ")." << endl;
#endif // DEBUG
+ socket << data << flush;
}
} // namespace Server
# Ubicación de archivos .a
LIB_FILES=../src
+MODEL_DIR=../../Model
# Opciones para el compilador.
-CXXFLAGS=-ansi -pedantic -Wall -I$(INCLUDE_DIR) \
- `pkg-config --cflags glibmm-2.0 gthread-2.0`
+CXXFLAGS=-ansi -pedantic -Wall -I$(INCLUDE_DIR) -I$(MODEL_DIR)/include \
+ `pkg-config --cflags glibmm-2.0 gthread-2.0` `xml2-config --cflags`
CXXFLAGS+=-g -DDEBUG
#CXXFLAGS+=-g
#CXXFLAGS+=-O2
-LDFLAGS=-lsocket++ `pkg-config --libs glibmm-2.0 gthread-2.0` #-L$(LIB_FILES)
+LDFLAGS=-lsocket++ `pkg-config --libs glibmm-2.0 gthread-2.0` \
+ `xml2-config --libs` #-L$(LIB_FILES)
TARGETS=server_test client_test
cd $(LIB_FILES) && $(MAKE)
# Tests
-server_test: $(LIB_FILES)/server.a server_test.o
+server_test: $(LIB_FILES)/server.a $(MODEL_DIR)/src/model.a server_test.o
# Tests
client_test: $(LIB_FILES)/server.a client_test.o