From ab9300aaf1217f0c3b45dd5f1f1fdc1c5e5bd1be Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Thu, 23 Oct 2003 02:21:07 +0000 Subject: [PATCH] Se eliminan los namespaces en los cuerpos de las definiones de los metodos que eran redundantes y se mejoran algunos mensajes de DEBUG. --- Server/src/controlclient.cpp | 2 +- Server/src/controlserver.cpp | 2 +- Server/src/receiver.cpp | 2 +- Server/src/request.cpp | 15 ++++++------- Server/src/runnable.cpp | 16 +++++++------- Server/src/server.cpp | 15 ++++++------- Server/src/serverconnection.cpp | 4 ++-- Server/src/tcpserver.cpp | 38 ++++++++++++++++++++++++--------- Server/src/transmitter.cpp | 2 +- 9 files changed, 56 insertions(+), 40 deletions(-) diff --git a/Server/src/controlclient.cpp b/Server/src/controlclient.cpp index fd0fdba..3ceaa9f 100644 --- a/Server/src/controlclient.cpp +++ b/Server/src/controlclient.cpp @@ -37,7 +37,7 @@ PlaQui::Server::ControlClient::~ControlClient(void) { } PlaQui::Server::ControlClient::ControlClient(std::string host, int port): - PlaQui::Server::Connection(sockbuf::sock_stream) { + Connection(sockbuf::sock_stream) { #ifdef DEBUG std::cerr << __FILE__ << ": host" << host << " | port = " << port << std::endl; diff --git a/Server/src/controlserver.cpp b/Server/src/controlserver.cpp index 753255e..0587bc1 100644 --- a/Server/src/controlserver.cpp +++ b/Server/src/controlserver.cpp @@ -40,7 +40,7 @@ PlaQui::Server::ControlServer::~ControlServer(void) { } PlaQui::Server::ControlServer::ControlServer(const sockbuf::sockdesc& sd): - PlaQui::Server::ServerConnection(sd) { + ServerConnection(sd) { #ifdef DEBUG std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl; #endif // DEBUG diff --git a/Server/src/receiver.cpp b/Server/src/receiver.cpp index c64eaad..9667e8c 100644 --- a/Server/src/receiver.cpp +++ b/Server/src/receiver.cpp @@ -37,7 +37,7 @@ PlaQui::Server::Receiver::~Receiver(void) { } PlaQui::Server::Receiver::Receiver(int port, std::string host): - PlaQui::Server::ServerConnection(sockbuf::sock_dgram) { + ServerConnection(sockbuf::sock_dgram) { #ifdef DEBUG std::cerr << __FILE__ << ": port = " << port << " | host = " << host << std::endl; diff --git a/Server/src/request.cpp b/Server/src/request.cpp index 9e6aadf..f40c9f9 100644 --- a/Server/src/request.cpp +++ b/Server/src/request.cpp @@ -70,7 +70,7 @@ void PlaQui::Server::Request::set_request(const std::string& req, std::cerr << __FILE__ << ": req = " << req << " | host = " << host << " | port = " << port << std::endl; #endif // DEBUG - PlaQui::Server::String request(req); + String request(req); (*this)["REMOTE_HOST"] = host; std::stringstream ss; ss << port; @@ -81,9 +81,8 @@ void PlaQui::Server::Request::set_request(const std::string& req, throw "HTTP/1.1 501 Method Not Implemented"; } // Averiguo método. - std::string::size_type pos = request.find_first_of( - PlaQui::Server::String::SPACE_CHARS); - PlaQui::Server::String method = request.substr(0, pos); + std::string::size_type pos = request.find_first_of(String::SPACE_CHARS); + String method = request.substr(0, pos); if ((method.to_upper() == "GET") || (method.to_upper() == "POST")) { (*this)["REQUEST_METHOD"] = method; } else { @@ -98,13 +97,13 @@ void PlaQui::Server::Request::set_request(const std::string& req, 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(PlaQui::Server::String::SPACE_CHARS); + pos = request.find_first_of(String::SPACE_CHARS); if (pos != std::string::npos) { // Si el resto es un protocolo válido, agrego más variables. - PlaQui::Server::String protocol = request.substr(pos + 1); + String protocol = request.substr(pos + 1); protocol = protocol.trim(); - if ((PlaQui::Server::String(protocol).to_upper() == "HTTP/1.0") - || (PlaQui::Server::String(protocol).to_upper() == "HTTP/1.1")) { + if ((String(protocol).to_upper() == "HTTP/1.0") + || (String(protocol).to_upper() == "HTTP/1.1")) { (*this)["SERVER_PROTOCOL"] = protocol; // Si no es un error. } else { diff --git a/Server/src/runnable.cpp b/Server/src/runnable.cpp index 0c6b477..7fd4105 100644 --- a/Server/src/runnable.cpp +++ b/Server/src/runnable.cpp @@ -34,7 +34,8 @@ PlaQui::Server::Runnable::~Runnable(void) { #ifdef DEBUG - std::cerr << __FILE__ << ": destructor." << std::endl; + std::cerr << __FILE__ << ": destructor(this = " << this << ")" + << std::endl; #endif // DEBUG } @@ -44,9 +45,10 @@ PlaQui::Server::Runnable::Runnable(void): thread(0), stop(false) { #endif // DEBUG } -void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) { +void PlaQui::Server::Runnable::static_run(Runnable* runner) { #ifdef DEBUG - std::cerr << __FILE__ << ": runner = " << runner << std::endl; + std::cerr << __FILE__ << ": static_run(runner = " << runner << ")" + << std::endl; #endif // DEBUG runner->real_run(); runner->signal_finished().emit(); @@ -55,7 +57,7 @@ void PlaQui::Server::Runnable::static_run(PlaQui::Server::Runnable* runner) { void PlaQui::Server::Runnable::run(bool detach) { #ifdef DEBUG - std::cerr << __FILE__ << ": detach = " << detach << std::endl; + std::cerr << __FILE__ << ": run(detach = " << detach << ")" << std::endl; #endif // DEBUG // Si vamos a correr la tarea en un thread. if (detach) { @@ -66,9 +68,7 @@ void PlaQui::Server::Runnable::run(bool detach) { // Corremos el thread en una funcion estática para poder destruirlo al // finalizar, pasandole el puntero al objeto. thread = Glib::Thread::create( - SigC::bind( - SigC::slot(&PlaQui::Server::Runnable::static_run), - this), + SigC::bind(SigC::slot(&Runnable::static_run), this), true); // Si no corremos la tarea normalmente. } else { @@ -79,7 +79,7 @@ void PlaQui::Server::Runnable::run(bool detach) { void PlaQui::Server::Runnable::finish(bool attach) { #ifdef DEBUG - std::cerr << __FILE__ << ": attach = " << attach << std::endl; + std::cerr << __FILE__ << ": finish(attach = " << attach << ")" << std::endl; #endif // DEBUG // TODO - necesita un mutex? stop = true; diff --git a/Server/src/server.cpp b/Server/src/server.cpp index 8f33449..134bcf5 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -40,7 +40,7 @@ PlaQui::Server::Server::~Server(void) { } PlaQui::Server::Server::Server(int port): - PlaQui::Server::TCPServer(port) { + TCPServer(port) { #ifdef DEBUG std::cerr << __FILE__ << ": port = " << port << std::endl; #endif // DEBUG @@ -56,19 +56,18 @@ bool PlaQui::Server::Server::start_transmission(std::string host, int port) { return false; } -PlaQui::Server::Connection* -PlaQui::Server::Server::new_connection(const sockbuf::sockdesc& sd) { +PlaQui::Server::Connection* PlaQui::Server::Server::new_connection( + const sockbuf::sockdesc& sd) { #ifdef DEBUG std::cerr << __FILE__ << ": new_connection(sd = " << sd.sock << ")" << std::endl; #endif // DEBUG - PlaQui::Server::ControlServer* conn = new PlaQui::Server::ControlServer(sd); + ControlServer* connection = new ControlServer(sd); // TODO verificar si el new se hace bien? no creo. - conn->signal_command_received().connect( - SigC::slot_class(*this, - &PlaQui::Server::Server::on_control_command_received)); + connection->signal_command_received().connect( + SigC::slot_class(*this, &Server::on_control_command_received)); // TODO: - return conn; + return connection; } /// \todo Implementar. diff --git a/Server/src/serverconnection.cpp b/Server/src/serverconnection.cpp index a5cbea3..6cbe0f3 100644 --- a/Server/src/serverconnection.cpp +++ b/Server/src/serverconnection.cpp @@ -38,14 +38,14 @@ PlaQui::Server::ServerConnection::~ServerConnection(void) { } PlaQui::Server::ServerConnection::ServerConnection(const sockbuf::sockdesc& sd): - PlaQui::Server::Connection(sd) { + Connection(sd) { #ifdef DEBUG std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl; #endif // DEBUG } PlaQui::Server::ServerConnection::ServerConnection(sockbuf::type type): - PlaQui::Server::Connection(type) { + Connection(type) { #ifdef DEBUG std::cerr << __FILE__ << ": type = " << type << std::endl; #endif // DEBUG diff --git a/Server/src/tcpserver.cpp b/Server/src/tcpserver.cpp index c00a8b6..4131224 100644 --- a/Server/src/tcpserver.cpp +++ b/Server/src/tcpserver.cpp @@ -55,36 +55,54 @@ PlaQui::Server::TCPServer::TCPServer(int port): } void PlaQui::Server::TCPServer::on_connection_finished( - PlaQui::Server::Connection* connection) { + Connection* connection) { #ifdef DEBUG std::cerr << __FILE__ << ": on_connection_finished(connection = " << connection << ")" << std::endl; #endif // DEBUG // TODO: poner lock. connections.remove(connection); +#ifdef DEBUG + std::cerr << __FILE__ << ": lista de conexiones" << std::endl; + for (ConnectionList::const_iterator i = connections.begin(); + i != connections.end(); i++) { + std::cerr << "\t " << *i << std::endl; + } +#endif // DEBUG // TODO: sacar lock. } void PlaQui::Server::TCPServer::real_run(void) { #ifdef DEBUG - std::cerr << __FILE__ << ": real_run" << std::endl; + std::cerr << __FILE__ << ": real_run()" << std::endl; #endif // DEBUG - PlaQui::Server::Connection* conn; + Connection* connection; 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()); + connection = new_connection(socket.accept()); +#ifdef DEBUG + std::cerr << __FILE__ << ": real_run(): connection = " << connection + << std::endl; +#endif // DEBUG // TODO: poner lock. - connections.push_back(conn); + connections.push_back(connection); +#ifdef DEBUG + std::cerr << __FILE__ << ": real_run(): lista de conexiones" << std::endl; + for (ConnectionList::const_iterator i = connections.begin(); + i != connections.end(); i++) { + std::cerr << "\t " << *i << std::endl; + } +#endif // DEBUG // 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( + connection->signal_finished().connect( + SigC::bind( SigC::slot_class(*this, - &PlaQui::Server::TCPServer::on_connection_finished), - conn)); - conn->run(); + &TCPServer::on_connection_finished), + connection)); + connection->run(); } } diff --git a/Server/src/transmitter.cpp b/Server/src/transmitter.cpp index 268f216..75f622d 100644 --- a/Server/src/transmitter.cpp +++ b/Server/src/transmitter.cpp @@ -40,7 +40,7 @@ PlaQui::Server::Transmitter::~Transmitter(void) { /// \todo debría conectarse en real_run() (?) PlaQui::Server::Transmitter::Transmitter(std::string host, int port): - PlaQui::Server::Connection(sockbuf::sock_dgram) { + Connection(sockbuf::sock_dgram) { #ifdef DEBUG std::cerr << __FILE__ << ": host = " << host << " | port = " << port << std::endl; -- 2.43.0