diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/luaquerymapper.cc | 33 | ||||
-rw-r--r-- | server/src/luaquerymapper.h | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc index 7ee43ff..fdb1248 100644 --- a/server/src/luaquerymapper.cc +++ b/server/src/luaquerymapper.cc @@ -162,6 +162,39 @@ void LUAQueryMapper::error(std::string message) throw(Exception) throw Exception("ERROR in LUAQueryMapper: " + message); } +std::string LUAQueryMapper::automap(const std::string &name) +{ + std::string group; + std::string groupcheck = "if("; + + for(size_t i = 0; i < name.length(); i++) { + group += name[i]; + if(name[i] == '.') groupcheck += " and " + group; + else groupcheck += name[i]; + } + groupcheck += " and " + name + ".value and " + name + ".timestamp and " + name + ".source"; + groupcheck += ")\n"; + + std::string automapstring = + "-- Returning 0, 0 invalidates the result\n" + "value = 0\n" + "timestamp = 0\n" + "source = 0\n" + "\n" + + groupcheck + + "then\n" + " value = " + name + ".value\n" + " timestamp = " + name + ".timestamp\n" + " source = " + name + ".source\n" + "end\n" + "return value, timestamp, source\n"; + + PRACRO_DEBUG(widget, "Automap:\n%s\n", automapstring.c_str()); + + return automapstring; +} + + #ifdef TEST_LUAQUERYMAPPER int main() diff --git a/server/src/luaquerymapper.h b/server/src/luaquerymapper.h index e8a25f8..2d3e72d 100644 --- a/server/src/luaquerymapper.h +++ b/server/src/luaquerymapper.h @@ -71,6 +71,8 @@ public: */ void addQueryResult(QueryResult &result) throw(Exception); + std::string automap(const std::string &name); + private: void error(std::string message) throw(Exception); |