summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2011-06-28 06:35:55 +0000
committerdeva <deva>2011-06-28 06:35:55 +0000
commit01febc40e2aad29bf6cf6cbeb457c44354aba0f9 (patch)
treeee86654206054f96e0dbad66bd294890df6a0e7f
parent91a243b89ce1a00a9167f95de4c4fd8c62769391 (diff)
Added praxisd accessibility through lua.
-rw-r--r--client/client.pro14
-rw-r--r--client/lua.cc2
-rw-r--r--client/luapraxisd.cc152
-rw-r--r--client/luapraxisd.h35
4 files changed, 203 insertions, 0 deletions
diff --git a/client/client.pro b/client/client.pro
index 9f4de5f..1481204 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -31,6 +31,18 @@ win32 {
unix {
LIBS += -llua
+ LIBS += -lcurl -lexpat
+
+ HEADERS += \
+ ../server/src/praxisd.h \
+ ../server/src/saxparser.h \
+ ../server/src/debug.h
+
+ SOURCES += \
+ ../server/src/praxisd.cc \
+ ../server/src/saxparser.cc
+
+ DEFINES += WITH_PRAXISD
}
HEADERS += \
@@ -41,6 +53,7 @@ HEADERS += \
launcherwindow.h \
lua.h \
luadb.h \
+ luapraxisd.h \
luawidget.h \
macro.h \
macrowindow.h \
@@ -79,6 +92,7 @@ SOURCES += \
launcherwindow.cc \
lua.cc \
luadb.cc \
+ luapraxisd.cc \
luawidget.cc \
macro.cc \
macrowindow.cc \
diff --git a/client/lua.cc b/client/lua.cc
index 5d6b194..48840ce 100644
--- a/client/lua.cc
+++ b/client/lua.cc
@@ -32,6 +32,7 @@
#include "luawidget.h"
#include "luadb.h"
+#include "luapraxisd.h"
#include "debug.h"
@@ -235,6 +236,7 @@ void LUA::clear()
register_widgets(L);
register_db(L);
+ register_praxisd(L);
}
QString LUA::runScriptS(QString script, Widget *widget, QString name)
diff --git a/client/luapraxisd.cc b/client/luapraxisd.cc
new file mode 100644
index 0000000..1d9da4c
--- /dev/null
+++ b/client/luapraxisd.cc
@@ -0,0 +1,152 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * luapraxisd.cc
+ *
+ * Thu May 5 11:16:20 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "luapraxisd.h"
+
+#ifdef WITH_PRAXISD
+
+#include "../server/src/praxisd.h"
+
+#include <lauxlib.h>
+#include <strings.h>
+
+#include "debug.h"
+
+#define luaL_checkbool(L, i) \
+ (lua_isboolean(L,i) ? lua_toboolean(L,i) : luaL_checkint(L,i))
+
+typedef struct px_userdata {
+ Praxisd *px;
+} px_userdata;
+
+static int px_getcave(lua_State *L)
+{
+ px_userdata *pxu;
+ pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd");
+ luaL_argcheck(L, pxu, 1, "Praxisd expected");
+
+ const char *cpr = luaL_checkstring(L, 2);
+
+ QVector<QString> cavelist;
+
+ Praxisd::patient_t patient = pxu->px->patient_get_by_cpr(cpr);
+ std::vector<Praxisd::sogeord_t>::iterator i = patient.sogeord.begin();
+ while(i != patient.sogeord.end()) {
+ std::string cavesogeord = i->sogenr.substr(1, i->sogenr.size() - 1);
+ std::vector<Praxisd::cave_t> cave = pxu->px->diverse_get_cave(cavesogeord);
+ if(cave.size() == 1) {
+ if(cave[0].cave != "ANDET") cavelist.push_back(cave[0].cave.c_str());
+ else cavelist.push_back(i->sogetxt.c_str());
+ }
+ i++;
+ }
+
+ lua_createtable(L, 0, cavelist.size());
+ int top = lua_gettop(L);
+
+ for(int i = 0; i < cavelist.size(); i++) {
+ lua_pushstring(L, QString::fromUtf8(cavelist[i].toStdString().c_str()).toStdString().c_str());
+ lua_rawseti(L, top, i);
+ }
+
+ return 1;
+}
+
+static int px_cavelist(lua_State *L)
+{
+ px_userdata *pxu;
+ pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd");
+ luaL_argcheck(L, pxu, 1, "Praxisd expected");
+
+ std::vector<Praxisd::cave_t> cavelist = pxu->px->diverse_get_cave("");
+
+ lua_createtable(L, 0, cavelist.size());
+ int top = lua_gettop(L);
+
+ for(size_t i = 0; i < cavelist.size(); i++) {
+ lua_pushstring(L, QString::fromUtf8(cavelist[i].cave.c_str()).toStdString().c_str());
+ lua_rawseti(L, top, i);
+ }
+
+ return 1;
+}
+
+static int px_new(lua_State *L)
+{
+ const char *host = luaL_checkstring(L, 1);
+ int port = luaL_checknumber(L, 2);
+
+ px_userdata *pxu;
+ pxu = (px_userdata *)lua_newuserdata(L, sizeof(px_userdata));
+
+ luaL_getmetatable(L, "Praxisd");
+ lua_setmetatable(L, -2);
+
+ pxu->px = new Praxisd(host, port);
+
+ return 1;
+}
+
+static int px_gc(lua_State *L)
+{
+ px_userdata *pxu;
+
+ pxu = (px_userdata *)luaL_checkudata(L, 1, "Praxisd");
+ luaL_argcheck(L, pxu, 1, "Praxisd expected");
+
+ delete pxu->px;
+
+ return 0;
+}
+
+static const struct luaL_Reg px_meths[] = {
+ {"__gc" ,px_gc},
+ {"cavelist", px_cavelist},
+ {"getcave", px_getcave},
+ {NULL, NULL}
+};
+
+static const struct luaL_reg px_funcs[] = {
+ {"new", px_new},
+ {NULL, NULL}
+};
+
+void register_praxisd(lua_State *L)
+{
+ luaL_newmetatable(L, "Praxisd");
+ lua_pushliteral(L, "__index");
+ lua_pushvalue(L, -2);
+ lua_rawset(L, -3);
+ luaL_register(L, NULL, px_meths);
+ luaL_openlib (L, "Praxisd", px_funcs, 0);
+}
+
+#else/*WITH_PRAXISD*/
+
+void register_praxisd(lua_State *L){}
+
+#endif/*WITH_PRAXISD*/
diff --git a/client/luapraxisd.h b/client/luapraxisd.h
new file mode 100644
index 0000000..86be31f
--- /dev/null
+++ b/client/luapraxisd.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * luapraxisd.h
+ *
+ * Thu May 5 11:16:20 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_LUAPRAXISD_H__
+#define __PRACRO_LUAPRAXISD_H__
+
+#include <lua.hpp>
+
+void register_praxisd(lua_State *L);
+
+#endif/*__PRACRO_LUAPRAXISD_H__*/