From bfe5d3000182cb10db583fe42ffa7b48f84d8b5b Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 4 Feb 2011 07:43:00 +0000 Subject: Session locking mechanism gone crazy. This needs a rewamp at some point. --- server/src/session.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'server/src/session.cc') diff --git a/server/src/session.cc b/server/src/session.cc index 58249af..c919e54 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -51,6 +51,8 @@ Session::Session(std::string sessionid, std::string pid, std::string t) patientid = pid; templ = t; + + isreadonly = true; database()->setSessionId(sessionid); } @@ -76,6 +78,11 @@ void Session::unlock() mutex.unlock(); } +bool Session::active() +{ + return isreadonly || database()->active(); +} + void Session::commit() { if(_journal != NULL) { @@ -146,16 +153,29 @@ static bool fexists(const std::string &f) } Session *Sessions::newSession(std::string patientid, std::string templ) + throw(SessionAlreadyActive) { std::map::iterator i = sessions.begin(); while(i != sessions.end()) { if(i->second->patientid == patientid && i->second->templ == templ) { - return i->second; + Session *s = i->second; + if(s->active()) throw SessionAlreadyActive(s->id()); + return s; } + i++; } + { // Look up patientid / template tupple in session files. + SessionSerialiser ser(Conf::session_path); + Session *session = ser.findFromTupple(patientid, templ); + if(session) { + sessions[session->id()] = session; + return session; + } + } + Session *session = new Session("", patientid, templ); sessions[session->id()] = session; return session; -- cgit v1.2.3