X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/a9cb053146d2f1dc73e536ed87597f458deebea3..ab9300aaf1217f0c3b45dd5f1f1fdc1c5e5bd1be:/Server/src/runnable.cpp?ds=sidebyside diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index d962980..7fd4105 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -25,21 +25,39 @@ // $Id$ // -#include "runnable.h" +#include "plaqui/server/runnable.h" #include #include #ifdef DEBUG # include #endif // DEBUG -using namespace Plaqui; +PlaQui::Server::Runnable::~Runnable(void) { +#ifdef DEBUG + std::cerr << __FILE__ << ": destructor(this = " << this << ")" + << std::endl; +#endif // DEBUG +} + +PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) { +#ifdef DEBUG + std::cerr << __FILE__ << ": constructor." << std::endl; +#endif // DEBUG +} -Runnable::Runnable(void): thread(0) { +void PlaQui::Server::Runnable::static_run(Runnable* runner) { +#ifdef DEBUG + std::cerr << __FILE__ << ": static_run(runner = " << runner << ")" + << std::endl; +#endif // DEBUG + runner->real_run(); + runner->signal_finished().emit(); + delete runner; } -void Runnable::run(bool detach) { +void PlaQui::Server::Runnable::run(bool detach) { #ifdef DEBUG - std::cerr << __FILE__ << ": detach = " << detach << std::endl; + std::cerr << __FILE__ << ": run(detach = " << detach << ")" << std::endl; #endif // DEBUG // Si vamos a correr la tarea en un thread. if (detach) { @@ -47,9 +65,11 @@ void Runnable::run(bool detach) { if (!Glib::thread_supported()) { Glib::thread_init(); } - // Corremos el thread. + // Corremos el thread en una funcion estática para poder destruirlo al + // finalizar, pasandole el puntero al objeto. thread = Glib::Thread::create( - SigC::slot_class(*this, &Runnable::real_run), true); + SigC::bind(SigC::slot(&Runnable::static_run), this), + true); // Si no corremos la tarea normalmente. } else { real_run(); @@ -57,3 +77,19 @@ void Runnable::run(bool detach) { } +void PlaQui::Server::Runnable::finish(bool attach) { +#ifdef DEBUG + std::cerr << __FILE__ << ": finish(attach = " << attach << ")" << std::endl; +#endif // DEBUG + // TODO - necesita un mutex? + stop = true; + if (attach) { + thread->join(); + } +} + +PlaQui::Server::Runnable::SignalFinished& +PlaQui::Server::Runnable::signal_finished(void) { + return finished; +} +