X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/a0481d50f6da9cac5efd3502c3657b3fc461ec0d..a359eb714e150b2b59856d0056b9880aaaedd128:/Server/src/server.cpp?ds=sidebyside diff --git a/Server/src/server.cpp b/Server/src/server.cpp index d4dd52a..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,17 +83,21 @@ 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__ << ": stop_transmission(host = " << host - << " | port = " << port << ")" << endl; + cerr << __FILE__ << ": on_plant_updated(plant = " << plant << ")." << endl; #endif // DEBUG - // TODO - return false; } -/// \todo Implementar. +void Server::on_plant_finished(const char* plant) { +#ifdef DEBUG + cerr << __FILE__ << ": on_plant_finished(plant_name = " << plant << endl; +#endif // DEBUG + Glib::Mutex::Lock lock(plants_mutex); + plants.erase(plant); +} + +/// \todo Terminar de implementar. void Server::on_control_command_received(const Command& command, ControlServer* controlserver) { #ifdef DEBUG @@ -123,11 +129,25 @@ void Server::on_control_command_received(const Command& command, "Invalid command for 'connection' taget!"); } } else if (command.get_target() == "transmission") { - response = new HTTPResponse(HTTPMessage::NOT_FOUND, - "Invalid command for 'transmission' taget!"); + 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") { - response = new HTTPResponse(HTTPMessage::NOT_FOUND, - "Invalid command for 'plant' taget!"); + 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!"); } @@ -148,11 +168,11 @@ HTTPResponse* Server::cmd_server_status(void) const { stringstream response_xml; response_xml << "" << endl; response_xml << " " << endl; - response_xml << " PlaQui v0.7" << endl; + response_xml << " PlaQui v0.8" << endl; response_xml << " " << endl; response_xml << " " << endl; response_xml << "

PlaQui

" << endl; - response_xml << "

versión 0.7

" << endl; + response_xml << "

versión 0.8

" << endl; /* response_xml << "

Comando

" << endl; response_xml << " " << endl; -*/ response_xml << "

Desarrollado por

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

Desarrollado por

" << endl; response_xml << "