X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/802f79cdb0d688127b8a639cd3173d801a1466cd..989d0da7e93d155dde399bf3047ab6b4af550bb6:/Server/src/runnable.cpp diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index 66579ac..68296e4 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -26,40 +26,51 @@ // #include "plaqui/server/runnable.h" -#include +#include #include #ifdef DEBUG # include #endif // DEBUG -PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) { +using namespace std; + +namespace PlaQui { + +namespace Server { + +Runnable::~Runnable(void) { +#ifdef DEBUG + cerr << __FILE__ << ": destructor(this = " << this << ")" + << endl; +#endif // DEBUG } -void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) { +Runnable::Runnable(void): thread(0), stop(false) { #ifdef DEBUG - std::cerr << __FILE__ << ": runner = " << runner << std::endl; + cerr << __FILE__ << ": constructor." << endl; +#endif // DEBUG +} + +void Runnable::static_run(Runnable* runner) { +#ifdef DEBUG + cerr << __FILE__ << ": static_run(runner = " << runner << ")" + << endl; #endif // DEBUG runner->real_run(); - runner->signal_finished().emit(); + runner->finished(); delete runner; } -void PlaQui::Server::Runnable::run(bool detach) { +void Runnable::run(bool detach) { #ifdef DEBUG - std::cerr << __FILE__ << ": detach = " << detach << std::endl; + cerr << __FILE__ << ": run(detach = " << detach << ")" << endl; #endif // DEBUG // Si vamos a correr la tarea en un thread. if (detach) { - // Nos aseguramos de tener threads. - if (!Glib::thread_supported()) { - Glib::thread_init(); - } // Corremos el thread en una funcion estática para poder destruirlo al // finalizar, pasandole el puntero al objeto. thread = Glib::Thread::create( - SigC::bind( - SigC::slot(&PlaQui::Server::Runnable::static_run), - this), + SigC::bind(SigC::slot(&Runnable::static_run), this), true); // Si no corremos la tarea normalmente. } else { @@ -68,19 +79,21 @@ void PlaQui::Server::Runnable::run(bool detach) { } -void PlaQui::Server::Runnable::finish(bool attach) { +void Runnable::finish(bool attach) { #ifdef DEBUG - std::cerr << __FILE__ << ": attach = " << attach << std::endl; + cerr << __FILE__ << ": finish(attach = " << attach << ")" << endl; #endif // DEBUG - // TODO - necesita un mutex? stop = true; if (attach) { thread->join(); } } -PlaQui::Server::Runnable::SignalFinished& -PlaQui::Server::Runnable::signal_finished(void) { +Runnable::SignalFinished& Runnable::signal_finished(void) { return finished; } +} // namespace Server + +} // namespace PlaQui +