diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp index dd192bbe18effb2728d0308c8478d2fc3898486c..1c26a2b39e059818dd0d097af3a5fc8f2d765faa 100644 --- a/Common/Gmsh.cpp +++ b/Common/Gmsh.cpp @@ -54,10 +54,7 @@ #endif #if defined(HAVE_ONELAB2) -#include "OnelabDatabase.h" -#include "NetworkUtils.h" - -OnelabDatabase *OnelabDatabase::_instance = NULL; +#include "OnelabServer.h" #endif int GmshInitialize(int argc, char **argv) @@ -207,10 +204,6 @@ int GmshBatch() OnelabServer::instance()->Run(); Msg::Exit(0); } - - if(CTX::instance()->onelab.server_ip[0] != '\0' && CTX::instance()->onelab.server_port > 0) { - OnelabDatabase::instance()->useAsNetworkClient(ip4_inet_pton(CTX::instance()->onelab.server_ip), CTX::instance()->onelab.server_port, "Gmsh"); - } #endif OpenProject(GModel::current()->getFileName()); diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 437d9a5ec43afd1bacd7811323c2cf161faa4021..66851fa8aa7542eea2b69d7d2fbea0f29df6349e 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -28,10 +28,12 @@ #if defined(HAVE_ONELAB) #include "onelab.h" #endif +#include "gmshLocalNetworkClient.h" + #if defined(HAVE_ONELAB2) #include "OnelabDatabase.h" +#include "NetworkUtils.h" #endif -#include "gmshLocalNetworkClient.h" #if defined(HAVE_PETSC) #include <petsc.h> @@ -47,6 +49,7 @@ #include "extraDialogs.h" #endif + int Msg::_commRank = 0; int Msg::_commSize = 1; int Msg::_verbosity = 5; @@ -62,8 +65,13 @@ std::string Msg::_commandLine; std::string Msg::_launchDate; GmshClient *Msg::_client = 0; std::string Msg::_execName; -#if defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB2) +OnelabDatabase *OnelabDatabase::_instance = NULL; +GmshNetworkClient *Msg::_onelabClient = 0; +#elif defined(HAVE_ONELAB) onelab::client *Msg::_onelabClient = 0; +#endif +#if defined(HAVE_ONELAB) onelab::server *onelab::server::_server = 0; #endif std::string Msg::_gmshOnelabAction = ""; @@ -715,17 +723,7 @@ bool Msg::UseOnelab() void Msg::SetOnelabNumber(std::string name, double val, bool visible) { -#ifdef HAVE_ONELAB2 - std::vector<onelab::number> numbers; - OnelabDatabase::instance()->get(numbers, name); - if(numbers.empty()) { - numbers.resize(1); - numbers[0].setName(name); - } - numbers[0].setValue(val); - numbers[0].setVisible(visible); - OnelabDatabase::instance()->set(numbers[0], std::string("Gmsh")); -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) if(_onelabClient){ std::vector<onelab::number> numbers; _onelabClient->get(numbers, name); @@ -742,17 +740,7 @@ void Msg::SetOnelabNumber(std::string name, double val, bool visible) void Msg::SetOnelabString(std::string name, std::string val, bool visible) { -#ifdef HAVE_ONELAB2 - std::vector<onelab::string> strings; - OnelabDatabase::instance()->get(strings, name); - if(strings.empty()){ - strings.resize(1); - strings[0].setName(name); - } - strings[0].setValue(val); - strings[0].setVisible(visible); - OnelabDatabase::instance()->set(strings[0], std::string("Gmsh")); -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) if(_onelabClient){ std::vector<onelab::string> strings; _onelabClient->get(strings, name); @@ -797,18 +785,52 @@ public: void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) { -#if defined(HAVE_ONELAB) +#ifdef HAVE_ONELAB2 + if(sockname.empty()){ + if(name != "Gmsh"){ // load db from file: + FILE *fp = Fopen(name.c_str(), "rb"); + if(fp){ + OnelabDatabase::instance()->fromFile(fp); + fclose(fp); + } + else + Error("Error loading onelab database '%s'", name.c_str()); + } + } + else{ + UInt32 address = 0; + UInt16 port = 1148; + size_t colon = sockname.find(':'); + if(colon != std::string::npos) { + address = ip4_inet_pton(sockname.substr(0,colon).c_str()); + port = atoi(sockname.substr(colon+1).c_str()); + } + GmshNetworkClient *c = OnelabDatabase::instance()->useAsNetworkClient(address, port, "Gmsh"); + if(c == NULL) { + Error("Unable to connect ONELAB server"); + Exit(1); + } + _onelabClient = c; + + SetOnelabNumber(name + "/UseCommandLine", 1, false); + SetOnelabString(name + "/FileExtension", ".geo", false); + SetOnelabString(name + "/9CheckCommand", "-", false); + SetOnelabString(name + "/9ComputeCommand", "-3", false); + std::vector<onelab::string> ps; + _onelabClient->get(ps, name + "/Action", true); // FIXME good idea ? + if(ps.size()){ + Info("Performing ONELAB '%s'", ps[0].getValue().c_str()); + if(ps[0].getValue() == "initialize") Exit(0); + } + } +#elif defined(HAVE_ONELAB) if(_onelabClient) delete _onelabClient; if(sockname.empty()){ _onelabClient = new localGmsh(); if(name != "Gmsh"){ // load db from file: FILE *fp = Fopen(name.c_str(), "rb"); if(fp){ -#ifdef HAVE_ONELAB2 - OnelabDatabase::instance()->fromFile(fp); -#else _onelabClient->fromFile(fp); -#endif fclose(fp); } else @@ -816,7 +838,6 @@ void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) } } else{ - // TODO ONELAB2 client... onelab::remoteNetworkClient *c = new onelab::remoteNetworkClient(name, sockname); _onelabClient = c; _client = c->getGmshClient(); @@ -937,11 +958,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key, } std::vector<onelab::number> ps; -#ifdef HAVE_ONELAB2 - OnelabDatabase::instance()->get(ps, name); -#else _onelabClient->get(ps, name); -#endif bool noRange = true, noChoices = true, noLoop = true; bool noGraph = true, noClosed = true; if(ps.size()){ @@ -1021,12 +1038,8 @@ void Msg::ExchangeOnelabParameter(const std::string &key, if(noClosed && fopt.count("Closed")) ps[0].setAttribute("Closed", fopt["Closed"][0] ? "1" : "0"); _setStandardOptions(&ps[0], fopt, copt); -#ifdef HAVE_ONELAB2 - OnelabDatabase::instance()->set(ps[0], std::string("Gmsh")); -#else _onelabClient->set(ps[0]); #endif -#endif } void Msg::ExchangeOnelabParameter(const std::string &key, @@ -1050,11 +1063,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key, } std::vector<onelab::string> ps; -#ifdef HAVE_ONELAB2 - OnelabDatabase::instance()->get(ps, name); -#else _onelabClient->get(ps, name); -#endif bool noChoices = true, noClosed = true, noMultipleSelection = true; if(ps.size()){ if(fopt.count("ReadOnly") && fopt["ReadOnly"][0]) @@ -1083,12 +1092,8 @@ void Msg::ExchangeOnelabParameter(const std::string &key, if(noMultipleSelection && copt.count("MultipleSelection")) ps[0].setAttribute("MultipleSelection", copt["MultipleSelection"][0]); _setStandardOptions(&ps[0], fopt, copt); -#ifdef HAVE_ONELAB2 - OnelabDatabase::instance()->set(ps[0], std::string("Gmsh")); -#else _onelabClient->set(ps[0]); #endif -#endif } void Msg::UndefineOnelabParameter(const std::string &name) @@ -1165,7 +1170,13 @@ void Msg::RunOnelabClient(const std::string &name, const std::string &command) void Msg::FinalizeOnelab() { -#if defined(HAVE_ONELAB) +#ifdef HAVE_ONELAB2 + if(_onelabClient) { + _onelabClient->disconnect(); + delete _onelabClient; + _onelabClient = 0; + } +#elif defined(HAVE_ONELAB) if(_onelabClient){ delete _onelabClient; _onelabClient = 0; diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index 131e47ae569e82bbe2d3d4e4160b35872762b700..420cedcb11d903377c3330bd0212f89b540372d5 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -11,8 +11,13 @@ #include <string> #include <stdarg.h> +#include "GmshConfig.h" + class GmshClient; namespace onelab{ class client; } +#ifdef HAVE_ONELAB2 +class GmshNetworkClient; +#endif // the external message handler class GmshMessage{ @@ -43,8 +48,13 @@ class Msg { static std::string _commandLine, _launchDate; // communication with Gmsh when run remotely static GmshClient *_client; +#if defined(HAVE_ONELAB2) + // communication with onelab server (replace _client and old _onelabClient) + static GmshNetworkClient *_onelabClient; +#elif defined(HAVE_ONELAB) // communication with onelab server static onelab::client *_onelabClient; +#endif // internal onelab status for Gmsh parser static std::string _gmshOnelabAction; // executable name @@ -97,7 +107,11 @@ class Msg { static std::string GetExecutableName() { return _execName; } static void LoadOnelabClient(const std::string &name, const std::string &sockName); static GmshClient *GetGmshClient(){ return _client; } +#ifdef HAVE_ONELAB2 + static GmshNetworkClient *GetOnelabClient(){ return _onelabClient; } +#else static onelab::client *GetOnelabClient(){ return _onelabClient; } +#endif static void FinalizeOnelab(); static bool UseOnelab(); static void SetOnelabNumber(std::string name, double val, bool visible); diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp index 60f35d61b5982852d0005fdf9994bae2b644d31f..89492202097afc91808aad7cb4f1dbafc0d6211a 100644 --- a/Fltk/Main.cpp +++ b/Fltk/Main.cpp @@ -11,7 +11,7 @@ #include "Options.h" #include "PluginManager.h" #include "GModel.h" -#if defined(HAVE_ONELAB2) && defined(__linux__) && !defined(BUILD_ANDROID) +#if defined(HAVE_ONELAB2) && defined(__linux__) #include <X11/Xlib.h> #endif @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) } // Interactive Gmsh with FLTK GUI -#if defined(HAVE_ONELAB2) && defined(__linux__) && !defined(BUILD_ANDROID) +#if defined(HAVE_ONELAB2) && defined(__linux__) XInitThreads(); #endif return GmshFLTK(argc, argv); diff --git a/contrib/onelab2/OnelabNetworkClient.h b/contrib/onelab2/OnelabNetworkClient.h index b9e2741e065f888d113b35268d81e9db7b92b21f..3e09c9fa72ffcafdc51ec38db49bf9d374024ed6 100644 --- a/contrib/onelab2/OnelabNetworkClient.h +++ b/contrib/onelab2/OnelabNetworkClient.h @@ -81,6 +81,10 @@ public: } return true; } + void clear(const std::string &name="", const std::string &client="") + { + // TODO + } FILE *openFile(const std::string name, const char *mode="rb") { FILE *fp = fopen(name.c_str(), mode); diff --git a/contrib/onelab2/OnelabServer.cpp b/contrib/onelab2/OnelabServer.cpp index 1b661de8dd0d0a7a9137909ef62076e3023c3393..669de1d8704810eb86c510754b7a479fb040df98 100644 --- a/contrib/onelab2/OnelabServer.cpp +++ b/contrib/onelab2/OnelabServer.cpp @@ -108,8 +108,7 @@ int OnelabServer::launchClient(const std::string &client) // FIXME OnelabDatabas //TODO sprintf(cmd, command, _sockname.c_str()); // TCP socket - if(client == "Gmsh") sprintf(cmd, command.c_str(), "-server %s:%d"); - else sprintf(cmd, command.c_str(), " %s:%d"); + sprintf(cmd, command.c_str(), " %s:%d"); command.assign(cmd); sprintf(cmd, command.c_str(), (_ip.address==0)?"127.0.0.1":ip4_inet_ntop(_ip.address).c_str(), _ip.port); @@ -183,12 +182,10 @@ void OnelabServer::performAction(const std::string action, const std::string cli onelabUtils::guessModelName(client); OnelabLocalNetworkClient *cli = getClient(client); OnelabLocalClient *localcli = getLocalClient(client); - if(cli != NULL || localcli == NULL) { - onelab::string o(client + "/Action", action); - o.setVisible(false); - o.setNeverChanged(true); - set(o); - } + onelab::string o(client + "/Action", action); + o.setVisible(false); + o.setNeverChanged(true); + set(o, client); if(cli != NULL){ // Gmsh is used as a server and the client is remote std::cout << action << " on " << client << "(client is remote)" << std::endl; cli->run(action); @@ -197,7 +194,7 @@ void OnelabServer::performAction(const std::string action, const std::string cli std::cout << action << " on " << client << "(client is local)" << std::endl; localcli->run(action); } - else { // client is Gmsh but do not exist (Gmsh is used as a server), launch Gmsh + else { // client does not exist (Gmsh is used as a server), launch the client std::cout << action << " on " << client << "(launch a new remote Gmsh)" << std::endl; if(launchClient(client) >= 0) ;// FIXME then action or action is store in onelab DB ? @@ -206,7 +203,7 @@ void OnelabServer::performAction(const std::string action, const std::string cli } } else { - // run all non Gmsh clients TODO, exclude GUI ? + // run all non Gmsh clients TODO; exclude GUI ? for(std::vector<OnelabLocalNetworkClient>::iterator it = _clients.begin(); it != _clients.end(); ++it) { if((*it).getName() == "Gmsh") continue; std::cout << action << " on " << (*it).getName() << "(remote)" << std::endl;