]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/plant.cpp
Capturo las seniales ANSI C SIGINT, SIGTERM y SIGQUIT para que el server salga
[z.facultad/75.42/plaqui.git] / Server / src / plant.cpp
index b020e2109e9882c4389bbe4405967c377825cb57..5704a88ddb16fefb9db741fdd6b3c6a9a201779c 100644 (file)
@@ -44,11 +44,20 @@ Plant::~Plant(void) {
        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)->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,12 +80,12 @@ 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
-       while (!stop) {
+       while (!stop()) {
                simulator_mutex.lock();
                simulator.simulate();
                string plantstatus = simulator.get_state_as_xml();
@@ -87,7 +96,7 @@ void Plant::real_run(void) {
                        (*i)->send(plantstatus);
                }
                transmissions_mutex.unlock();
-               Glib::usleep(1000000);
+               Glib::usleep(100000);
        }
 }
 
@@ -130,7 +139,7 @@ bool Plant::transmission_start(string& host, Connection::Port& port) {
 //             return false;
        }
        transmissions.push_back(trans);
-       trans->signal_finished().connect(SigC::bind<Transmitter*>(
+       trans->signal_finished().connect(SigC::bind(
                                SigC::slot_class(*this, &Plant::on_transmission_finished),
                                trans));
        trans->run();