summaryrefslogtreecommitdiff
path: root/server/src/session.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/session.cc')
-rw-r--r--server/src/session.cc22
1 files changed, 21 insertions, 1 deletions
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<std::string, Session *>::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;