From 2f5c973fdf3f7fb25b13996b66d566c58066f6a0 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 9 Nov 2003 23:59:33 +0000 Subject: [PATCH] Ya se mandan seniales cuando se reciben comandos. --- Server/include/plaqui/server/command.h | 6 ++--- Server/include/plaqui/server/controlserver.h | 27 ++++++++++++++++++-- Server/include/plaqui/server/receiver.h | 4 +-- Server/include/plaqui/server/server.h | 3 ++- Server/src/Makefile | 6 ++--- Server/src/command.cpp | 6 ++--- Server/src/controlserver.cpp | 15 +++++------ Server/src/receiver.cpp | 3 +-- Server/src/server.cpp | 9 ++++--- 9 files changed, 52 insertions(+), 27 deletions(-) diff --git a/Server/include/plaqui/server/command.h b/Server/include/plaqui/server/command.h index 019cad2..fafa951 100644 --- a/Server/include/plaqui/server/command.h +++ b/Server/include/plaqui/server/command.h @@ -91,7 +91,7 @@ namespace Server { /** * Obtiene el destino. */ - const std::string& get_target(void); + const std::string& get_target(void) const; /** * Establece el comando. @@ -101,7 +101,7 @@ namespace Server { /** * Obtiene el comand. */ - const std::string& get_command(void); + const std::string& get_command(void) const; /** * Establece los argumentos. @@ -111,7 +111,7 @@ namespace Server { /** * Obtiene los argumentos. */ - const Arguments& get_args(void); + const Arguments& get_args(void) const; /** * Agrega un argumentos. diff --git a/Server/include/plaqui/server/controlserver.h b/Server/include/plaqui/server/controlserver.h index f269e4b..5b6eb23 100644 --- a/Server/include/plaqui/server/controlserver.h +++ b/Server/include/plaqui/server/controlserver.h @@ -28,7 +28,8 @@ #ifndef PLAQUI_CONTROLSERVER_H #define PLAQUI_CONTROLSERVER_H -#include "plaqui/server/serverconnection.h" +#include "plaqui/server/connection.h" +#include "plaqui/server/command.h" #include namespace PlaQui { @@ -36,7 +37,24 @@ namespace PlaQui { namespace Server { /// Conexión para recibir comandos de control para una planta. - class ControlServer: public ServerConnection { + class ControlServer: public Connection { + + // Tipos. + + public: + + /// Tipo de señal para indicar que se recibió un comando. + typedef SigC::Signal1 SignalCommandReceived; + + // Atributos. + + private: + + /// Señal para indicar que se recibió un comando. + SignalCommandReceived command_received; + + + // Métodos. protected: @@ -59,6 +77,11 @@ namespace Server { */ ControlServer(const sockbuf::sockdesc& sd); + /** + * Obtiene la señal que avisa cuando se recibió un comando. + */ + SignalCommandReceived& signal_command_received(void); + }; } diff --git a/Server/include/plaqui/server/receiver.h b/Server/include/plaqui/server/receiver.h index de481f6..5b8c635 100644 --- a/Server/include/plaqui/server/receiver.h +++ b/Server/include/plaqui/server/receiver.h @@ -28,7 +28,7 @@ #ifndef PLAQUI_RECEIVER_H #define PLAQUI_RECEIVER_H -#include "plaqui/server/serverconnection.h" +#include "plaqui/server/connection.h" #include #include @@ -37,7 +37,7 @@ namespace PlaQui { namespace Server { /// Conexión para recibir el estado de una planta. - class Receiver: public ServerConnection { + class Receiver: public Connection { private: diff --git a/Server/include/plaqui/server/server.h b/Server/include/plaqui/server/server.h index 3776cc7..e66be38 100644 --- a/Server/include/plaqui/server/server.h +++ b/Server/include/plaqui/server/server.h @@ -31,6 +31,7 @@ #include "plaqui/server/tcpserver.h" #include "plaqui/server/controlserver.h" #include "plaqui/server/transmitter.h" +#include "plaqui/server/command.h" #include #include #include @@ -124,7 +125,7 @@ namespace Server { * * \todo Hacer un tipo Command abstracto o algo así. */ - void on_control_command_received(void* command); + void on_control_command_received(const Command& command); }; diff --git a/Server/src/Makefile b/Server/src/Makefile index 683723f..0403d20 100644 --- a/Server/src/Makefile +++ b/Server/src/Makefile @@ -74,9 +74,9 @@ connection_h=$(runnable_h) $(INCLUDE_DIR)/connection.h objects+=connection.o connection.o: $(connection_h) connection.cpp -serverconnection_h=$(connection_h) $(INCLUDE_DIR)/serverconnection.h -objects+=serverconnection.o -serverconnection.o: $(serverconnection_h) serverconnection.cpp +#serverconnection_h=$(connection_h) $(INCLUDE_DIR)/serverconnection.h +#objects+=serverconnection.o +#serverconnection.o: $(serverconnection_h) serverconnection.cpp controlclient_h=$(connection_h) $(command_h) $(INCLUDE_DIR)/controlclient.h objects+=controlclient.o diff --git a/Server/src/command.cpp b/Server/src/command.cpp index 91d82ce..5448ea6 100644 --- a/Server/src/command.cpp +++ b/Server/src/command.cpp @@ -64,7 +64,7 @@ void Command::set_target(const std::string& _target) { build(); } -const std::string& Command::get_target(void) { +const std::string& Command::get_target(void) const { return target; } @@ -73,7 +73,7 @@ void Command::set_command(const std::string& _command) { build(); } -const std::string& Command::get_command(void) { +const std::string& Command::get_command(void) const { return command; } @@ -82,7 +82,7 @@ void Command::set_args(const Command::Arguments& _args) { build(); } -const Command::Arguments& Command::get_args(void) { +const Command::Arguments& Command::get_args(void) const { return args; } diff --git a/Server/src/controlserver.cpp b/Server/src/controlserver.cpp index 7a4cedc..c5e163f 100644 --- a/Server/src/controlserver.cpp +++ b/Server/src/controlserver.cpp @@ -47,7 +47,7 @@ ControlServer::~ControlServer(void) { } ControlServer::ControlServer(const sockbuf::sockdesc& sd): - ServerConnection(sd) { + Connection(sd) { #ifdef DEBUG cerr << __FILE__ << ": sd = " << sd.sock << endl; #endif // DEBUG @@ -110,18 +110,13 @@ void ControlServer::real_run(void) { } } */ - // TODO: Manda el comando. - // Command command = parse_command(request.uri); - //signal_command_received().emit(command); + // Manda el comando. + command_received.emit(command); #ifdef DEBUG cerr << "Comando: target = " << command.get_target() << " | command = " << command.get_command() << " | args = [" << String::join(command.get_args(), ", ") << "]" << endl; - //for (HTTPRequest::const_iterator i = request.begin(); - // i != request.end(); i++) { - // cerr << " " << i->first << ": " << i->second << endl; - //} #endif // DEBUG // FIXME - hacer respuesta XML. // La respuesta hay que mandarla asincrónicamente porque no puedo @@ -182,6 +177,10 @@ Accept-Ranges: bytes } } +ControlServer::SignalCommandReceived& ControlServer::signal_command_received(void) { + return command_received; +} + } // namespace Server } // namespace PlaQui diff --git a/Server/src/receiver.cpp b/Server/src/receiver.cpp index 2a8e9bf..c381c7d 100644 --- a/Server/src/receiver.cpp +++ b/Server/src/receiver.cpp @@ -42,8 +42,7 @@ Receiver::~Receiver(void) { #endif // DEBUG } -Receiver::Receiver(int port, string host): - ServerConnection(sockbuf::sock_dgram) { +Receiver::Receiver(int port, string host): Connection(sockbuf::sock_dgram) { #ifdef DEBUG cerr << __FILE__ << ": port = " << port << " | host = " << host << endl; diff --git a/Server/src/server.cpp b/Server/src/server.cpp index 9d123f1..a05285a 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -30,6 +30,7 @@ #include "plaqui/server/controlserver.h" #include #ifdef DEBUG +# include "plaqui/server/string.h" # include #endif // DEBUG @@ -87,10 +88,12 @@ bool Server::stop_transmission(string host, int port) { } /// \todo Implementar. -void Server::on_control_command_received(void* command) { +void Server::on_control_command_received(const Command& command) { #ifdef DEBUG - cerr << __FILE__ << ": on_control_command_received(command = " - << command << ")" << endl; + cerr << __FILE__ << ": on_control_command_received(target = " + << command.get_target() << ", command = " << command.get_command() + << ", args = [" << String::join(command.get_args(), ", ") << "])" + << endl; #endif // DEBUG } -- 2.43.0