diff options
author | deva <deva> | 2010-05-27 09:40:55 +0000 |
---|---|---|
committer | deva <deva> | 2010-05-27 09:40:55 +0000 |
commit | 3d48d173bc89b8868bf28f22d875ff0667a24021 (patch) | |
tree | cbbcc672d448b5e3fcabcc31249f7acdf781f79e | |
parent | ad98026d4a949c62f7361fd41f366e8483f76946 (diff) |
New commit/discard methods
-rw-r--r-- | client/netcom.cc | 54 | ||||
-rw-r--r-- | client/netcom.h | 17 |
2 files changed, 46 insertions, 25 deletions
diff --git a/client/netcom.cc b/client/netcom.cc index 4deba49..918b8e7 100644 --- a/client/netcom.cc +++ b/client/netcom.cc @@ -46,11 +46,8 @@ #endif #endif -NetCom::NetCom(QString host, quint16 port, QString user, QString cpr) +NetCom::NetCom(QString host, quint16 port) { - this->user = user; - this->cpr = cpr; - // // Setup connection // @@ -65,20 +62,11 @@ NetCom::NetCom(QString host, quint16 port, QString user, QString cpr) manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); - - QDomDocument doc; - makeTransfer(doc, false, true); } NetCom::~NetCom() { // - // Send commit - // - QDomDocument doc; - makeTransfer(doc, true, true); - - // // Clean up // delete manager; @@ -89,7 +77,8 @@ void NetCom::replyFinished(QNetworkReply *reply) finished[reply] = true; } -QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool commit, bool lockgui) +QDomDocument NetCom::makeTransfer(QDomDocument &doc, + bool commit, bool lockgui, bool discard) { printf("\nMaking transfer:\n%s", doc.toString().toStdString().c_str()); @@ -98,7 +87,13 @@ QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool commit, bool lockgui) if(sessionid != "") request.setRawHeader("SessionID", sessionid.toStdString().c_str()); - if(commit) request.setRawHeader("SessionCommit", "yes"); + if(commit) { + request.setRawHeader("SessionCommit", "yes"); + } + + if(discard) { + request.setRawHeader("SessionDiscard", "yes"); + } // QNetworkReply *reply = manager->get(request); QNetworkReply *reply = manager->post(request, doc.toByteArray()); @@ -108,10 +103,13 @@ QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool commit, bool lockgui) } finished.remove(reply); + QByteArray data = reply->readAll(); QDomDocument res_doc; - res_doc.setContent(reply->readAll()); + res_doc.setContent(data); + + printf("\nRecieved reponse:\n%s", data.data()); - printf("\nRecieved repons:\n%s", res_doc.toString().toStdString().c_str()); + printf("\nRecieved reponse (Parsed):\n%s", res_doc.toByteArray().data()); if(reply->hasRawHeader("SessionID")) { sessionid = reply->rawHeader("SessionID"); @@ -124,6 +122,24 @@ QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool commit, bool lockgui) return res_doc; } +QDomDocument NetCom::initConnection() +{ + QDomDocument doc; + return makeTransfer(doc, false, true); +} + +QDomDocument NetCom::commit() +{ + QDomDocument doc; + return makeTransfer(doc, true, true); +} + +QDomDocument NetCom::discard() +{ + QDomDocument doc; + return makeTransfer(doc, false, true, true); +} + QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) { QDomDocument doc; @@ -134,7 +150,7 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui) QDomElement pracro_elem = doc.createElement("pracro"); pracro_elem.setAttribute("version", "1.0"); - pracro_elem.setAttribute("cpr", cpr); + pracro_elem.setAttribute("cpr", patientid); pracro_elem.setAttribute("user", user); doc.appendChild(pracro_elem); @@ -157,7 +173,7 @@ QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ, QDomElement pracro_elem = doc.createElement("pracro"); pracro_elem.setAttribute("version", "1.0"); - pracro_elem.setAttribute("cpr", cpr); + pracro_elem.setAttribute("cpr", patientid); pracro_elem.setAttribute("user", user); doc.appendChild(pracro_elem); diff --git a/client/netcom.h b/client/netcom.h index d890cb0..88b604e 100644 --- a/client/netcom.h +++ b/client/netcom.h @@ -42,28 +42,33 @@ class Widget; class NetCom : public QObject { Q_OBJECT public: - NetCom(QString host, quint16 port, QString user, QString cpr); + NetCom(QString host, quint16 port); ~NetCom(); QDomDocument send(QString templ, QString macro = "", bool lockgui = true); QDomDocument send(QVector< Widget* > widgets, QString templ, QString macro, QString version); + QDomDocument initConnection(); + QDomDocument commit(); + QDomDocument discard(); + + QString sessionid; + QString user; + QString patientid; public slots: void replyFinished(QNetworkReply*); private: - QString user; - QString cpr; - QNetworkAccessManager *manager; QNetworkRequest request; - QString sessionid; + // QString sessionid; QMap<QNetworkReply *, bool> finished; - QDomDocument makeTransfer(QDomDocument &dom, bool commit, bool lockgui); + QDomDocument makeTransfer(QDomDocument &dom, + bool commit, bool lockgui, bool discard = false); }; #endif/*__PRACRO_NETCOM_H__*/ |