]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/plant.cpp
Se ponen mas simples algunos SigC::bind() :)
[z.facultad/75.42/plaqui.git] / Server / src / plant.cpp
index ce9f737d19822eba5ba4dac9d74875f36a9c8a64..5704a88ddb16fefb9db741fdd6b3c6a9a201779c 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "plaqui/server/plant.h"
 #include <glibmm/timer.h>
 
 #include "plaqui/server/plant.h"
 #include <glibmm/timer.h>
-#include <sigc++/slot.h>
+#include <sigc++/class_slot.h>
 #include <fstream>
 #ifdef DEBUG
 #      include <iostream>
 #include <fstream>
 #ifdef DEBUG
 #      include <iostream>
@@ -44,11 +44,20 @@ Plant::~Plant(void) {
        cerr << __FILE__ << "(" << __LINE__ << ")"
                << ": destructor." << endl;
 #endif // DEBUG
        cerr << __FILE__ << "(" << __LINE__ << ")"
                << ": destructor." << endl;
 #endif // DEBUG
-       // Termino transmisiones.
-       Glib::Mutex::Lock lock(transmissions_mutex);
-       for (TransmitterList::iterator trans = transmissions.end();
+       // Mando a terminar todas las transmisiones.
+       transmissions_mutex.lock();
+       for (TransmitterList::iterator trans = transmissions.begin();
                        trans != transmissions.end(); trans++) {
                        trans != transmissions.end(); trans++) {
-               (*trans)->finish(true);
+               (*trans)->finish();
+       }
+       TransmitterList::size_type count = transmissions.size();
+       transmissions_mutex.unlock();
+       // Espero que terminen realmente.
+       while (count) {
+               Glib::usleep(10000); // 10 milisegundos
+               transmissions_mutex.lock();
+               count = transmissions.size();
+               transmissions_mutex.unlock();
        }
 }
 
        }
 }
 
@@ -71,22 +80,23 @@ Plant::Plant(const string& filename): simulator(filename), filename(filename) {
 */     
 }
 
 */     
 }
 
-void Plant::real_run(void) {
+void Plant::real_run(void) throw() {
 #ifdef DEBUG
        cerr << __FILE__ << "(" << __LINE__ << ")"
                << ": real_run." << endl;
 #endif // DEBUG
 #ifdef DEBUG
        cerr << __FILE__ << "(" << __LINE__ << ")"
                << ": real_run." << endl;
 #endif // DEBUG
-       while (!stop) {
+       while (!stop()) {
                simulator_mutex.lock();
                simulator.simulate();
                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++) {
                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();
                }
                transmissions_mutex.unlock();
-               Glib::usleep(1000000);
+               Glib::usleep(100000);
        }
 }
 
        }
 }
 
@@ -129,6 +139,9 @@ bool Plant::transmission_start(string& host, Connection::Port& port) {
 //             return false;
        }
        transmissions.push_back(trans);
 //             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();
        trans->run();
        host = trans->get_host();
        port = trans->get_port();
@@ -138,9 +151,9 @@ bool Plant::transmission_start(string& host, Connection::Port& port) {
 bool Plant::transmission_stop(const string& host,
                const Connection::Port& port) {
 #ifdef DEBUG
 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();
 #endif // DEBUG
        Glib::Mutex::Lock lock(transmissions_mutex);
        for (TransmitterList::iterator i = transmissions.begin();
@@ -153,7 +166,7 @@ bool Plant::transmission_stop(const string& host,
        return false; // No la encontró.
 }
 
        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 = "
 #ifdef DEBUG
        cerr << __FILE__ << "(" << __LINE__ << ")"
                <<  ": on_transmission_finished(transmission = "