X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/f27c218d18ebf7198e07249aca1eed625da914fd..a359eb714e150b2b59856d0056b9880aaaedd128:/Server/src/server.cpp?ds=inline diff --git a/Server/src/server.cpp b/Server/src/server.cpp index 73963ba..8704d69 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -46,25 +46,27 @@ Server::~Server(void) { #ifdef DEBUG cerr << __FILE__ << ": destructor." << endl; #endif // DEBUG + // Termino plantas. + Glib::Mutex::Lock lock(plants_mutex); + for (PlantList::iterator i = plants.end(); i != plants.end(); i++) { + i->second->finish(true); + } } -Server::Server(int port): - TCPServer(port) { +Server::Server(int port): TCPServer(port) { #ifdef DEBUG cerr << __FILE__ << ": port = " << port << endl; #endif // DEBUG + // FIXME + Glib::Mutex::Lock lock(plants_mutex); + plants["prueba"] = new Plant("prueba.xml"); + plants["prueba"]->signal_finished().connect( + SigC::bind( + SigC::slot_class(*this, &Server::on_plant_finished), + "prueba")); + plants["prueba"]->run(); } -/// \todo Implementar. -bool Server::start_transmission(string host, int port) { -#ifdef DEBUG - cerr << __FILE__ << ": start_transmission(host = " << host - << " | port = " << port << ")" << endl; -#endif // DEBUG - // TODO - return false; -} - Connection* Server::new_connection( const sockbuf::sockdesc& sd) { #ifdef DEBUG @@ -81,35 +83,97 @@ Connection* Server::new_connection( return connection; } -/// \todo Implementar. -bool Server::stop_transmission(string host, int port) { +void Server::on_plant_updated(const Plant* plant) { +#ifdef DEBUG + cerr << __FILE__ << ": on_plant_updated(plant = " << plant << ")." << endl; +#endif // DEBUG +} + +void Server::on_plant_finished(const char* plant) { #ifdef DEBUG - cerr << __FILE__ << ": stop_transmission(host = " << host - << " | port = " << port << ")" << endl; + cerr << __FILE__ << ": on_plant_finished(plant_name = " << plant << endl; #endif // DEBUG - // TODO - return false; + Glib::Mutex::Lock lock(plants_mutex); + plants.erase(plant); } -/// \todo Implementar. +/// \todo Terminar de implementar. void Server::on_control_command_received(const Command& command, - ControlServer* server) { + ControlServer* controlserver) { #ifdef DEBUG cerr << __FILE__ << ": on_control_command_received(target = " << command.get_target() << ", command = " << command.get_command() << ", args = [" << String::join(command.get_args(), ", ") << "])" << endl; #endif // DEBUG - // TODO, seguir aca! + HTTPResponse* response; + //bool stop_controlserver = false; + if (command.get_target() == "server") { + if (command.get_command() == "status") { + response = cmd_server_status(); + } else if (command.get_command() == "stop") { + finish(); + response = new HTTPResponse(HTTPMessage::OK, + "El server se apagará en instantes..."); + } else { + response = new HTTPResponse(HTTPMessage::NOT_FOUND, + "Invalid command for 'server' taget!"); + } + } else if (command.get_target() == "connection") { + if (command.get_command() == "list") { + response = cmd_connection_list(); + } else if (command.get_command() == "stop") { + response = cmd_connection_stop(command); + } else { + response = new HTTPResponse(HTTPMessage::NOT_FOUND, + "Invalid command for 'connection' taget!"); + } + } else if (command.get_target() == "transmission") { + if (command.get_command() == "list") { + response = cmd_transmission_list(); + } else if (command.get_command() == "start") { + response = cmd_transmission_start(command); + } else if (command.get_command() == "stop") { + response = cmd_transmission_stop(command); + } else { + response = new HTTPResponse(HTTPMessage::NOT_FOUND, + "Invalid command for 'transmission' taget!"); + } + } else if (command.get_target() == "plant") { + if (command.get_command() == "list") { + response = cmd_plant_list(); + } else if (command.get_command() == "stop") { + response = cmd_plant_stop(command); + } else { + response = new HTTPResponse(HTTPMessage::NOT_FOUND, + "Invalid command for 'plant' taget!"); + } + } else { + response = new HTTPResponse(HTTPMessage::NOT_FOUND, "Invalid taget!"); + } + // FIXME + response->headers["Content-Type"] = "text/html; charset=iso-8859-1"; + //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(); + //} +} + +HTTPResponse* Server::cmd_server_status(void) const { + // FIXME stringstream response_xml; response_xml << "" << endl; response_xml << " " << endl; - response_xml << " PlaQui v0.4" << endl; + response_xml << " PlaQui v0.8" << endl; response_xml << " " << endl; response_xml << " " << endl; response_xml << "

PlaQui

" << endl; - response_xml << "

versión 0.4

" << endl; - response_xml << "

Comando

" << endl; + response_xml << "

versión 0.8

" << endl; +/* response_xml << "

Comando

" << endl; response_xml << " " << endl; + response_xml << " " << endl;*/ response_xml << "

Desarrollado por

" << endl; response_xml << "