1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
7 // PlaQui is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2 of the License, or (at your option) any later
12 // PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 // You should have received a copy of the GNU General Public License along
18 // with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 //----------------------------------------------------------------------------
21 // Creado: Sat Oct 18 18:18:36 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #ifndef PLAQUI_SERVER_H
29 #define PLAQUI_SERVER_H
31 #include "plaqui/server/tcpserver.h"
32 #include "plaqui/server/controlserver.h"
33 #include "plaqui/server/transmitter.h"
34 #include "plaqui/server/plant.h"
35 #include "plaqui/server/command.h"
36 #include <socket++/sockinet.h>
45 * Servidor de plantas químicas.
46 * Maneja múltiples conexiones, de control o de transmisión.
48 class Server: public TCPServer {
50 /////////////////////////////////////////////////////////////////////
55 /// Lista de plantas químicas.
56 typedef std::map<std::string, Plant*> PlantList;
58 /////////////////////////////////////////////////////////////////////
63 // Plantas disponibles en el servidor.
66 /// Mutex para las plantas.
67 Glib::Mutex plants_mutex;
69 /////////////////////////////////////////////////////////////////////
75 * Obtiene una nueva \ref Connection "conexión".
77 * \param sd Descriptor del socket de la nueva conexión.
79 * \return Nueva conexión.
81 virtual Connection* new_connection(const sockbuf::sockdesc& sd);
84 * Maneja el comando server/status.
86 HTTPResponse* cmd_server_status(void) const;
89 * Maneja el comando connection/list.
91 HTTPResponse* cmd_connection_list(void);
94 * Maneja el comando connection/stop.
96 HTTPResponse* cmd_connection_stop(const Command& command);
99 * Maneja el comando transmission/list.
101 HTTPResponse* cmd_transmission_list(void);
104 * Maneja el comando transmission/start.
106 HTTPResponse* cmd_transmission_start(const Command& command);
109 * Maneja el comando transmission/stop.
111 HTTPResponse* cmd_transmission_stop(const Command& command);
114 * Maneja el comando plant/list.
116 HTTPResponse* cmd_plant_list(void);
119 * Maneja el comando plant/get.
121 HTTPResponse* cmd_plant_get(const Command& command);
124 * Maneja el comando plant/set.
126 HTTPResponse* cmd_plant_set(const Command& command);
129 * Maneja el comando plant/set_frequency.
131 HTTPResponse* cmd_plant_set_frequency(const Command& command);
134 * Maneja el comando plant/start.
136 HTTPResponse* cmd_plant_start(const Command& command);
139 * Maneja el comando plant/stop.
141 HTTPResponse* cmd_plant_stop(const Command& command);
144 * Maneja el comando plant/remove.
146 HTTPResponse* cmd_plant_remove(const Command& command);
153 virtual ~Server(void);
158 * \param plant_filename Nombre del archivo con la planta a cargar.
159 * \param port Puerto en el cual escuchar.
161 Server(const std::string& plant_filename,
162 const Connection::Port& port = 7522) throw(sockerr);
165 * Maneja los comandos recibidos por las conexiones.
167 void on_control_command_received(const Command& command,
168 ControlServer* controlserver);
171 * Se encarga de borrar una planta de la lista cuando finaliza.
173 * \param plant Nombre de la planta a elminar.
175 void on_plant_finished(const char* plant);
183 #endif // PLAQUI_SERVER_H