summaryrefslogtreecommitdiff
path: root/server/src/server.cc
diff options
context:
space:
mode:
authordeva <deva>2008-05-16 15:00:12 +0000
committerdeva <deva>2008-05-16 15:00:12 +0000
commitd22c5966c130ef7768bac7914cb4dafa74088036 (patch)
tree9e0cffb41f582cdf01f592257dd6c85677241f2e /server/src/server.cc
parent3f2a5d6e373a79260594382c67d693d4b97c4ffa (diff)
Worked on the connection of the various elements of the server.
Diffstat (limited to 'server/src/server.cc')
-rw-r--r--server/src/server.cc192
1 files changed, 129 insertions, 63 deletions
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 <config.h>
+
#include "tcpsocket.h"
#include <errno.h>
@@ -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*/