]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
Se termina de migrar lo que habia hecho al nuevo modelo cliente-servidor, pero
authorLeandro Lucarella <llucax@gmail.com>
Wed, 22 Oct 2003 07:31:08 +0000 (07:31 +0000)
committerLeandro Lucarella <llucax@gmail.com>
Wed, 22 Oct 2003 07:31:08 +0000 (07:31 +0000)
tengo problemas para compilar el ejemplo en el directorio Server/tests (la lib
aparentemente compila).

21 files changed:
Server/Doxyfile
Server/include/plaqui/server/connection.h
Server/include/plaqui/server/controlclient.h
Server/include/plaqui/server/controlserver.h
Server/include/plaqui/server/receiver.h
Server/include/plaqui/server/runnable.h
Server/include/plaqui/server/server.h
Server/include/plaqui/server/serverconnection.h
Server/include/plaqui/server/tcpserver.h
Server/include/plaqui/server/transmitter.h
Server/src/Makefile
Server/src/controlclient.cpp
Server/src/controlserver.cpp
Server/src/receiver.cpp
Server/src/request.cpp
Server/src/runnable.cpp
Server/src/server.cpp
Server/src/serverconnection.cpp
Server/src/string.cpp
Server/src/tcpserver.cpp [new file with mode: 0644]
Server/src/transmitter.cpp

index e01cc5e5d5b54e917612883a925f79188804dea3..d0fcea6fcff795339b74a77e9a74f7b5479dfae2 100644 (file)
@@ -13,8 +13,8 @@ REPEAT_BRIEF           = YES
 ALWAYS_DETAILED_SEC    = NO
 INLINE_INHERITED_MEMB  = NO
 FULL_PATH_NAMES        = YES
 ALWAYS_DETAILED_SEC    = NO
 INLINE_INHERITED_MEMB  = NO
 FULL_PATH_NAMES        = YES
-STRIP_FROM_PATH        = /home/luca/facultad/75.42/2003-2/final/Server/include \
-                         /home/luca/facultad/75.42/2003-2/final/Server/src
+STRIP_FROM_PATH        = /home/luca/facultad/75.42/2003-2/final/Server/include/ \
+                         /home/luca/facultad/75.42/2003-2/final/Server/
 SHORT_NAMES            = NO
 JAVADOC_AUTOBRIEF      = YES
 MULTILINE_CPP_IS_BRIEF = YES
 SHORT_NAMES            = NO
 JAVADOC_AUTOBRIEF      = YES
 MULTILINE_CPP_IS_BRIEF = YES
