X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/f27c218d18ebf7198e07249aca1eed625da914fd..dd5a5045d5549015b6500726098cb43d1e1c614c:/Server/src/server.cpp diff --git a/Server/src/server.cpp b/Server/src/server.cpp index 73963ba..837295f 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -46,25 +46,28 @@ 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): +Server::Server(const string& plant_filename, const Connection::Port& port): TCPServer(port) { #ifdef DEBUG cerr << __FILE__ << ": port = " << port << endl; #endif // DEBUG + // FIXME + 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(); } -/// \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 +84,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 << "