diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/configuration.cc | 4 | ||||
-rw-r--r-- | server/src/luaquerymapper.cc | 19 | ||||
-rw-r--r-- | server/src/luaquerymapper.h | 4 | ||||
-rw-r--r-- | server/src/server.cc | 44 |
4 files changed, 41 insertions, 30 deletions
diff --git a/server/src/configuration.cc b/server/src/configuration.cc index 33f3256..8e932d1 100644 --- a/server/src/configuration.cc +++ b/server/src/configuration.cc @@ -33,8 +33,8 @@ std::string Conf::server_group = "pracro"; std::string Conf::journal_commit_addr = "localhost"; port_t Conf::journal_commit_port = 18112; -time_t Conf::db_max_ttl = 60 * 60 * 24; -time_t Conf::pentominos_max_ttl = 60 * 60 * 24; +time_t Conf::db_max_ttl = 7 * 60 * 60 * 24; +time_t Conf::pentominos_max_ttl = 7 * 60 * 60 * 24; std::string Conf::pentominos_addr = "localhost"; port_t Conf::pentominos_port = 11108; diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc index acd6b26..9f8293d 100644 --- a/server/src/luaquerymapper.cc +++ b/server/src/luaquerymapper.cc @@ -53,7 +53,7 @@ static std::string loadresultstring(QueryResult &res, std::string group = "") return s; } -LUAQueryMapper::LUAQueryMapper(QueryResult &res) +LUAQueryMapper::LUAQueryMapper() { L = luaL_newstate(); if(L == NULL) { @@ -63,7 +63,17 @@ LUAQueryMapper::LUAQueryMapper(QueryResult &res) luaL_openlibs(L); - std::string preload = loadresultstring(res); + clean_top = lua_gettop(L); +} + +LUAQueryMapper::~LUAQueryMapper() +{ + lua_close(L); +} + +void LUAQueryMapper::addQueryResult(QueryResult &result) +{ + std::string preload = loadresultstring(result); if(luaL_loadbuffer(L, preload.c_str(), preload.size(), "preload")) { error(lua_tostring(L, lua_gettop(L))); @@ -79,11 +89,6 @@ LUAQueryMapper::LUAQueryMapper(QueryResult &res) clean_top = lua_gettop(L); } -LUAQueryMapper::~LUAQueryMapper() -{ - lua_close(L); -} - Value LUAQueryMapper::map(const std::string &mapper) { Value v; diff --git a/server/src/luaquerymapper.h b/server/src/luaquerymapper.h index 685abe7..4648606 100644 --- a/server/src/luaquerymapper.h +++ b/server/src/luaquerymapper.h @@ -41,7 +41,7 @@ */ class LUAQueryMapper { public: - LUAQueryMapper(QueryResult &res); + LUAQueryMapper(); ~LUAQueryMapper(); /** @@ -52,6 +52,8 @@ public: void error(std::string message); + void addQueryResult(QueryResult &result); + private: lua_State *L; int clean_top; diff --git a/server/src/server.cc b/server/src/server.cc index b98cc94..5d72098 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -137,15 +137,6 @@ static std::string handleTransaction(Transaction &transaction) else answer += "\"false\""; answer += ">\n"; - /////////////////////////////// - // Send the queries to Pentominos (if any) - TCPSocket s; -#ifndef WITHOUT_PENTOMINOS - s.connect(Conf::pentominos_addr, Conf::pentominos_port); -#endif/*WITHOUT_PENTOMINOS*/ - QueryHandler qh(&s, transaction.cpr); - /////////////////////////////// - if(macro.attributes["name"] == request.macro) { foundmacro = true; @@ -154,15 +145,36 @@ static std::string handleTransaction(Transaction &transaction) mp.parse(); Macro *m = mp.getMacro(); + LUAQueryMapper lqm; + //////////////////////// std::vector< Query >::iterator qi = m->queries.begin(); while(qi != m->queries.end()) { + /////////////////////////////// + // Send the queries to Pentominos (if any) + TCPSocket s; +#ifndef WITHOUT_PENTOMINOS + s.connect(Conf::pentominos_addr, Conf::pentominos_port); +#endif/*WITHOUT_PENTOMINOS*/ + QueryHandler qh(&s, transaction.cpr); + /////////////////////////////// + qh.addQuery(*qi); + + std::string result = qh.exec(); + printf("Got result: [%s]\n", result.c_str()); + ///////////////////////// + + ///////////////////////// + // Parse the result from the queries to pentominos + QueryParser qp(result); + qp.parse(); + // Map the results + lqm.addQueryResult(qp.result); + //////////////////////// + qi++; } - std::string result = qh.exec(); - printf("Got result: [%s]\n", result.c_str()); - ///////////////////////// // Handle scripts if(m->scripts.size()) { @@ -179,14 +191,6 @@ static std::string handleTransaction(Transaction &transaction) answer += " </scripts>\n"; } - ///////////////////////// - // Parse the result from the queries to pentominos - QueryParser qp(result); - qp.parse(); - // Map the results - LUAQueryMapper lqm(qp.result); - //////////////////////// - answer += widgetgenerator(transaction.cpr, *m, lqm, db); } answer += " </macro>\n"; |