/transmission/stop/.
- Aparentemente tambien se arregla el bug de desconexion del cliente (pero no
estoy seguro, despues de cambiar varias cosas creo que al final quedo como al
principio).
*
* \param transmission Transmisión a eliminar.
*/
*
* \param transmission Transmisión a eliminar.
*/
- bool on_transmission_finished(Transmitter* transmission);
+ void on_transmission_finished(Transmitter* transmission);
/**
* Abre (o cierra) un elemento de la planta.
/**
* Abre (o cierra) un elemento de la planta.
#define PLAQUI_TRANSMITTER_H
#include "plaqui/server/connection.h"
#define PLAQUI_TRANSMITTER_H
#include "plaqui/server/connection.h"
-//#include "plaqui/server/plant.h"
#include <string>
namespace PlaQui {
#include <string>
namespace PlaQui {
#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>
while (!stop) {
simulator_mutex.lock();
simulator.simulate();
while (!stop) {
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();
Glib::usleep(1000000);
}
transmissions_mutex.unlock();
Glib::usleep(1000000);
// return false;
}
transmissions.push_back(trans);
// return false;
}
transmissions.push_back(trans);
+ trans->signal_finished().connect(SigC::bind<Transmitter*>(
+ 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();
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();
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 = "
#endif // DEBUG
runner->real_run();
runner->finished();
#endif // DEBUG
runner->real_run();
runner->finished();
+ //runner->thread->join();
// finalizar, pasandole el puntero al objeto.
thread = Glib::Thread::create(
SigC::bind<Runnable*>(SigC::slot(&Runnable::static_run), this),
// finalizar, pasandole el puntero al objeto.
thread = Glib::Thread::create(
SigC::bind<Runnable*>(SigC::slot(&Runnable::static_run), this),
// Si no corremos la tarea normalmente.
} else {
real_run();
// Si no corremos la tarea normalmente.
} else {
real_run();
void Transmitter::send(const string& data) {
#ifdef DEBUG
void Transmitter::send(const string& data) {
#ifdef DEBUG
- cerr << __FILE__ << "(" << __LINE__ << ")"
- << ": send(data = " << data << ")." << endl;
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": send()." << endl;
+// << ": send(data = " << data << ")." << endl;
#endif // DEBUG
if (stop) {
return;
#endif // DEBUG
if (stop) {
return;
#include "plaqui/server/server.h"
#include "plaqui/server/string.h"
#include <socket++/sockinet.h>
#include "plaqui/server/server.h"
#include "plaqui/server/string.h"
#include <socket++/sockinet.h>
+#include <glibmm/timer.h>
#include <iostream>
#include <exception>
using namespace std;
using namespace PlaQui::Server;
#include <iostream>
#include <exception>
using namespace std;
using namespace PlaQui::Server;
+Server* server = NULL;
+
void on_error(const Runnable::Error& code, const string& desc) {
cerr << "--------------------------------------------------------" << endl;
cerr << "Error en el servidor:" << endl;
void on_error(const Runnable::Error& code, const string& desc) {
cerr << "--------------------------------------------------------" << endl;
cerr << "Error en el servidor:" << endl;
cerr << "--------------------------------------------------------" << endl;
}
cerr << "--------------------------------------------------------" << endl;
}
+void on_finished(void) {
+ cerr << "Murió el servidor!" << endl;
+ server = NULL;
+}
+
int main(int argc, char* argv[]) {
// Termina con mas informacion si hay una excepcion no manejada.
int main(int argc, char* argv[]) {
// Termina con mas informacion si hay una excepcion no manejada.
// Inicializa threads.
Glib::thread_init();
// Inicializa threads.
Glib::thread_init();
try {
// Crea el server (empieza a escuchar).
server = new Server(filename, port);
try {
// Crea el server (empieza a escuchar).
server = new Server(filename, port);
// Corre el server.
server->run(false);
// Corre el server.
server->run(false);
+ // Espera a que el server se muera.
+ while (server) {
+ Glib::usleep(1000000);
+ }
+
// Como no detachee el server, lo tengo que eliminar a mano.
// Como no detachee el server, lo tengo que eliminar a mano.