From 26a6b739a38e928d005ac689e693a4d4dd7dc3ea Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 19 Aug 2008 07:50:47 +0000 Subject: Made the netcom object global, for socket reuse. --- client/macro.cc | 3 +-- client/macrowindow.cc | 45 +-------------------------------------------- client/netcom.cc | 2 ++ client/netcom.h | 4 ++++ client/pracro.cc | 6 ++++++ 5 files changed, 14 insertions(+), 46 deletions(-) (limited to 'client') diff --git a/client/macro.cc b/client/macro.cc index b0943d0..7f3286c 100644 --- a/client/macro.cc +++ b/client/macro.cc @@ -76,8 +76,7 @@ static MacroEventFilter *macro_event_filter = NULL; */ static void create_macro(QString course, QString macro) { - NetCom netcom(host, port, user, cpr); - QDomDocument xml_doc = netcom.send(course, macro); + QDomDocument xml_doc = Global::netcom->send(course, macro); cleanup_macros(); diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 6837e1d..e3d4846 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -130,50 +130,7 @@ bool MacroWindow::doCommit() if(faulty == 0) { printf("MacroWindow -> committing...\n"); -#if 0 - // Build the XML commit - QString xml_string; - xml_string.append("\n"); - xml_string.append("\n"); - xml_string.append(" \n"); - - // Iterate the different entries, and append their results to the commit string - QVector< Widget* >::iterator i = widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - - xml_string.append(" getName() - + "\" value=\"" + w->getValue() + "\"/>\n"); - i++; - } - - xml_string.append(" \n"); - xml_string.append("\n"); - - // Print commit to stdout for debug purposes - printf("%s\n", xml_string.toStdString().c_str()); - - // Convert the commit to Utf-8 charset - QByteArray xml_array = xml_string.toUtf8(); - QDomDocument xml_result; - - // Use setContent of QDomDocument to validate the xml commit - if (!xml_result.setContent(xml_array)) { - printf("Parse error: Invalid XML\n"); - } - - // Commit the xml data to the server - SendRecieve macro_commit(host, port); - macro_commit.makeConnection(&xml_result); - // Recieve answer from server whether successful or not - //QByteArray ba = macro_commit.getResult(); - QString ba = macro_commit.getResult(); - printf("Server returned result: %s", ba.toStdString().c_str()); -#endif/*0*/ - - NetCom netcom(host, port, user, cpr); - netcom.send(widgets, macro, version); + Global::netcom->send(widgets, macro, version); return true; } else { diff --git a/client/netcom.cc b/client/netcom.cc index cbe44d1..0f73e60 100644 --- a/client/netcom.cc +++ b/client/netcom.cc @@ -28,6 +28,8 @@ #include +NetCom *Global::netcom = NULL; + NetCom::NetCom(QString host, quint16 port, QString user, QString cpr) { this->user = user; diff --git a/client/netcom.h b/client/netcom.h index 18d6dbe..33a57f4 100644 --- a/client/netcom.h +++ b/client/netcom.h @@ -56,4 +56,8 @@ private: QString cpr; }; +namespace Global { + extern NetCom *netcom; +}; + #endif/*__PRACRO_NETCOM_H__*/ diff --git a/client/pracro.cc b/client/pracro.cc index 051fe2b..fdb0d7d 100644 --- a/client/pracro.cc +++ b/client/pracro.cc @@ -30,7 +30,9 @@ #include #include #include + #include "macro.h" +#include "netcom.h" #define VERSION "1.0" @@ -136,6 +138,8 @@ int main(int argc, char *argv[]) port = settings.value("port").toInt(); settings.endGroup(); + Global::netcom = new NetCom(host, port, user, cpr); + new_macro(course, macro); //app.setQuitOnLastWindowClosed(false); @@ -143,5 +147,7 @@ int main(int argc, char *argv[]) cleanup_macros(); + delete Global::netcom; + return ret; } -- cgit v1.2.3