diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2011-10-19 10:47:42 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2011-10-19 10:47:42 +0200 |
commit | 158aadf2a79a109f56866f2cc2da1d16ca4051a7 (patch) | |
tree | 21cb3f4f7e096f3fc798e66ec3a162c694b9465a | |
parent | 611f9ce04145d9934dc3c8dc451f0a38721f89dc (diff) |
Make error handling for sync connection.
-rw-r--r-- | client/luapraxisd.cc | 10 | ||||
-rw-r--r-- | client/praxisd.cc | 37 | ||||
-rw-r--r-- | client/praxisd.h | 12 |
3 files changed, 58 insertions, 1 deletions
diff --git a/client/luapraxisd.cc b/client/luapraxisd.cc index 0696674..11d619e 100644 --- a/client/luapraxisd.cc +++ b/client/luapraxisd.cc @@ -52,6 +52,11 @@ static int px_getcave(lua_State *L) QVector<QString> cavelist; Patient patient = pxu->px->patient_get_by_cpr(cpr); + if(pxu->px->hasError()) { + lua_pushstring(L, pxu->px->errorString().toStdString().c_str()); + lua_error(L); + return 1; + } QVector<sogeord_t>::iterator i = patient.sogeord.begin(); while(i != patient.sogeord.end()) { QString cavesogeord = i->sogenr;//.mid(1, i->sogenr.size() - 1); @@ -81,6 +86,11 @@ static int px_cavelist(lua_State *L) luaL_argcheck(L, pxu, 1, "Praxisd expected"); QVector<cave_t> cavelist = pxu->px->diverse_get_cave(""); + if(pxu->px->hasError()) { + lua_pushstring(L, pxu->px->errorString().toStdString().c_str()); + lua_error(L); + return 1; + } lua_createtable(L, 0, cavelist.size()); int top = lua_gettop(L); diff --git a/client/praxisd.cc b/client/praxisd.cc index 740825e..5a0d88e 100644 --- a/client/praxisd.cc +++ b/client/praxisd.cc @@ -295,14 +295,25 @@ PraxisdSync::PraxisdSync(QString host, unsigned short int port) { this->host = host; this->port = port; + this->running = true; start(); } +PraxisdSync::~PraxisdSync() +{ + this->running = false; + wsem.release(); + wait(); +} + void PraxisdSync::run() { Praxisd praxisd(host, port); + connect(&praxisd, SIGNAL(networkError(QString)), + this, SLOT(networkError(QString)), Qt::DirectConnection); + connect(&praxisd, SIGNAL(gotCaveList(CaveVector)), this, SLOT(gotCaveList(CaveVector)), Qt::DirectConnection); @@ -314,7 +325,13 @@ void PraxisdSync::run() while(true) { wsem.acquire(); + + // Reset error state + error = false; + errorStr = ""; + if(this->running == false) break; + switch(request_type) { case Praxisd::journal: break; @@ -333,6 +350,26 @@ void PraxisdSync::run() exec(); } + + rsem.release(); +} + +bool PraxisdSync::hasError() +{ + return error; +} + +QString PraxisdSync::errorString() +{ + return errorStr; +} + +void PraxisdSync::networkError(QString err) +{ + error = true; + errorStr = err; + rsem.release(); + quit(); } void PraxisdSync::gotCaveList(CaveVector cl) diff --git a/client/praxisd.h b/client/praxisd.h index 1268be7..0989274 100644 --- a/client/praxisd.h +++ b/client/praxisd.h @@ -156,6 +156,7 @@ class PraxisdSync : public QThread { Q_OBJECT public: PraxisdSync(QString host, unsigned short int port); + ~PraxisdSync(); QString journal_get_by_cpr(QString patientid); CaveVector diverse_get_cave(QString sogenr); @@ -163,9 +164,13 @@ public: DokMenuVector dokmenu_get_all_by_cpr(QString cpr); QString dokmenu_get_by_cpr_and_name(QString cpr, QString name); + bool hasError(); + QString errorString(); + void run(); -public slots: +private slots: + void networkError(QString); void gotCaveList(CaveVector); void gotPatient(Patient); void gotDokMenu(DokMenuVector); @@ -184,6 +189,11 @@ private: CaveVector cavelist; Patient patient; DokMenuVector dokmenu; + + volatile bool running; + + bool error; + QString errorStr; }; #endif/*__PRACRO_PRAXISD_H__*/ |