# include <iostream>
#endif // DEBUG
-using namespace Plaqui;
+PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) {
+}
-Runnable::Runnable(void): thread(0) {
+void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) {
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": 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;
#endif // DEBUG
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<Runnable*>(
+ SigC::slot(&PlaQui::Server::Runnable::static_run),
+ this),
+ true);
// Si no corremos la tarea normalmente.
} else {
real_run();
}
+void PlaQui::Server::Runnable::finish(bool attach) {
+#ifdef DEBUG
+ std::cerr << __FILE__ << ": 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;
+}
+