From 87e733a200df0965073226f5bc62da980cbddb21 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 19 Oct 2011 20:52:10 +0000
Subject: [PATCH] all the old client-server code has been ported to onelab...
 need some serious testing now!

---
 Common/Gmsh.cpp        |  2 --
 Common/GmshMessage.cpp | 31 ++++++-------------------------
 Common/GmshMessage.h   |  4 +---
 Common/GmshRemote.cpp  |  2 +-
 Common/onelab.h        |  3 ++-
 Fltk/Main.cpp          |  2 +-
 Fltk/menuWindow.cpp    |  2 +-
 Fltk/onelabWindow.cpp  |  2 --
 Post/PViewDataRemote.h |  2 +-
 9 files changed, 13 insertions(+), 37 deletions(-)

diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp
index c676b9732f..5890ce3c52 100644
--- a/Common/Gmsh.cpp
+++ b/Common/Gmsh.cpp
@@ -197,8 +197,6 @@ int GmshBatch()
   currtime.resize(currtime.size() - 1);
   Msg::Info("Stopped on %s", currtime.c_str());
 
-  Msg::FinalizeClient();
-
   return 1;
 }
 
diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 5988a5894c..532f894c99 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -574,36 +574,16 @@ int Msg::GetAnswer(const char *question, int defaultval, const char *zero,
     return atoi(ret);
 }
 
-void Msg::InitClient(std::string sockname)
-{
-  if(_client) delete _client;
-  _client = new GmshClient();
-  if(_client->Connect(sockname.c_str()) < 0){
-    Msg::Error("Unable to connect to server on %s", sockname.c_str());
-    delete _client;
-    _client = 0;
-  }
-  else
-    _client->Start();
-}
-
-void Msg::FinalizeClient()
-{
-  if(_client){
-    _client->Stop();
-    _client->Disconnect();
-    delete _client;
-  }
-  _client = 0;
-}
-
 void Msg::InitializeOnelab(const std::string &name, const std::string &sockname)
 {
   if(_onelabClient) delete _onelabClient;
   if (sockname.empty())
     _onelabClient = new onelab::localClient(name);
-  else
-    _onelabClient = new onelab::remoteNetworkClient(name, sockname);
+  else{
+    onelab::remoteNetworkClient *c = new onelab::remoteNetworkClient(name, sockname);
+    _onelabClient = c;
+    _client = c->getGmshClient();
+  }
 }
 
 void Msg::ExchangeOnelabParameter(const std::string &key,
@@ -657,6 +637,7 @@ void Msg::FinalizeOnelab()
   if(_onelabClient){
     delete _onelabClient;
     _onelabClient = 0;
+    _client = 0;
   }
 }
 
diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h
index 868496348b..10c99dcda9 100644
--- a/Common/GmshMessage.h
+++ b/Common/GmshMessage.h
@@ -81,10 +81,8 @@ class Msg {
   static std::string GetString(const char *text, std::string defaultval);
   static int GetAnswer(const char *question, int defaultval, const char *zero, 
                        const char *one, const char *two=0);
-  static void InitClient(std::string sockname);
-  static GmshClient *GetClient(){ return _client; }
-  static void FinalizeClient();
   static void InitializeOnelab(const std::string &name, const std::string &sockname="");
+  static GmshClient *GetGmshClient(){ return _client; }
   static void FinalizeOnelab();
   static bool UseOnelab(){ return _onelabClient ? true : false; }
   static void ExchangeOnelabParameter(const std::string &key, 
diff --git a/Common/GmshRemote.cpp b/Common/GmshRemote.cpp
index f00d82943d..d26315466c 100644
--- a/Common/GmshRemote.cpp
+++ b/Common/GmshRemote.cpp
@@ -168,7 +168,7 @@ static void gatherAndSendVertexArrays(GmshClient* client, bool swap)
 
 int GmshRemote()
 {
-  GmshClient *client = Msg::GetClient();
+  GmshClient *client = Msg::GetGmshClient();
 
   int rank = Msg::GetCommRank();
   int nbDaemon = Msg::GetCommSize();
diff --git a/Common/onelab.h b/Common/onelab.h
index 3c81032c1f..3f88b7c48d 100644
--- a/Common/onelab.h
+++ b/Common/onelab.h
@@ -589,7 +589,7 @@ namespace onelab{
     void setSocketSwitch(const std::string &s){ _socketSwitch = s; }
     int getPid(){ return _pid; }
     void setPid(int pid){ _pid = pid; }
-    GmshServer const *getServer(){ return _gmshServer; }
+    GmshServer *getGmshServer(){ return _gmshServer; }
     void setServer(GmshServer *server){ _gmshServer = server; }
     virtual bool run(const std::string &what);
     virtual bool kill();
@@ -678,6 +678,7 @@ namespace onelab{
         _gmshClient = 0;
       }
     }
+    GmshClient *getGmshClient(){ return _gmshClient; }
     virtual bool isNetworkClient(){ return true; }
     virtual bool set(number &p, bool value=true){ return _set(p); }
     virtual bool set(string &p, bool value=true){ return _set(p); }
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index dd2bb166a6..7ffc64f3c4 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
 
   // Non-interactive Gmsh
   if(CTX::instance()->batch) {
-    if(!Msg::GetClient()) CTX::instance()->terminal = 1;
+    if(!Msg::GetGmshClient()) CTX::instance()->terminal = 1;
     GmshBatch();
     GmshFinalize();
     Msg::Exit(0);
diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp
index b238e2bb25..39cc74c319 100644
--- a/Fltk/menuWindow.cpp
+++ b/Fltk/menuWindow.cpp
@@ -174,7 +174,7 @@ static void file_remote_cb(Fl_Widget *w, void *data)
   }
   else
     c = (onelab::localNetworkClient*)it->second;
-  GmshServer *server = (GmshServer*)c->getServer();
+  GmshServer *server = c->getGmshServer();
   
   std::string str((const char*)data);
 
diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp
index 56549836b3..5c20460fab 100644
--- a/Fltk/onelabWindow.cpp
+++ b/Fltk/onelabWindow.cpp
@@ -237,7 +237,6 @@ bool onelab::localNetworkClient::run(const std::string &what)
       Msg::Info("got %d Mb message in %g seconds",
                 length / 1024 / 1024, GetTimeInSeconds() - timer);
       break;
-    /* FIXME PViewDataRemote should store the onelab::localNetworkClient
     case GmshSocket::GMSH_VERTEX_ARRAY:
       {
         int n = PView::list.size();
@@ -246,7 +245,6 @@ bool onelab::localNetworkClient::run(const std::string &what)
         drawContext::global()->draw();
       }
       break;
-    */
     default:
       Msg::Warning("Received unknown message type (%d)", type);
       break;
diff --git a/Post/PViewDataRemote.h b/Post/PViewDataRemote.h
index 3716200774..4e9f10c1de 100644
--- a/Post/PViewDataRemote.h
+++ b/Post/PViewDataRemote.h
@@ -49,7 +49,7 @@ class PViewDataRemote : public PViewData {
   bool isRemote(){ return true; }
   int fillRemoteVertexArrays(std::string &options)
   {
-    GmshServer *server = (GmshServer*)_remote->getServer();
+    GmshServer *server = _remote->getGmshServer();
     if(!server){
       Msg::Error("Remote server not running: please start server");
       return 1;
-- 
GitLab