From d22c5966c130ef7768bac7914cb4dafa74088036 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 16 May 2008 15:00:12 +0000 Subject: Worked on the connection of the various elements of the server. --- server/src/server.cc | 192 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 129 insertions(+), 63 deletions(-) (limited to 'server/src/server.cc') diff --git a/server/src/server.cc b/server/src/server.cc index f6c1771..4254f47 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -26,6 +26,9 @@ */ #include "server.h" +// For XML +#include + #include "tcpsocket.h" #include @@ -39,9 +42,134 @@ #include "transaction.h" #include "transactionparser.h" +#include "templateparser.h" +#include "queryhandler.h" +#include "queryparser.h" +#include "luaquerymapper.h" #include "database.h" +static void connection(TCPSocket &socket) +{ + Transaction t; + TransactionParser parser(socket, t); + parser.parse(); + + // Handle requests + Requests::iterator i = t.requests.begin(); + while(i != t.requests.end()) { + Request request = *i; + + // Read and parse the template file. + TemplateParser tp(XML"/example2.xml"); + tp.parse(); + + // Send the queries to Pentominos (if any) + TCPSocket s; + s.connect("localhost", 11108); + QueryHandler qh(&s, t.cpr); + std::string result = qh.exec(); + + // Parse the result from the queries to pentominos + QueryParser qp(result); + qp.parse(); + + // Map the results + LUAQueryMapper lqm(qp.result); + + + i++; + } + +} + + +void server() +{ + int port; + try { + port = config()->lookup("port"); + } catch( ... ) { + fprintf(stderr, "Could not read port."); + return; + } + + TCPSocket *socket; + + try { + socket = new TCPSocket(); + socket->listen(port); + } catch (Exception &e) { + fprintf(stderr, "Error during parsing:\n%s\n", + e.what()); + delete socket; + return; + } + + while(socket->connected()) { + + { // Reload if new port i assigned. + int old_port = port; + try { + port = config()->lookup("port"); + } catch( ... ) { + fprintf(stderr, "Could not read port."); + return; + } + + if(port != old_port) { + // Start listening on the new port + delete socket; + socket = new TCPSocket(); + socket->listen(port); + } + } + + TCPSocket child = socket->accept(); + if(child.connected()) { + switch(fork()) { + case -1: // error + fprintf(stderr, "Could not fork: %s\n", strerror(errno)); + break; + + case 0: // child + socket->disconnect(); + connection(child); + delete socket; + return; + + default: // parent + break; + } + } + } + + delete socket; + fprintf(stderr, "Oups... dropped out of the main loop\n"); +} + + + + + + + + + + + + + + + + +// +// +// OLD CODE! +// +// +#if 0 + #include "macro.h" #include "macro_parser.h" @@ -145,66 +273,4 @@ static void connection(TCPSocket &socket) printf("Done with connection.\n"); } -void server() -{ - int port; - try { - port = config()->lookup("port"); - } catch( ... ) { - fprintf(stderr, "Could not read port."); - return; - } - - TCPSocket *socket; - - try { - socket = new TCPSocket(); - socket->listen(port); - } catch (Exception &e) { - fprintf(stderr, "Error during parsing:\n%s\n", - e.what()); - delete socket; - return; - } - - while(socket->connected()) { - - { // Reload if new port i assigned. - int old_port = port; - try { - port = config()->lookup("port"); - } catch( ... ) { - fprintf(stderr, "Could not read port."); - return; - } - - if(port != old_port) { - // Start listening on the new port - delete socket; - socket = new TCPSocket(); - socket->listen(port); - } - } - - TCPSocket child = socket->accept(); - if(child.connected()) { - switch(fork()) { - case -1: // error - fprintf(stderr, "Could not fork: %s\n", strerror(errno)); - break; - - case 0: // child - socket->disconnect(); - connection(child); - delete socket; - return; - - default: // parent - break; - } - } - } - - delete socket; - fprintf(stderr, "Oups... dropped out of the main loop\n"); -} +#endif/*0*/ -- cgit v1.2.3