summaryrefslogtreecommitdiff
path: root/server/src/session.cc
diff options
context:
space:
mode:
authordeva <deva>2011-02-04 07:43:00 +0000
committerdeva <deva>2011-02-04 07:43:00 +0000
commitbfe5d3000182cb10db583fe42ffa7b48f84d8b5b (patch)
tree8b4228e258716267e854975df7f8a01294c89562 /server/src/session.cc
parentf825cb9f6f5a01f2029c79a363a89047b482c788 (diff)
Session locking mechanism gone crazy. This needs a rewamp at some point.
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;