index 5b777db38d7a6ee69247211f0e2536682b7d41c1..4cdf44b296ef6f794d79c27405897bf999a2e27a 100644 (file)
@@ -51,7 +51,7 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~Connection(void) {}
+                       virtual ~Connection(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
index 8341a5f4549698b4bfb86a0ed8ee5f5bdda33446..73acdcfda36d704c60ae5d7c7ece035aba3d20ce 100644 (file)
@@ -41,7 +41,7 @@ namespace Server {
                private:
 
                        /**
                private:
 
                        /**
-                        * Atiende la conexión.
+                        * Realiza la conexión al servidor.
                         */
                        virtual void real_run(void);
 
                         */
                        virtual void real_run(void);
 
@@ -50,7 +50,7 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~ControlClient(void) {}
+                       virtual ~ControlClient(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
index 8a646c659fcbf797ddb25deda7a11a88d899c30e..f269e4b92427e5b87de7a5fa02675491b3f9ac19 100644 (file)
@@ -50,7 +50,7 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~ControlServer(void) {}
+                       virtual ~ControlServer(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
index aa06544ff6ec912939fd4cda72d83d3634031fbb..de481f6e77a23548ffc15b31b31cf21374af9b73 100644 (file)
@@ -39,12 +39,19 @@ namespace Server {
        /// Conexión para recibir el estado de una planta.
        class Receiver: public ServerConnection {
 
        /// Conexión para recibir el estado de una planta.
        class Receiver: public ServerConnection {
 
+               private:
+
+                       /**
+                        * Recibe la transmisión.
+                        */
+                       virtual void real_run(void);
+
                public:
 
                        /**
                         * Destructor.
                         */
                public:
 
                        /**
                         * Destructor.
                         */
-                       virtual ~Receiver(void) {}
+                       virtual ~Receiver(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
@@ -54,11 +61,6 @@ namespace Server {
                         */
                        Receiver(int port = 7528, std::string host = "localhost");
 
                         */
                        Receiver(int port = 7528, std::string host = "localhost");
 
-                       /**
-                        * Recibe la transmisión.
-                        */
-                       virtual void run(void);
-
        };
 
 }
        };
 
 }
index 2d34e6cc285ad5ed20ca4bf2a6a2c9c4d3d98ff1..7896090370af01d016ff3da2bd31b84326a80db3 100644 (file)
@@ -52,12 +52,18 @@ namespace Server {
                        /// Thread en el cual correr la tarea.
                        Glib::Thread* thread;
 
                        /// Thread en el cual correr la tarea.
                        Glib::Thread* thread;
 
-                       /// Indica si se debe frinalizar la tarea.
-                       bool stop;
-
                        /// Señal que indica que se finalizó la tarea.
                        SignalFinished finished;
 
                        /// Señal que indica que se finalizó la tarea.
                        SignalFinished finished;
 
+               protected:
+
+                       /**
+                        * Indica si se debe frinalizar la tarea.
+                        *
+                        * \todo Poner como privado y poner get() set() con locks.
+                        */
+                       bool stop;
+
                // Métodos.
 
                private:
                // Métodos.
 
                private:
@@ -79,7 +85,7 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~Runnable(void) {}
+                       virtual ~Runnable(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
index f16e2dfbb5eed5e0e4666abf23386345fa7982a4..3776cc72e9462dd1e6a2fd569b9b247efa68d016 100644 (file)
@@ -67,19 +67,23 @@ namespace Server {
 
                // Métodos.
 
 
                // Métodos.
 
-               private:
+               protected:
 
                        /**
 
                        /**
-                        * Entra en el loop para atender conexiones.
+                        * Obtiene una nueva \ref Connection "conexión".
+                        *
+                        * \param sd Descriptor del socket de la nueva conexión.
+                        *
+                        * \return Nueva conexión.
                         */
                         */
-                       virtual void real_run(void);
+                       virtual Connection* new_connection(const sockbuf::sockdesc& sd);
 
                public:
 
                        /**
                         * Destructor.
                         */
 
                public:
 
                        /**
                         * Destructor.
                         */
-                       virtual ~Server(void) {}
+                       virtual ~Server(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
@@ -120,7 +124,7 @@ namespace Server {
                         *
                         * \todo Hacer un tipo Command abstracto o algo así.
                         */
                         *
                         * \todo Hacer un tipo Command abstracto o algo así.
                         */
-                       void on_connection_command_received(void* command);
+                       void on_control_command_received(void* command);
 
        };
 
 
        };
 
index 91fa37f8f44f756355f30265c811f3a3950884d5..14443432dbe3bf382ed8b27d01f8b82eb5d42d10 100644 (file)
@@ -62,7 +62,21 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~ServerConnection(void) {}
+                       virtual ~ServerConnection(void);
+
+                       /**
+                        * Constructor.
+                        *
+                        * \param socket Descriptor de socket a usar en la conexión.
+                        */
+                       ServerConnection(const sockbuf::sockdesc& sd);
+
+                       /**
+                        * Constructor.
+                        *
+                        * \param type Tipo de socket a usar.
+                        */
+                       ServerConnection(sockbuf::type type);
 
                        /**
                         * Obtiene la señal que avisa que se recibió un comando.
 
                        /**
                         * Obtiene la señal que avisa que se recibió un comando.
index b37984428858668a09da3b2a4a7c0486496d0280..b3ecfa6c25c1b0f392103b592e360560eb8570bd 100644 (file)
 #ifndef PLAQUI_TCPSERVER_H
 #define PLAQUI_TCPSERVER_H
 
 #ifndef PLAQUI_TCPSERVER_H
 #define PLAQUI_TCPSERVER_H
 
-#include "plaqui/server/controlserver.h"
-#include "plaqui/server/transmitter.h"
+#include "plaqui/server/runnable.h"
+#include "plaqui/server/connection.h"
 #include <socket++/sockinet.h>
 #include <socket++/sockinet.h>
-#include <string>
 #include <list>
 
 namespace PlaQui {
 #include <list>
 
 namespace PlaQui {
@@ -49,7 +48,7 @@ namespace Server {
                private:
 
                        /// Lista de conexiones de control.
                private:
 
                        /// Lista de conexiones de control.
-                       typedef std::list<Connnection*> ConnectionList;
+                       typedef std::list<Connection*> ConnectionList;
 
                // Atributos.
 
 
                // Atributos.
 
@@ -86,7 +85,7 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~TCPServer(void) {}
+                       virtual ~TCPServer(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
index c3467a4b90d559d7e44ef05209c6df0c7f13459a..93b47e97d287cff7b0eef5ec0b62899f0a5bfa89 100644 (file)
@@ -50,7 +50,7 @@ namespace Server {
                        /**
                         * Destructor.
                         */
                        /**
                         * Destructor.
                         */
-                       virtual ~Transmitter(void) {}
+                       virtual ~Transmitter(void);
 
                        /**
                         * Constructor.
 
                        /**
                         * Constructor.
index f1a4b8364b46b58f9ce5ea6f1ae9ff0a6014a4bd..76ab99b5b833b4868039855b89b9051cf2789ab0 100644 (file)
@@ -59,6 +59,10 @@ connection_h=$(runnable_h) $(INCLUDE_DIR)/connection.h
 objects+=connection.o
 connection.o: $(connection_h) connection.cpp
 
 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
+
 controlclient_h=$(connection_h) $(INCLUDE_DIR)/controlclient.h
 objects+=controlclient.o
 controlclient.o: $(controlclient_h) controlclient.cpp
 controlclient_h=$(connection_h) $(INCLUDE_DIR)/controlclient.h
 objects+=controlclient.o
 controlclient.o: $(controlclient_h) controlclient.cpp
@@ -75,7 +79,12 @@ transmitter_h=$(connection_h) $(INCLUDE_DIR)/transmitter.h
 objects+=transmitter.o
 transmitter.o: $(transmitter_h) transmitter.cpp
 
 objects+=transmitter.o
 transmitter.o: $(transmitter_h) transmitter.cpp
 
-server_h=$(controlserver_h) $(transmitter_h) $(INCLUDE_DIR)/server.h
+tcpserver_h=$(connection_h) $(INCLUDE_DIR)/tcpserver.h
+objects+=tcpserver.o
+tcpserver.o: $(tcpserver_h) tcpserver.cpp
+
+server_h=$(tcpserver) $(controlserver_h) $(transmitter_h) \
+                $(INCLUDE_DIR)/server.h
 objects+=server.o
 server.o: $(server_h) server.cpp
 
 objects+=server.o
 server.o: $(server_h) server.cpp
 
index 7138b44f09820ef5005dd0fe4b9bbc3ab77b74c9..99c5348ff9821f555b1f9d375e5539fd9bdbd357 100644 (file)
 //
 
 #include "plaqui/server/controlclient.h"
 //
 
 #include "plaqui/server/controlclient.h"
-// XXX
-#include <iostream>
+#ifdef DEBUG
+#      include <iostream>
+#endif // DEBUG
 
 
-using namespace PlaQui::Server;
+PlaQui::Server::ControlClient::~ControlClient(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": destructor." << std::endl;
+#endif // DEBUG
+}
 
 
-ControlClient::ControlClient(std::string host, int port):
+PlaQui::Server::ControlClient::ControlClient(std::string host, int port):
                Connection(sockbuf::sock_stream) {
                Connection(sockbuf::sock_stream) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": host" << host
+               << " | port = " << port << std::endl;
+#endif // DEBUG
        // FIXME - poner en run().
        socket->connect(host.c_str(), port);
 }
 
        // FIXME - poner en run().
        socket->connect(host.c_str(), port);
 }
 
-void ControlClient::real_run(void) {
+void PlaQui::Server::ControlClient::real_run(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": real_run." << std::endl;
+#endif // DEBUG
+#ifdef DEBUG
        // FIXME - debería tirar una excepción?
        if (!socket->is_open()) {
                std::cerr << "No se pudo conectar a " << socket->peerhost() <<
        // FIXME - debería tirar una excepción?
        if (!socket->is_open()) {
                std::cerr << "No se pudo conectar a " << socket->peerhost() <<
@@ -45,6 +58,7 @@ void ControlClient::real_run(void) {
        } else {
                std::cerr << "Conectado a " << socket->peerhost() <<
                        ":" << socket->peerport() << "." << std::endl;
        } else {
                std::cerr << "Conectado a " << socket->peerhost() <<
                        ":" << socket->peerport() << "." << std::endl;
+#endif // DEBUG
        }
 }
 
        }
 }
 
index 544483fadade053c10fe81b4dac59524b4233c93..64f4cfe1f99c0b69c282a84d678e0193e12f3bf6 100644 (file)
@@ -40,7 +40,7 @@ PlaQui::Server::ControlServer::~ControlServer(void) {
 }
 
 PlaQui::Server::ControlServer::ControlServer(const sockbuf::sockdesc& sd):
 }
 
 PlaQui::Server::ControlServer::ControlServer(const sockbuf::sockdesc& sd):
-               Connection(sd) {
+               PlaQui::Server::ServerConnection(sd) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
 #endif // DEBUG
 #ifdef DEBUG
        std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
 #endif // DEBUG
index c492fe13abfebb9f8c78861dd2e43a39d6a76708..c64eaad235e905bd7fe88ebaa735a9a73a390503 100644 (file)
 //
 
 #include "plaqui/server/receiver.h"
 //
 
 #include "plaqui/server/receiver.h"
+#ifdef DEBUG
+#      include <iostream>
+#endif // DEBUG
 
 
-using namespace PlaQui::Server;
+PlaQui::Server::Receiver::~Receiver(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": destructor." << std::endl;
+#endif // DEBUG
+}
 
 
-Receiver::Receiver(int port, std::string host):
-               Connection(sockbuf::sock_dgram) {
+PlaQui::Server::Receiver::Receiver(int port, std::string host):
+               PlaQui::Server::ServerConnection(sockbuf::sock_dgram) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": port = " << port
+               << " | host = " << host << std::endl;
+#endif // DEBUG
        // FIXME - deberia ir en run().
        socket->bind(port);
 }
 
        // FIXME - deberia ir en run().
        socket->bind(port);
 }
 
-void Receiver::run(void) {
+void PlaQui::Server::Receiver::real_run(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": real_run." << std::endl;
+#endif // DEBUG
        // FIXME - debería tirar una excepción?
        if (!socket->is_open()) {
                std::cerr << "No se pudo conectar a " << socket->peerhost() <<
        // FIXME - debería tirar una excepción?
        if (!socket->is_open()) {
                std::cerr << "No se pudo conectar a " << socket->peerhost() <<
index 92bb7e1d7c7fc9386318e0122f225ea4db77ac65..d17ca72bbed0757d73c5244bef7273a5a6124647 100644 (file)
 #      include <iostream>
 #endif // DEBUG
 
 #      include <iostream>
 #endif // DEBUG
 
-using namespace PlaQui::Server;
+const std::string
+PlaQui::Server::Request::CHARS_DIGIT = "0123456789";
 
 
-const std::string Request::CHARS_DIGIT = "0123456789";
+const std::string
+PlaQui::Server::Request::CHARS_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
 
 
-const std::string Request::CHARS_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
+const std::string
+PlaQui::Server::Request::CHARS_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
 
-const std::string Request::CHARS_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+const std::string
+PlaQui::Server::Request::CHARS_ALPHA = CHARS_LOWALPHA + CHARS_UPALPHA;
 
 
-const std::string Request::CHARS_ALPHA = CHARS_LOWALPHA + CHARS_UPALPHA;
+const std::string
+PlaQui::Server::Request::CHARS_ALPHANUM = CHARS_DIGIT + CHARS_ALPHA;
 
 
-const std::string Request::CHARS_ALPHANUM = CHARS_DIGIT + CHARS_ALPHA;
+const std::string
+PlaQui::Server::Request::CHARS_RESERVED = ";/?:@&=+$,";
 
 
-const std::string Request::CHARS_RESERVED = ";/?:@&=+$,";
+const std::string
+PlaQui::Server::Request::CHARS_MARK = "-_.!~*'()";
 
 
-const std::string Request::CHARS_MARK = "-_.!~*'()";
+const std::string
+PlaQui::Server::Request::CHARS_UNRESERVED = CHARS_ALPHANUM + CHARS_MARK;
 
 
-const std::string Request::CHARS_UNRESERVED = CHARS_ALPHANUM + CHARS_MARK;
+const std::string
+PlaQui::Server::Request::CHARS_HEX = CHARS_DIGIT + std::string("abcdefABCDEF");
 
 
-const std::string Request::CHARS_HEX = CHARS_DIGIT + std::string("abcdefABCDEF");
-
-void Request::set_request(const std::string& req, const std::string& host,
-               unsigned port) {
+void PlaQui::Server::Request::set_request(const std::string& req,
+               const std::string& host, unsigned port) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": req = " << req << " | host = " << host
                << " | port = " << port << std::endl;
 #endif // DEBUG
 #ifdef DEBUG
        std::cerr << __FILE__ << ": req = " << req << " | host = " << host
                << " | port = " << port << std::endl;
 #endif // DEBUG
-       String request(req);
+       PlaQui::Server::String request(req);
        (*this)["REMOTE_HOST"] = host;
        std::stringstream ss;
        ss << port;
        (*this)["REMOTE_HOST"] = host;
        std::stringstream ss;
        ss << port;
@@ -71,8 +78,9 @@ void Request::set_request(const std::string& req, const std::string& host,
                throw "HTTP/1.1 501 Method Not Implemented";
        }
        // Averiguo método.
                throw "HTTP/1.1 501 Method Not Implemented";
        }
        // Averiguo método.
-       std::string::size_type pos = request.find_first_of(String::SPACE_CHARS);
-       String method = request.substr(0, pos); 
+       std::string::size_type pos = request.find_first_of(
+                       PlaQui::Server::String::SPACE_CHARS);
+       PlaQui::Server::String method = request.substr(0, pos); 
        if ((method.to_upper() == "GET") || (method.to_upper() == "POST")) {
                (*this)["REQUEST_METHOD"] = method;
        } else {
        if ((method.to_upper() == "GET") || (method.to_upper() == "POST")) {
                (*this)["REQUEST_METHOD"] = method;
        } else {
@@ -87,13 +95,13 @@ void Request::set_request(const std::string& req, const std::string& host,
                throw "HTTP/1.1 400 Bad Request";
        }
        // Si tiene más espacios, tengo la URI y el protocolo (o un error).
                throw "HTTP/1.1 400 Bad Request";
        }
        // Si tiene más espacios, tengo la URI y el protocolo (o un error).
-       pos = request.find_first_of(String::SPACE_CHARS);
+       pos = request.find_first_of(PlaQui::Server::String::SPACE_CHARS);
        if (pos != std::string::npos) {
                // Si el resto es un protocolo válido, agrego más variables.
        if (pos != std::string::npos) {
                // Si el resto es un protocolo válido, agrego más variables.
-               String protocol = request.substr(pos + 1);
+               PlaQui::Server::String protocol = request.substr(pos + 1);
                protocol = protocol.trim();
                protocol = protocol.trim();
-               if ((String(protocol).to_upper() == "HTTP/1.0")
-                               || (String(protocol).to_upper() == "HTTP/1.1")) {
+               if ((PlaQui::Server::String(protocol).to_upper() == "HTTP/1.0")
+                               || (PlaQui::Server::String(protocol).to_upper() == "HTTP/1.1")) {
                        (*this)["SERVER_PROTOCOL"] = protocol;
                // Si no es un error.
                } else {
                        (*this)["SERVER_PROTOCOL"] = protocol;
                // Si no es un error.
                } else {
@@ -120,7 +128,7 @@ void Request::set_request(const std::string& req, const std::string& host,
        (*this)["SCRIPT_NAME"] = request.substr(0, pos);
 }
 
        (*this)["SCRIPT_NAME"] = request.substr(0, pos);
 }
 
-void Request::parse_header(const std::string& header) {
+void PlaQui::Server::Request::parse_header(const std::string& header) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": header = " << header << std::endl;
 #endif // DEBUG
 #ifdef DEBUG
        std::cerr << __FILE__ << ": header = " << header << std::endl;
 #endif // DEBUG
index 66579acda263b663cd45a67c7e237e3162de3ff7..0c6b477306347ffd64f012fc5b43817b7094bf5d 100644 (file)
 #      include <iostream>
 #endif // DEBUG
 
 #      include <iostream>
 #endif // DEBUG
 
+PlaQui::Server::Runnable::~Runnable(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": destructor." << std::endl;
+#endif // DEBUG
+}
+
 PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) {
 PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": constructor." << std::endl;
+#endif // DEBUG
 }
 
 void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) {
 }
 
 void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) {
index 1206b1c16ea7a8670284fb352b5ca1d0ddc50add..81285cbe61fdabd24338cc250f578548999c1897 100644 (file)
 #      include <iostream>
 #endif // DEBUG
 
 #      include <iostream>
 #endif // DEBUG
 
-using namespace PlaQui::Server;
+PlaQui::Server::Server::~Server(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": destructor." << std::endl;
+#endif // DEBUG
+}
 
 
-Server::Server(int port):
-               socket(sockbuf::sock_stream) {
-       socket.bind(port);
+PlaQui::Server::Server::Server(int port):
+               PlaQui::Server::Server::TCPServer(port) {
 #ifdef DEBUG
 #ifdef DEBUG
-       std::cerr << "Escuchando en " << socket.localhost() <<
-               ":" << socket.localport() << "." << std::endl;
+       std::cerr << __FILE__ <<  ": port = " << port << std::endl;
 #endif // DEBUG
 #endif // DEBUG
-       socket.listen();
 }
 
 }
 
-bool Server::start_transmission(std::string host, int port) {
+/// \todo Implementar.
+bool PlaQui::Server::Server::start_transmission(std::string host, int port) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": start_transmission(host = " << host
+               << " | port = " << port << ")" << std::endl;
+#endif // DEBUG
        // TODO
        return false;
 }
 
        // TODO
        return false;
 }
 
-bool Server::stop_transmission(std::string host, int port) {
+/// \todo Implementar.
+bool PlaQui::Server::Server::stop_transmission(std::string host, int port) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": stop_transmission(host = " << host
+               << " | port = " << port << ")" << std::endl;
+#endif // DEBUG
        // TODO
        return false;
 }
 
        // TODO
        return false;
 }
 
-void Server::real_run(void) {
-       // FIXME se tiene que ir a la clase para poder frenarlo desde afuera.
-       bool stop = false;
-       ControlServer* control_server;
-       while (!stop) {
-               control_server = new ControlServer(socket.accept());
-               controllers.push_back(control_server);
-               control_server->run();
-       }
+/// \todo Implementar.
+void PlaQui::Server::Server::on_control_command_received(void* command) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": on_control_command_received(command = "
+               << command << ")" << std::endl;
+#endif // DEBUG
 }
 
 }
 
index 5e159c3a8d61da16bfe1a84bb9100d6c3d11f663..a5cbea395c15b7e041060120801cbba87e5a812e 100644 (file)
@@ -37,21 +37,19 @@ PlaQui::Server::ServerConnection::~ServerConnection(void) {
 #endif // DEBUG
 }
 
 #endif // DEBUG
 }
 
-/*
 PlaQui::Server::ServerConnection::ServerConnection(const sockbuf::sockdesc& sd):
 PlaQui::Server::ServerConnection::ServerConnection(const sockbuf::sockdesc& sd):
-               socket(sd) {
+               PlaQui::Server::Connection(sd) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
 #endif // DEBUG
 }
 
 PlaQui::Server::ServerConnection::ServerConnection(sockbuf::type type):
 #ifdef DEBUG
        std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
 #endif // DEBUG
 }
 
 PlaQui::Server::ServerConnection::ServerConnection(sockbuf::type type):
-               socket(type) {
+               PlaQui::Server::Connection(type) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": type = " << type << std::endl;
 #endif // DEBUG
 }
 #ifdef DEBUG
        std::cerr << __FILE__ << ": type = " << type << std::endl;
 #endif // DEBUG
 }
-*/
 
 PlaQui::Server::ServerConnection::SignalCommandReceived&
 PlaQui::Server::ServerConnection::signal_command_received(void) {
 
 PlaQui::Server::ServerConnection::SignalCommandReceived&
 PlaQui::Server::ServerConnection::signal_command_received(void) {
index 24904a76c3bf00d751fa59fb21a7876fa3c6cf93..edc522c3d17a6c4312205d5f74df1978175592ae 100644 (file)
 #      include <iostream>
 #endif // DEBUG
 
 #      include <iostream>
 #endif // DEBUG
 
-using namespace PlaQui::Server;
-
-const std::string String::SPACE_CHARS = " \t\n\r";
+const std::string PlaQui::Server::String::SPACE_CHARS = " \t\n\r";
                        
                        
-String::String(const std::string& str): std::string(str.c_str()) {
+PlaQui::Server::String::String(const std::string& str):
+               std::string(str.c_str()) {
 }
 
 }
 
-String& String::trim(const String& clist) {
+PlaQui::Server::String& PlaQui::Server::String::trim(
+               const PlaQui::Server::String& clist) {
        erase(0, find_first_not_of(clist));
        erase(find_last_not_of(clist) + 1);
        return *this;
 }
 
        erase(0, find_first_not_of(clist));
        erase(find_last_not_of(clist) + 1);
        return *this;
 }
 
-String& String::to_lower(void) {
+PlaQui::Server::String& PlaQui::Server::String::to_lower(void) {
        std::transform(begin(), end(), begin(), tolower);
        return *this;
 }
 
        std::transform(begin(), end(), begin(), tolower);
        return *this;
 }
 
-String& String::to_upper(void) {
+PlaQui::Server::String& PlaQui::Server::String::to_upper(void) {
        std::transform(begin(), end(), begin(), toupper);
        return *this;
 }
        std::transform(begin(), end(), begin(), toupper);
        return *this;
 }
diff --git a/Server/src/tcpserver.cpp b/Server/src/tcpserver.cpp
new file mode 100644 (file)
index 0000000..82f1577
--- /dev/null
@@ -0,0 +1,90 @@
+// vim: set noexpandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+//                                  PlaQui
+//----------------------------------------------------------------------------
+// This file is part of PlaQui.
+//
+// PlaQui is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA  02111-1307  USA
+//----------------------------------------------------------------------------
+// Creado:  Sat Oct 18 18:18:36 2003
+// Autores: Leandro Lucarella <llucare@fi.uba.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#include "plaqui/server/tcpserver.h"
+#include <sigc++/class_slot.h> // FIXME
+#ifdef DEBUG
+#      include <iostream>
+#endif // DEBUG
+
+PlaQui::Server::TCPServer::~TCPServer(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": destructor." << std::endl;
+#endif // DEBUG
+}
+
+PlaQui::Server::TCPServer::TCPServer(int port):
+               socket(sockbuf::sock_stream) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": port = " << port << std::endl;
+#endif // DEBUG
+       socket.bind(port);
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": escuchando en " << socket.localhost()
+               << ":" << socket.localport() << "." << std::endl;
+#endif // DEBUG
+       socket.listen();
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": [despues de listen()] escuchando en "
+               << socket.localhost() << ":" << socket.localport() << "." << std::endl;
+#endif // DEBUG
+}
+
+void PlaQui::Server::TCPServer::on_connection_finished(
+               PlaQui::Server::Connection* connection) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": on_connection_finished(connection = "
+               << connection << ")" << std::endl;
+#endif // DEBUG
+       // TODO: poner lock.
+       connections.remove(connection);
+       // TODO: sacar lock.
+}
+
+void PlaQui::Server::TCPServer::real_run(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ <<  ": real_run" << std::endl;
+#endif // DEBUG
+       PlaQui::Server::Connection* conn;
+       while (!stop) {
+               // TODO: ver tema de timeout o como salir de un accept().
+               // Forma grasa de salir del accept: crear conexion que salga al toque.
+               conn = new_connection(socket.accept());
+               // TODO: poner lock.
+               connections.push_back(conn);
+               // TODO: sacar lock.
+               // TODO: esto va en Server::new_connection()
+               // Conecto la señal para cuando termina una conexión, borrarla.
+               conn->signal_finished().connect(
+                               SigC::bind<PlaQui::Server::Connection*>(
+                                       SigC::slot_class(*this,
+                                               &PlaQui::Server::TCPServer::on_connection_finished),
+                                       conn));
+               conn->run();
+       }
+}
+
index 37113cc1b8f2147bfe4d0755b4fd8362e05d7701..268f2168baaeb7c9fa7d425b59ac1c38e9d0139b 100644 (file)
 #include "plaqui/server/transmitter.h"
 #include <socket++/sockinet.h>
 #include <string>
 #include "plaqui/server/transmitter.h"
 #include <socket++/sockinet.h>
 #include <string>
+#ifdef DEBUG
+#      include <iostream>
+#endif // DEBUG
 
 
-using namespace PlaQui::Server;
+PlaQui::Server::Transmitter::~Transmitter(void) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": destructor." << std::endl;
+#endif // DEBUG
+}
 
 
-Transmitter::Transmitter(std::string host, int port):
-               Connection(sockbuf::sock_dgram) {
+/// \todo debría conectarse en real_run() (?)
+PlaQui::Server::Transmitter::Transmitter(std::string host, int port):
+               PlaQui::Server::Connection(sockbuf::sock_dgram) {
+#ifdef DEBUG
+       std::cerr << __FILE__ << ": host = " << host
+               << " | port = " << port << std::endl;
+#endif // DEBUG
        // FIXME - deberia ir en run().
        socket->connect(host.c_str(), port);
 }
 
        // FIXME - deberia ir en run().
        socket->connect(host.c_str(), port);
 }
 
-void Transmitter::real_run(void) {
+/// \todo debría dar una excepción (?)
+void PlaQui::Server::Transmitter::real_run(void) {
+#ifdef DEBUG
        // FIXME - debería tirar una excepción?
        if (!socket->is_open()) {
                std::cerr << "No se pudo conectar a " << socket->peerhost() <<
        // FIXME - debería tirar una excepción?
        if (!socket->is_open()) {
                std::cerr << "No se pudo conectar a " << socket->peerhost() <<
@@ -46,5 +60,6 @@ void Transmitter::real_run(void) {
                std::cerr << "Conectado a " << socket->peerhost() <<
                        ":" << socket->peerport() << "." << std::endl;
        }
                std::cerr << "Conectado a " << socket->peerhost() <<
                        ":" << socket->peerport() << "." << std::endl;
        }
+#endif // DEBUG
 }
 
 }