]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/server.cpp
Se agregan un par de mutex porque el server se muere con segmentation fault
[z.facultad/75.42/plaqui.git] / Server / src / server.cpp
index 6507d6d7862ac95365a2089390caa023eae6ad8a..134bcf517f9f1d386c1d8a75ea648c744a651e5d 100644 (file)
 //
 
 #include "plaqui/server/server.h"
 //
 
 #include "plaqui/server/server.h"
+#include "plaqui/server/connection.h"
+#include "plaqui/server/controlserver.h"
+#include <sigc++/class_slot.h>
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
 
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
 
-using namespace Plaqui;
+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):
+               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;
 }
+                       
+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
+       ControlServer* connection = new ControlServer(sd);
+       // TODO verificar si el new se hace bien? no creo.
+       connection->signal_command_received().connect(
+                       SigC::slot_class(*this, &Server::on_control_command_received));
+       // TODO: 
+       return connection;
+}
 
 
-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
 }
 
 }