X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/ffc9f02ea0544d4b1aa86e29afe12a2b4bace953..ce820fc7d9a8552468fe0e60f83d08c890270d38:/Server/src/server.cpp?ds=sidebyside diff --git a/Server/src/server.cpp b/Server/src/server.cpp index ca1f763..692db97 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -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 - // 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); - 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) { @@ -86,11 +92,9 @@ Connection* Server::new_connection(const sockbuf::sockdesc& 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)); - // TODO: return connection; } @@ -103,7 +107,6 @@ void Server::on_plant_finished(const char* plant) { plants.erase(plant); } -/// \todo Terminar de implementar. void Server::on_control_command_received(const Command& command, ControlServer* controlserver) { #ifdef DEBUG @@ -114,7 +117,6 @@ void Server::on_control_command_received(const Command& command, << endl; #endif // DEBUG Response* response; - //bool stop_controlserver = false; if (command.get_target() == "server") { if (command.get_command() == "info") { response = cmd_server_info(); @@ -122,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 - // 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; @@ -179,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"); } - // FIXME - //response->headers["Connection"] = "close"; 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 { - // FIXME stringstream xml; xml << "" << endl; xml << "\t" VERSION "" << endl; @@ -205,7 +200,7 @@ Response* Server::cmd_server_info(void) const { } Response* Server::cmd_connection_list(void) { - // FIXME + // TODO implementar con lista genérica. TCPServer::ConnectionInfoList cil = get_connected(); stringstream xml; xml << "" << endl; @@ -236,10 +231,10 @@ Response* Server::cmd_connection_stop(const Command& command) { } Response* Server::cmd_transmission_list(void) { - // FIXME + // TODO implementar con lista genérica. stringstream xml; xml << "" << endl; -/*TODO plants_mutex.lock(); +/*FIXME plants_mutex.lock(); for (PlantList::const_iterator i = plants.begin(); i != plants.end(); i++) { trans @@ -332,7 +327,6 @@ Response* Server::cmd_plant_get(const Command& command) { 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); @@ -392,7 +386,7 @@ Response* Server::cmd_plant_set_frequency(const Command& command) { } 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,