]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/server.cpp
Se arregla el bug que hacia que el cliente levante mal archivos XML grandes.
[z.facultad/75.42/plaqui.git] / Server / src / server.cpp
index 5e7197acd3adcae385a75e83735332b97f2d2d00..692db97a0228d378b6e8271b558dde909be82a81 100644 (file)
@@ -64,19 +64,25 @@ Server::~Server(void) {
        }
 }
 
        }
 }
 
-Server::Server(const string& plant_filename, const Connection::Port& port)
+Server::Server(const Connection::Port& port)
                throw(sockerr): TCPServer(port) {
 #ifdef DEBUG
        cerr << __FILE__ << "(" << __LINE__ << ")"
                <<  ": port = " << port << endl;
 #endif // DEBUG
                throw(sockerr): TCPServer(port) {
 #ifdef DEBUG
        cerr << __FILE__ << "(" << __LINE__ << ")"
                <<  ": port = " << port << endl;
 #endif // DEBUG
-       // FIXME - hacer que se puedan cargar mas plantas bien.
+}
+
+bool Server::add_plant(const string& name, const string& filename) {
        Glib::Mutex::Lock lock(plants_mutex);
        Glib::Mutex::Lock lock(plants_mutex);
-       plants["default"] = new Plant(plant_filename);
-       plants["default"]->signal_finished().connect(SigC::bind(
-                       SigC::slot_class(*this, &Server::on_plant_finished),
-                       "default"));
-       plants["default"]->run();
+       if (plants.find(name) == plants.end()) { // No existe
+               plants[name] = new Plant(filename);
+               plants[name]->signal_finished().connect(SigC::bind(
+                               SigC::slot_class(*this, &Server::on_plant_finished),
+                               name.c_str()));
+               plants[name]->run();
+               return true;
+       }
+       return false;
 }
 
 Connection* Server::new_connection(const sockbuf::sockdesc& sd) {
 }
 
 Connection* Server::new_connection(const sockbuf::sockdesc& sd) {
@@ -86,11 +92,9 @@ Connection* Server::new_connection(const sockbuf::sockdesc& sd) {
                << endl;
 #endif // DEBUG
        ControlServer* connection = new ControlServer(sd);
                << endl;
 #endif // DEBUG
        ControlServer* connection = new ControlServer(sd);
-       // TODO verificar si el new se hace bien? no creo.
        connection->signal_command_received().connect(SigC::bind(
                        SigC::slot_class(*this, &Server::on_control_command_received),
                        connection));
        connection->signal_command_received().connect(SigC::bind(
                        SigC::slot_class(*this, &Server::on_control_command_received),
                        connection));
-       // TODO: 
        return connection;
 }
 
        return connection;
 }
 
@@ -103,7 +107,6 @@ void Server::on_plant_finished(const char* plant) {
        plants.erase(plant);
 }
 
        plants.erase(plant);
 }
 
-/// \todo Terminar de implementar.
 void Server::on_control_command_received(const Command& command,
                ControlServer* controlserver) {
 #ifdef DEBUG
 void Server::on_control_command_received(const Command& command,
                ControlServer* controlserver) {
 #ifdef DEBUG
@@ -121,7 +124,8 @@ void Server::on_control_command_received(const Command& command,
                        response = new Response(Response::OK,
                                        "El server se cerrará en instantes");
                        // XXX - Sin mandar la respuesta enseguida podría ser que el server
                        response = new Response(Response::OK,
                                        "El server se cerrará en instantes");
                        // XXX - Sin mandar la respuesta enseguida podría ser que el server
-                       // cierre la conexión antes de mandar la respuesta.
+                       // cierre la conexión antes de mandar la respuesta. En las pruebas
+                       // esto nunca pasó.
                        //response->headers["Content-Type"] = "text/xml; charset=iso-8859-1";
                        //controlserver->send(*response);
                        //delete response;
                        //response->headers["Content-Type"] = "text/xml; charset=iso-8859-1";
                        //controlserver->send(*response);
                        //delete response;
@@ -178,19 +182,11 @@ void Server::on_control_command_received(const Command& command,
                response = new Response(Response::INVALID_TARGET, command.get_target()
                                + " es un destino inválido");
        }
                response = new Response(Response::INVALID_TARGET, command.get_target()
                                + " es un destino inválido");
        }
-       // FIXME
-       //response->headers["Connection"] = "close";
        controlserver->send(*response);
        delete response;
        controlserver->send(*response);
        delete response;
-       // FIXME con timeout no debería ser necesario. Verificar cabecera Connection
-       // para saber si hay que finish()earlo o no.
-       //if (stop_controlserver) {
-       //      controlserver->finish();
-       //}
 }
 
 Response* Server::cmd_server_info(void) const {
 }
 
 Response* Server::cmd_server_info(void) const {
-       // FIXME
        stringstream xml;
        xml << "<serverstatus>" << endl;
        xml << "\t<version>" VERSION "</version>" << endl;
        stringstream xml;
        xml << "<serverstatus>" << endl;
        xml << "\t<version>" VERSION "</version>" << endl;
@@ -204,7 +200,7 @@ Response* Server::cmd_server_info(void) const {
 }
 
 Response* Server::cmd_connection_list(void) {
 }
 
 Response* Server::cmd_connection_list(void) {
-       // FIXME
+       // TODO implementar con lista genérica.
        TCPServer::ConnectionInfoList cil = get_connected();
        stringstream xml;
        xml << "<list type=\"connection\">" << endl;
        TCPServer::ConnectionInfoList cil = get_connected();
        stringstream xml;
        xml << "<list type=\"connection\">" << endl;
@@ -235,10 +231,10 @@ Response* Server::cmd_connection_stop(const Command& command) {
 }
 
 Response* Server::cmd_transmission_list(void) {
 }
 
 Response* Server::cmd_transmission_list(void) {
-       // FIXME
+       // TODO implementar con lista genérica.
        stringstream xml;
        xml << "<list type=\"transmission\">" << endl;
        stringstream xml;
        xml << "<list type=\"transmission\">" << endl;
-/*TODO plants_mutex.lock();
+/*FIXME        plants_mutex.lock();
        for (PlantList::const_iterator i = plants.begin();
                        i != plants.end(); i++) {
                trans
        for (PlantList::const_iterator i = plants.begin();
                        i != plants.end(); i++) {
                trans
@@ -331,7 +327,6 @@ Response* Server::cmd_plant_get(const Command& command) {
                return new Response(Response::PLANT_NOT_FOUND,
                                string("No existe la planta '") + plant + "'");
        }
                return new Response(Response::PLANT_NOT_FOUND,
                                string("No existe la planta '") + plant + "'");
        }
-       // TODO try/catch?
        string xml = plants[plant]->get_xml();
        if (xml.length()) {
                return new Response(xml);
        string xml = plants[plant]->get_xml();
        if (xml.length()) {
                return new Response(xml);
@@ -391,7 +386,7 @@ Response* Server::cmd_plant_set_frequency(const Command& command) {
        }
        unsigned hz;
        to(command.get_args()[1], hz);
        }
        unsigned hz;
        to(command.get_args()[1], hz);
-       /* TODO poner cantidad real que tomó: hz = */plants[name]->set_frequency(hz);
+       plants[name]->set_frequency(hz);
        String shz;
        shz.from(hz);
        return new Response(Response::OK,
        String shz;
        shz.from(hz);
        return new Response(Response::OK,