X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/a0481d50f6da9cac5efd3502c3657b3fc461ec0d..dd5a5045d5549015b6500726098cb43d1e1c614c:/Server/src/server.cpp?ds=inline diff --git a/Server/src/server.cpp b/Server/src/server.cpp index d4dd52a..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,17 +84,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 +130,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 +169,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 << "