summaryrefslogtreecommitdiff
path: root/client/netcom.cc
diff options
context:
space:
mode:
authordeva <deva>2011-03-10 08:45:16 +0000
committerdeva <deva>2011-03-10 08:45:16 +0000
commitded5e8cd771c9affef086b77e25c93b4868f3f29 (patch)
tree537bec9b557ca9bd2ba6e5429434fdc0250f1e8d /client/netcom.cc
parentd8a34adcc1a69a2b77881a6e504d0f0ad896eb3a (diff)
Callback based client implementation is now finished. Testing is up.
Diffstat (limited to 'client/netcom.cc')
-rw-r--r--client/netcom.cc83
1 files changed, 32 insertions, 51 deletions
diff --git a/client/netcom.cc b/client/netcom.cc
index 9d9a5bb..0680f8c 100644
--- a/client/netcom.cc
+++ b/client/netcom.cc
@@ -54,9 +54,6 @@ NetCom::NetCom(QWidget *wdg, QString host, quint16 port)
{
this->wdg = wdg;
- //
- // Setup connection
- //
QUrl url;
url.setHost(host);
url.setPort(port);
@@ -72,25 +69,30 @@ NetCom::NetCom(QWidget *wdg, QString host, quint16 port)
NetCom::~NetCom()
{
- //
- // Clean up
- //
delete manager;
}
void NetCom::replyFinished(QNetworkReply *reply)
{
- finished[reply] = true;
+ if(reply->error() == QNetworkReply::NoError) {
+ if(reply->hasRawHeader("SessionID")) {
+ sessionid = reply->rawHeader("SessionID");
+ LOG(netcom, "Reply SESSION ID: %s\n", sessionid.toStdString().c_str());
+ }
+
+ QDomDocument doc;
+ doc.setContent(reply->readAll());
+ emit gotReply(doc);
+
+ } else {
+ emit networkError("Network Error", reply->errorString());
+ }
}
-QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool lockgui,
- session_state_t state)
+void NetCom::makeTransfer(QDomDocument &doc, session_state_t state)
{
DEBUG(netcom, "Making transfer:\n%s", doc.toString().toStdString().c_str());
- if(lockgui && wdg) wdg->setEnabled(false);
- if(lockgui) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-
LOG(netcom, "SESSION ID: %s\n", sessionid.toStdString().c_str());
request.setRawHeader("User-Agent", "Pracro Client v"VERSION);
@@ -117,58 +119,33 @@ QDomDocument NetCom::makeTransfer(QDomDocument &doc, bool lockgui,
break;
}
- // QNetworkReply *reply = manager->get(request);
- QNetworkReply *reply = manager->post(request, doc.toByteArray());
- finished[reply] = false;
- while(finished[reply] == false) {
- qApp->processEvents(QEventLoop::WaitForMoreEvents, 100);
- }
- finished.remove(reply);
-
- QByteArray data = reply->readAll();
- QDomDocument res_doc;
- res_doc.setContent(data);
-
- DEBUG(netcom, "Recieved reponse:\n%s", data.data());
-
- DEBUG(netcom, "Recieved reponse (Parsed):\n%s", res_doc.toByteArray().data());
-
- if(reply->hasRawHeader("SessionID")) {
- sessionid = reply->rawHeader("SessionID");
- LOG(netcom, "Reply SESSION ID: %s\n", sessionid.toStdString().c_str());
- }
-
- if(lockgui) QApplication::restoreOverrideCursor();
- if(lockgui && wdg) wdg->setEnabled(true);
-
- return res_doc;
+ manager->post(request, doc.toByteArray());
}
-QDomDocument NetCom::initConnection()
+void NetCom::initConnection()
{
- QDomDocument doc;
- return makeTransfer(doc, true);
+ send(templ); // Initialise by sending a template-only request.
}
-QDomDocument NetCom::commit()
+void NetCom::commit()
{
QDomDocument doc;
- return makeTransfer(doc, true, ::commit);
+ makeTransfer(doc, ::commit);
}
-QDomDocument NetCom::nocommit()
+void NetCom::nocommit()
{
QDomDocument doc;
- return makeTransfer(doc, true, ::nocommit);
+ makeTransfer(doc, ::nocommit);
}
-QDomDocument NetCom::discard()
+void NetCom::discard()
{
QDomDocument doc;
- return makeTransfer(doc, true, ::discard);
+ makeTransfer(doc, ::discard);
}
-QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
+void NetCom::send(QString templ, QString macro)
{
QDomDocument doc;
@@ -187,11 +164,11 @@ QDomDocument NetCom::send(QString templ, QString macro, bool lockgui)
if(macro != "") request_elem.setAttribute("macro", macro);
pracro_elem.appendChild(request_elem);
- return makeTransfer(doc, lockgui);
+ makeTransfer(doc);
}
-QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ,
- QString macro, QString version)
+void NetCom::send(QVector< Widget* > widgets, QString templ,
+ QString macro, QString version)
{
QDomDocument doc;
@@ -229,6 +206,10 @@ QDomDocument NetCom::send(QVector< Widget* > widgets, QString templ,
}
i++;
}
+
+ QDomElement request_elem = doc.createElement("request");
+ request_elem.setAttribute("template", templ);
+ pracro_elem.appendChild(request_elem);
- return makeTransfer(doc, true);
+ makeTransfer(doc);
}