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 "plaqui/server/response.h"
37 #include <socket++/sockinet.h>
46 * Servidor de plantas químicas.
47 * Maneja múltiples conexiones, de control o de transmisión.
49 class Server: public TCPServer {
51 /////////////////////////////////////////////////////////////////////
56 /// Lista de plantas químicas.
57 typedef std::map<std::string, Plant*> PlantList;
59 /////////////////////////////////////////////////////////////////////
64 // Plantas disponibles en el servidor.
67 /// Mutex para las plantas.
68 Glib::Mutex plants_mutex;
70 /////////////////////////////////////////////////////////////////////
76 * Obtiene una nueva \ref Connection "conexión".
78 * \param sd Descriptor del socket de la nueva conexión.
80 * \return Nueva conexión.
82 virtual Connection* new_connection(const sockbuf::sockdesc& sd);
85 * Maneja el comando server/info.
87 Response* cmd_server_info(void) const;
90 * Maneja el comando connection/list.
92 Response* cmd_connection_list(void);
95 * Maneja el comando connection/stop.
97 Response* cmd_connection_stop(const Command& command);
100 * Maneja el comando transmission/list.
102 Response* cmd_transmission_list(void);
105 * Maneja el comando transmission/start.
107 Response* cmd_transmission_start(const Command& command);
110 * Maneja el comando transmission/stop.
112 Response* cmd_transmission_stop(const Command& command);
115 * Maneja el comando plant/list.
117 Response* cmd_plant_list(void);
120 * Maneja el comando plant/get.
122 Response* cmd_plant_get(const Command& command);
125 * Maneja el comando plant/set.
127 Response* cmd_plant_set(const Command& command);
130 * Maneja el comando plant/set_frequency.
132 Response* cmd_plant_set_frequency(const Command& command);
135 * Maneja el comando plant/start.
137 Response* cmd_plant_start(const Command& command);
140 * Maneja el comando plant/stop.
142 Response* cmd_plant_stop(const Command& command);
145 * Maneja el comando plant/remove.
147 Response* cmd_plant_remove(const Command& command);
154 virtual ~Server(void);
159 * \param plant_filename Nombre del archivo con la planta a cargar.
160 * \param port Puerto en el cual escuchar.
162 Server(const std::string& plant_filename,
163 const Connection::Port& port = 7522) throw(sockerr);
166 * Maneja los comandos recibidos por las conexiones.
168 void on_control_command_received(const Command& command,
169 ControlServer* controlserver);
172 * Se encarga de borrar una planta de la lista cuando finaliza.
174 * \param plant Nombre de la planta a elminar.
176 void on_plant_finished(const char* plant);
184 #endif // PLAQUI_SERVER_H