summaryrefslogtreecommitdiff
path: root/server/src/sessionserialiser.cc
diff options
context:
space:
mode:
authordeva <deva>2010-06-10 07:03:06 +0000
committerdeva <deva>2010-06-10 07:03:06 +0000
commit198b0d886817f2c5bc97cfd11857d4b314dffae3 (patch)
tree4fc2d51de46ab69b9e67149abf0ab6a332032f27 /server/src/sessionserialiser.cc
parent730eb796bbce6f124be9194f1565b7dda1daddf1 (diff)
Add transaction support on database pr. pracro session. Makes it possible to discard all edited macros.
Diffstat (limited to 'server/src/sessionserialiser.cc')
-rw-r--r--server/src/sessionserialiser.cc27
1 files changed, 21 insertions, 6 deletions
diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc
index 10d449d..2c35d2a 100644
--- a/server/src/sessionserialiser.cc
+++ b/server/src/sessionserialiser.cc
@@ -30,6 +30,9 @@
#include "journalwriter.h"
#include "sessionparser.h"
+#include "database.h"
+
+#include "xml_encode_decode.h"
#include <stdio.h>
#include <string.h>
@@ -54,19 +57,25 @@ SessionSerialiser::SessionSerialiser(std::string path, Session *session)
this->path = path;
}
+#define XENC(s) xml_encode(s)
+#define XDEC(s) xml_decode(s)
+
void SessionSerialiser::loadStr(const std::string &xml)
{
// SessionAutolock lock(*session);
SessionParser parser;
parser.parse(xml.data(), xml.length());
+
JournalWriter *j = session->journal();
- j->currentuser = parser.userid;
- j->currentcpr = parser.patientid;
+ j->currentuser = XDEC(parser.userid);
+ j->currentcpr = XDEC(parser.patientid);
std::vector<SessionParser::Entry>::iterator i = parser.entries.begin();
while(i != parser.entries.end()) {
- j->addEntry(i->resume, i->macro, i->index);
+ j->addEntry(XDEC(i->resume), xml_decode(i->macro), i->index);
i++;
}
+
+ session->database()->restore(XDEC(parser.database));
}
std::string SessionSerialiser::saveStr()
@@ -81,8 +90,8 @@ std::string SessionSerialiser::saveStr()
JournalWriter *journal = session->journal();
- xml += " <journal patientid=\"" + journal->currentcpr +
- "\" userid=\"" + journal->currentuser + "\">\n";
+ xml += " <journal patientid=\"" + XENC(journal->currentcpr) +
+ "\" userid=\"" + XENC(journal->currentuser) + "\">\n";
std::map< int, JournalWriter::ResumeEntry >::iterator i =
journal->entrylist.begin();
@@ -90,13 +99,19 @@ std::string SessionSerialiser::saveStr()
xml += " <entry index=\""+itostr(i->first) + "\""
" macro=\"" + i->second.macro + "\">\n";
- xml += " <resume>" + i->second.resume + "</resume>\n";
+ xml += " <resume>" + XENC(i->second.resume) + "</resume>\n";
xml += " </entry>\n";
i++;
}
xml += " </journal>\n";
+
+ std::string dbtype = "pgsql";
+ xml += " <database type=\""+dbtype+"\">"+
+ XENC(session->database()->serialise())+
+ "</database>\n";
+
xml += "</session>\n";
return xml;