From: Leandro Lucarella Date: Thu, 20 Nov 2003 07:24:09 +0000 (+0000) Subject: - Se corrige el bug que hacia que no se deje de transmitir con el comando X-Git-Tag: svn_import~227 X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/commitdiff_plain/e46a2c7e43af9156a434d9cf41c2beb5b25b36d1?ds=sidebyside - Se corrige el bug que hacia que no se deje de transmitir con el comando /transmission/stop/. - Aparentemente tambien se arregla el bug de desconexion del cliente (pero no estoy seguro, despues de cambiar varias cosas creo que al final quedo como al principio). --- diff --git a/Server/include/plaqui/server/plant.h b/Server/include/plaqui/server/plant.h index 78dea2f..31aea96 100644 --- a/Server/include/plaqui/server/plant.h +++ b/Server/include/plaqui/server/plant.h @@ -112,7 +112,7 @@ namespace Server { * * \param transmission Transmisión a eliminar. */ - bool on_transmission_finished(Transmitter* transmission); + void on_transmission_finished(Transmitter* transmission); /** * Abre (o cierra) un elemento de la planta. diff --git a/Server/include/plaqui/server/transmitter.h b/Server/include/plaqui/server/transmitter.h index 3e99f41..acf38e8 100644 --- a/Server/include/plaqui/server/transmitter.h +++ b/Server/include/plaqui/server/transmitter.h @@ -29,7 +29,6 @@ #define PLAQUI_TRANSMITTER_H #include "plaqui/server/connection.h" -//#include "plaqui/server/plant.h" #include namespace PlaQui { diff --git a/Server/src/plant.cpp b/Server/src/plant.cpp index ce9f737..b020e21 100644 --- a/Server/src/plant.cpp +++ b/Server/src/plant.cpp @@ -27,7 +27,7 @@ #include "plaqui/server/plant.h" #include -#include +#include #include #ifdef DEBUG # include @@ -79,11 +79,12 @@ void Plant::real_run(void) { while (!stop) { simulator_mutex.lock(); simulator.simulate(); + string plantstatus = simulator.get_state_as_xml(); simulator_mutex.unlock(); transmissions_mutex.lock(); for (TransmitterList::iterator i = transmissions.begin(); i != transmissions.end(); i++) { - (*i)->send(simulator.get_state_as_xml()); + (*i)->send(plantstatus); } transmissions_mutex.unlock(); Glib::usleep(1000000); @@ -129,6 +130,9 @@ bool Plant::transmission_start(string& host, Connection::Port& port) { // return false; } transmissions.push_back(trans); + trans->signal_finished().connect(SigC::bind( + SigC::slot_class(*this, &Plant::on_transmission_finished), + trans)); trans->run(); host = trans->get_host(); port = trans->get_port(); @@ -138,9 +142,9 @@ bool Plant::transmission_start(string& host, Connection::Port& port) { bool Plant::transmission_stop(const string& host, const Connection::Port& port) { #ifdef DEBUG - cerr << __FILE__ << "(" << __LINE__ << ")" - << ": transmission_stop(host = " << host << - ", port = " << port << ")." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": transmission_stop(host = " << host << + ", port = " << port << ")." << endl; #endif // DEBUG Glib::Mutex::Lock lock(transmissions_mutex); for (TransmitterList::iterator i = transmissions.begin(); @@ -153,7 +157,7 @@ bool Plant::transmission_stop(const string& host, return false; // No la encontró. } -bool Plant::on_transmission_finished(Transmitter* transmission) { +void Plant::on_transmission_finished(Transmitter* transmission) { #ifdef DEBUG cerr << __FILE__ << "(" << __LINE__ << ")" << ": on_transmission_finished(transmission = " diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index c134b83..d9d5048 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -61,6 +61,7 @@ void Runnable::static_run(Runnable* runner) { #endif // DEBUG runner->real_run(); runner->finished(); + //runner->thread->join(); delete runner; } @@ -75,7 +76,7 @@ void Runnable::run(bool detach) { // finalizar, pasandole el puntero al objeto. thread = Glib::Thread::create( SigC::bind(SigC::slot(&Runnable::static_run), this), - true); + true);//false); // Si no corremos la tarea normalmente. } else { real_run(); diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index b59992e..6ab9260 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -78,8 +78,9 @@ void Transmitter::real_run(void) { void Transmitter::send(const string& data) { #ifdef DEBUG - cerr << __FILE__ << "(" << __LINE__ << ")" - << ": send(data = " << data << ")." << endl; + cerr << __FILE__ << "(" << __LINE__ << ")" + << ": send()." << endl; +// << ": send(data = " << data << ")." << endl; #endif // DEBUG if (stop) { return; diff --git a/Server/tests/server_test.cpp b/Server/tests/server_test.cpp index 25d01a6..1f505ee 100644 --- a/Server/tests/server_test.cpp +++ b/Server/tests/server_test.cpp @@ -29,12 +29,15 @@ #include "plaqui/server/server.h" #include "plaqui/server/string.h" #include +#include #include #include using namespace std; using namespace PlaQui::Server; +Server* server = NULL; + void on_error(const Runnable::Error& code, const string& desc) { cerr << "--------------------------------------------------------" << endl; cerr << "Error en el servidor:" << endl; @@ -43,6 +46,11 @@ void on_error(const Runnable::Error& code, const string& desc) { cerr << "--------------------------------------------------------" << endl; } +void on_finished(void) { + cerr << "Murió el servidor!" << endl; + server = NULL; +} + int main(int argc, char* argv[]) { // Termina con mas informacion si hay una excepcion no manejada. @@ -68,7 +76,6 @@ int main(int argc, char* argv[]) { // Inicializa threads. Glib::thread_init(); - Server* server = NULL; try { // Crea el server (empieza a escuchar). server = new Server(filename, port); @@ -108,8 +115,13 @@ int main(int argc, char* argv[]) { // Corre el server. server->run(false); + // Espera a que el server se muera. + while (server) { + Glib::usleep(1000000); + } + // Como no detachee el server, lo tengo que eliminar a mano. - delete server; + //delete server; return 0; }