From 40ac944c45e09b6166370c27550018cec1d8642e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sat, 13 Feb 2016 08:40:35 +0000 Subject: [PATCH] simplifcation of ONELAB code: - removed onelab::region and onelab::function (they complexify the interface, but bring no additional value compared to onelab::string) - removed ONELAB2 experiment - made client/Model name persistent, and define Gmsh/Model name so that we can uncouple e.g. .geo/.pro pairs --- CMakeLists.txt | 23 - Common/CommandLine.cpp | 15 - Common/Context.cpp | 2 - Common/Context.h | 7 - Common/Gmsh.cpp | 52 +- Common/GmshMessage.cpp | 161 +-- Common/GmshMessage.h | 29 +- Common/GmshRemote.cpp | 2 +- Common/OpenFile.cpp | 29 +- Common/Options.cpp | 4 - Common/gmshLocalNetworkClient.cpp | 40 - Common/onelab.h | 550 +-------- Common/onelabUtils.cpp | 172 +-- Common/onelabUtils.h | 6 - Fltk/CMakeLists.txt | 12 +- Fltk/FlGui.cpp | 12 - Fltk/Main.cpp | 6 - Fltk/drawContextFltk.h | 3 - Fltk/graphicWindow.cpp | 9 - Fltk/graphicWindow.h | 4 - Fltk/onelab2Group.cpp | 1045 ------------------ Fltk/onelab2Group.h | 95 -- Fltk/onelabGroup.cpp | 86 -- Fltk/onelabGroup.h | 4 - Fltk/optionWindow.cpp | 5 +- Fltk/viewButton.cpp | 4 - Geo/GModel.cpp | 7 + Geo/GModel.h | 6 +- Geo/GeoStringInterface.cpp | 6 - contrib/onelab/OnelabClients.cpp | 25 - contrib/onelab/OnelabParser.cpp | 61 - contrib/onelab/python/onelab.py | 2 +- contrib/onelab2/CMakeLists.txt | 46 - contrib/onelab2/GmshLocalClient.cpp | 83 -- contrib/onelab2/GmshLocalClient.h | 39 - contrib/onelab2/GmshNetworkClient.cpp | 54 - contrib/onelab2/GmshNetworkClient.h | 36 - contrib/onelab2/NetworkUtils.cpp | 189 ---- contrib/onelab2/NetworkUtils.h | 168 --- contrib/onelab2/Onelab.cpp | 68 -- contrib/onelab2/OnelabAttributes.cpp | 198 ---- contrib/onelab2/OnelabAttributes.h | 233 ---- contrib/onelab2/OnelabDatabase.cpp | 118 -- contrib/onelab2/OnelabDatabase.h | 283 ----- contrib/onelab2/OnelabException.h | 48 - contrib/onelab2/OnelabLocalClient.h | 30 - contrib/onelab2/OnelabLocalNetworkClient.cpp | 75 -- contrib/onelab2/OnelabLocalNetworkClient.h | 40 - contrib/onelab2/OnelabNetworkClient.cpp | 244 ---- contrib/onelab2/OnelabNetworkClient.h | 185 ---- contrib/onelab2/OnelabProtocol.cpp | 162 --- contrib/onelab2/OnelabProtocol.h | 44 - contrib/onelab2/OnelabServer.cpp | 884 --------------- contrib/onelab2/OnelabServer.h | 171 --- contrib/onelab2/OnelabWindow.cpp | 239 ---- contrib/onelab2/OnelabWindow.h | 34 - contrib/onelab2/UdtUtils.h | 80 -- contrib/onelab2/VirtualClient.h | 44 - contrib/onelab2/noudt.cpp | 74 -- contrib/onelab2/noudt.h | 25 - contrib/onelab2/python/onelab2.py | 458 -------- utils/solvers/c++/onelab.h | 595 +--------- 62 files changed, 107 insertions(+), 7324 deletions(-) delete mode 100644 Fltk/onelab2Group.cpp delete mode 100644 Fltk/onelab2Group.h delete mode 100644 contrib/onelab2/CMakeLists.txt delete mode 100644 contrib/onelab2/GmshLocalClient.cpp delete mode 100644 contrib/onelab2/GmshLocalClient.h delete mode 100644 contrib/onelab2/GmshNetworkClient.cpp delete mode 100644 contrib/onelab2/GmshNetworkClient.h delete mode 100644 contrib/onelab2/NetworkUtils.cpp delete mode 100644 contrib/onelab2/NetworkUtils.h delete mode 100644 contrib/onelab2/Onelab.cpp delete mode 100644 contrib/onelab2/OnelabAttributes.cpp delete mode 100644 contrib/onelab2/OnelabAttributes.h delete mode 100644 contrib/onelab2/OnelabDatabase.cpp delete mode 100644 contrib/onelab2/OnelabDatabase.h delete mode 100644 contrib/onelab2/OnelabException.h delete mode 100644 contrib/onelab2/OnelabLocalClient.h delete mode 100644 contrib/onelab2/OnelabLocalNetworkClient.cpp delete mode 100644 contrib/onelab2/OnelabLocalNetworkClient.h delete mode 100644 contrib/onelab2/OnelabNetworkClient.cpp delete mode 100644 contrib/onelab2/OnelabNetworkClient.h delete mode 100644 contrib/onelab2/OnelabProtocol.cpp delete mode 100644 contrib/onelab2/OnelabProtocol.h delete mode 100644 contrib/onelab2/OnelabServer.cpp delete mode 100644 contrib/onelab2/OnelabServer.h delete mode 100644 contrib/onelab2/OnelabWindow.cpp delete mode 100644 contrib/onelab2/OnelabWindow.h delete mode 100644 contrib/onelab2/UdtUtils.h delete mode 100644 contrib/onelab2/VirtualClient.h delete mode 100644 contrib/onelab2/noudt.cpp delete mode 100644 contrib/onelab2/noudt.h delete mode 100755 contrib/onelab2/python/onelab2.py diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5ffff9ca..722935aa2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,10 +67,6 @@ opt(NUMPY "Enable conversion between fullMatrix and numpy array (requires SWIG)" opt(PETSC4PY "Enable petsc4py wrappers for petsc matrices" ON) opt(OCC "Enable Open CASCADE geometrical models" ${DEFAULT}) opt(ONELAB "Enable ONELAB solver interface" ${DEFAULT}) -opt(ONELAB2 "Enable experimental ONELAB-Cloud solver interface" OFF) -if(ENABLE_ONELAB2) - opt(UDT "Enable UDT library for ONELAB-Cloud" ON) -endif(ENABLE_ONELAB2) opt(ONELAB_METAMODEL "Enable ONELAB metamodels (experimental)" ${DEFAULT}) opt(OPENMP "Enable OpenMP (experimental)" OFF) opt(OPTHOM "Enable high-order mesh optimization tools" ${DEFAULT}) @@ -548,25 +544,6 @@ if(ENABLE_NATIVE_FILE_CHOOSER) set_config_option(HAVE_NATIVE_FILE_CHOOSER "NativeFileChooser") endif(ENABLE_NATIVE_FILE_CHOOSER) -if(ENABLE_ONELAB2) - if(ENABLE_UDT) - find_package(Threads REQUIRED) - find_path(UDT_INCLUDE_DIR "udt.h" PATH_SUFFIXES include udt) - find_library(UDT_LIBRARY udt) - if(UDT_INCLUDE_DIR AND UDT_LIBRARY AND Threads_FOUND) - set_config_option(HAVE_UDT "UDT") - list(APPEND EXTERNAL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) - list(APPEND EXTERNAL_LIBRARIES ${UDT_LIBRARY}) - list(APPEND EXTERNAL_INCLUDES ${UDT_INCLUDE_DIR}) - else(UDT_INCLUDE_DIR AND UDT_LIBRARY AND Threads_FOUND) - message(FATAL_ERROR "Unable to find UDT library or threads") - endif(UDT_INCLUDE_DIR AND UDT_LIBRARY AND Threads_FOUND) - endif(ENABLE_UDT) - set_config_option(HAVE_ONELAB2 "ONELAB2") - add_subdirectory(contrib/onelab2) - include_directories(contrib/onelab2) -endif(ENABLE_ONELAB2) - if(ENABLE_ONELAB) set_config_option(HAVE_ONELAB "ONELAB") if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/contrib/onelab) diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index 080105b480..e986f1c036 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -919,22 +919,7 @@ void GetOptions(int argc, char *argv[]) } else if(!strcmp(argv[i] + 1, "listen")) { i++; -#if !defined(HAVE_ONELAB2) CTX::instance()->solver.listen = 1; -#else - if(argv[i]) { - if(strstr(argv[i], "/") || strstr(argv[i], "\\") || !strstr(argv[i], ":")) // UNIX - CTX::instance()->onelab.unixSock = std::string(argv[i]); - else if(argv[i][0] == 'u') // UDT - CTX::instance()->onelab.udtSock = std::string(argv[i++]); - else if(argv[i][0] == 't') // TCP - CTX::instance()->onelab.tcpSock = std::string(argv[i++]); - else // TCP - CTX::instance()->onelab.tcpSock = std::string(argv[i]); - } - else // TCP - CTX::instance()->onelab.tcpSock = "127.0.0.1:1148"; -#endif } else if(!strcmp(argv[i] + 1, "minterpreter")) { i++; diff --git a/Common/Context.cpp b/Common/Context.cpp index d00d8f0be8..67dcc74b80 100644 --- a/Common/Context.cpp +++ b/Common/Context.cpp @@ -45,7 +45,6 @@ CTX::CTX() : gamepad(0) bgmFileName = ""; createAppendMeshStatReport = 0; launchSolverAtStartup = -1; - solverToRun = -1; lc = 1.; min[0] = min[1] = min[2] = max[2] = 0.; max[0] = max[1] = 1.; // for nice view when adding point in new model @@ -151,4 +150,3 @@ int CTX::unpackAlpha(unsigned int X) else return ( ( (X) >> 24 ) & 0xff ); } - diff --git a/Common/Context.h b/Common/Context.h index 7647532ecf..2f85aa0bf2 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -104,8 +104,6 @@ class CTX { int createAppendMeshStatReport; // should we launch a solver at startup? int launchSolverAtStartup ; - // solver to use with ONELAB2 - int solverToRun ; // save session/option file on exit? int sessionSave, optionsSave; // ask confirmation when overwriting files? @@ -264,11 +262,6 @@ class CTX { int autoSaveDatabase, autoArchiveOutputFiles, autoMesh, autoMergeFile; int autoShowViews, autoShowLastStep, autoCheck, showInvisibleParameters; }solver; - // onelab options - struct{ - std::string unixSock, tcpSock, udtSock; - bool unixConnected, tcpConnected, udtConnected; - }onelab; // print options struct{ int fileFormat, epsQuality, epsCompress, epsPS3Shading; diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp index 83b2de8145..96193518af 100644 --- a/Common/Gmsh.cpp +++ b/Common/Gmsh.cpp @@ -27,7 +27,7 @@ #include "PViewOptions.h" #endif -#if defined(HAVE_ONELAB) && !defined(HAVE_ONELAB2) +#if defined(HAVE_ONELAB) #include "gmshLocalNetworkClient.h" #endif @@ -45,18 +45,8 @@ #include "FlGui.h" #include "graphicWindow.h" #include "drawContext.h" -#if defined(HAVE_ONELAB2) -#include "onelab2Group.h" -#else #include "onelabGroup.h" #endif -#endif - -#if defined(HAVE_ONELAB2) -#include "OnelabServer.h" -#include "OnelabDatabase.h" -#include "OnelabException.h" -#endif int GmshInitialize(int argc, char **argv) { @@ -237,7 +227,7 @@ int GmshFinalize() delete PView::list[i]; } PView::list.clear(); - + // Delete static _interpolationSchemes of PViewData class PViewData::removeAllInterpolationSchemes(); #endif @@ -256,39 +246,6 @@ int GmshBatch() Msg::GetCommSize(), Msg::GetCommSize() > 1 ? "s" : "", Msg::GetMaxThreads(), Msg::GetMaxThreads() > 1 ? "s" : ""); Msg::Info("Started on %s", Msg::GetLaunchDate().c_str()); -#if defined(HAVE_ONELAB2) - try { - if(CTX::instance()->onelab.unixSock.size() > 0) { // UNIX - std::ostringstream tmp; - tmp << CTX::instance()->homeDir << CTX::instance()->onelab.unixSock; - OnelabServer::instance()->listenOnUnix(tmp.str().c_str()); - } - if(CTX::instance()->onelab.tcpSock.size() > 0) { - std::size_t colon = CTX::instance()->onelab.tcpSock.find(":"); - OnelabServer::instance()->listenOnTcp( - ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()), - atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str())); - } -#if defined(HAVE_UDT) - if(CTX::instance()->onelab.udtSock.size() > 0) { - std::size_t colon = CTX::instance()->onelab.tcpSock.find(":"); - OnelabServer::instance()->listenOnUdt( - ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()), - atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str())); - } -#endif - } catch(NetworkException e) { - std::cout << e.what() << std::endl; - Msg::Exit(1); - } - if(CTX::instance()->onelab.unixSock.size() > 0 - || CTX::instance()->onelab.tcpSock.size() > 0 - || CTX::instance()->onelab.udtSock.size() > 0) { - std::cout << "Press any key to stop the server." << std::endl; - std::cin.get(); - Msg::Exit(0); - } -#endif OpenProject(GModel::current()->getFileName()); bool open = false; @@ -318,9 +275,7 @@ int GmshBatch() #endif if(CTX::instance()->batch == -3){ -#if !defined(HAVE_ONELAB2) GmshRemote(); -#endif } else if(CTX::instance()->batch == -2){ GModel::current()->checkMeshCoherence(CTX::instance()->geom.tolerance); @@ -434,13 +389,12 @@ int GmshFLTK(int argc, char **argv) else Msg::Error("Invalid background mesh (no view)"); } -#if !defined(HAVE_ONELAB2) + // listen to external solvers if(CTX::instance()->solver.listen){ gmshLocalNetworkClient *c = new gmshLocalNetworkClient("Listen", ""); c->run(); } -#endif // launch solver (if requested) and fill onelab tree solver_cb(0, (void*)CTX::instance()->launchSolverAtStartup); diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 9939ac2931..8ba2171ee7 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -28,14 +28,8 @@ #if defined(HAVE_ONELAB) #include "onelab.h" #endif -#if !defined(HAVE_ONELAB2) -#include "gmshLocalNetworkClient.h" -#endif -#if defined(HAVE_ONELAB2) -#include "OnelabDatabase.h" -#include "NetworkUtils.h" -#endif +#include "gmshLocalNetworkClient.h" #if defined(HAVE_PETSC) #include <petsc.h> @@ -67,17 +61,10 @@ std::string Msg::_commandLine; std::string Msg::_launchDate; std::map<std::string, std::vector<double> > Msg::_commandLineNumbers; std::map<std::string, std::string> Msg::_commandLineStrings; -#if !defined(HAVE_ONELAB2) GmshClient *Msg::_client = 0; -#endif std::string Msg::_execName; -#if defined(HAVE_ONELAB2) -OnelabDatabase *OnelabDatabase::_instance = NULL; -OnelabDatabase *Msg::_onelabClient = 0; -#elif defined(HAVE_ONELAB) -onelab::client *Msg::_onelabClient = 0; -#endif #if defined(HAVE_ONELAB) +onelab::client *Msg::_onelabClient = 0; onelab::server *onelab::server::_server = 0; #endif @@ -275,9 +262,7 @@ void Msg::Fatal(const char *fmt, ...) va_end(args); if(_callback) (*_callback)("Fatal", str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Error(str); -#endif #if defined(HAVE_FLTK) if(FlGui::available()){ @@ -325,9 +310,7 @@ void Msg::Error(const char *fmt, ...) va_end(args); if(_callback) (*_callback)("Error", str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Error(str); -#endif #if defined(HAVE_FLTK) if(FlGui::available()){ @@ -367,9 +350,8 @@ void Msg::Warning(const char *fmt, ...) va_end(args); if(_callback) (*_callback)("Warning", str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Warning(str); -#endif + #if defined(HAVE_FLTK) if(FlGui::available()){ if(FlGui::instance()->in_main_thread()) FlGui::instance()->check(); @@ -405,9 +387,7 @@ void Msg::Info(const char *fmt, ...) va_end(args); if(_callback) (*_callback)("Info", str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Info(str); -#endif #if defined(HAVE_FLTK) #if defined(_OPENMP) @@ -447,9 +427,7 @@ void Msg::Direct(const char *fmt, ...) va_end(args); if(_callback) (*_callback)("Direct", str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Info(str); -#endif #if defined(HAVE_FLTK) #if defined(_OPENMP) @@ -489,9 +467,7 @@ void Msg::StatusBar(bool log, const char *fmt, ...) va_end(args); if(_callback && log) (*_callback)("Info", str); -#if !defined(HAVE_ONELAB2) if(_client && log) _client->Info(str); -#endif #if defined(HAVE_FLTK) #if defined(_OPENMP) @@ -544,9 +520,7 @@ void Msg::Debug(const char *fmt, ...) va_end(args); if(_callback) (*_callback)("Debug", str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Info(str); -#endif #if defined(HAVE_FLTK) if(FlGui::available()){ @@ -579,9 +553,7 @@ void Msg::ProgressMeter(int n, int N, bool log, const char *fmt, ...) va_end(args); sprintf(str2, "%3d%% : %s", _progressMeterCurrent, str); -#if !defined(HAVE_ONELAB2) if(_client) _client->Progress(str2); -#endif #if defined(HAVE_FLTK) if(FlGui::available() && _verbosity > 4){ @@ -753,77 +725,62 @@ int Msg::GetAnswer(const char *question, int defaultval, const char *zero, bool Msg::UseOnelab() { -#if defined(HAVE_ONELAB2) - return true; -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) return _onelabClient ? true : false; #else return false; #endif } -void Msg::SetOnelabNumber(std::string name, double val, bool visible) +void Msg::SetOnelabNumber(std::string name, double val, bool visible, + bool persistent, bool readOnly) { #if defined(HAVE_ONELAB) if(_onelabClient){ std::vector<onelab::number> numbers; -#if defined(HAVE_ONELAB2) - _onelabClient->get(numbers, name, "Gmsh"); -#else _onelabClient->get(numbers, name); -#endif if(numbers.empty()){ numbers.resize(1); numbers[0].setName(name); } numbers[0].setValue(val); numbers[0].setVisible(visible); -#if defined(HAVE_ONELAB2) - _onelabClient->set(numbers[0], "Gmsh"); -#else + if(persistent) numbers[0].setAttribute("Persistent", "1"); + numbers[0].setReadOnly(readOnly); _onelabClient->set(numbers[0]); -#endif } #endif } -void Msg::SetOnelabString(std::string name, std::string val, bool visible) +void Msg::SetOnelabString(std::string name, std::string val, bool visible, + bool persistent, bool readOnly) { #if defined(HAVE_ONELAB) if(_onelabClient){ std::vector<onelab::string> strings; -#if defined(HAVE_ONELAB2) - _onelabClient->get(strings, name, "Gmsh"); -#else _onelabClient->get(strings, name); -#endif if(strings.empty()){ strings.resize(1); strings[0].setName(name); } strings[0].setValue(val); strings[0].setVisible(visible); -#if defined(HAVE_ONELAB2) - _onelabClient->set(strings[0], "Gmsh"); -#else + if(persistent) strings[0].setAttribute("Persistent", "1"); + strings[0].setReadOnly(readOnly); _onelabClient->set(strings[0]); -#endif } #endif } -double Msg::GetOnelabNumber(std::string name) +double Msg::GetOnelabNumber(std::string name, bool warnIfMissing) { #if defined(HAVE_ONELAB) if(_onelabClient){ std::vector<onelab::number> numbers; -#if defined(HAVE_ONELAB2) - _onelabClient->get(numbers, name, "Gmsh"); -#else _onelabClient->get(numbers, name); -#endif if(numbers.empty()){ - Msg::Error("Unknown ONELAB number parameter '%s'", name.c_str()); + if(warnIfMissing) + Msg::Error("Unknown ONELAB number parameter '%s'", name.c_str()); return 0.; } else @@ -834,18 +791,15 @@ double Msg::GetOnelabNumber(std::string name) return 0.; } -std::string Msg::GetOnelabString(std::string name) +std::string Msg::GetOnelabString(std::string name, bool warnIfMissing) { #if defined(HAVE_ONELAB) if(_onelabClient){ std::vector<onelab::string> strings; -#if defined(HAVE_ONELAB2) - _onelabClient->get(strings, name, "Gmsh"); -#else _onelabClient->get(strings, name); -#endif if(strings.empty()){ - Msg::Error("Unknown ONELAB string parameter '%s'", name.c_str()); + if(warnIfMissing) + Msg::Error("Unknown ONELAB string parameter '%s'", name.c_str()); return ""; } else @@ -886,52 +840,7 @@ public: void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) { -#if defined(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()); - } - _onelabClient = OnelabDatabase::instance(); - } - 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, name); - if(c == NULL) { - Error("Unable to connect ONELAB server (%s)", sockname.c_str()); - Exit(1); - } -#if defined(HAVE_FLTK) - else if(FlGui::available()) // FIXME - c->setCallback(FlGui::instance()->onelab); - else - Warning("FlGUI not available"); -#endif - _onelabClient = OnelabDatabase::instance(); - - 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", "Gmsh"); - if(ps.size()){ - Info("Performing ONELAB '%s'", ps[0].getValue().c_str()); - if(ps[0].getValue() == "initialize") Exit(0); - } - } -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) if(_onelabClient) delete _onelabClient; if(sockname.empty()){ _onelabClient = new localGmsh(); @@ -950,8 +859,8 @@ void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) _onelabClient = c; _client = c->getGmshClient(); - SetOnelabNumber(name + "/UseCommandLine", 1, false); - SetOnelabString(name + "/FileExtension", ".geo", false); + SetOnelabNumber(name + "/Use command line", 1, false); + SetOnelabString(name + "/File extension", ".geo", false); SetOnelabString(name + "/9CheckCommand", "-", false); SetOnelabString(name + "/9ComputeCommand", "-3", false); @@ -983,9 +892,6 @@ std::string Msg::GetOnelabAction() if(_onelabClient){ std::vector<onelab::string> ps; _onelabClient->get(ps, _onelabClient->getName() + "/Action"); -#ifdef HAVE_ONELAB2 - _onelabClient->recvfrom(); -#endif if(ps.size()) return ps[0].getValue(); } return ""; @@ -1097,11 +1003,7 @@ void Msg::ExchangeOnelabParameter(const std::string &key, } std::vector<onelab::number> ps; -#if defined(HAVE_ONELAB2) - _onelabClient->get(ps, name, "Gmsh"); -#else _onelabClient->get(ps, name); -#endif bool noRange = true, noChoices = true, noLoop = true; bool noGraph = true, noClosed = true; if(ps.size()){ @@ -1181,12 +1083,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); -#if defined(HAVE_ONELAB2) - _onelabClient->set(ps[0], "Gmsh"); -#else _onelabClient->set(ps[0]); #endif -#endif } void Msg::ExchangeOnelabParameter(const std::string &key, @@ -1239,12 +1137,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); -#if defined(HAVE_ONELAB2) - _onelabClient->set(ps[0], "Gmsh"); -#else _onelabClient->set(ps[0]); #endif -#endif } void Msg::UndefineOnelabParameter(const std::string &name) @@ -1311,8 +1205,9 @@ void Msg::ImportPhysicalGroupsInOnelab() void Msg::RunOnelabClient(const std::string &name, const std::string &command) { -#if defined(HAVE_ONELAB) && !defined(HAVE_ONELAB2) - onelab::remoteNetworkClient *c = dynamic_cast<onelab::remoteNetworkClient*>(_onelabClient); +#if defined(HAVE_ONELAB) + onelab::remoteNetworkClient *c = + dynamic_cast<onelab::remoteNetworkClient*>(_onelabClient); if(c){ c->runSubClient(name, command); } @@ -1325,13 +1220,7 @@ void Msg::RunOnelabClient(const std::string &name, const std::string &command) void Msg::FinalizeOnelab() { -#if defined(HAVE_ONELAB2) - if(_onelabClient) { - _onelabClient->finalize(); - delete _onelabClient; - _onelabClient = 0; - } -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) if(_onelabClient){ delete _onelabClient; _onelabClient = 0; diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index 8d209e1bcb..84b962ef27 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -16,10 +16,6 @@ class GmshClient; namespace onelab{ class client; } -#if defined(HAVE_ONELAB2) -class OnelabDatabase; -#endif - // the external message handler class GmshMessage{ public: @@ -50,14 +46,9 @@ class Msg { // command-line-specified numbers and strings static std::map<std::string, std::vector<double> > _commandLineNumbers; static std::map<std::string, std::string> _commandLineStrings; -#if !defined(HAVE_ONELAB2) // communication with Gmsh when run remotely static GmshClient *_client; -#endif -#if defined(HAVE_ONELAB2) - // communication with onelab server (replace _client and old _onelabClient) - static OnelabDatabase *_onelabClient; -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) // communication with onelab server static onelab::client *_onelabClient; #endif @@ -118,22 +109,18 @@ class Msg { static void SetExecutableName(const std::string &name) { _execName.assign(name); } static std::string GetExecutableName() { return _execName; } static void LoadOnelabClient(const std::string &name, const std::string &sockName); -#if !defined(HAVE_ONELAB2) static GmshClient *GetGmshClient(){ return _client; } -#else - static int GetGmshClient(){ return 1; } -#endif -#if defined(HAVE_ONELAB2) - static OnelabDatabase *GetOnelabClient(){ return _onelabClient; } -#elif defined(HAVE_ONELAB) +#if defined(HAVE_ONELAB) static onelab::client *GetOnelabClient(){ return _onelabClient; } #endif static void FinalizeOnelab(); static bool UseOnelab(); - static void SetOnelabNumber(std::string name, double val, bool visible=true); - static void SetOnelabString(std::string name, std::string val, bool visible=true); - static double GetOnelabNumber(std::string name); - static std::string GetOnelabString(std::string name); + static void SetOnelabNumber(std::string name, double val, bool visible=true, + bool persistent=false, bool readOnly=false); + static void SetOnelabString(std::string name, std::string val, bool visible=true, + bool persistent=false, bool readOnly=false); + static double GetOnelabNumber(std::string name, bool warnIfMissing=true); + static std::string GetOnelabString(std::string name, bool warnIfMissing=true); static void SetOnelabAction(const std::string &action); static std::string GetOnelabAction(); static void ExchangeOnelabParameter(const std::string &key, diff --git a/Common/GmshRemote.cpp b/Common/GmshRemote.cpp index 9ca7d10ec2..ad03da2a0a 100644 --- a/Common/GmshRemote.cpp +++ b/Common/GmshRemote.cpp @@ -19,7 +19,7 @@ #include <sstream> #include "GmshMessage.h" -#if defined(HAVE_ONELAB) && defined(HAVE_POST) && !defined(HAVE_ONELAB2) +#if defined(HAVE_ONELAB) && defined(HAVE_POST) #include "onelab.h" #include "OpenFile.h" diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index 435a53bca4..678d42eaed 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -43,11 +43,7 @@ #if defined(HAVE_FLTK) #include <FL/fl_ask.H> #include "FlGui.h" -#if defined(HAVE_ONELAB2) -#include "onelab2Group.h" -#else #include "onelabGroup.h" -#endif #include "graphicWindow.h" #include "drawContext.h" #endif @@ -298,14 +294,9 @@ static int defineSolver(const std::string &name) int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTitle, bool setBoundingBox) { - if(GModel::current()->getName() == ""){ - GModel::current()->setFileName(fileName); - GModel::current()->setName(SplitFileName(fileName)[1]); - } - #if defined(HAVE_FLTK) if(FlGui::available() && setWindowTitle) - FlGui::instance()->setGraphicTitle(GModel::current()->getFileName()); + FlGui::instance()->setGraphicTitle(fileName); #endif // added 'b' for pure Windows programs, since some of these files @@ -356,10 +347,13 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit std::string solver = getSolverForExtension(ext); if(solver.size()){ int num = defineSolver(solver); - GModel::current()->setName(split[1] + ".geo"); - GModel::current()->setFileName(split[0] + split[1] + ".geo"); + Msg::SetOnelabString(solver + "/Model name", fileName, true, true); + if(GModel::current()->getName() == "" || + Msg::GetOnelabString("Gmsh/Model name", false).empty()){ + GModel::current()->setFileName(split[0] + split[1] + ".geo"); + GModel::current()->setName(split[1] + ".geo"); + } CTX::instance()->launchSolverAtStartup = num; - CTX::instance()->solverToRun = num; // used in ONELAB2 CTX::instance()->geom.draw = 1; return 1; } @@ -369,7 +363,6 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit int num = defineSolver(split[1]); opt_solver_executable(num, GMSH_SET, fileName); CTX::instance()->launchSolverAtStartup = num; - CTX::instance()->solverToRun = num; // used in ONELAB2 CTX::instance()->geom.draw = 1; return 1; } @@ -508,12 +501,14 @@ int MergeFile(const std::string &fileName, bool warnIfMissing, bool setWindowTit #endif else { status = GModel::readGEO(fileName); -#ifdef HAVE_ONELAB2 - Msg::SetOnelabString("Gmsh/1ModelName", fileName, false); -#endif } } + if(GModel::current()->getName() == ""){ + GModel::current()->setFileName(fileName); + GModel::current()->setName(SplitFileName(fileName)[1]); + } + ComputeMaxEntityNum(); if(setBoundingBox) SetBoundingBox(); CTX::instance()->geom.draw = 1; diff --git a/Common/Options.cpp b/Common/Options.cpp index cc107d063b..289864266b 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -50,11 +50,7 @@ #include "manipWindow.h" #include "contextWindow.h" #include "clippingWindow.h" -#ifdef HAVE_ONELAB2 -#include "onelab2Group.h" -#else #include "onelabGroup.h" -#endif #include "viewButton.h" #include "drawContextFltkCairo.h" #include "drawContextFltkStringTexture.h" diff --git a/Common/gmshLocalNetworkClient.cpp b/Common/gmshLocalNetworkClient.cpp index e90731f29b..8e7ec52ab5 100644 --- a/Common/gmshLocalNetworkClient.cpp +++ b/Common/gmshLocalNetworkClient.cpp @@ -225,12 +225,6 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) } set(p); } - else if(ptype == "region"){ - onelab::region p; p.fromChar(message); set(p); - } - else if(ptype == "function"){ - onelab::function p; p.fromChar(message); set(p); - } else Msg::Error("Unknown ONELAB parameter type: %s", ptype.c_str()); } @@ -251,14 +245,6 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) std::vector<onelab::string> par; get(par, name); if(par.size() == 1) reply = par[0].toChar(); } - else if(ptype == "region"){ - std::vector<onelab::region> par; get(par, name); - if(par.size() == 1) reply = par[0].toChar(); - } - else if(ptype == "function"){ - std::vector<onelab::function> par; get(par, name); - if(par.size() == 1) reply = par[0].toChar(); - } else Msg::Error("Unknown ONELAB parameter type in query: %s", ptype.c_str()); @@ -292,16 +278,6 @@ bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master) for(std::vector<onelab::string>::iterator it = strings.begin(); it != strings.end(); it++) replies.push_back((*it).toChar()); } - else if(ptype == "region"){ - std::vector<onelab::region> regions; get(regions); - for(std::vector<onelab::region>::iterator it = regions.begin(); - it != regions.end(); it++) replies.push_back((*it).toChar()); - } - else if(ptype == "function"){ - std::vector<onelab::function> functions; get(functions); - for(std::vector<onelab::function>::iterator it = functions.begin(); - it != functions.end(); it++) replies.push_back((*it).toChar()); - } else Msg::Error("Unknown ONELAB parameter type in query: %s", ptype.c_str()); @@ -763,22 +739,6 @@ void resetDb(bool runGmshClient) persistentStrings.push_back(allStrings[i]); } - // TODO FIXME: this will be removed once the new stable version of getdp is - // released - for(onelab::server::citer it = onelab::server::instance()->firstClient(); - it != onelab::server::instance()->lastClient(); it++){ - onelab::client *c = *it; - std::vector<onelab::number> ps; - c->get(ps, c->getName() + "/UseCommandLine"); - if(ps.size()) persistentNumbers.push_back(ps[0]); - c->get(ps, c->getName() + "/GuessModelName"); - if(ps.size()) persistentNumbers.push_back(ps[0]); - std::vector<onelab::string> ps2; - c->get(ps2, c->getName() + "/FileExtension"); - if(ps2.size()) persistentStrings.push_back(ps2[0]); - } - // END TODO - // clear the db onelab::server::instance()->clear(); diff --git a/Common/onelab.h b/Common/onelab.h index 0ebdb4e005..ecfc6904a0 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -38,19 +38,10 @@ #include <sstream> #include "GmshSocket.h" -#ifdef HAVE_ONELAB2 -#include "NetworkUtils.h" -#include "OnelabAttributes.h" -#endif - namespace onelab{ // The base parameter class. -#ifdef HAVE_ONELAB2 - class parameter : public OnelabAttr{ -#else class parameter { -#endif private: // the name of the parameter, including its '/'-separated path in the // parameter hierarchy. Parameters or subpaths can start with numbers to @@ -309,86 +300,6 @@ namespace onelab{ } return true; } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x05;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = _name.length()+_label.length()+_help.length()+10; - for(std::map<std::string, bool>::const_iterator it = getClients().begin(); it != getClients().end(); it++) - len += it->first.size()+2; - for(std::map<std::string, std::string>::const_iterator it = _attributes.begin(); it != _attributes.end(); it++) - len += it->first.size()+it->second.size()+2; - return len; - } - virtual UInt8 *encodeAttribute(UInt8 *dst) - { - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, (UInt8 *)_name.c_str(), this->_name.length()+1); - dst = encode(dst, (UInt8 *)_label.c_str(), this->_label.length()+1); - dst = encode(dst, (UInt8 *)_help.c_str(), this->_help.length()+1); - dst = encode(dst, (UInt8)_readOnly); - dst = encode(dst, (UInt8)_neverChanged); - dst = encode(dst, (UInt8)_visible); - - dst = encode(dst, (UInt16)_attributes.size()); - for(std::map<std::string, std::string>::const_iterator it = _attributes.begin(); it != _attributes.end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - - dst = encode(dst, (UInt16)_clients.size()); - for(std::map<std::string, bool>::const_iterator it = getClients().begin(); it != getClients().end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8)it->second); - } - - return dst; - } - virtual UInt8 *parseAttribute(UInt8 *src, UInt32 length) - { - UInt8 tmp; - UInt16 n; - - src = parse(src, _name, '\0'); - src = parse(src, _label, '\0'); - src = parse(src, _help, '\0'); - src = parse(src, tmp); - this->_readOnly = (bool)tmp; - src = parse(src, tmp); - this->_neverChanged = (bool)tmp; - src = parse(src, tmp); - this->_visible = (bool)tmp; - - src = parse(src, n); - for(int i=0; i<n; i++) { - std::string key, value; - src = parse(src, key, '\0'); - src = parse(src, value, '\0'); - setAttribute(key, value); - } - - src = parse(src, n); - for(int i=0; i<n; i++) { - std::string client; - src = parse(src, client, '\0'); - src = parse(src, tmp); - addClient(client, (bool)tmp); - } - - return src; - } - void showAttribute() const - { - std::cout << "Name: " << getName() << std::endl - << "Label: " << getLabel() << std::endl - << "Help: " << getHelp() << std::endl - << "Never changed: " << getNeverChanged() << std::endl - << "Changed: " << getChanged() << std::endl - << "Visible: " << getVisible() << std::endl; - } -#endif }; class parameterLessThan{ @@ -400,8 +311,8 @@ namespace onelab{ }; // The number class. Numbers are stored internally as double precision real - // numbers. All more complicated types (complex numbers, vectors, etc.) are - // supposed to be either exchanged as strings or encapsulated in functions. + // numbers. All more complicated types (complex numbers, vectors, expressions, + // functions, etc.) are supposed to be exchanged as strings. class number : public parameter{ private: double _value, _min, _max, _step; @@ -509,73 +420,6 @@ namespace onelab{ } return pos; } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x06;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = parameter::getAttributeLength()+sizeof(double)*4+8+sizeof(double)*_choices.size(); - for(std::map<double, std::string>::const_iterator it = _valueLabels.begin(); it != _valueLabels.end(); it++) - len += it->second.size()+1+sizeof(double); - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst); - - dst = encode(dst, _value); - dst = encode(dst, _min); - dst = encode(dst, _max); - dst = encode(dst, _step); - dst = encode(dst, (UInt32)_index); - - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++) - dst = encode(dst, _choices[i]); - - dst = encode(dst, (UInt16)_valueLabels.size()); - for(std::map<double, std::string>::const_iterator it = _valueLabels.begin(); it != _valueLabels.end(); it++) { - dst = encode(dst, it->first); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 length) - { - UInt16 n; - - src = parameter::parseAttribute(src, length); - - src = parse(src, _value); - src = parse(src, _min); - src = parse(src, _max); - src = parse(src, _step); - src = parse(src, *(UInt32 *)&_index); - - src = parse(src, n); - _choices.resize(n); - for(unsigned int i = 0; i < n; i++) - src = parse(src, _choices[i]); - - src = parse(src, n); - for(int i=0; i<n; i++) { - double value; - std::string label; - src = parse(src, value); - src = parse(src, label, '\0'); - setValueLabel(value, label); - } - - return src; - } - void showAttribute() const - { - parameter::showAttribute(); - std::cout << "Value: " << this->_value << std::endl - << "Min: " << this->_min << std::endl - << "Max: " << this->_max << std::endl; - } -#endif }; // The string class. A string has a mutable "kind": we do not derive @@ -640,337 +484,6 @@ namespace onelab{ _choices[i] = getNextToken(msg, pos); return pos; } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x07;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const - { - UInt16 len = parameter::getAttributeLength(); - len += _value.size()+_kind.size()+4; - for(unsigned int i = 0; i < _choices.size(); i++) - len += _choices[i].size()+1; - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst); - - dst = encode(dst, (UInt8 *)_value.c_str(), _value.size()+1); - dst = encode(dst, (UInt8 *)_kind.c_str(), _kind.size()+1); - - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++) - dst = encode(dst, (UInt8 *)_choices[i].c_str(), _choices[i].size()+1); - - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 length) - { - UInt16 n; - src = parameter::parseAttribute(src, length); - src = parse(src, _value, '\0'); - src = parse(src, _kind, '\0'); - - src = parse(src, n); - _choices.resize(n); - for(unsigned int i=0; i<n; i++) { - src = parse(src, _choices[i], '\0'); - } - - return src; - } - void showAttribute() const - { - parameter::showAttribute(); - std::cout << "Value: " << this->_value << std::endl; - } -#endif - }; - - // The region class. A region can be any kind of geometrical entity, - // represented as identifiers of physical regions. Operations on regions will - // include union, intersection, etc. - class region : public parameter{ - private: - std::set<std::string> _value; - // optional geometrical dimension - int _dimension; - std::vector<std::set<std::string> > _choices; - public: - region(const std::string &name="", - const std::set<std::string> &value = std::set<std::string>(), - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _value(value), _dimension(-1) {} - region(const std::string &name, const std::string &value, - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _dimension(-1) - { - if(value.size()) _value.insert(value); - } - void setValue(const std::set<std::string> &value){ _value = value; } - void setDimension(int dim){ _dimension = dim; } - void setChoices(const std::vector<std::set<std::string> > &choices) - { - _choices = choices; - } - std::string getType() const { return "region"; } - const std::set<std::string> &getValue() const { return _value; } - int getDimension() const { return _dimension; } - const std::vector<std::set<std::string> > &getChoices() const - { - return _choices; - } - void update(const region &p) - { - addClients(p.getClients()); - setLabel(p.getLabel()); - setHelp(p.getHelp()); - setAttributes(p.getAttributes()); - if(p.getValue() != getValue()){ - setValue(p.getValue()); - setChanged(true); - } - setDimension(p.getDimension()); - setChoices(p.getChoices()); - if(getNeverChanged()) setChanged(false); - } - std::string toChar() const - { - std::ostringstream sstream; - sstream << parameter::toChar() << _value.size() << charSep(); - for(std::set<std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) - sstream << sanitize(*it) << charSep(); - sstream << _dimension << charSep(); - sstream << _choices.size() << charSep(); - for(unsigned int i = 0; i < _choices.size(); i++){ - sstream << _choices[i].size() << charSep(); - for(std::set<std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) - sstream << sanitize(*it) << charSep(); - } - return sstream.str(); - } - std::string::size_type fromChar(const std::string &msg) - { - std::string::size_type pos = parameter::fromChar(msg); - if(!pos) return 0; - int n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++) - _value.insert(getNextToken(msg, pos)); - setDimension(atoi(getNextToken(msg, pos).c_str())); - _choices.resize(atoi(getNextToken(msg, pos).c_str())); - for(unsigned int i = 0; i < _choices.size(); i++){ - n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++) - _choices[i].insert(getNextToken(msg, pos)); - } - return pos; - } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x08;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = parameter::getAttributeLength(); - len += 2; - for(std::set<std::string>::const_iterator it = _value.begin(); it != _value.end(); it++) - len += it->size()+1; - len += 4; - len += 2; - for(unsigned int i = 0; i < _choices.size(); i++){ - len += 2; - for(std::set<std::string>::const_iterator it = _choices[i].begin(); it != _choices[i].end(); it++) - len += it->size()+1; - } - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst); - dst = encode(dst, (UInt16)this->_value.size()); - for(std::set<std::string>::const_iterator it = _value.begin(); it != _value.end(); it++) - dst = encode(dst, (UInt8 *)it->c_str(), it->size()+1); - dst = encode(dst, (UInt32)_dimension); - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++){ - dst = encode(dst, (UInt16)_choices[i].size()); - for(std::set<std::string>::const_iterator it = _choices[i].begin(); it != _choices[i].end(); it++) - dst = encode(dst, (UInt8 *)it->c_str(), it->size()+1); - } - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 len) - { - src = parameter::parseAttribute(src, len); - UInt16 m = 0, n = 0; - std::string value; - src = parse(src, n); - for(int i=0; i<n; i++) { - src = parse(src, value, '\0'); - _value.insert(value); - } - src = parse(src, *(UInt32 *)&_dimension); - src = parse(src, n); - _choices.resize(n); - for(int i=0; i<n; i++) { - src = parse(src, m); - for(int j=0; j<m; j++) { - src = parse(src, value, '\0'); - _choices[i].insert(value); - } - } - return src; - } - void showAttribute() const {} -#endif - - }; - - // The (possibly piece-wise defined on regions) function class. Functions are - // entirely client-dependent: they are just represented internally as onelab - // strings, defined on onelab regions. - class function : public parameter{ - private: - std::map<std::string, std::string> _value; - std::vector<std::map<std::string, std::string> > _choices; - public: - function(const std::string &name="") : parameter(name, "", "") {} - function(const std::string &name, const std::map<std::string, std::string> &value, - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _value(value) {} - void setValue(const std::map<std::string, std::string> &value) - { - _value = value; - } - void setChoices(const std::vector<std::map<std::string, std::string> > &choices) - { - _choices = choices; - } - std::string getType() const { return "function"; } - const std::map<std::string, std::string> &getValue() const { return _value; } - const std::string getValue(const std::string ®ion) const - { - std::map<std::string, std::string>::const_iterator it = _value.find(region); - if(it != _value.end()) return it->second; - return ""; - } - const std::vector<std::map<std::string, std::string> > &getChoices() const - { - return _choices; - } - void update(const function &p) - { - addClients(p.getClients()); - setLabel(p.getLabel()); - setHelp(p.getHelp()); - setAttributes(p.getAttributes()); - if(p.getValue() != getValue()){ - setValue(p.getValue()); - setChanged(true); - } - setChoices(p.getChoices()); - if(getNeverChanged()) setChanged(false); - } - std::string toChar() const - { - std::ostringstream sstream; - sstream << parameter::toChar() << _value.size() << charSep(); - for(std::map<std::string, std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) - sstream << sanitize(it->first) << charSep() - << sanitize(it->second) << charSep(); - sstream << _choices.size() << charSep(); - for(unsigned int i = 0; i < _choices.size(); i++){ - sstream << _choices[i].size() << charSep(); - for(std::map<std::string, std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) - sstream << sanitize(it->first) << charSep() - << sanitize(it->second) << charSep(); - } - return sstream.str(); - } - std::string::size_type fromChar(const std::string &msg) - { - std::string::size_type pos = parameter::fromChar(msg); - if(!pos) return 0; - int n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++){ - std::string key = getNextToken(msg, pos); - _value[key] = getNextToken(msg, pos); - } - _choices.resize(atoi(getNextToken(msg, pos).c_str())); - for(unsigned int i = 0; i < _choices.size(); i++){ - n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++){ - std::string key = getNextToken(msg, pos); - _choices[i][key] = getNextToken(msg, pos); - } - } - return pos; - } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x09;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = parameter::getAttributeLength(); - len += 2; - for(std::map<std::string, std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) - len += 2+it->first.size()+it->second.size(); - for(unsigned int i = 0; i < _choices.size(); i++){ - len += 2; - for(std::map<std::string, std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) { - len += 2+it->first.size()+it->second.size(); - } - } - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst), - dst = encode(dst, (UInt16)this->_value.size()); - for(std::map<std::string, std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++){ - dst = encode(dst, (UInt16)_choices[i].size()); - for(std::map<std::string, std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - } - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 len) - { - src = parameter::parseAttribute(src, len); - UInt16 m = 0, n = 0; - std::string key, value; - src = parse(src, n); - for(int i=0; i<n; i++) { - src = parse(src, key, '\0'); - src = parse(src, value, '\0'); - _value[key] = value; - } - src = parse(src, n); - _choices.resize(n); - for(int i=0; i<n; i++) { - src = parse(src, m); - for(int j=0; j<m; j++) { - src = parse(src, key, '\0'); - src = parse(src, value, '\0'); - _choices[i][key] = value; - } - } - return src; - } - void showAttribute() const {} -#endif }; // The parameter space, i.e., the set of parameters stored and handled by the @@ -979,8 +492,6 @@ namespace onelab{ private: std::set<number*, parameterLessThan> _numbers; std::set<string*, parameterLessThan> _strings; - std::set<region*, parameterLessThan> _regions; - std::set<function*, parameterLessThan> _functions; // delete a parameter from the parameter space template <class T> bool _clear(const std::string &name, const std::string &client, @@ -1028,9 +539,6 @@ namespace onelab{ } else{ T* newp = new T(p); -#ifdef HAVE_ONELAB2 - newp->isInDatabase(true); -#endif if(client.size()) newp->addClient(client, true); ps.insert(newp); } @@ -1074,8 +582,6 @@ namespace onelab{ { ps.insert(_numbers.begin(), _numbers.end()); ps.insert(_strings.begin(), _strings.end()); - ps.insert(_regions.begin(), _regions.end()); - ps.insert(_functions.begin(), _functions.end()); } public: parameterSpace(){} @@ -1090,50 +596,32 @@ namespace onelab{ delete *it; _numbers.clear(); _strings.clear(); - _regions.clear(); - _functions.clear(); } else{ bool done = _clear(name, client, _numbers); if(!done) done = _clear(name, client, _strings); - if(!done) done = _clear(name, client, _regions); - if(!done) done = _clear(name, client, _functions); } } bool set(const number &p, const std::string &client=""){ return _set(p, client, _numbers); } bool set(const string &p, const std::string &client=""){ return _set(p, client, _strings); } - bool set(const region &p, - const std::string &client=""){ return _set(p, client, _regions); } - bool set(const function &p, - const std::string &client=""){ return _set(p, client, _functions); } bool get(std::vector<number> &ps, const std::string &name="", const std::string &client=""){ return _get(ps, name, client, _numbers); } bool get(std::vector<onelab::string> &ps, const std::string &name="", const std::string &client=""){ return _get(ps, name, client, _strings); } - bool get(std::vector<region> &ps, const std::string &name="", - const std::string &client=""){ return _get(ps, name, client, _regions); } - bool get(std::vector<function> &ps, const std::string &name="", - const std::string &client=""){ return _get(ps, name, client, _functions); } void getPtr(number **ptr, const std::string name, const std::string client="") {*ptr = _getPtr(name, client, _numbers);} void getPtr(string **ptr, const std::string name, const std::string client="") {*ptr = _getPtr(name, client, _strings);} - void getPtr(region **ptr, const std::string name, const std::string client="") - {*ptr = _getPtr(name, client, _regions);} - void getPtr(function **ptr, const std::string name, const std::string client="") - {*ptr = _getPtr(name, client, _functions);} void getAllParameters(std::set<parameter*, parameterLessThan> &ps) const { ps.insert(_numbers.begin(), _numbers.end()); ps.insert(_strings.begin(), _strings.end()); - ps.insert(_regions.begin(), _regions.end()); - ps.insert(_functions.begin(), _functions.end()); } unsigned int getNumParameters() { - return (int)(_numbers.size() + _strings.size() + _regions.size() + _functions.size()); + return (int)(_numbers.size() + _strings.size()); } // check if at least one parameter depends on the given client bool hasClient(const std::string &client) const @@ -1197,12 +685,6 @@ namespace onelab{ else if(type == "string"){ onelab::string p; p.fromChar(msg[i]); set(p, client); } - else if(type == "region"){ - onelab::region p; p.fromChar(msg[i]); set(p, client); - } - else if(type == "function"){ - onelab::function p; p.fromChar(msg[i]); set(p, client); - } else return false; } @@ -1243,12 +725,8 @@ namespace onelab{ virtual bool clear(const std::string &name) = 0; virtual bool set(const number &p) = 0; virtual bool set(const string &p) = 0; - virtual bool set(const region &p) = 0; - virtual bool set(const function &p) = 0; virtual bool get(std::vector<number> &ps, const std::string &name="") = 0; virtual bool get(std::vector<onelab::string> &ps, const std::string &name="") = 0; - virtual bool get(std::vector<region> &ps, const std::string &name="") = 0; - virtual bool get(std::vector<function> &ps, const std::string &name="") = 0; std::vector<std::string> toChar() { std::vector<std::string> out; @@ -1256,10 +734,6 @@ namespace onelab{ for(unsigned int i = 0; i < n.size(); i++) out.push_back(n[i].toChar()); std::vector<string> s; get(s); for(unsigned int i = 0; i < s.size(); i++) out.push_back(s[i].toChar()); - std::vector<region> r; get(r); - for(unsigned int i = 0; i < r.size(); i++) out.push_back(r[i].toChar()); - std::vector<function> f; get(f); - for(unsigned int i = 0; i < f.size(); i++) out.push_back(f[i].toChar()); return out; } bool fromChar(const std::vector<std::string> &msg) @@ -1274,12 +748,6 @@ namespace onelab{ else if(type == "string"){ onelab::string p; p.fromChar(msg[i]); set(p); } - else if(type == "region"){ - onelab::region p; p.fromChar(msg[i]); set(p); - } - else if(type == "function"){ - onelab::function p; p.fromChar(msg[i]); set(p); - } else return false; } @@ -1405,16 +873,10 @@ namespace onelab{ } virtual bool set(const number &p){ return _set(p); } virtual bool set(const string &p){ return _set(p); } - virtual bool set(const function &p){ return _set(p); } - virtual bool set(const region &p){ return _set(p); } virtual bool get(std::vector<number> &ps, const std::string &name=""){ return _get(ps, name); } virtual bool get(std::vector<onelab::string> &ps, const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<function> &ps, - const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<region> &ps, - const std::string &name=""){ return _get(ps, name); } }; // The local part of a network client. @@ -1604,16 +1066,10 @@ namespace onelab{ } virtual bool set(const number &p){ return _set(p); } virtual bool set(const string &p){ return _set(p); } - virtual bool set(const function &p){ return _set(p); } - virtual bool set(const region &p){ return _set(p); } virtual bool get(std::vector<number> &ps, const std::string &name=""){ return _get(ps, name); } virtual bool get(std::vector<onelab::string> &ps, const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<function> &ps, - const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<region> &ps, - const std::string &name=""){ return _get(ps, name); } void sendInfo(const std::string &msg) { if(_gmshClient) _gmshClient->Info(msg.c_str()); diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp index ccb5138120..d0607fbeef 100644 --- a/Common/onelabUtils.cpp +++ b/Common/onelabUtils.cpp @@ -22,98 +22,21 @@ #include "PViewOptions.h" #endif -#if defined(HAVE_ONELAB2) -#include "OnelabDatabase.h" -#include "OnelabServer.h" -#endif - namespace onelabUtils { // get command line arguments for the client if "UseCommandLine" is set for // this client -#ifdef HAVE_ONELAB2 - std::vector<std::string> getCommandLine(const std::string &client) - { - std::vector<std::string> args; - std::vector<onelab::number> n; - OnelabDatabase::instance()->get(n, client + "/UseCommandLine"); - if(n.size() && n[0].getValue()){ - std::vector<onelab::string> ps; - OnelabDatabase::instance()->get(ps, client + "/Action"); - std::string action = (ps.empty() ? "" : ps[0].getValue()); - OnelabDatabase::instance()->get(ps, client + "/1ModelName"); - std::string modelName = (ps.empty() ? "" : ps[0].getValue()); - OnelabDatabase::instance()->get(ps, client + "/9CheckCommand"); - std::string checkCommand = (ps.empty() ? "" : ps[0].getValue()); - OnelabDatabase::instance()->get(ps, client + "/9ComputeCommand"); - std::string computeCommand = (ps.empty() ? "" : ps[0].getValue()); - if(modelName.size()) args.push_back(" \"" + modelName + "\""); - if(action == "check") - args.push_back(" " + checkCommand) ; - else if(action == "compute") - args.push_back(" " + computeCommand); - } - return args; - } - std::string getMshFileName() - { - std::string name; - std::vector<onelab::string> ps; - OnelabDatabase::instance()->get(ps, "Gmsh/MshFileName"); - if(ps.size()){ - name = ps[0].getValue(); - } - else{ - name = CTX::instance()->outputFileName; - if(name.empty()){ - if(CTX::instance()->mesh.fileFormat == FORMAT_AUTO) - name = GetDefaultFileName(FORMAT_MSH); - else - name = GetDefaultFileName(CTX::instance()->mesh.fileFormat); - } - onelab::string o("Gmsh/MshFileName", name, "Mesh name"); - o.setKind("file"); - o.setAttribute("Closed", "1"); - OnelabDatabase::instance()->set(o, std::string("Gmsh")); - } - return name; - } - - void guessModelName(const std::string &client) - { - std::vector<onelab::number> n; - OnelabDatabase::instance()->get(n, client + "/GuessModelName"); - if(n.size() && n[0].getValue()){ - std::vector<onelab::string> ps; - OnelabDatabase::instance()->get(ps, client + "/1ModelName"); - if(ps.empty()){ - OnelabDatabase::instance()->get(ps, "Gmsh/1ModelName"); - std::vector<std::string> split; - if(!ps.empty()) split = SplitFileName(ps[0].getValue()); - else split = SplitFileName(GModel::current()->getFileName()); - std::string ext = ""; - OnelabDatabase::instance()->get(ps, client + "/FileExtension"); - if(ps.size()) ext = ps[0].getValue(); - std::string name(split[0] + split[1] + ext); - onelab::string o(client + "/1ModelName", name, "Model name"); - o.setKind("file"); - OnelabDatabase::instance()->set(o, client); - } - } - } - -#else std::vector<std::string> getCommandLine(onelab::client *c) { std::vector<std::string> args; std::string name(c->getName()); std::vector<onelab::number> n; - c->get(n, name + "/UseCommandLine"); + c->get(n, name + "/Use command line"); if(n.size() && n[0].getValue()){ std::vector<onelab::string> ps; c->get(ps, name + "/Action"); std::string action = (ps.empty() ? "" : ps[0].getValue()); - c->get(ps, name + "/1ModelName"); + c->get(ps, name + "/Model name"); std::string modelName = (ps.empty() ? "" : ps[0].getValue()); c->get(ps, name + "/9CheckCommand"); std::string checkCommand = (ps.empty() ? "" : ps[0].getValue()); @@ -129,7 +52,8 @@ namespace onelabUtils { std::ostringstream sstream; sstream.precision(16); std::map<std::string, std::vector<double> > cln(Msg::GetCommandLineNumbers()); - for(std::map<std::string, std::vector<double> >::iterator it = cln.begin(); it != cln.end(); it++){ + for(std::map<std::string, std::vector<double> >::iterator it = cln.begin(); + it != cln.end(); it++){ if(it->second.size() == 1){ sstream << " -setnumber " << it->first << " " << it->second[0]; } @@ -140,7 +64,8 @@ namespace onelabUtils { } } std::map<std::string, std::string> cls(Msg::GetCommandLineStrings()); - for(std::map<std::string, std::string>::iterator it = cls.begin(); it != cls.end(); it++) + for(std::map<std::string, std::string>::iterator it = cls.begin(); + it != cls.end(); it++) sstream << " -setstring " << it->first << " " << it->second; args.push_back(sstream.str()); } @@ -183,25 +108,24 @@ namespace onelabUtils { void guessModelName(onelab::client *c) { std::vector<onelab::number> n; - c->get(n, c->getName() + "/GuessModelName"); + c->get(n, c->getName() + "/Guess model name"); if(n.size() && n[0].getValue()){ std::vector<onelab::string> ps; - c->get(ps, c->getName() + "/1ModelName"); + c->get(ps, c->getName() + "/Model name"); if(ps.empty()){ std::vector<std::string> split = SplitFileName(GModel::current()->getFileName()); std::string ext = ""; - onelab::server::instance()->get(ps, c->getName() + "/FileExtension"); + onelab::server::instance()->get(ps, c->getName() + "/File extension"); if(ps.size()) ext = ps[0].getValue(); std::string name(split[0] + split[1] + ext); - onelab::string o(c->getName() + "/1ModelName", name, "Model name"); + onelab::string o(c->getName() + "/Model name", name); o.setKind("file"); + o.setAttribute("Persistent", "1"); c->set(o); } } } -#endif - void initializeLoop(const std::string &level) { bool changed = false; @@ -392,78 +316,6 @@ namespace onelabUtils { static bool _firstComputation = true; void setFirstComputationFlag(bool val){ _firstComputation = val; } bool getFirstComputationFlag(){ return _firstComputation; } -#ifdef HAVE_ONELAB2 - bool runGmshClient(const std::string &action, int meshAuto) - { - bool redraw = false; - - // do nothing in case of a python metamodel - std::vector<onelab::number> pn; - OnelabDatabase::instance()->get(pn, "IsPyMetamodel"); - if(pn.size() && pn[0].getValue()) return redraw; - - OnelabLocalNetworkClient *c = OnelabServer::instance()->getClient("Gmsh"); - if(c != NULL) return redraw; // Gmsh is remote TODO - - std::string mshFileName = onelabUtils::getMshFileName(); - - Msg::SetOnelabAction(action); - - static std::string modelName = GModel::current()->getName(); - - if(action == "initialize"){ - // nothing to do - } - else if(action == "reset"){ - setFirstComputationFlag(false); - // nothing more to do: "check" will be called right afterwards - } - else if(action == "check"){ - if(OnelabServer::instance()->getChanged("Gmsh") || - modelName != GModel::current()->getName()){ - // reload geometry if Gmsh parameters have been modified or - // if the model name has changed - modelName = GModel::current()->getName(); - redraw = true; - OpenProject(GModel::current()->getFileName(), false); - OnelabServer::instance()->setChanged(true, "Gmsh"); - } - } - else if(action == "compute"){ - if(OnelabServer::instance()->getChanged("Gmsh") || - modelName != GModel::current()->getName()){ - // reload the geometry, mesh it and save the mesh if Gmsh parameters - // have been modified or if the model name has changed - modelName = GModel::current()->getName(); - redraw = true; - OpenProject(GModel::current()->getFileName(), false); - if(getFirstComputationFlag() && !StatFile(mshFileName) && meshAuto != 2){ - Msg::Info("Skipping mesh generation: assuming '%s' is up-to-date " - "(use Solver.AutoMesh=2 to force mesh generation)", - mshFileName.c_str()); - } - else if(!GModel::current()->empty() && meshAuto){ - GModel::current()->mesh(3); - CreateOutputFile(mshFileName, CTX::instance()->mesh.fileFormat); - } - } - else if(StatFile(mshFileName)){ - // mesh+save if the mesh file does not exist - if(meshAuto){ - redraw = true; - GModel::current()->mesh(3); - CreateOutputFile(mshFileName, CTX::instance()->mesh.fileFormat); - } - } - setFirstComputationFlag(false); - OnelabServer::instance()->setChanged(false, "Gmsh"); - } - - Msg::SetOnelabAction(""); - - return redraw; - } -#else bool runGmshClient(const std::string &action, int meshAuto) { bool redraw = false; @@ -534,7 +386,7 @@ namespace onelabUtils { return redraw; } -#endif + // update x using y, giving priority to any settings in x that can be set in // the GUI. The value of x is only changed if y is read-only. double updateNumber(onelab::number &x, onelab::number &y, const bool readOnlyRange) diff --git a/Common/onelabUtils.h b/Common/onelabUtils.h index 595b700c04..211d3880af 100644 --- a/Common/onelabUtils.h +++ b/Common/onelabUtils.h @@ -12,15 +12,9 @@ // onelab servers namespace onelabUtils { -#ifdef HAVE_ONELAB2 - std::vector<std::string> getCommandLine(const std::string &client); - std::string getMshFileName(); - void guessModelName(const std::string &client); -#else std::vector<std::string> getCommandLine(onelab::client *c); std::string getMshFileName(onelab::client *c); void guessModelName(onelab::client *c); -#endif void initializeLoop(const std::string &level); bool incrementLoop(const std::string &level); std::vector<double> getRange(onelab::number &p); diff --git a/Fltk/CMakeLists.txt b/Fltk/CMakeLists.txt index a8740ea4b5..06986d40d6 100644 --- a/Fltk/CMakeLists.txt +++ b/Fltk/CMakeLists.txt @@ -29,18 +29,8 @@ set(SRC inputValue.cpp inputRegion.cpp viewButton.cpp solverButton.cpp Navigator.cpp -) -if(ENABLE_ONELAB2) - set(SRC - ${SRC} - onelab2Group.cpp - ) -else(ENABLE_ONELAB2) - set(SRC - ${SRC} onelabGroup.cpp - ) -endif(ENABLE_ONELAB2) +) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) append_gmsh_src(Fltk "${SRC};${HDR}") diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index 711d1bce40..2428044eba 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -29,12 +29,7 @@ typedef unsigned long intptr_t; #include "clippingWindow.h" #include "manipWindow.h" #include "contextWindow.h" -#ifdef HAVE_ONELAB2 -#include "onelab2Group.h" -#include "OnelabWindow.h" -#else #include "onelabGroup.h" -#endif #include "helpWindow.h" #include "colorbarWindow.h" #include "fileDialogs.h" @@ -446,9 +441,6 @@ FlGui::FlGui(int argc, char **argv) // create all other windows options = new optionWindow(CTX::instance()->deltaFontSize); -#if defined(HAVE_ONELAB2) - onelab2 = new onelabWindow(); -#endif fields = new fieldWindow(CTX::instance()->deltaFontSize); plugins = new pluginWindow(CTX::instance()->deltaFontSize); stats = new statisticsWindow(CTX::instance()->deltaFontSize); @@ -481,10 +473,6 @@ FlGui *FlGui::instance(int argc, char **argv) _instance = new FlGui(argc, argv); // set all options in the new GUI InitOptionsGUI(0); -#ifdef HAVE_ONELAB2 - // Enable multi-thread support by locking from the main thread - Fl::lock(); -#endif // say welcome! Msg::StatusBar(false, "Gmsh %s", GetGmshVersion()); diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp index 3dfc02b332..2b4a549f78 100644 --- a/Fltk/Main.cpp +++ b/Fltk/Main.cpp @@ -11,9 +11,6 @@ #include "Options.h" #include "PluginManager.h" #include "GModel.h" -#if defined(HAVE_ONELAB2) && defined(__linux__) -#include <X11/Xlib.h> -#endif int main(int argc, char *argv[]) { @@ -41,8 +38,5 @@ int main(int argc, char *argv[]) } // Interactive Gmsh with FLTK GUI -#if defined(HAVE_ONELAB2) && defined(__linux__) - XInitThreads(); -#endif return GmshFLTK(argc, argv); } diff --git a/Fltk/drawContextFltk.h b/Fltk/drawContextFltk.h index c3babe88f5..a4b079cbee 100644 --- a/Fltk/drawContextFltk.h +++ b/Fltk/drawContextFltk.h @@ -35,9 +35,6 @@ class drawContextFltk : public drawContextGlobal{ } } } -#ifndef HAVE_ONELAB2 - FlGui::instance()->check(); -#endif } void drawCurrentOpenglWindow(bool make_current) { diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index ca249f1135..85aad3c9ae 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -33,11 +33,7 @@ typedef unsigned long intptr_t; #include "fieldWindow.h" #include "pluginWindow.h" #include "helpWindow.h" -#if defined(HAVE_ONELAB2) -#include "OnelabWindow.h" -#else #include "gmshLocalNetworkClient.h" -#endif #include "fileDialogs.h" #include "extraDialogs.h" #include "partitionDialog.h" @@ -184,7 +180,6 @@ static void file_clear_cb(Fl_Widget *w, void *data) static void file_remote_cb(Fl_Widget *w, void *data) { -#if not defined(HAVE_ONELAB2) onelab::localNetworkClient *c; onelab::server::citer it = onelab::server::instance()->findClient("GmshRemote"); if(it == onelab::server::instance()->lastClient()){ @@ -228,7 +223,6 @@ static void file_remote_cb(Fl_Widget *w, void *data) server->SendString(GmshSocket::GMSH_SPEED_TEST, "Speed test"); } } -#endif } static void file_window_cb(Fl_Widget *w, void *data) @@ -2020,9 +2014,6 @@ static Fl_Menu_Item bar_table[] = { {0}, {"&Tools", 0, 0, 0, FL_SUBMENU}, {"&Options", FL_CTRL+FL_SHIFT+'n', (Fl_Callback *)options_cb, 0}, -#if defined(HAVE_ONELAB2) - {"&Onelab2", 0, (Fl_Callback *)onelab2_cb, 0}, -#endif {"Pl&ugins", FL_CTRL+FL_SHIFT+'u', (Fl_Callback *)plugin_cb, (void*)(-1)}, {"&Visibility", FL_CTRL+FL_SHIFT+'v', (Fl_Callback *)visibility_cb, 0}, {"&Clipping", FL_CTRL+FL_SHIFT+'c', (Fl_Callback *)clip_cb, 0}, diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h index 58b2da58ff..52859e118f 100644 --- a/Fltk/graphicWindow.h +++ b/Fltk/graphicWindow.h @@ -19,11 +19,7 @@ #endif #include <FL/Fl_Menu_Bar.H> #include "openglWindow.h" -#ifdef HAVE_ONELAB2 -#include "onelab2Group.h" -#else #include "onelabGroup.h" -#endif class graphicWindow{ private: diff --git a/Fltk/onelab2Group.cpp b/Fltk/onelab2Group.cpp deleted file mode 100644 index 6517dba073..0000000000 --- a/Fltk/onelab2Group.cpp +++ /dev/null @@ -1,1045 +0,0 @@ -#include "onelab2Group.h" - -#include "FlGui.h" -#include <FL/Fl_Box.H> -#include <FL/Fl_Check_Button.H> -#include <FL/Fl_Input_Choice.H> -#include <FL/Fl_Choice.H> -#include <FL/Fl_Menu_Item.H> -#include "inputRange.h" -#include "outputRange.h" -#include "inputRegion.h" -#include "drawContext.h" -#include "viewButton.h" -#include "solverButton.h" -#include "PView.h" -#include "PViewOptions.h" - -#include "Gmsh.h" -#include "onelabUtils.h" -#include "OnelabDatabase.h" -#include "Options.h" -#include "Context.h" - -static void updateGraphs() -{ - bool redraw = true; //FIXME false; - for(int i = 0; i < 18; i++){ - std::ostringstream tmp; - tmp << i; - bool ret = onelabUtils::updateGraph(tmp.str()); - redraw = redraw || ret; - } - if(redraw){ - // don't delete the widgets, as this is called in widget callbacks - FlGui::instance()->updateViews(true, false); - drawContext::global()->draw(); - } -} - -void connect_cb(Fl_Widget *w, void *arg) -{ - if(!arg) return; - onelabGroup *obj = (onelabGroup *)arg; - if(strcmp(w->label(), "Connect") == 0) { - if(!obj->useServer()) return; - obj->clearTree(); - GmshNetworkClient *cli = OnelabDatabase::instance()->useAsNetworkClient(obj->getServerIP(), obj->getServerPort()); - if(cli) { - cli->setCallback(obj); - w->label("Disconnect"); - } - else - fl_alert("Unable to connect to server"); - } - else { - obj->clearTree(); - OnelabDatabase::instance()->useAsClient()->setCallback(obj); - w->label("Connect"); - } -} - -void useserver_cb(Fl_Widget *w, void *arg) -{ - if(!arg) return; - Fl_Check_Button *checkbox = (Fl_Check_Button *)w; - onelabGroup *obj = (onelabGroup *)arg; - obj->useServer(checkbox->value() == 1); -} - -void onelab_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - - std::string action((const char*)data); - - if(action == "refresh"){ - updateGraphs(); - return; - } - - if(action == "stop"){ // TODO send stop if server is not local - //FlGui::instance()->onelab->stop(true); - FlGui::instance()->onelab->setButtonMode("", ""); // wait for the client to stop - OnelabServer::instance()->stopClients(); - return; - } - - if(FlGui::instance()->onelab->isBusy()){ - Msg::Info("I'm busy! Ask me that later..."); - return; - } - - if(action == "reset"){ - OnelabDatabase::instance()->clear(); // TODO keep persitant - OnelabDatabase::instance()->run(action, "Gmsh"); - FlGui::instance()->onelab->clearTree(true); - - action = "check"; - } - - Msg::ResetErrorCounter(); - - FlGui::instance()->onelab->setButtonMode("", "stop"); - - OnelabDatabase::instance()->run(action); - drawContext::global()->draw(); -} - -void onelab_option_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - std::string what((const char*)data); - double val = ((Fl_Menu_*)w)->mvalue()->value() ? 1. : 0.; - if(what == "save") - CTX::instance()->solver.autoSaveDatabase = val; - else if(what == "archive") - CTX::instance()->solver.autoArchiveOutputFiles = val; - else if(what == "check"){ - CTX::instance()->solver.autoCheck = val; - FlGui::instance()->onelab->setButtonVisibility(); - } - else if(what == "mesh") - CTX::instance()->solver.autoMesh = val; - else if(what == "merge") - CTX::instance()->solver.autoMergeFile = val; - else if(what == "show") - CTX::instance()->solver.autoShowViews = val ? 2 : 0; - else if(what == "step") - CTX::instance()->solver.autoShowLastStep = val; - else if(what == "invisible"){ - CTX::instance()->solver.showInvisibleParameters = val; - //FlGui::instance()->onelab->rebuildTree(true); - } -} - -void solver_cb(Fl_Widget *w, void *data) -{ - if(!FlGui::instance()->onelab) return; - - if(FlGui::instance()->onelab->isBusy()) - FlGui::instance()->onelab->show(); - - int num = (intptr_t)data; - if(num >= 0){ - onelab_cb(0, (void*)"reset"); - std::string name = opt_solver_name(num, GMSH_GET, ""); - if(name.empty()) return;// TODO - std::string exe = opt_solver_executable(num, GMSH_GET, ""); - std::string host = opt_solver_remote_login(num, GMSH_GET, ""); - OnelabDatabase::instance()->run("initialize", name); - FlGui::instance()->onelab->addSolver(name, exe, host, num); - } - - if(num >= 0) { - onelab_cb(0, (void*)"check"); - } - else { - onelab_cb(0, (void*)"refresh"); - } - FlGui::instance()->onelab->updateGearMenu(); -} - -static bool getFlColor(const std::string &str, Fl_Color &c) -{ - if(str == "1"){ - c = FL_YELLOW; - return true; - } - int r, g, b; - if(str.size() && GetRGBForString(str.c_str(), r, g, b)){ - c = fl_color_cube(r * (FL_NUM_RED - 1) / 255, - g * (FL_NUM_GREEN - 1) / 255, - b * (FL_NUM_BLUE - 1) / 255); - return true; - } - c = FL_BLACK; - return false; -} - -#if !defined(__APPLE__) -#define gear_width 16 -#define gear_height 16 -static unsigned char gear_bits[] = { - 0x80, 0x01, 0x80, 0x01, 0x8c, 0x31, 0xfc, 0x3f, 0xf8, 0x1f, 0xf8, 0x1f, - 0x38, 0x1c, 0x3f, 0xfc, 0x3f, 0xfc, 0x38, 0x1c, 0xf8, 0x1f, 0xf8, 0x1f, - 0xfc, 0x3f, 0x8c, 0x31, 0x80, 0x01, 0x80, 0x01 }; -#endif - -onelabGroup::onelabGroup(int x, int y, int w, int h, const char *l) - : Fl_Group(x, y, w, h, l), _stop(false), _enableTreeWidgetResize(false) -{ - int col = FL_BACKGROUND2_COLOR; - color(col); - - box(GMSH_SIMPLE_RIGHT_BOX); - int dx = Fl::box_dx(box()); - int dy = Fl::box_dy(box()); - int dw = Fl::box_dw(box()); - int dh = Fl::box_dh(box()); - - _tree = new Fl_Tree(x + dx, y + dy, w - dw, h - dh - BH - 2 * WB - 6*BH); - _tree->color(col); - // TODO _tree->callback(onelab_tree_cb); - _tree->connectorstyle(FL_TREE_CONNECTOR_SOLID); - _tree->showroot(0); - _tree->box(FL_FLAT_BOX); - _tree->scrollbar_size(std::max(10, FL_NORMAL_SIZE - 2)); - _tree->add("0Post-processing/"); - _tree->end(); - - _computeWidths(); - _widgetLabelRatio = 0.48; - - int BB2 = BB / 2 + 4; - _butt[0] = new Fl_Button(x + w - 3 * WB - 3 * BB2, y + h - WB - BH, BB2, BH, "Check"); - _butt[0]->callback(onelab_cb, (void*)"check"); - - _butt[1] = new Fl_Button(x + w - 2 * WB - 2 * BB2, y + h - WB - BH, BB2, BH, "Run"); - _butt[1]->callback(onelab_cb, (void*)"compute"); - - _gear = new Fl_Menu_Button(x + w - WB - BB2, y + h - WB - BH, BB2, BH); -#if defined(__APPLE__) - _gear->label("@-1gmsh_gear"); -#else - _gear->image(new Fl_Bitmap(gear_bits, gear_width, gear_height)); -#endif - _gear->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); - _gear->add("Reset database", 0, onelab_cb, (void*)"reset"); - _gear->add("Save database...", 0, onelab_cb, (void*)"save"); - _gear->add("_Load database...", 0, onelab_cb, (void*)"load"); - - _minWindowWidth = 3 * BB2 + 4 * WB; - _minWindowHeight = 2 * BH + 3 * WB; - - _gearOptionsStart = _gear->menu()->size(); - - _gear->add("Save && load database automatically", 0, onelab_option_cb, (void*)"save", - FL_MENU_TOGGLE); - _gear->add("Archive output files automatically", 0, onelab_option_cb, (void*)"archive", - FL_MENU_TOGGLE); - _gear->add("Check model after each change", 0, onelab_option_cb, (void*)"check", - FL_MENU_TOGGLE); - _gear->add("Remesh automatically", 0, onelab_option_cb, (void*)"mesh", - FL_MENU_TOGGLE); - _gear->add("Merge results automatically", 0, onelab_option_cb, (void*)"merge", - FL_MENU_TOGGLE); - _gear->add("Show new views", 0, onelab_option_cb, (void*)"show", - FL_MENU_TOGGLE); - _gear->add("Always show last step", 0, onelab_option_cb, (void*)"step", - FL_MENU_TOGGLE); - _gear->add("_Show hidden parameters", 0, onelab_option_cb, (void*)"invisible", - FL_MENU_TOGGLE); - - _gearOptionsEnd = _gear->menu()->size(); - - //_gear->add("Add new solver...", 0, onelab_add_solver_cb); - - end(); - - Fl_Box *resbox = new Fl_Box(x + WB, y + WB, WB, WB); - resizable(resbox); - - rebuildSolverList(); - - if(!OnelabDatabase::instance()->isNetworkClient()) OnelabDatabase::instance()->useAsClient()->setCallback(this); -} -onelabGroup::~onelabGroup() -{ - Fl::delete_widget(_tree); -} - -void onelabGroup::clearTree(bool deleteWidgets) -{ - _tree->clear(); - _tree->sortorder(FL_TREE_SORT_ASCENDING); - _tree->selectmode(FL_TREE_SELECT_NONE); - - std::vector<Fl_Widget*> delWidgets; - std::vector<char*> delStrings; - if(deleteWidgets){ - delWidgets = _treeWidgets; - delStrings = _treeStrings; - _treeWidgets.clear(); - _treeStrings.clear(); - } - FlGui::check(); - if(deleteWidgets){ - for(unsigned int i = 0; i < delWidgets.size(); i++) - Fl::delete_widget(delWidgets[i]); - for(unsigned int i = 0; i < delStrings.size(); i++) - free(delStrings[i]); - } - _tree->redraw(); -} - -void onelabGroup::openTreeItem(const std::string &name) -{ - Fl_Tree_Item *n = _tree->find_item(name.c_str()); - if(n && n->has_children()){ - n->open(); - _tree->redraw(); - } -} - -void onelabGroup::setButtonVisibility() -{ - std::vector<onelab::number> numbers; - OnelabDatabase::instance()->get(numbers); - bool showRun = /*OnelabDatabase::instance()->getNumClients() > 1 FIXME*/true || numbers.size(); - if(CTX::instance()->solver.autoCheck){ - _butt[0]->hide(); - if(showRun) - _butt[1]->show(); - else - _butt[1]->hide(); - } - else if(showRun){ - _butt[0]->show(); - _butt[1]->show(); - } - else{ - _butt[0]->hide(); - _butt[1]->hide(); - } - redraw(); -} - -void onelabGroup::setButtonMode(const std::string &butt0, const std::string &butt1) -{ - if(butt0 == "check"){ - _butt[0]->activate(); - _butt[0]->label("Check"); - _butt[0]->callback(onelab_cb, (void*)"check"); - } - else{ - _butt[0]->deactivate(); - } - - if(butt1 == "compute"){ - _butt[1]->activate(); - _butt[1]->label("Run"); - _butt[1]->callback(onelab_cb, (void*)"compute"); - for(int i = 0; i < _gear->menu()->size(); i++) - ((Fl_Menu_Item*)_gear->menu())[i].activate(); - } - else if(butt1 == "stop"){ - _butt[1]->activate(); - _butt[1]->label("Stop"); - _butt[1]->callback(onelab_cb, (void*)"stop"); - for(int i = 0; i < _gear->menu()->size(); i++) - if(i < _gearOptionsStart - 1 || i > _gearOptionsEnd - 2) - ((Fl_Menu_Item*)_gear->menu())[i].deactivate(); - } - else if(butt1 == "kill"){ - _butt[1]->activate(); - _butt[1]->label("Kill"); - _butt[1]->callback(onelab_cb, (void*)"kill"); - for(int i = 0; i < _gear->menu()->size(); i++) - if(i < _gearOptionsStart - 1 || i > _gearOptionsEnd - 2) - ((Fl_Menu_Item*)_gear->menu())[i].deactivate(); - } - else{ - _butt[1]->deactivate(); - for(int i = 0; i < _gear->menu()->size(); i++) - if(i < _gearOptionsStart - 1 || i > _gearOptionsEnd - 2) - ((Fl_Menu_Item*)_gear->menu())[i].deactivate(); - } -} - -void onelabGroup::updateGearMenu() -{ - Fl_Menu_Item* menu = (Fl_Menu_Item*)_gear->menu(); - int values[8] = {CTX::instance()->solver.autoSaveDatabase, - CTX::instance()->solver.autoArchiveOutputFiles, - CTX::instance()->solver.autoCheck, - CTX::instance()->solver.autoMesh, - CTX::instance()->solver.autoMergeFile, - CTX::instance()->solver.autoShowViews, - CTX::instance()->solver.autoShowLastStep, - CTX::instance()->solver.showInvisibleParameters}; - for(int i = 0; i < 8; i++){ - int idx = _gearOptionsStart - 1 + i; - if(values[i]) - menu[idx].set(); - else - menu[idx].clear(); - } -} - -void onelabGroup::addLastPostProcessing() -{ - _tree->sortorder(FL_TREE_SORT_NONE); - _addViewMenu(PView::list.size()-1); - _tree->sortorder(FL_TREE_SORT_ASCENDING); - for(unsigned int i = 0; i < PView::list.size(); i++) - getViewButton(i)->value(PView::list[i]->getOptions()->visible); -} - -void onelabGroup::rebuildSolverList() -{ - updateGearMenu(); - - std::vector<std::string> names, exes, hosts; - for(int i = 0; i < NUM_SOLVERS; i++){ - if(opt_solver_name(i, GMSH_GET, "").size()){ - names.push_back(opt_solver_name(i, GMSH_GET, "")); - exes.push_back(opt_solver_executable(i, GMSH_GET, "")); - hosts.push_back(opt_solver_remote_login(i, GMSH_GET, "")); - } - } - for(unsigned int i = 0; i < NUM_SOLVERS; i++){ - if(i < names.size()){ - onelab::server::citer it = onelab::server::instance()->findClient(names[i]); - if(it != onelab::server::instance()->lastClient()) - (*it)->setIndex(i); - opt_solver_name(i, GMSH_SET, names[i]); - opt_solver_executable(i, GMSH_SET, exes[i]); - opt_solver_remote_login(i, GMSH_SET, hosts[i]); - } - else{ - opt_solver_name(i, GMSH_SET, ""); - opt_solver_executable(i, GMSH_SET, ""); - opt_solver_remote_login(i, GMSH_SET, ""); - } - } - - setButtonVisibility(); - //refreshTree(true); -} - -void onelabGroup::addSolver(const std::string &name, const std::string &executable, - const std::string &remoteLogin, int index) -{ - //onelab::server::citer it = onelab::server::instance()->findClient(name); - //if(it != onelab::server::instance()->lastClient()){ - // if(needToChooseExe(executable)) - // onelab_choose_executable_cb(0, (void *)(*it)); - // return; // solver already exists - //} - - //// delete the other non-local clients so we keep only the new one - //std::vector<onelab::client*> networkClients; - //for(onelab::server::citer it = onelab::server::instance()->firstClient(); - // it != onelab::server::instance()->lastClient(); it++) - // if((*it)->isNetworkClient()) - // networkClients.push_back(*it); - //for(unsigned int i = 0; i < networkClients.size(); i++){ - // delete networkClients[i]; - //} - - //// create and register the new client - //onelab::localNetworkClient *c = new gmshLocalNetworkClient(name, executable, - // remoteLogin); - //c->setIndex(index); - //opt_solver_name(index, GMSH_SET, name); - //if(needToChooseExe(executable)) - // onelab_choose_executable_cb(0, (void *)c); - //opt_solver_remote_login(index, GMSH_SET, remoteLogin); - - FlGui::instance()->onelab->rebuildSolverList(); -} - -bool onelabGroup::useServer() {return !server_ip->readonly();} -void onelabGroup::useServer(bool use=false) -{ - server_ip->readonly(!use); - server_port->readonly(!use); -} - -void onelabGroup::addParameter(onelab::parameter &p) -{ - if(!p.getVisible() || CTX::instance()->solver.showInvisibleParameters) return; - - bool highlight = false; - Fl_Color c; - if(getFlColor(p.getAttribute("Highlight"), c)) highlight = true; - Fl_Tree_Item *n = _tree->add(p.getName().c_str()); - if(!n) return; - n->labelsize(FL_NORMAL_SIZE + 4); - _tree->begin(); - int ww = _baseWidth - (n->depth() + 1) * _indent; - ww *= _widgetLabelRatio; // FIXME CHANGE THIS - int hh = n->labelsize() + 4; - Fl_Group *grp = new Fl_Group(1, 1, ww, hh); - Fl_Widget *widget = _addParameterWidget(p, ww, hh, n, highlight, c); - grp->end(); - if(!_enableTreeWidgetResize) grp->resizable(0); - _treeWidgets.push_back(grp); - widget->copy_label(p.getShortName().c_str()); - std::string help = p.getLabel().size() ? p.getLabel() : p.getShortName(); - if(p.getHelp().size()) help += ":\n" + p.getHelp(); - widget->copy_tooltip(help.c_str()); - n->widget(grp); - _tree->end(); - if(p.getAttribute("Closed") == "1" && p.getPath().size()) _tree->close(p.getPath().c_str(), 0); - _tree->redraw(); -} -Fl_Widget *onelabGroup::_addParameterWidget(onelab::parameter &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - int type = p.getAttributeType(); - if(type == onelab::number::attributeType()) - return _addParameterWidget(*(onelab::number *)&p, ww, hh, n, highlight, c); - if(type == onelab::string::attributeType()) - return _addParameterWidget(*(onelab::string *)&p, ww, hh, n, highlight, c); - if(type == onelab::region::attributeType()) - return _addParameterWidget(*(onelab::region *)&p, ww, hh, n, highlight, c); - if(type == onelab::function::attributeType()) - return _addParameterWidget(*(onelab::function *)&p, ww, hh, n, highlight, c); - return NULL; -} - -template<class T> -static void autoCheck(const T &pold, const T &pnew, bool force=false) -{ - if(onelabUtils::getFirstComputationFlag()){ - if(pold.getValue() != pnew.getValue()) - onelabUtils::setFirstComputationFlag(false); - } - - if((CTX::instance()->solver.autoCheck && pnew.getAttribute("AutoCheck") != "0") || - pnew.getAttribute("AutoCheck") == "1"){ - if(force || pold.getValue() != pnew.getValue()) - onelab_cb(0, (void*)"check"); - } -} - -template <class T> -static void setGmshOption(T &n) -{ - std::string opt = n.getAttribute("GmshOption"); - if(opt.empty()) return; - if(opt == "ResetDatabase"){ // special option to reset the onelab db - OnelabDatabase::instance()->clear(); - //TODO OnelabDatabase::instance()->reset(false); - //FlGui::instance()->rebuildTree(false); - return; - } - if(opt == "Reset"){ // reset db + models except current one - OnelabDatabase::instance()->clear(); - //TODO OnelabDatabase::instance()->reset(false); - //for(int i = PView::list.size() - 1; i >= 0; i--) - // delete PView::list[i]; - //for(int i = GModel::list.size() - 1; i >= 0; i--) - // if(GModel::list[i] != GModel::current()) delete GModel::list[i]; - //FlGui::instance()->rebuildTree(false); - return; - } - std::string::size_type dot = opt.find('.'); - if(dot == std::string::npos) return; - GmshSetOption(opt.substr(0, dot), opt.substr(dot + 1), n.getValue()); - drawContext::global()->draw(); -} - -// callback for number -static void onelab_number_input_range_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - std::string name((char*)data); - std::vector<onelab::number> numbers; - OnelabDatabase::instance()->get(numbers, name); - if(numbers.size()){ - inputRange *o = (inputRange*)w; - onelab::number old = numbers[0]; - if(o->doCallbackOnValues()){ - numbers[0].setValue(o->value()); - numbers[0].setMin(o->minimum()); - numbers[0].setMax(o->maximum()); - numbers[0].setStep(o->step()); - numbers[0].setChoices(o->choices()); - } - o->doCallbackOnValues(true); - numbers[0].setAttribute("Loop", o->loop()); - numbers[0].setAttribute("Graph", o->graph()); - setGmshOption(numbers[0]); - OnelabDatabase::instance()->set(numbers[0], std::string("localGUI")); - updateGraphs(); - autoCheck(old, numbers[0]); - } -} -static void onelab_number_choice_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - std::string name((char*)data); - std::vector<onelab::number> numbers; - OnelabDatabase::instance()->get(numbers, name); - if(numbers.size()){ - Fl_Choice *o = (Fl_Choice*)w; - std::vector<double> choices = numbers[0].getChoices(); - onelab::number old = numbers[0]; - if(o->value() < (int)choices.size()) numbers[0].setValue(choices[o->value()]); - setGmshOption(numbers[0]); - OnelabDatabase::instance()->set(numbers[0], std::string("localGUI")); - autoCheck(old, numbers[0]); - } -} -static void onelab_number_check_button_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - std::string name((char*)data); - std::vector<onelab::number> numbers; - OnelabDatabase::instance()->get(numbers, name); - if(numbers.size()){ - Fl_Check_Button *o = (Fl_Check_Button*)w; - onelab::number old = numbers[0]; - numbers[0].setValue(o->value()); - setGmshOption(numbers[0]); - OnelabDatabase::instance()->set(numbers[0], std::string("localGUI")); - autoCheck(old, numbers[0]); - } -} -// add a parameter number to the tree -Fl_Widget *onelabGroup::_addParameterWidget(onelab::number &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - char *path = strdup(getPath(n).c_str()); - _treeStrings.push_back(path); - - // enumeration (display choices as value labels, not numbers) - if(p.getChoices().size() && - p.getChoices().size() == p.getValueLabels().size()){ - Fl_Choice *but = new Fl_Choice(1, 1, ww, hh); - std::vector<Fl_Menu_Item> menu; - std::map<double, std::string> labels(p.getValueLabels()); - for(std::map<double, std::string>::iterator it = labels.begin(); - it != labels.end(); it++){ - char *str = strdup(it->second.c_str()); - _treeStrings.push_back(str); - Fl_Menu_Item menuItem = {str, 0, 0, 0, 0}; - if(highlight) menuItem.labelcolor(c); - menu.push_back(menuItem); - } - Fl_Menu_Item it = {0}; - menu.push_back(it); - but->copy(&menu[0]); - for(unsigned int i = 0; i < p.getChoices().size(); i++){ - if(p.getValue() == p.getChoices()[i]){ - but->value(i); - break; - } - } - but->callback(onelab_number_choice_cb, (void*)path); - but->align(FL_ALIGN_RIGHT); - if(p.getReadOnly()) but->deactivate(); - return but; - } - - // check box (boolean choice) - if(p.getChoices().size() == 2 && - p.getChoices()[0] == 0 && p.getChoices()[1] == 1){ - n->labelsize(FL_NORMAL_SIZE + 2); - Fl_Check_Button *but = new Fl_Check_Button(1, 1, ww / _widgetLabelRatio, hh); - but->box(FL_FLAT_BOX); - but->color(_tree->color()); - but->value(p.getValue()); - but->callback(onelab_number_check_button_cb, (void*)path); - if(highlight) but->color(c); - if(p.getReadOnly()) but->deactivate(); - return but; - } - - // non-editable value - if(p.getReadOnly()){ - outputRange *but = new outputRange(1, 1, ww, hh); - //TODO but->callback(onelab_number_output_range_cb, (void*)path); - but->value(p.getValue()); - but->align(FL_ALIGN_RIGHT); - but->graph(p.getAttribute("Graph")); - if(highlight) but->color(c); - return but; - } - - // general number input - inputRange *but = new inputRange(1, 1, ww, hh, onelab::parameter::maxNumber(), - p.getAttribute("ReadOnlyRange") == "1"); - but->value(p.getValue()); - but->minimum(p.getMin()); - but->maximum(p.getMax()); - but->step(p.getStep()); - but->choices(p.getChoices()); - but->loop(p.getAttribute("Loop")); - but->graph(p.getAttribute("Graph")); - but->callback(onelab_number_input_range_cb, (void*)path); - but->when(FL_WHEN_RELEASE | FL_WHEN_ENTER_KEY); - but->align(FL_ALIGN_RIGHT); - if(highlight) but->color(c); - return but; -} -// callback for string -static void onelab_string_input_choice_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - std::string name((char*)data); - std::vector<onelab::string> strings; - OnelabDatabase::instance()->get(strings, name); - if(strings.size()){ - Fl_Input_Choice *o = (Fl_Input_Choice*)w; - onelab::string old = strings[0]; - strings[0].setValue(o->value()); - std::string choices; - for(int i = 0; i < o->menubutton()->menu()->size(); i++){ - if(o->menubutton()->menu()[i].flags & FL_MENU_TOGGLE){ - if(o->menubutton()->menu()[i].flags & FL_MENU_VALUE) - choices += "1"; - else - choices += "0"; - } - } - if(choices.size()) - strings[0].setAttribute("MultipleSelection", choices); - //setGmshOption(strings[0]); - OnelabDatabase::instance()->set(strings[0], "localGUI"); - autoCheck(old, strings[0]); - } -} -// add parameter string to tree -Fl_Widget *onelabGroup::_addParameterWidget(onelab::string &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - char *path = strdup(getPath(n).c_str()); - _treeStrings.push_back(path); - - // macro button - if(p.getAttribute("Macro") == "Gmsh"){ - Fl_Button *but = new Fl_Button(1, 1, ww / _widgetLabelRatio, hh); - but->box(FL_FLAT_BOX); - but->color(_tree->color()); - but->selection_color(_tree->color()); - but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); - //TODO but->callback(onelab_string_button_cb, (void*)path); - if(highlight) but->color(c); - return but; - } - - // non-editable value - if(p.getReadOnly()){ - Fl_Output *but = new Fl_Output(1, 1, ww, hh); - but->value(p.getValue().c_str()); - but->align(FL_ALIGN_RIGHT); - if(highlight) but->color(c); - return but; - } - - // simple string (no menu) - if(p.getChoices().empty() && p.getKind() != "file"){ - Fl_Input *but = new Fl_Input(1, 1, ww, hh); - but->value(p.getValue().c_str()); - //TODO but->callback(onelab_string_input_cb, (void*)path); - but->when(FL_WHEN_ENTER_KEY); - but->align(FL_ALIGN_RIGHT); - if(highlight) but->color(c); - return but; - } - - // general string input - Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, ww, hh); - std::string multipleSelection = p.getAttribute("MultipleSelection"); - if(multipleSelection.size()) - ;//but->menubutton()->callback(multiple_selection_menu_cb, but); - std::vector<Fl_Menu_Item> menu; - for(unsigned int j = 0; j < p.getChoices().size(); j++){ - char *str = strdup(p.getChoices()[j].c_str()); - _treeStrings.push_back(str); - bool divider = (p.getKind() == "file" && - j == p.getChoices().size() - 1); - int choice = multipleSelection.size() ? FL_MENU_TOGGLE : 0; - if(multipleSelection.size() > j && multipleSelection[j] == '1') - choice |= FL_MENU_VALUE; - Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : choice}; - menu.push_back(it); - } - //if(p.getKind() == "file"){ - // Fl_Menu_Item it = {"Choose...", 0, onelab_input_choice_file_chooser_cb, (void*)n}; - // menu.push_back(it); - // Fl_Menu_Item it2 = {"Edit...", 0, onelab_input_choice_file_edit_cb, (void*)n}; - // menu.push_back(it2); - // if(GuessFileFormatFromFileName(p.getValue()) >= 0){ - // Fl_Menu_Item it3 = {"Merge...", 0, onelab_input_choice_file_merge_cb, (void*)n}; - // menu.push_back(it3); - // } - //} - Fl_Menu_Item it = {0}; - menu.push_back(it); - but->menubutton()->copy(&menu[0]); - but->value(p.getValue().c_str()); - but->callback(onelab_string_input_choice_cb, (void*)path); - but->input()->when(FL_WHEN_ENTER_KEY); - but->align(FL_ALIGN_RIGHT); - if(highlight) but->input()->color(c); - return but; -} -Fl_Widget *onelabGroup::_addParameterWidget(onelab::region &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - char *path = strdup(getPath(n).c_str()); - _treeStrings.push_back(path); - - // non-editable value - if(p.getReadOnly()){ - inputRegion *but = new inputRegion(1, 1, ww, hh, true); - but->value(p.getValue()); - but->align(FL_ALIGN_RIGHT); - if(highlight) but->color(c); - return but; - } - - inputRegion *but = new inputRegion(1, 1, ww, hh, false); - but->value(p.getValue()); - but->align(FL_ALIGN_RIGHT); - //TODO but->callback(onelab_region_input_cb, (void*)path); - if(highlight) but->color(c); - return but; -} - -Fl_Widget *onelabGroup::_addParameterWidget(onelab::function &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - // non-editable value - if(1 || p.getReadOnly()){ - Fl_Output *but = new Fl_Output(1, 1, ww, hh); - but->value("TODO function"); - but->align(FL_ALIGN_RIGHT); - if(highlight) but->color(c); - return but; - } -} - -void onelabGroup::updateParameter(onelab::parameter &p) -{ - int type = p.getAttributeType(); - if(type == onelab::number::attributeType()) - return updateParameter(*(onelab::number *)&p); - if(type == onelab::string::attributeType()) - return updateParameter(*(onelab::string *)&p); -} -void onelabGroup::updateParameter(onelab::number &p) -{ - Fl_Tree_Item *n = _tree->find_item(p.getName().c_str()); - if(!n) { - addParameter(p); - return; - } - Fl_Group *grp = (Fl_Group *)n->widget(); - // enumeration (display choices as value labels, not numbers) - if(p.getChoices().size() && - p.getChoices().size() == p.getValueLabels().size()){ - Fl_Choice *but = (Fl_Choice *)grp->child(0); - //std::vector<Fl_Menu_Item> menu; - //std::map<double, std::string> labels(p.getValueLabels()); - //for(std::map<double, std::string>::iterator it = labels.begin(); - // it != labels.end(); it++){ - // char *str = strdup(it->second.c_str()); - // _treeStrings.push_back(str); - // Fl_Menu_Item menuItem = {str, 0, 0, 0, 0}; - // if(highlight) menuItem.labelcolor(c); - // menu.push_back(menuItem); - //} - //Fl_Menu_Item it = {0}; - //menu.push_back(it); - //but->copy(&menu[0]); - for(unsigned int i = 0; i < p.getChoices().size(); i++){ - if(p.getValue() == p.getChoices()[i]){ - but->value(i); - break; - } - } - return; - } - - // check box (boolean choice) - if(p.getChoices().size() == 2 && - p.getChoices()[0] == 0 && p.getChoices()[1] == 1){ - Fl_Check_Button *but = (Fl_Check_Button *)grp->child(0); - but->value(p.getValue()); - return; - } - - // non-editable value FIXME - if(p.getReadOnly()){ - outputRange *but = (outputRange *)grp->child(0);; - but->value(p.getValue()); - but->graph(p.getAttribute("Graph")); - return; - } - - // general number input - inputRange *but = (inputRange *)grp->child(0); - but->value(p.getValue()); - but->minimum(p.getMin()); - but->maximum(p.getMax()); - but->step(p.getStep()); - but->choices(p.getChoices()); - but->loop(p.getAttribute("Loop")); - but->graph(p.getAttribute("Graph")); -} -void onelabGroup::updateParameter(onelab::string &p) -{ - Fl_Tree_Item *n = _tree->find_item(p.getName().c_str()); - if(!n) { - addParameter(p); - return; - } - Fl_Group *grp = (Fl_Group *)n->widget(); - // macro button - if(p.getAttribute("Macro") == "Gmsh"){ - return; - } - - // non-editable value FIXME - if(p.getReadOnly()){ - Fl_Output *but = (Fl_Output *)grp->child(0); - but->value(p.getValue().c_str()); - return; - } - - // simple string (no menu) - if(p.getChoices().empty() && p.getKind() != "file"){ - Fl_Input *but = (Fl_Input *)grp->child(0); - but->value(p.getValue().c_str()); - return; - } - - // general string input TODO - Fl_Input_Choice *but = (Fl_Input_Choice *)grp->child(0); - but->value(p.getValue().c_str()); -} - -void onelabGroup::removeParameter(onelab::parameter &p) -{ - Fl_Tree_Item *n = _tree->find_item(p.getName().c_str()); - _tree->remove(n); -} - -void onelabGroup::_computeWidths() -{ - _baseWidth = (int)(_tree->w() - _tree->marginleft()); - _indent = (int)(_tree->connectorwidth() / 2. + _tree->openicon()->w() / 2.); -} - -bool onelabGroup::isBusy() -{ - std::string s(_butt[1]->label()); - if(s == "Run") return false; - return true; -} - -std::string onelabGroup::getPath(Fl_Tree_Item *item) -{ - if(!item){ - Msg::Error("No item for path"); - return ""; - } - char path[1024]; - if(_tree->item_pathname(path, sizeof(path), item)){ - Msg::Error("Could not get path for item"); - return ""; - } - return std::string(path); -} - -void onelabGroup::_addMenu(const std::string &path, Fl_Callback *callback, void *data) -{ - Fl_Tree_Item *n = _tree->add(path.c_str()); - _tree->begin(); - int ww = _baseWidth - (n->depth() + 1) * _indent; - int hh = n->labelsize() + 4; - Fl_Group *grp = new Fl_Group(1, 1, ww, hh); - Fl_Button *but = new Fl_Button(1, 1, ww, hh); - but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); - but->callback(callback, data); - but->box(FL_FLAT_BOX); - but->color(_tree->color()); - but->selection_color(_tree->color()); - grp->end(); - if(!_enableTreeWidgetResize) grp->resizable(0); - _treeWidgets.push_back(grp); - std::string label = path; - std::string::size_type last = path.find_last_of('/'); - if(last != std::string::npos) label = path.substr(last + 1); - but->copy_label(label.c_str()); - n->widget(grp); - _tree->end(); -} - -void onelabGroup::_addSolverMenu(int num) -{ - std::ostringstream path; - path << "0Solver/View" << num; - Fl_Tree_Item *n = _tree->add(path.str().c_str()); - int ww = _baseWidth - (n->depth() + 1) * _indent; - int hh = n->labelsize() + 4; - _tree->begin(); - Fl_Group *grp = new Fl_Group(1, 1, ww, hh); - new solverButton(1, 1, ww, hh, num, _tree->color()); - grp->end(); - if(!_enableTreeWidgetResize) grp->resizable(0); - _treeWidgets.push_back(grp); - n->widget(grp); - _tree->end(); -} - -void onelabGroup::_addViewMenu(int num) -{ - std::ostringstream path; - path << "0Post-processing/View" << num; - Fl_Tree_Item *n; - if((n = _tree->find_item(path.str().c_str())) != NULL) { // check if the item already exists - _tree->remove(n); - } - n = _tree->add(path.str().c_str()); - int ww = _baseWidth - (n->depth() + 1) * _indent; - int hh = n->labelsize() + 4; - _tree->begin(); - Fl_Group *grp = new Fl_Group(1, 1, ww, hh); - new viewButton(1, 1, ww, hh, num, _tree->color()); - grp->end(); - if(!_enableTreeWidgetResize) grp->resizable(0); - _treeWidgets.push_back(grp); - n->widget(grp); - _tree->end(); -} - -viewButton *onelabGroup::getViewButton(int num) -{ - char tmp[256]; - sprintf(tmp, "0Post-processing/View%d", num); - Fl_Tree_Item *n = _tree->find_item(tmp); - if(n){ - Fl_Group *grp = (Fl_Group*)n->widget(); - return (viewButton*)grp->child(0); - } - return 0; -} - -void onelabGroup::openCloseViewButton(int num) -{ - //std::string path = getViewPathName(num); - //if(path.empty()) return; - //Fl_Tree_Item *n = _tree->find_item(path.c_str()); - //if(n){ - // if(PView::list[num]->getOptions()->closed) - // n->parent()->close(); - // else - // n->parent()->open(); - // _tree->redraw(); - //} -} diff --git a/Fltk/onelab2Group.h b/Fltk/onelab2Group.h deleted file mode 100644 index ae56f025d4..0000000000 --- a/Fltk/onelab2Group.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef _ONELAB2_GROUP_H_ -#define _ONELAB2_GROUP_H_ - -#include <vector> -#include <set> -#include <string> -#include <FL/Fl.H> -#include <FL/Fl_Button.H> -#include <FL/Fl_Tree.H> -#include <FL/Fl_Menu_Button.H> -#include <FL/Fl_Input.H> -#include "NetworkUtils.h" -#include "onelab.h" - -class viewButton; - -class onelabGroup : public Fl_Group{ -private: - Fl_Input *server_ip, *server_port; - Fl_Tree *_tree; - Fl_Button *_butt[2]; - Fl_Menu_Button *_gear; - int _gearOptionsStart, _gearOptionsEnd; - std::vector<Fl_Widget*> _treeWidgets; - std::vector<char*> _treeStrings; - bool _stop; - int _baseWidth, _indent; - int _minWindowWidth, _minWindowHeight; - double _widgetLabelRatio; - std::set<std::string> _manuallyClosed; - bool _enableTreeWidgetResize; - - Fl_Widget *_addParameterWidget(onelab::parameter &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c); - Fl_Widget *_addParameterWidget(onelab::number &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c); - Fl_Widget *_addParameterWidget(onelab::string &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c); - Fl_Widget *_addParameterWidget(onelab::function &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c); - Fl_Widget *_addParameterWidget(onelab::region &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c); - void _computeWidths(); - void _addMenu(const std::string &path, Fl_Callback *callback, void *data); - void _addSolverMenu(int num); - void _addViewMenu(int num); - std::set<std::string> _getClosedGmshMenus(); - void _addGmshMenus(); - -public: - onelabGroup(int x, int y, int w, int h, const char *l=0); - ~onelabGroup(); - void updateGearMenu(); - void rebuildSolverList(); - void addLastPostProcessing(); - void rebuildTree(bool deleteWidgets) {} - void enableTreeWidgetResize(bool value){ _enableTreeWidgetResize = value; } - void clearTree(bool deleteWidgets=true); - void openTreeItem(const std::string &name); - void createRemoteTree(bool keepLocal=true); - void setButtonVisibility(); - void setButtonMode(const std::string &butt0, const std::string &butt1); - UInt32 getServerIP() {return ip4_inet_pton(server_ip->value());} - UInt16 getServerPort() {return (UInt16)strtoul(server_port->value(), NULL, 0);} - bool useServer(); - void useServer(bool); - bool isBusy(); - int getMinWindowWidth(){ return _minWindowWidth; } - int getMinWindowHeight(){ return _minWindowHeight; } - //template <class T> void addParameter(T &p); - void addParameter(onelab::parameter &p); - void updateParameter(onelab::parameter &p); - void updateParameter(onelab::number &p); - void updateParameter(onelab::string &p); - void removeParameter(onelab::parameter &p); - std::string getPath(Fl_Tree_Item *item); - void addSolver(const std::string &name, const std::string &exe, - const std::string &hostName, int index); - void insertInManuallyClosed(const std::string &path) - { - _manuallyClosed.insert(path); - } - void removeFromManuallyClosed(const std::string &path) - { - _manuallyClosed.erase(path); - } - bool isManuallyClosed(const std::string &path) - { - return _manuallyClosed.find(path) != _manuallyClosed.end(); - } - viewButton *getViewButton(int num); - void openCloseViewButton(int num); -}; - -void connect_cb(Fl_Widget *w, void *arg); -void onelab_cb(Fl_Widget *w, void *data); -inline void onelab_cb(void *data) {onelab_cb(0, data);} -void solver_cb(Fl_Widget *w, void *data); - -#endif diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp index 9e5b2ceb6b..0aacb9ebe5 100644 --- a/Fltk/onelabGroup.cpp +++ b/Fltk/onelabGroup.cpp @@ -344,16 +344,12 @@ static void setOpenedClosed(Fl_Tree_Item *item, int reason) { std::vector<onelab::number> numbers; std::vector<onelab::string> strings; - std::vector<onelab::region> regions; - std::vector<onelab::function> functions; std::string path = FlGui::instance()->onelab->getPath(item); switch(reason){ case FL_TREE_REASON_OPENED: FlGui::instance()->onelab->removeFromManuallyClosed(path); setClosed(path, numbers, "0"); setClosed(path, strings, "0"); - setClosed(path, regions, "0"); - setClosed(path, functions, "0"); for(unsigned int i = 0; i < PView::list.size(); i++){ if(getViewPath(i) == path) PView::list[i]->getOptions()->closed = 0; } @@ -362,8 +358,6 @@ static void setOpenedClosed(Fl_Tree_Item *item, int reason) FlGui::instance()->onelab->insertInManuallyClosed(path); setClosed(path, numbers, "1"); setClosed(path, strings, "1"); - setClosed(path, regions, "1"); - setClosed(path, functions, "1"); for(unsigned int i = 0; i < PView::list.size(); i++){ if(getViewPath(i) == path) PView::list[i]->getOptions()->closed = 1; } @@ -1016,21 +1010,6 @@ Fl_Widget *onelabGroup::_addParameterWidget(onelab::string &p, int ww, int hh, return but; } -static void onelab_region_input_cb(Fl_Widget *w, void *data) -{ - if(!data) return; - std::string name((char*)data); - std::vector<onelab::region> regions; - onelab::server::instance()->get(regions, name); - if(regions.size()){ - inputRegion *o = (inputRegion*)w; - onelab::region old = regions[0]; - regions[0].setValue(o->value()); - onelab::server::instance()->set(regions[0]); - autoCheck(old, regions[0]); - } -} - static void view_group_cb(Fl_Widget *w, void *data) { if(!data) return; @@ -1047,51 +1026,6 @@ static void view_group_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); } -Fl_Widget *onelabGroup::_addParameterWidget(onelab::region &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - char *path = strdup(getPath(n).c_str()); - _treeStrings.push_back(path); - - // non-editable value - if(p.getReadOnly()){ - inputRegion *but = new inputRegion(1, 1, ww, hh, true); - but->value(p.getValue()); - but->align(FL_ALIGN_RIGHT | FL_ALIGN_CLIP); - if(highlight){ - but->color(c); - but->labelcolor(fl_contrast(FL_FOREGROUND_COLOR, c)); - } - return but; - } - - inputRegion *but = new inputRegion(1, 1, ww, hh, false); - but->value(p.getValue()); - but->align(FL_ALIGN_RIGHT | FL_ALIGN_CLIP); - but->callback(onelab_region_input_cb, (void*)path); - if(highlight){ - but->color(c); - but->labelcolor(fl_contrast(FL_FOREGROUND_COLOR, c)); - } - return but; -} - -Fl_Widget *onelabGroup::_addParameterWidget(onelab::function &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c) -{ - // non-editable value - if(1 || p.getReadOnly()){ - Fl_Output *but = new Fl_Output(1, 1, ww, hh); - but->value("TODO function"); - but->align(FL_ALIGN_RIGHT | FL_ALIGN_CLIP); - if(highlight){ - but->color(c); - but->textcolor(fl_contrast(FL_FOREGROUND_COLOR, c)); - } - return but; - } -} - void onelabGroup::rebuildTree(bool deleteWidgets) { FL_NORMAL_SIZE -= CTX::instance()->deltaFontSize; @@ -1152,26 +1086,6 @@ void onelabGroup::rebuildTree(bool deleteWidgets) _addParameter(strings[i]); } - std::vector<onelab::region> regions; - onelab::server::instance()->get(regions); - for(unsigned int i = 0; i < regions.size(); i++){ - if(!regions[i].getVisible() && !CTX::instance()->solver.showInvisibleParameters) - continue; - if(regions[i].getAttribute("Closed") == "1") - closed.insert(regions[i].getPath()); - _addParameter(regions[i]); - } - - std::vector<onelab::function> functions; - onelab::server::instance()->get(functions); - for(unsigned int i = 0; i < functions.size(); i++){ - if(!functions[i].getVisible() && !CTX::instance()->solver.showInvisibleParameters) - continue; - if(functions[i].getAttribute("Closed") == "1") - closed.insert(functions[i].getPath()); - _addParameter(functions[i]); - } - for(Fl_Tree_Item *n = _tree->first(); n; n = n->next()){ if(n->has_children()){ int ww = (int)(_baseWidth - (n->depth() + 1) * _indent); diff --git a/Fltk/onelabGroup.h b/Fltk/onelabGroup.h index 271e7c3833..171b73cf72 100644 --- a/Fltk/onelabGroup.h +++ b/Fltk/onelabGroup.h @@ -36,10 +36,6 @@ class onelabGroup : public Fl_Group{ Fl_Tree_Item *n, bool highlight, Fl_Color c); Fl_Widget *_addParameterWidget(onelab::string &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c); - Fl_Widget *_addParameterWidget(onelab::region &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c); - Fl_Widget *_addParameterWidget(onelab::function &p, int ww, int hh, - Fl_Tree_Item *n, bool highlight, Fl_Color c); void _addMenu(const std::string &path, Fl_Callback *callback, void *data); void _addSolverMenu(int num); void _addViewMenu(int num); diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index 5ab0ef15b3..d1f6185fb1 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -35,10 +35,7 @@ typedef unsigned long intptr_t; #include "OS.h" #include "Context.h" #include "StringUtils.h" - -#if defined(HAVE_ONELAB) && not defined(HAVE_ONELAB2) #include "gmshLocalNetworkClient.h" -#endif extern StringXColor GeneralOptions_Color[] ; extern StringXColor GeometryOptions_Color[] ; @@ -569,7 +566,7 @@ static void solver_options_ok_cb(Fl_Widget *w, void *data) optionWindow *o = FlGui::instance()->options; o->activate((const char*)data); -#if defined(HAVE_ONELAB) && not defined(HAVE_ONELAB2) +#if defined(HAVE_ONELAB) int old_listen = (int)opt_solver_listen(0, GMSH_GET, o->solver.butt[0]->value()); opt_solver_listen(0, GMSH_SET, o->solver.butt[0]->value()); if(!old_listen && o->solver.butt[0]->value()){ diff --git a/Fltk/viewButton.cpp b/Fltk/viewButton.cpp index ceb62494e0..80eb388c97 100644 --- a/Fltk/viewButton.cpp +++ b/Fltk/viewButton.cpp @@ -18,11 +18,7 @@ #include "OpenFile.h" #include "Field.h" #include "OS.h" -#ifdef HAVE_ONELAB2 -#include "onelab2Group.h" -#else #include "onelabGroup.h" -#endif #include "viewButton.h" static void view_toggle_cb(Fl_Widget *w, void *data) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 3a166fdc20..33df446c3e 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -118,6 +118,13 @@ GModel::~GModel() delete _factory; } +void GModel::setFileName(std::string fileName) +{ + _fileName = fileName; + _fileNames.insert(fileName); + Msg::SetOnelabString("Gmsh/Model name", fileName, false, false, true); +} + GModel *GModel::current(int index) { if(list.empty()){ diff --git a/Geo/GModel.h b/Geo/GModel.h index 27faded960..50df4a2355 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -223,11 +223,7 @@ class GModel std::string getName(){ return _name; } // get/set the model file name - void setFileName(std::string fileName) - { - _fileName = fileName; - _fileNames.insert(fileName); - } + void setFileName(std::string fileName); std::string getFileName(){ return _fileName; } bool hasFileName(const std::string &name) { diff --git a/Geo/GeoStringInterface.cpp b/Geo/GeoStringInterface.cpp index 9d22451414..2e4e44c8a4 100644 --- a/Geo/GeoStringInterface.cpp +++ b/Geo/GeoStringInterface.cpp @@ -23,9 +23,6 @@ #if defined(HAVE_ONELAB) #include "onelab.h" #endif -#if defined(HAVE_ONELAB2) -#include "OnelabDatabase.h" -#endif void add_infile(const std::string &text, const std::string &fileName, bool forceDestroy) { @@ -146,9 +143,6 @@ void add_infile(const std::string &text, const std::string &fileName, bool force #if defined(HAVE_ONELAB) onelab::server::instance()->setChanged(true, "Gmsh"); #endif -#if defined(HAVE_ONELAB2) - OnelabDatabase::instance()->setChanged(true, "Gmsh"); -#endif } void coherence(const std::string &fileName) diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index d448bc3c01..3535dd3d59 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -141,12 +141,6 @@ bool localNetworkSolverClient::receiveMessage(){ else if(type == "string"){ onelab::string p; p.fromChar(message); set(p); } - else if(type == "region"){ - onelab::region p; p.fromChar(message); set(p); - } - else if(type == "function"){ - onelab::function p; p.fromChar(message); set(p); - } else OLMsg::Error("FIXME query not done for this parameter type: <%s>", message.c_str()); @@ -168,14 +162,6 @@ bool localNetworkSolverClient::receiveMessage(){ std::vector<onelab::string> par; get(par, name); if(par.size() == 1) reply = par[0].toChar(); } - else if(type == "region"){ - std::vector<onelab::region> par; get(par, name); - if(par.size() == 1) par[0].toChar(); - } - else if(type == "function"){ - std::vector<onelab::function> par; get(par, name); - if(par.size() == 1) reply = par[0].toChar(); - } else OLMsg::Error("Unknown OneLab parameter type in query: %s", type.c_str()); @@ -209,16 +195,6 @@ bool localNetworkSolverClient::receiveMessage(){ for(std::vector<onelab::string>::iterator it = strings.begin(); it != strings.end(); it++) replies.push_back((*it).toChar()); } - else if(type == "region"){ - std::vector<onelab::region> regions; get(regions); - for(std::vector<onelab::region>::iterator it = regions.begin(); - it != regions.end(); it++) replies.push_back((*it).toChar()); - } - else if(type == "function"){ - std::vector<onelab::function> functions; get(functions); - for(std::vector<onelab::function>::iterator it = functions.begin(); - it != functions.end(); it++) replies.push_back((*it).toChar()); - } else OLMsg::Error("Unknown OneLab parameter type in query: %s", type.c_str()); @@ -1515,4 +1491,3 @@ array read_array(std::string fileName, char sep){ } return array; } - diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index cfd9dba3f8..39e4def700 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -22,7 +22,6 @@ namespace olkey{ static std::string olelse(label+"else"), olendif(label+"endif"); static std::string getValue(label+"get"); static std::string mathex(label+"eval"); - static std::string getRegion(label+"region"); } // Client member functions defined here because they use parser commands @@ -899,7 +898,6 @@ void localSolverClient::modify_tags(const std::string lab, const std::string com olkey::olendif.assign(olkey::label+"endif"); olkey::getValue.assign(olkey::label+"get"); olkey::mathex.assign(olkey::label+"eval"); - olkey::getRegion.assign(olkey::label+"region"); } if(com.compare(olkey::comment) && com.size()){ changed=true; @@ -1151,9 +1149,6 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) { else if ( (pos=line.find(olkey::mathex)) != std::string::npos) { // onelab.mathex: nothing to do } - else if ( (pos=line.find(olkey::getRegion)) != std::string::npos) { - // onelab.getRegion: nothing to do - } else if( (pos=line.find(olkey::label)) != std::string::npos) { OLMsg::Error("Unknown ONELAB keyword in <%s>",line.c_str()); } @@ -1259,7 +1254,6 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, std::vector<std::string> arguments; std::vector<onelab::number> numbers; std::vector<onelab::string> strings; - std::vector<onelab::region> regions; if((pos=line.find_first_not_of(" \t"))==std::string::npos){ // empty line, we keep them @@ -1372,61 +1366,6 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, else if ( (pos=line.find(olkey::getValue)) != std::string::npos) { outfile << resolveGetVal(line) << std::endl; } - else if ( (pos=line.find(olkey::getRegion)) != std::string::npos) { - // onelab.getRegion, possibly several times on the line - cursor=0; - std::string buff,action; - while ( (pos=line.find(olkey::getRegion,cursor)) != std::string::npos){ - int pos0=pos; - cursor = pos+olkey::getRegion.length(); - int NumArg=enclosed(line.substr(cursor),arguments,pos); - - if(NumArg>0){ - std::string paramName; - paramName.assign("Gmsh parameters/Physical groups/"+arguments[0]); - get(regions,paramName); - if (regions.size()){ - std::set<std::string> region; - region=regions[0].getValue(); - - if(NumArg>1) - action.assign(arguments[1]); - else - action.assign("expand"); - - if(!action.compare("size")) - buff.assign(ftoa(region.size())); - else if(!action.compare("expand")){ - std::string pattern; - if(NumArg>=3) - pattern.assign(extractExpandPattern(arguments[2])); - else - pattern.assign(" "); - - buff.assign(1,pattern[0]); - for(std::set<std::string>::const_iterator it = region.begin(); - it != region.end(); it++){ - if(it != region.begin()) - buff.append(1,pattern[1]); - buff.append((*it)); - } - buff.append(1,pattern[2]); - } - else - OLMsg::Error("Unknown %s action: <%s>", - olkey::getRegion.c_str(), arguments[1].c_str()); - } - else - OLMsg::Error("Unknown region: <%s>",paramName.c_str()); - } - else - OLMsg::Error("Misformed <%s> statement: (%s)", - olkey::getRegion.c_str(),line.c_str()); - line.replace(pos0,cursor+pos-pos0,buff); - cursor=pos0+buff.length(); - } - outfile << line << std::endl; - } else if ( (pos=line.find(olkey::label)) != std::string::npos){ OLMsg::Error("Unidentified onelab command in <%s>",line.c_str()); } diff --git a/contrib/onelab/python/onelab.py b/contrib/onelab/python/onelab.py index 7dc106fbe4..6f16aea0f5 100755 --- a/contrib/onelab/python/onelab.py +++ b/contrib/onelab/python/onelab.py @@ -1,5 +1,5 @@ """ -OneLab - Copyright (C) 2011-2014 ULg-UCL +OneLab - Copyright (C) 2011-2016 ULg-UCL Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/contrib/onelab2/CMakeLists.txt b/contrib/onelab2/CMakeLists.txt deleted file mode 100644 index 689c5f188f..0000000000 --- a/contrib/onelab2/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -set(SRC - NetworkUtils.cpp - OnelabAttributes.cpp - OnelabDatabase.cpp - OnelabProtocol.cpp - OnelabLocalNetworkClient.cpp - OnelabServer.cpp - OnelabNetworkClient.cpp - GmshNetworkClient.cpp - GmshLocalClient.cpp) - -if(HAVE_FLTK) -set(SRC - ${SRC} - OnelabWindow.cpp) -endif(HAVE_FLTK) - -if(NOT ENABLE_UDT) -set(SRC - ${SRC} - noudt.cpp) -endif(NOT ENABLE_UDT) - -file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) -append_gmsh_src(contrib/onelab2 "${SRC};${HDR}") - -# build only the server -if(HAVE_UDT) - find_package(Threads REQUIRED) - find_path(UDT_INCLUDE_DIR udt.h PATH_SUFFIXES include udt) - find_library(UDT_LIBRARY udt) - if(UDT_INCLUDE_DIR AND UDT_LIBRARY AND Threads_FOUND) - list(APPEND EXTERNAL_INCLUDES ${UDT_INCLUDE_DIR}) - list(APPEND EXTERNAL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) - list(APPEND EXTERNAL_LIBRARIES ${UDT_LIBRARY}) - else(UDT_INCLUDE_DIR AND UDT_LIBRARY AND Threads_FOUND) - message(FATAL_ERROR "Unable to find UDT library") - endif(UDT_INCLUDE_DIR AND UDT_LIBRARY AND Threads_FOUND) -endif(HAVE_UDT) - -include_directories(${CMAKE_SOURCE_DIR}/Common/) # for onelab.h -include_directories(${CMAKE_BINARY_DIR}/Common/) # for GmshConfig.h -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/) -include_directories(${EXTERNAL_INCLUDES}) # for UDT -add_executable (onelabserver Onelab.cpp OnelabServer.cpp OnelabNetworkClient.cpp OnelabLocalNetworkClient.cpp NetworkUtils.cpp OnelabProtocol.cpp OnelabAttributes.cpp) -target_link_libraries(onelabserver ${EXTERNAL_LIBRARIES}) diff --git a/contrib/onelab2/GmshLocalClient.cpp b/contrib/onelab2/GmshLocalClient.cpp deleted file mode 100644 index 8554f04334..0000000000 --- a/contrib/onelab2/GmshLocalClient.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "GmshLocalClient.h" -#include "onelabUtils.h" -#ifdef HAVE_FLTK -#include "FlGui.h" -#include "GmshMessage.h" -#include "onelab2Group.h" -#include "OpenFile.h" -#include "Context.h" - -void GmshLocalClient::setCallback(onelabGroup *cb) {_cb_obj = cb;} -void GmshLocalClient::onNewParameter(onelab::parameter *p) -{ - if(_cb_obj) { - FlGui::instance()->lock(); - _cb_obj->addParameter(*p); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -void GmshLocalClient::onUpdateParameter(onelab::parameter *p) -{ - if(_cb_obj) { - FlGui::instance()->lock(); - _cb_obj->updateParameter(*p); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -void GmshLocalClient::onRemoveParameter(onelab::parameter *p) -{ - if(_cb_obj) { - FlGui::instance()->lock(); - _cb_obj->removeParameter(*p); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -void GmshLocalClient::onMessage(const std::string & name, const std::string &message, int level) -{ - FlGui::instance()->lock(); - switch(level) { - case OnelabAttrMessage::Info: - Msg::Direct("Info : %s - %s", name.c_str(), message.c_str()); - break; - case OnelabAttrMessage::Warning: - Msg::Warning("%s - %s", name.c_str(), message.c_str()); - break; - case OnelabAttrMessage::Error: - Msg::Error("%s - %s", name.c_str(), message.c_str()); - break; - } - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); -} -void GmshLocalClient::onStop() -{ - FlGui::instance()->lock(); - _cb_obj->setButtonMode("check", "compute"); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); -} -void GmshLocalClient::refresh() -{ - Fl::awake(onelab_cb, (void*)"refresh"); -} -void GmshLocalClient::mergeFile(const std::string &filename) -{ - FlGui::instance()->lock(); - MergePostProcessingFile(filename, CTX::instance()->solver.autoShowViews, CTX::instance()->solver.autoShowLastStep, true); - _cb_obj->addLastPostProcessing(); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); -} - -void GmshLocalClient::run(std::string action) { - if(getName() == "Gmsh") { - FlGui::instance()->lock(); - onelabUtils::runGmshClient(action, 2); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -#endif diff --git a/contrib/onelab2/GmshLocalClient.h b/contrib/onelab2/GmshLocalClient.h deleted file mode 100644 index 6701064a69..0000000000 --- a/contrib/onelab2/GmshLocalClient.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _GMSHLOCLACLIENT_H_ -#define _GMSHLOCALCLIENT_H_ - -#include "OnelabLocalClient.h" - -#ifdef HAVE_FLTK -class onelabGroup; -#endif - -class GmshLocalClient : public OnelabLocalClient -{ -private: -#ifdef HAVE_FLTK - onelabGroup *_cb_obj; -#endif -public: -#ifdef HAVE_FLTK - GmshLocalClient(std::string name, onelab::parameterSpace *parameterSpace) - : OnelabLocalClient(name, parameterSpace){ - _cb_obj = NULL; - } - ~GmshLocalClient(){} - void setCallback(onelabGroup *cb); - void onNewParameter(onelab::parameter *p); - void onUpdateParameter(onelab::parameter *p); - void onRemoveParameter(onelab::parameter *p); - void onMessage(const std::string &name, const std::string &message, int level); - void onStop(); - void refresh(); - void mergeFile(const std::string &filename); -#else - GmshLocalClient(std::string name, onelab::parameterSpace *parameterSpace) - : OnelabLocalClient(name, parameterSpace){} -#endif - - void run(std::string action); -}; - -#endif diff --git a/contrib/onelab2/GmshNetworkClient.cpp b/contrib/onelab2/GmshNetworkClient.cpp deleted file mode 100644 index f0c2be1284..0000000000 --- a/contrib/onelab2/GmshNetworkClient.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include <iostream> - -#include "GmshNetworkClient.h" -#ifdef HAVE_FLTK -#include "FlGui.h" -#include "onelab2Group.h" -#include "GmshMessage.h" - -void GmshNetworkClient::setCallback(onelabGroup *cb) {_cb_obj = cb;} -void GmshNetworkClient::onNewParameter(onelab::parameter *p) -{ - if(_cb_obj) { - FlGui::instance()->lock(); - _cb_obj->addParameter(*p); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -void GmshNetworkClient::onUpdateParameter(onelab::parameter *p) -{ - if(_cb_obj) { - FlGui::instance()->lock(); - _cb_obj->updateParameter(*p); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -void GmshNetworkClient::onRemoveParameter(onelab::parameter *p) -{ - if(_cb_obj) { - FlGui::instance()->lock(); - _cb_obj->removeParameter(*p); - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); - } -} -void GmshNetworkClient::onMessage(const std::string & name, const std::string &message, int level) -{ - FlGui::instance()->lock(); - switch(level) { - case OnelabAttrMessage::Info: - Msg::Direct("Info : %s - %s", name.c_str(), message.c_str()); - break; - case OnelabAttrMessage::Warning: - Msg::Warning("%s - %s", name.c_str(), message.c_str()); - break; - case OnelabAttrMessage::Error: - Msg::Error("%s - %s", name.c_str(), message.c_str()); - break; - } - FlGui::instance()->unlock(); - Fl::awake((void *)NULL); -} -#endif diff --git a/contrib/onelab2/GmshNetworkClient.h b/contrib/onelab2/GmshNetworkClient.h deleted file mode 100644 index 8af71336b7..0000000000 --- a/contrib/onelab2/GmshNetworkClient.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _GMSHCLIENT_H_ -#define _GMSHCLIENT_H_ - -#include <vector> - -#include "VirtualClient.h" -#include "NetworkUtils.h" -#include "OnelabNetworkClient.h" -#include "OnelabProtocol.h" - -#ifdef HAVE_FLTK -class onelabGroup; -#endif - -class GmshNetworkClient : public OnelabNetworkClient -{ -private: -#ifdef HAVE_FLTK - onelabGroup *_cb_obj; -#endif -public: -#ifdef HAVE_FLTK - GmshNetworkClient(std::string name) : OnelabNetworkClient(name) {_cb_obj=NULL;} - GmshNetworkClient(std::string name, unsigned int ip, unsigned short port) : OnelabNetworkClient(name, ip, port) {_cb_obj =NULL;} - void setCallback(onelabGroup *cb); - void onNewParameter(onelab::parameter *p); - void onUpdateParameter(onelab::parameter *p); - void onRemoveParameter(onelab::parameter *p); - void onMessage(const std::string &name, const std::string &message, int level); -#else - GmshNetworkClient(std::string name) : OnelabNetworkClient(name) {} - GmshNetworkClient(std::string name, unsigned int ip, unsigned short port) : OnelabNetworkClient(name, ip, port) {} -#endif -}; - -#endif diff --git a/contrib/onelab2/NetworkUtils.cpp b/contrib/onelab2/NetworkUtils.cpp deleted file mode 100644 index 4f0f6001bd..0000000000 --- a/contrib/onelab2/NetworkUtils.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include <sys/socket.h> -#include <sys/un.h> -#include <netdb.h> -#include <ifaddrs.h> -#include <iostream> -#include <unistd.h> - -#include "NetworkUtils.h" -#include "OnelabException.h" - -UInt32 ip4_inet_pton(const char *ip) -{ - struct in_addr dst; - if(inet_pton(AF_INET, ip, &dst) == 0) - return 0; // the string seems to contain an invalid ip - return ntohl(dst.s_addr); -} - -UInt32 ip4_inet_resolve(const char *hostname) -{ - struct hostent *he; - struct in_addr **addr_list; - - if((he = gethostbyname(hostname)) == NULL) - return 0; - - addr_list = (struct in_addr **) he->h_addr_list; - - for(int i = 0; addr_list[i] != NULL; i++) - return ntoh32(addr_list[i]->s_addr); - - return 0; -} - -void ip4_socket_ip(Socket fd, IPv4 &ip) -{ - struct sockaddr_in sin; - socklen_t len = sizeof(sin); - if(getsockname(fd, (struct sockaddr *)&sin, &len) != -1){ - ip.address = ntoh32(sin.sin_addr.s_addr); - ip.port = ntoh16(sin.sin_port); - } -} - -UInt32 ip4_default_iface() -{ - struct ifaddrs *ifas = NULL; - UInt32 ip = 0; - - getifaddrs(&ifas); - for (struct ifaddrs *ifa = ifas; ifa != NULL; ifa = ifa->ifa_next) { - if(ifa->ifa_addr->sa_family == AF_INET) { - UInt32 tmp = ntoh32((UInt32)((struct sockaddr_in *) ifa->ifa_addr)->sin_addr.s_addr); - if(!ip4_is_loopback(tmp)) { - ip = tmp; - break; - } - } - } - freeifaddrs(ifas); - return ip; -} - -Socket ip4_socket(IPv4 ip, int socketType) -{ - Socket fd; - struct sockaddr_in addr; - - memset(&addr, 0, sizeof(struct sockaddr_in)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = hton32((ip.address==0)? INADDR_ANY : ip.address); - addr.sin_port = hton16(ip.port); - - if((fd = socket(AF_INET, socketType, 0)) < 0) throw NetworkException(NetworkException::Create); - - if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) != 0) throw NetworkException(NetworkException::Bind); - - return fd; -} - -void ip4_socket_timeout(Socket fd, long tos, long tous) -{ - struct timeval tv; - tv.tv_sec = tos; // seconds - tv.tv_usec = tous; // microseconds - setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); -} - -int ip4_socket_send(Socket fd, UInt8 *src, int length) -{ - ssize_t sent = send(fd, src, length, 0); - - // TODO handle error (length != sent) for ??? and (sent < 0) for local error - //std::cout << "ip: send " << sent << "/" << length << "bytes" << std::endl; - return (int)sent; -} -int ip4_socket_send(Socket fd, UInt8 *src, int length, IPv4 dst) -{ - struct sockaddr_in to; - socklen_t tol = sizeof(to); - memset(&to, 0, tol); - - to.sin_family = AF_INET; - to.sin_port = hton16(dst.port); - to.sin_addr.s_addr = hton32(dst.address); - - ssize_t sent = sendto(fd, src, length, 0, (struct sockaddr *)&to, tol); - - // TODO handle error (length != sent) for ??? and (sent < 0) for local error - //std::cout << "ip: send " << sent << "/" << length << "bytes to " << ip4_inet_ntop(dst.address)<< ':' << dst.port << std::endl; - return (int)sent; -} - -int ip4_socket_recv(Socket fd, UInt8 *dst, int maxlength) -{ - ssize_t recved = recv(fd, dst, maxlength, 0); - - // TODO handle error if(recvlength < 0) - //std::cout << "ip: recv " << recved << "bytes" << std::endl; - return recved; -} -int ip4_socket_recv(Socket fd, UInt8 *dst, int maxlength, IPv4 &src) -{ - struct sockaddr_in from; - socklen_t froml = sizeof(from); - memset(&from, 0, froml); - - ssize_t recvlength = recvfrom(fd, dst, maxlength, 0, (struct sockaddr *)&from, &froml); - src.port = ntoh16(from.sin_port); - src.address = ntoh32(from.sin_addr.s_addr); - - // TODO handle error if(recvlength < 0) - //std::cout << "ip: recv " << recvlength << "bytes from " << ip4_inet_ntop(src.address)<< ':' << src.port << std::endl; - return recvlength; -} - -bool ip4_socket_get_local_address(Socket fd, IPv4 &ip) -{ - struct sockaddr_in addr_in; - socklen_t len = sizeof(addr_in); - - if(getsockname(fd, (struct sockaddr *)&addr_in, &len) != -1) { - ip.port = ntoh16(addr_in.sin_port); - ip.address = ntoh32(addr_in.sin_addr.s_addr); - return true; - } - return false; -} - -Socket unix_socket(int socketType) -{ - Socket fd; - - if((fd = socket(PF_UNIX, socketType, 0)) < 0) throw NetworkException(NetworkException::Create); - - return fd; -} -void unix_socket_listen(Socket fd, const char *sockname, int maxconnection) -{ - struct sockaddr_un addr; - memset(&addr, 0, sizeof(struct sockaddr_un)); - addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, sockname); - - if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) != 0) throw NetworkException(NetworkException::Bind); - if(-1 == listen(fd, maxconnection)) throw NetworkException(NetworkException::Listen); -} -Socket unix_socket_accept(Socket fd) -{ - struct sockaddr_un addr; - unsigned int addrl = sizeof(addr); - - memset(&addr, 0, addrl); - addr.sun_family = AF_UNIX; - - Socket cli = accept(fd, (struct sockaddr*)&addr, &addrl); - return cli; -} - -Socket unix_socket_connect(Socket fd, const char* sockname) -{ - struct sockaddr_un addr; - memset(&addr, 0, sizeof(addr)); - - addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, sockname); - - return connect(fd, (struct sockaddr *)&addr, sizeof(addr)); -} diff --git a/contrib/onelab2/NetworkUtils.h b/contrib/onelab2/NetworkUtils.h deleted file mode 100644 index d6eab1d82c..0000000000 --- a/contrib/onelab2/NetworkUtils.h +++ /dev/null @@ -1,168 +0,0 @@ -#ifndef _NETWORKUTILS_H_ -#define _NETWORKUTILS_H_ - -#include <cstring> -#include <sstream> -#include <unistd.h> -#include <arpa/inet.h> - -#define ERROR_SOCKET_CREATE 10 -#define ERROR_SOCKET_BIND 11 -#define ERROR_SOCKET_CONNECT 12 -#define ERROR_SOCKET_LISTEN 13 -#define ERROR_SOCKET_RECV 14 - -#ifdef WIN32 -typedef SOCKET Socket; -typedef int socklen_t; -#else -typedef int Socket; -#endif - -#include "GmshConfig.h" -#ifndef HAVE_UDT -#include "noudt.h" -#endif - -typedef unsigned char UInt8; -typedef unsigned short UInt16; -typedef unsigned int UInt32; -typedef unsigned long long UInt64; -typedef struct {unsigned char bytes[16];} UInt128; -typedef struct {UInt32 address; UInt16 port;} IPv4; - -// TODO check double/float size - -// host to network (and network to host) order, Reference RFC 791 -#define hton64 ntoh64 -#define hton32 htonl -#define ntoh32 ntohl -#define hton16 htons -#define ntoh16 ntohs -#if BYTE_ORDER == BIG_ENDIAN -inline UInt64 ntoh64(UInt64 n) {return n;} -inline double ntoh64(double n) {return n;} -#else -inline UInt64 ntoh64(UInt64 n) { - union - { - UInt64 d; - UInt8 b[8]; - }in, out; - in.d = n; - out.b[0] = in.b[7]; - out.b[1] = in.b[6]; - out.b[2] = in.b[5]; - out.b[3] = in.b[4]; - out.b[4] = in.b[3]; - out.b[5] = in.b[2]; - out.b[6] = in.b[1]; - out.b[7] = in.b[0]; - return out.d; -} -inline double ntoh64(double n) { - union - { - double d; - UInt8 b[8]; - }in, out; - in.d = n; - out.b[0] = in.b[7]; - out.b[1] = in.b[6]; - out.b[2] = in.b[5]; - out.b[3] = in.b[4]; - out.b[4] = in.b[3]; - out.b[5] = in.b[2]; - out.b[6] = in.b[1]; - out.b[7] = in.b[0]; - return out.d; -} -#endif - -inline UInt8 *encode(UInt8 *dst, UInt8 data) {memcpy(dst, reinterpret_cast<void*>(&data), sizeof(UInt8));return dst+ sizeof(UInt8);} -inline UInt8 *encode(UInt8 *dst, UInt16 data) {data = hton16(data);memcpy(dst, reinterpret_cast<void*>(&data), sizeof(UInt16));return dst+ sizeof(UInt16);} -inline UInt8 *encode(UInt8 *dst, UInt32 data) {data = hton32(data);memcpy(dst, reinterpret_cast<void*>(&data), sizeof(UInt32));return dst+ sizeof(UInt32);} -inline UInt8 *encode(UInt8 *dst, UInt64 data) {data = hton64(data);memcpy(dst, reinterpret_cast<void*>(&data), sizeof(UInt64));return dst+ sizeof(UInt64);} -inline UInt8 *encode(UInt8 *dst, UInt8 *data, unsigned int length) {memcpy(dst, reinterpret_cast<void*>(data), length);return dst+ length;} -inline UInt8 *encode(UInt8 *dst, double data) {data = hton64(data);memcpy(dst, reinterpret_cast<void*>(&data), sizeof(double));return dst+ sizeof(double);} - -inline UInt8 *parse(UInt8 *src, UInt8 &data) {memcpy(reinterpret_cast<void*>(&data), src, sizeof(UInt8)); return src+ sizeof(UInt8);} -inline UInt8 *parse(UInt8 *src, UInt16 &data) {memcpy(reinterpret_cast<void*>(&data), src, sizeof(UInt16));data = ntoh16(data);return src+ sizeof(UInt16);} -inline UInt8 *parse(UInt8 *src, UInt32 &data) {memcpy(reinterpret_cast<void*>(&data), src, sizeof(UInt32));data = ntoh32(data);return src+ sizeof(UInt32);} -inline UInt8 *parse(UInt8 *src, UInt64 &data) {memcpy(reinterpret_cast<void*>(&data), src, sizeof(UInt64));data = ntoh64(data);return src+ sizeof(UInt64);} -inline UInt8 *parse(UInt8 *src, UInt8 *data, UInt16 length) {memcpy(reinterpret_cast<void*>(data), src, length);return src+length;} -inline UInt8 *parse(UInt8 *src, double &data) {memcpy(reinterpret_cast<void*>(&data), src, sizeof(double));data = ntoh64(data);return src+ sizeof(double);} -inline UInt8 *parse(UInt8 *src, std::string &data, UInt16 length) {data.assign((char *)src, length-1); return src+length;} -inline UInt8 *parse(UInt8 *src, std::string &data, char limiter) {UInt16 len = strchr((char *)src, limiter)-(char*)src+1; return parse(src, data, len);} - -inline bool ip4_is_loopback(const unsigned int ip) { // Reference RFC 1122 - return (unsigned int)(ip & 0xFF000000) == (unsigned int)0x7F000000; // 127.0.0.0/8 -} -inline bool ip4_is_private(const unsigned int ip) { // Refercence RFC 1918 - return (unsigned int)(ip & 0xFFFF0000) == (unsigned int)0xC0A80000 || // 192.168.0.0/16 - (unsigned int)(ip & 0xFFF00000) == (unsigned int)0xAC100000 || // 172.16.0.0/12 - (unsigned int)(ip & 0xFF000000) == (unsigned int)0x0A000000; // 10.0.0.0/8 -} -UInt32 ip4_inet_pton(const char *); -UInt32 ip4_inet_resolve(const char *hostname); -UInt32 ip4_default_iface(); -inline std::string ip4_inet_ntop(UInt32 address) { - std::ostringstream oss; - oss << ((address >> 24) & 0xFF) << '.' - << ((address >> 16) & 0xFF) << '.' - << ((address >> 8) & 0xFF) << '.' - << (address & 0xFF); - return oss.str(); -} -void ip4_socket_ip(Socket fd, IPv4 &ip); - -Socket ip4_socket(IPv4 ip, int socketType); -int ip4_socket_send(Socket fd, UInt8 *src, int length); -int ip4_socket_send(Socket fd, UInt8 *src, int length, IPv4 dst); -int ip4_socket_recv(Socket fd, UInt8 *dst, int maxlength, IPv4 &src); -int ip4_socket_recv(Socket fd, UInt8 *dst, int maxlength); -inline void ip4_socket_listen(Socket fd, int maxconnection=1024) -{ - if(-1 == listen(fd, maxconnection)) throw ERROR_SOCKET_LISTEN; -} -inline Socket ip4_socket_accept(Socket fd, IPv4 &ip) -{ - Socket cli; - struct sockaddr_in addr; - unsigned int addrl = sizeof(addr); - - cli = accept(fd, (struct sockaddr*)&addr, &addrl); - ip.address = ntoh32(addr.sin_addr.s_addr); - ip.port = ntoh16(addr.sin_port); - - return cli; -} -inline int ip4_socket_connect(Socket fd, IPv4 &ip) -{ - struct sockaddr_in addr; - unsigned int addrl = sizeof(addr); - memset(&addr, 0, sizeof(struct sockaddr_in)); - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = hton32(ip.address); - addr.sin_port = hton16(ip.port); - return connect(fd, (struct sockaddr*)&addr, addrl); -} -inline bool ip4_socket_connected(Socket fd) -{ - int error_code; - unsigned int optlen = sizeof(error_code); - getsockopt(fd, SOL_SOCKET, SO_ERROR, &error_code, &optlen); - return (error_code == 0); -} -bool ip4_socket_get_local_address(Socket fd, IPv4 &ip); -void ip4_socket_timeout(Socket d, long tos, long tous=0); -inline void ip4_socket_reuse_address(Socket fd, bool reuse=true) {setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof reuse);} -inline void ip4_socket_close(Socket fd) {/*if(-1 == */close(fd);} - -Socket unix_socket(int socketType); -void unix_socket_listen(Socket fd, const char *sockname, int maxconnection=1024); -Socket unix_socket_accept(Socket fd); -Socket unix_socket_connect(Socket fd, const char *sockname); - -#endif diff --git a/contrib/onelab2/Onelab.cpp b/contrib/onelab2/Onelab.cpp deleted file mode 100644 index 4b3989de2a..0000000000 --- a/contrib/onelab2/Onelab.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include <iostream> - -#include "OnelabServer.h" -#include "OnelabNetworkClient.h" - -#include "NetworkUtils.h" - -OnelabServer *OnelabServer::_server = 0; - -void usage() -{ - //TODO std::cout << std::endl; -} - -int server(unsigned short port=0) -{ - OnelabServer::instance(0, port); - OnelabServer::instance()->Run(); -} - -int main(int argc, char **argv) -{ - bool isServer = false; - unsigned int ip = 0; - unsigned short port = 0; - for(int arg=1; arg<argc; arg++) { - if(strcmp(argv[arg], "-l") == 0 || strcmp(argv[arg], "--listen") == 0) - isServer = true; - else if(strcmp(argv[arg], "-p") == 0 || strcmp(argv[arg], "--port") == 0) { - if(++arg >= argc) { - usage(); - return 1; - } - port = atoi(argv[arg]); - } - else if(strcmp(argv[arg], "-i") == 0 || strcmp(argv[arg], "--ip") == 0) { - if(++arg >= argc) { - usage(); - return 1; - } - ip = ip4_inet_pton(argv[arg]); - - } - else { - usage(); - return 1; - } - } - try { - if(isServer && port != 0) - server(port); - else { - usage(); - return -1; - } - } - catch(int &e) { - if(e == ERROR_SOCKET_CREATE || e == ERROR_SOCKET_BIND || e == ERROR_SOCKET_CONNECT || e == ERROR_SOCKET_LISTEN || e == ERROR_SOCKET_RECV) - std::cerr << "UDT fail: " << UDT::getlasterror().getErrorMessage() << std::endl; - std::cerr << "Fail with code " << e << std::endl; - return e; - } - catch(const char*e) { - std::cout << e << std::endl; - return 1; - } - return 0; -} diff --git a/contrib/onelab2/OnelabAttributes.cpp b/contrib/onelab2/OnelabAttributes.cpp deleted file mode 100644 index f89c9897d6..0000000000 --- a/contrib/onelab2/OnelabAttributes.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include <cstring> -#include <iostream> - -#include "OnelabAttributes.h" - -UInt8 *OnelabAttrStart::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, (UInt8 *)_name.c_str(), _name.size()); - - return dst; -} -UInt8 *OnelabAttrStart::parseAttribute(UInt8 *src, UInt32 length) -{ - _name.assign((char *)src, (int)length); - - return src+length; -} -void OnelabAttrStart::showAttribute() const -{ - std::cout << "\033[1m" << "Attribute start:"<< getAttributeType() << "\033[0m"<< std::endl - << "name: " << _name << std::endl; -} - -UInt8 *OnelabAttrParameterQuery::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, _ptype); - dst = encode(dst, (UInt8 *)_pname.c_str(), _pname.size()); - - return dst; -} -UInt8 *OnelabAttrParameterQuery::parseAttribute(UInt8 *src, UInt32 length) -{ - if(length < 1) throw ERROR_INVALID_ATTRIBUTE_SIZE; - - src = parse(src, _ptype); - _pname.assign((char *)src, (int)(length-1)); - - return src+length; -} -void OnelabAttrParameterQuery::showAttribute() const -{ - std::cout << "\033[1m" << "Attribute parameter query:"<< getAttributeType() << "\033[0m"<< std::endl - << "type: " << this->_ptype << std::endl - << "name: " << this->_pname << std::endl; -} - -UInt8 *OnelabAttrMessage::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, _level); - dst = encode(dst, _message, _messageLength); - - return dst; -} -UInt8 *OnelabAttrMessage::parseAttribute(UInt8 *src, UInt32 length) -{ - if(length < 1) throw ERROR_INVALID_ATTRIBUTE_SIZE; - - src = parse(src, _level); - _messageLength = length-1; - if(_message != NULL) free(_message); - _message = (UInt8 *)malloc(_messageLength); - src = parse(src, _message, _messageLength); - - return src; -} -void OnelabAttrMessage::showAttribute() const -{ - std::cout << "Attribute message:" << std::endl - << "Level: " << _level << std::endl - << "Message: " << _message << std::endl; -} - -UInt8 *OnelabAttrAction::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, (UInt8 *)_client.c_str(), _client.size()+1); - dst = encode(dst, (UInt8 *)_action.c_str(), _action.size()); - - return dst; -} - -UInt8 *OnelabAttrAction::parseAttribute(UInt8 *src, UInt32 length) -{ - _client.assign((char *)src); - src += _client.size()+1; - _action.assign((char *)src, length-_client.size()-1); - src += _action.size(); - return src; -} - -void OnelabAttrAction::showAttribute() const -{ - std::cout << "\033[1m" << "Attribute action:"<< getAttributeType() << "\033[0m"<< std::endl - << "client (target): " << _client << std::endl - << "action: " << _action << std::endl; -} - -UInt8 *OnelabAttrFileQuery::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, (UInt8 *)_name, _length); - dst = encode(dst, (UInt8 *)_client.c_str(), _client.length()+1); - - return dst; -} -UInt8 *OnelabAttrFileQuery::parseAttribute(UInt8 *src, UInt32 length) -{ - if(_name != NULL) free(_name); - _length = length; - _name = (char *)malloc(_length+1); - src = parse(src, (UInt8 *)_name, _length); - _name[_length] = '\0'; - - return src; -} -void OnelabAttrFileQuery::setFilename(const std::string name) -{ - if(_name != NULL) free(_name); - - _length = name.size(); - _name = strndup(name.c_str(), _length); -} -void OnelabAttrFileQuery::showAttribute() const -{ - std::cout << "\033[1m" << "Attribute file query:"<< getAttributeType() << "\033[0m"<< std::endl - << "client (file): " << _client << std::endl - << "file: " << _name << std::endl; -} - - -UInt8 *OnelabAttrMergeFile::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, (UInt8 *)_name, _length); - - return dst; -} -UInt8 *OnelabAttrMergeFile::parseAttribute(UInt8 *src, UInt32 length) -{ - if(_name != NULL) free(_name); - _length = length; - _name = (char *)malloc(_length+1); - src = parse(src, (UInt8 *)_name, _length); - _name[_length] = '\0'; - return src; -} -void OnelabAttrMergeFile::setFilename(const std::string name) -{ - if(_name != NULL) free(_name); - - _length = name.size(); - _name = strndup(name.c_str(), _length+1); -} -void OnelabAttrMergeFile::showAttribute() const -{ - std::cout << "\033[1m" << "Attribute merge file:"<< getAttributeType() << "\033[0m"<< std::endl - << "file: " << _name << std::endl; -} - - -UInt8 *OnelabAttrFile::encodeAttribute(UInt8 *dst) -{ - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, _filelength); - dst = encode(dst, (UInt8 *)_name, strlen(_name)+1); - return dst; -} -UInt8 *OnelabAttrFile::parseAttribute(UInt8 *src, UInt32 length) -{ - if(length < 5) throw ERROR_INVALID_ATTRIBUTE_SIZE; - if(_name != NULL) free(_name); - - src = parse(src, _filelength); - _name = strndup((char *)src, length-4); - return src+length-4; -} -void OnelabAttrFile::showAttribute() const -{ - std::cout << "\033[1m" << "Attribute file:"<< getAttributeType() << "\033[0m"<< std::endl - << "file: " << _name << std::endl; -} diff --git a/contrib/onelab2/OnelabAttributes.h b/contrib/onelab2/OnelabAttributes.h deleted file mode 100644 index f06a0e9137..0000000000 --- a/contrib/onelab2/OnelabAttributes.h +++ /dev/null @@ -1,233 +0,0 @@ -#ifndef _ONELAB_ATTRIBUTES_H -#define _ONELAB_ATTRIBUTES_H - -#define SESSION_SIZE 32 - -#define ERROR_BUFFER_TOO_SMALL 50 -#define ERROR_INVALID_ATTRIBUTE_SIZE 51 - -#include <stdlib.h> -#include <stdio.h> - -#include "NetworkUtils.h" - -class OnelabAttr -{ -protected: - // Header : - //UInt16 _type; - //UInt16 _size; - - bool _stored; // is the attribute in the database ? -public: - OnelabAttr() {} - virtual ~OnelabAttr(){} - - virtual UInt8 *encodeAttribute(UInt8 *dst) = 0; - virtual UInt8 *parseAttribute(UInt8 *src, UInt32 length) = 0; - virtual void showAttribute() const = 0; - - virtual inline UInt16 getAttributeType() const = 0; - virtual inline UInt16 getAttributeLength() const = 0; - - bool isInDatabase() const {return this->_stored;} - void isInDatabase(bool isInDb) {this->_stored = isInDb;} - - // attributes type to connect peers - static const UInt16 Peer = 0x01; - static const UInt16 Server = 0x02; - static const UInt16 Session = 0x03; - - // attributes type for onelab - static const UInt16 Start = 0x04; - static const UInt16 Parameter = 0x05; - static const UInt16 Number = 0x06; - static const UInt16 String = 0x07; - static const UInt16 Region = 0x08; - static const UInt16 Function = 0x09; - - // other message for onelab - static const UInt16 Message = 0x0A; - -}; - -class OnelabAttrStart : public OnelabAttr -{ -private: - std::string _name; -public: - OnelabAttrStart() {} - OnelabAttrStart(const std::string name) {_name = name;} - ~OnelabAttrStart(){} - UInt8 *encodeAttribute(UInt8 *dst); - UInt8 *parseAttribute(UInt8 *src, UInt32 length); - void showAttribute() const; - - static UInt16 attributeType() {return 0x04;} - inline UInt16 getAttributeType() const {return this->attributeType();} - inline UInt16 getAttributeLength() const {return _name.size();} - - std::string name(){return _name;} -}; - -class OnelabAttrParameterQuery : public OnelabAttr -{ -private: - UInt8 _ptype; - std::string _pname; -public: - OnelabAttrParameterQuery() {} - OnelabAttrParameterQuery(const std::string name, UInt8 parameter) {_ptype = parameter; _pname = name;} - ~OnelabAttrParameterQuery() {} - UInt8 *encodeAttribute(UInt8 *buff); - UInt8 *parseAttribute(UInt8 *buff, UInt32 length); - void showAttribute() const; - - static UInt16 attributeType() {return 0x05;} - inline UInt16 getAttributeType() const {return this->attributeType();} - inline UInt16 getAttributeLength() const {return 1+_pname.size();} - - inline UInt8 paramType() const {return this->_ptype;} - std::string getName() const {return this->_pname;} -}; - -class OnelabAttrMessage : public OnelabAttr -{ -private: - UInt8 *_message; - UInt16 _messageLength; - UInt8 _level; - -public: - OnelabAttrMessage() : _message(NULL), _messageLength(0), _level(0) {} - OnelabAttrMessage(const std::string &message, const int level=OnelabAttrMessage::Debug) : _message(NULL){setMessage(message, level);} - ~OnelabAttrMessage(){if(_message != NULL) free(_message);}; - UInt8 *encodeAttribute(UInt8 *dst); - UInt8 *parseAttribute(UInt8 *src, UInt32 length); - void showAttribute() const; - - static UInt16 attributeType() {return 0x0A;} - inline UInt16 getAttributeType() const {return this->attributeType();} - inline UInt16 getAttributeLength() const {return 1+_messageLength;} - - void setMessage(const std::string &message, const int level=OnelabAttrMessage::Debug) { - _level = level; - _messageLength = message.size()+1; - if(_message != NULL) free(_message); - _message = (UInt8 *)strndup(message.c_str(), _messageLength); - } - const char *getMessage() {return (char *)_message;} - int getLevel() {return _level;} - - typedef enum { - Debug=99, - Info=5, - Warning=3, - Error=2, - Fatal=1 - } OnelabMessageLvl; -}; - -class OnelabAttrAction : public OnelabAttr -{ -private: - std::string _action; - std::string _client; - -public: - OnelabAttrAction() : _action(""), _client("") {} - OnelabAttrAction(std::string action, std::string client) : _action(action), _client(client) {} - ~OnelabAttrAction() {} - - UInt8 *encodeAttribute(UInt8 *dst); - UInt8 *parseAttribute(UInt8 *src, UInt32 lenght); - void showAttribute() const; - - static UInt16 attributeType() {return 0x10;} - inline UInt16 getAttributeType() const {return attributeType();} - inline UInt16 getAttributeLength() const {return _client.size()+1+_action.size();} - - void setAction(std::string action) {_action = action;} - void setClient(std::string client) {_client = client;} - std::string getAction() {return _action;} - std::string getClient() {return _client;} -}; - -class OnelabAttrFileQuery : public OnelabAttr -{ -private: - char *_name; - UInt16 _length; - std::string _client; - -public: - OnelabAttrFileQuery() : _name(NULL), _length(0){} - OnelabAttrFileQuery(const std::string filename) : _name(NULL), _length(0) {setFilename(filename);} - ~OnelabAttrFileQuery() {if(_name != NULL) free(_name);} - UInt8 *encodeAttribute(UInt8 *dst); - UInt8 *parseAttribute(UInt8 *src, UInt32 length); - void showAttribute() const; - - static UInt16 attributeType() {return 0x0B;} - inline UInt16 getAttributeType() const {return attributeType();} - inline UInt16 getAttributeLength() const {return _length+_client.length()+1;} - - void setFilename(std::string name); - void setClient(std::string client) {_client = client;} - const char *getFilename() {return _name;} -}; - -class OnelabAttrMergeFile : public OnelabAttr -{ -private: - char *_name; - UInt16 _length; - -public: - OnelabAttrMergeFile() : _name(NULL), _length(0){} - OnelabAttrMergeFile(const std::string filename) : _name(NULL), _length(0) {setFilename(filename);} - ~OnelabAttrMergeFile() {if(_name != NULL) free(_name);} - UInt8 *encodeAttribute(UInt8 *dst); - UInt8 *parseAttribute(UInt8 *src, UInt32 length); - void showAttribute() const; - - static UInt16 attributeType() {return 0x0D;} - inline UInt16 getAttributeType() const {return attributeType();} - inline UInt16 getAttributeLength() const {return _length;} - - void setFilename(std::string name); - const char *getFilename() {return _name;} -}; - -class OnelabAttrFile : public OnelabAttr -{ -private: - char *_name; - FILE *_fd; - UInt32 _filelength; - -public: - OnelabAttrFile() : _name(NULL), _filelength(0) {} - OnelabAttrFile(const std::string filename, FILE *fd) {setFile(filename, fd);} - ~OnelabAttrFile() {if(_name != NULL) free(_name);} - UInt8 *encodeAttribute(UInt8 *dst); - UInt8 *parseAttribute(UInt8 *src, UInt32 length); - void showAttribute() const; - - static UInt16 attributeType() {return 0x0C;} - inline UInt16 getAttributeType() const {return attributeType();} - inline UInt16 getAttributeLength() const {return 4+strlen(_name);} - - void setFile(std::string name, FILE *fd) - { - if(_name != NULL) free(_name); - _name = strndup(name.c_str(), name.size()+1); - _fd = fd; - long pos = ftell(fd); fseek(fd, 0, SEEK_END); - _filelength = (UInt32)ftell(fd); fseek(fd, pos, SEEK_SET); - } - const char *getFilename() {return _name;} - unsigned int getFileSize() {return _filelength;} -}; - -#endif diff --git a/contrib/onelab2/OnelabDatabase.cpp b/contrib/onelab2/OnelabDatabase.cpp deleted file mode 100644 index 165440c390..0000000000 --- a/contrib/onelab2/OnelabDatabase.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "OnelabDatabase.h" - -OnelabServer *OnelabServer::_server = NULL; - -#ifndef WIN32 -void *OnelabDatabase_listen(void *arg) -#else -DWORD WINAPI OnelabDatabase_listen(LPVOID arg) -#endif -{ - std::string *client = (std::string *)arg; - OnelabProtocol msg(-1); - UInt8 buff[1024]; - int recvlen = 0; - while(1) { - recvlen = OnelabDatabase::instance()->listen(msg); - if(recvlen <= 0) - break; // invalid len - switch(msg.msgType()) { - case OnelabProtocol::OnelabStop: - std::clog << "\033[0;35m" << "Client is going to stop" << "\033[0;0m" << std::endl; - return NULL; - case OnelabProtocol::OnelabMessage: - if(msg.attrs.size()==1 && msg.attrs[0]->getAttributeType() == OnelabAttrMessage::attributeType()) { - OnelabNetworkClient *gui = OnelabDatabase::instance()->getNetworkClient(); - if(gui) gui->onMessage("Server", ((OnelabAttrMessage *)msg.attrs[0])->getMessage(), ((OnelabAttrMessage *)msg.attrs[0])->getLevel()); - } - break; - case OnelabProtocol::OnelabResponse: - case OnelabProtocol::OnelabUpdate: - std::clog << "\033[0;35m" << "Update " << msg.attrs.size() << " parameter(s) on client:" << "\033[0;0m" << std::endl; - for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { - std::clog << " - " << ((onelab::parameter *)*it)->getName() << std::endl; // FIXME - if((*it)->getAttributeType() == OnelabAttr::Number) { - onelab::number *attr = (onelab::number *)*it; - OnelabDatabase::instance()->set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttr::String) { - onelab::string *attr = (onelab::string *)*it; - OnelabDatabase::instance()->set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttr::Region) { - onelab::region *attr = (onelab::region *)*it; - OnelabDatabase::instance()->set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttr::Function) { - onelab::function *attr = (onelab::function *)*it; - OnelabDatabase::instance()->set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttrFileQuery::attributeType()) { - OnelabAttrFileQuery *attr = (OnelabAttrFileQuery *)*it; - const char *filename = attr->getFilename(); - // FIXME path/filename ? - std::clog << "try to open " << filename << " for reading" << std::endl; - FILE *fp = fopen(filename, "rb"); - if(fp != NULL){ - OnelabProtocol rep(OnelabProtocol::OnelabUpdate); - rep.attrs.push_back(new OnelabAttrFile(std::string(filename), fp)); - recvlen = rep.encodeMsg(buff, 1024); - OnelabDatabase::instance()->sendbytes(buff, recvlen); - while((recvlen = fread(buff, 1, 1024, fp)) > 0) - OnelabDatabase::instance()->sendbytes(buff, recvlen); - } - } - else if((*it)->getAttributeType() == OnelabAttrFile::attributeType()) { - OnelabAttrFile *attr = (OnelabAttrFile *)*it; - const char *filename = attr->getFilename(); - std::clog << "try to open " << filename << " for writing" << std::endl; - FILE *fp = fopen(filename, "wb"); - if(fp != NULL){ - unsigned int filesize = ((OnelabAttrFile *)attr)->getFileSize(); - unsigned int downloadsize = 0; - while(downloadsize < filesize) { - recvlen = OnelabDatabase::instance()->listen(buff, 1024); - downloadsize += recvlen; - fwrite(buff, 1, recvlen, fp); - } - } - } - } - break; - case OnelabProtocol::OnelabAction: - { - std::clog << "\033[0;35m" << "Client have to perform an action" << "\033[0;0m" << std::endl; - // nothing to do ? - } - } - } -} - -void OnelabDatabase::finalize() -{ - if(_client) { - _client->disconnect(); - pthread_join(_listenThread, NULL); - } - else { - OnelabServer::instance()->finalize(); - } -} - -void solver_batch_cb(void *data) -{ - int num = (intptr_t)data; - if(num < 0) return; - std::string name = opt_solver_name(num, GMSH_GET, ""); - std::string exe = opt_solver_executable(num, GMSH_GET, ""); - std::string host = opt_solver_remote_login(num, GMSH_GET, ""); - if(exe.empty()){ - Msg::Error("Solver executable name not provided"); - return; - } - - onelab::number n("0Metamodel/Batch", CTX::instance()->batch); - n.setVisible(false); - //onelab::server::instance()->set(n); - // TODO -} diff --git a/contrib/onelab2/OnelabDatabase.h b/contrib/onelab2/OnelabDatabase.h deleted file mode 100644 index d263358bf8..0000000000 --- a/contrib/onelab2/OnelabDatabase.h +++ /dev/null @@ -1,283 +0,0 @@ -#ifndef _ONELABDATABASE_H_ -#define _ONELABDATABASE_H_ -#endif -#include <signal.h> -#include <stdio.h> - -#include "GmshMessage.h" -#include "Options.h" -#include "Context.h" -#include "onelabUtils.h" -#include "OnelabServer.h" -#include "VirtualClient.h" -#include "GmshNetworkClient.h" -#include "GmshLocalClient.h" - -#include "OnelabException.h" - -void solver_batch_cb(void *data); -#ifndef WIN32 -void *OnelabDatabase_listen(void *arg); -#else -DWORD WINAPI OnelabDatabase_listen(LPVOID arg); -#endif - -static void initializeLoops(); -static bool incrementLoops(); - -// OnelabDatabase is a singleton that get/set/... parameters from server/clients -class OnelabDatabase { -private: - static OnelabDatabase *_instance; -#ifndef WIN32 - pthread_t _listenThread, _serverThread; -#else - HANDLER _listenThread, _serverThread; -#endif - GmshNetworkClient *_client; - GmshLocalClient *_localGUI, *_localGmsh; - void _clear() { -#ifndef WIN32 - if(_client) pthread_cancel(_listenThread); - else { - OnelabServer::instance()->stopTcp(); - OnelabServer::instance()->stopUnix(); -#ifdef HAVE_UDT - OnelabServer::instance()->stopUdt(); -#endif - } -#else - // TODO -#endif - if(_client) { - _client->disconnect(); - delete _client; - } - if(_localGUI) delete _localGUI; - if(_localGmsh) delete _localGmsh; - _client = NULL; _localGUI = _localGmsh = NULL; - } - -public: - OnelabDatabase() { - _localGUI = NULL; _client = NULL; _localGmsh = NULL; - } - static OnelabDatabase *instance() { - if(!_instance) _instance = new OnelabDatabase; - return _instance; - } - GmshLocalClient *useAsClient(){ - // the server is in the same memory space - _clear(); - - CTX::instance()->onelab.unixConnected = CTX::instance()->onelab.tcpConnected = CTX::instance()->onelab.udtConnected = false; - - try { - if(CTX::instance()->onelab.unixSock.size() > 0) { // UNIX - std::ostringstream tmp; - tmp << CTX::instance()->homeDir << CTX::instance()->onelab.unixSock; - OnelabServer::instance()->listenOnUnix(tmp.str().c_str()); - CTX::instance()->onelab.unixConnected = true; - } - if(CTX::instance()->onelab.tcpSock.size() > 0) { - std::size_t colon = CTX::instance()->onelab.tcpSock.find(":"); - OnelabServer::instance()->listenOnTcp( - ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()), - atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str())); - CTX::instance()->onelab.tcpConnected = true; - } -#ifdef HAVE_UDT - if(CTX::instance()->onelab.udtSock.size() > 0) { - std::size_t colon = CTX::instance()->onelab.tcpSock.find(":"); - OnelabServer::instance()->listenOnUdt( - ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()), - atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str())); - CTX::instance()->onelab.udtConnected = true; - } -#endif - if(CTX::instance()->onelab.unixSock.size() == 0 && CTX::instance()->onelab.tcpSock.size() == 0 && CTX::instance()->onelab.udtSock.size() == 0) { - OnelabServer::instance()->listenOnTcp(0x7F000001, 0); - CTX::instance()->onelab.tcpConnected = true; - } - } catch(NetworkException e) { - std::cout << e.what() << std::endl; - OnelabServer::instance()->listenOnTcp(0x7F000001, 0); - CTX::instance()->onelab.tcpSock = "127.0.0.1:0"; - CTX::instance()->onelab.tcpConnected = true; - } - _localGUI = new GmshLocalClient("localGUI", OnelabServer::instance()->getParameterSpace()); - OnelabServer::instance()->addClient(_localGUI); - _localGmsh = new GmshLocalClient("Gmsh", OnelabServer::instance()->getParameterSpace()); - OnelabServer::instance()->addClient(_localGmsh); - - return _localGUI; - } - GmshNetworkClient *useAsNetworkClient(UInt32 address, UInt16 port, std::string cli="GUI"){ - // use this as a network client (take server address/port) - if(!_client) { - _clear(); - - _client = new GmshNetworkClient(cli, address, port); - if(_client->connect()) { -#ifndef WIN32 - pthread_create(&_listenThread, NULL, OnelabDatabase_listen, &(((OnelabLocalClient *)_client)->getName())); -#else - _listenThread = CreateThread(NULL, 0, NULL, OnelabDatabase_listen, 0, NULL); -#endif - return _client; - } - else { - delete _client; - _client = NULL; - return NULL; - } - } - else { -#ifndef WIN32 - pthread_create(&_listenThread, NULL, OnelabDatabase_listen, &(((OnelabLocalClient *)_client)->getName())); -#else - _listenThread = CreateThread(NULL, 0, NULL, OnelabDatabase_listen, 0, NULL); -#endif - return _client; - } - return NULL; - } - bool isNetworkClient() {return _client != NULL;} - GmshNetworkClient *getNetworkClient(){return _client;} - void finalize(); - int listen(OnelabProtocol &msg) { - if(_client) return _client->recvfrom(msg); - return 0; - } - int listen(UInt8 *buff, unsigned int maxlen){ - if(_client) return _client->recvfrom(buff, maxlen); - return 0; - } - void sendbytes(UInt8 *buff, unsigned int len){ - if(_client) _client->sendto(buff, len); - } - GmshLocalClient *useAsServer(UInt32 address, UInt16 port){ - // use this as a network server (take interface/port to listen to) - _clear(); - - // FIXME TCP / UDT ? - OnelabServer::instance()->listenOnTcp(address, port); - _localGUI = new GmshLocalClient("localGUI", OnelabServer::instance()->getParameterSpace()); - return _localGUI; - } - template <class T> bool set(const T &p, const std::string &client) { - if(_client) return _client->set(p, true); - return OnelabServer::instance()->set(p, client); - } - template <class T> bool set(const T &p, bool update=true) { - if(_client) return _client->set(p, update); - //if(_localGUI) return _localGUI->set(p); - return OnelabServer::instance()->set(p); - } - template <class T> bool get(std::vector<T> &ps, const std::string &name="", const std::string &client="") { - if(_client) return _client->get(ps, name); - //if(_localGUI) _localGUI->get(ps, name); - return OnelabServer::instance()->get(ps, name, client); - } - void clear(const std::string &name="", const std::string &client="") { - if(_client) return _client->clear(name, client); - return OnelabServer::instance()->clear(name, client); - } - bool fromFile(FILE *fp, const std::string &client="") - { - if(_client) return _client->fromFile(fp, client); - return OnelabServer::instance()->fromFile(fp, client); - - } - bool run(const std::string action, const std::string client="") { - UInt8 buff[1024]; - OnelabProtocol msg(OnelabProtocol::OnelabAction); - if(client.size()) { - std::cout << "try to " << action << ' ' << client << std::endl; - if(_client && ((OnelabLocalClient *)_client)->getName() == client) { - if(client == "Gmsh") onelabUtils::runGmshClient(action, true); - } - else if(_client) { - std::cout << "client is remote" << std::endl; - msg.attrs.push_back(new OnelabAttrAction(action, client)); - int size = msg.encodeMsg(buff, 1024); - sendbytes(buff, size); - return true; - } - else { - std::cout << "client is local" << std::endl; - OnelabServer::instance()->performAction(action, client); - return true; - } - } - else { // run all client - if(action == "compute") initializeLoops(); - - do{ // enter loop - run(action, "Gmsh"); // run Gmsh client - - if(CTX::instance()->solverToRun >= 0) { // launch the solver - std::string solver = opt_solver_name(CTX::instance()->solverToRun, GMSH_GET, ""); - std::string exe = opt_solver_executable(CTX::instance()->solverToRun, GMSH_GET, ""); - if(_client && exe.size()) { - onelab::string o(solver + "/CommandLine", exe); - o.setVisible(false); - o.setNeverChanged(true); - set(o, solver); - } - run(action, solver); - } - else { // send action to all connected client except Gmsh - if(_client) { - std::cout << "server is remote" << std::endl; - msg.attrs.push_back(new OnelabAttrAction(action, client)); - int size = msg.encodeMsg(buff, 1024); - sendbytes(buff, size); - } - else { - std::cout << "server is local" << std::endl; - OnelabServer::instance()->performAction(action, client, true); - } - return true; - } - } while(action == "compute" && /*!FlGui::instance()->onelab->stop() &&*/ - incrementLoops()); - } - return false; - } - bool getChanged(const std::string &client="") const { - if(!_client) - return OnelabServer::instance()->getChanged(client); - else - return true; // TODO - } - void setChanged(bool changed, const std::string &client="") { - if(!_client) - OnelabServer::instance()->setChanged(changed, client); - else - return; // TODO - } -}; - -static void initializeLoops() -{ - onelabUtils::initializeLoop("1"); - onelabUtils::initializeLoop("2"); - onelabUtils::initializeLoop("3"); -} - -static bool incrementLoops() -{ - bool ret = false; - if(onelabUtils::incrementLoop("3")) ret = true; - else if(onelabUtils::incrementLoop("2")) ret = true; - else if(onelabUtils::incrementLoop("1")) ret = true; - - //Define ONELAB parameter indicating whether or not in a loop - onelab::number n("0Metamodel/Loop",ret?1:0); - n.setVisible(false); - OnelabDatabase::instance()->set(n); - - return ret; -} - diff --git a/contrib/onelab2/OnelabException.h b/contrib/onelab2/OnelabException.h deleted file mode 100644 index 43fa0ffbd6..0000000000 --- a/contrib/onelab2/OnelabException.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _ONELABEXCEPTION_H_ -#define _ONELABEXCEPTION_H_ -#include <exception> - -//class OnelabException : public std::exception - - -class NetworkException : public std::exception -{ - private: - int _code; - - public: - NetworkException(int code) : _code(code) {} - - typedef enum { - Create, - Bind, - Connect, - Listen, - Send, - Recv, - nUnix - } NetworkExceptionCode; - - virtual const char* what(){ - switch(_code) { - case Create: - return "Unable to create the socket"; - case Bind: - return "Unable to bind the socket"; - case Connect: - return "Unable to connect the socket"; - case Listen: - return "Unable to listen on the socket"; - case Send: - return "Unable to send on the socket"; - case Recv: - return "Unable to recv on the socket"; - case nUnix: - return "UNIX sockets are unavailable"; - default: - return "Unkonown error with the socket"; - } - } -}; - -#endif diff --git a/contrib/onelab2/OnelabLocalClient.h b/contrib/onelab2/OnelabLocalClient.h deleted file mode 100644 index 96c8d6977d..0000000000 --- a/contrib/onelab2/OnelabLocalClient.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _ONELABLOCALCLIENT_H_ -#define _ONELABLOCALCLIENT_H_ - -#include "VirtualClient.h" - -/** - @class OnelabLocalClient - @brief This class is used for client in the same memory space as the server. - -*/ - -class OnelabLocalClient : public VirtualClient -{ -public: - OnelabLocalClient(std::string name, onelab::parameterSpace *parameterSpace) - : VirtualClient(name, parameterSpace){ - } - virtual ~OnelabLocalClient(){} - virtual void onNewParameter(onelab::parameter *p){} - virtual void onUpdateParameter(onelab::parameter *p){} - virtual void onRemoveParameter(onelab::parameter *p){} - virtual void onMessage(const std::string &name, const std::string &message, int level){} - virtual void onStop() {} - virtual void refresh(){} - virtual void mergeFile(const std::string &filename){} - - virtual void run(std::string action) {} -}; - -#endif diff --git a/contrib/onelab2/OnelabLocalNetworkClient.cpp b/contrib/onelab2/OnelabLocalNetworkClient.cpp deleted file mode 100644 index 17635b3ead..0000000000 --- a/contrib/onelab2/OnelabLocalNetworkClient.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "OnelabLocalNetworkClient.h" -#include "OnelabProtocol.h" - -#ifdef HAVE_UDT -OnelabLocalNetworkClient::OnelabLocalNetworkClient(std::string name, UDTSOCKET fd, unsigned int ip, unsigned short port, bool UDT) -{ - _mutex_wait = PTHREAD_MUTEX_INITIALIZER; - _name = name; - _fds = 0; - _fdu = fd; - _ip.address = ip; - _ip.port = port; -} -#endif -OnelabLocalNetworkClient::OnelabLocalNetworkClient(std::string name, Socket fd, unsigned int ip, unsigned short port) -{ - _mutex_wait = PTHREAD_MUTEX_INITIALIZER; - _name = name; - _fds = fd; - _ip.address = ip; - _ip.port = port; -} -void OnelabLocalNetworkClient::sendto(UInt8 *buff, unsigned int len) -{ -#ifdef HAVE_UDT - if(_fds) ip4_socket_send(_fds, buff, len); - else udt_socket_send(_fdu, buff, len); -#else - ip4_socket_send(_fds, buff, len); -#endif -} -int OnelabLocalNetworkClient::recvfrom(UInt8 *buff, unsigned int maxlen) -{ - IPv4 unused; -#ifdef HAVE_UDT - if(_fds) return ip4_socket_recv(_fds, buff, maxlen, unused); - return udt_socket_recv(_fdu, buff, maxlen); -#else - return ip4_socket_recv(_fds, buff, maxlen); -#endif -} -int OnelabLocalNetworkClient::recvmsg(OnelabProtocol &msg) -{ - UInt8 header[8]; - UInt8 *buff = NULL; - int recvlen = 0; - // recv the header - recvlen = recvfrom(header, 4); - if(recvlen != 4) return recvlen; - int msglen = msg.parseHeader(header, recvlen); - // then recv the message - if(msglen == 0) return 4; - buff = (UInt8 *) malloc(sizeof(UInt8)*msglen); - recvlen = recvfrom(buff, msglen); // recvlen should be equals to msglen - msg.parseMessage(buff, recvlen); - free(buff); - return recvlen + 4; -} -void OnelabLocalNetworkClient::updateParameter(onelab::parameter *p) -{ - if(p == NULL) return; - OnelabProtocol msg(OnelabProtocol::OnelabUpdate); - msg.attrs.push_back(p); - UInt8 buff[1024]; - unsigned int recvlen = msg.encodeMsg(buff, 1024); - sendto(buff, recvlen); -} -void OnelabLocalNetworkClient::run(std::string action) -{ - OnelabProtocol msg(OnelabProtocol::OnelabAction); - msg.attrs.push_back(new OnelabAttrAction(action, _name)); - UInt8 buff[1024]; - unsigned int size = msg.encodeMsg(buff, 1024); - sendto(buff, size); -} diff --git a/contrib/onelab2/OnelabLocalNetworkClient.h b/contrib/onelab2/OnelabLocalNetworkClient.h deleted file mode 100644 index cdc54a12fe..0000000000 --- a/contrib/onelab2/OnelabLocalNetworkClient.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _ONELABLOCALNETWORKCLIENT_H_ -#define _ONELABLOCALNETWORKCLIENT_H_ - -#include <string> -#include "onelab.h" -#ifdef HAVE_UDT -#include "UdtUtils.h" -#endif -#include "NetworkUtils.h" -#include "OnelabProtocol.h" - -class OnelabLocalNetworkClient -{ -private: - Socket _fds; -#ifdef HAVE_UDT - UDTSOCKET _fdu; -#endif - IPv4 _ip; - std::string _name; - pthread_mutex_t _mutex_wait; -public: -#ifdef HAVE_UDT - OnelabLocalNetworkClient(std::string name, UDTSOCKET fd, unsigned int ip, unsigned short port, bool UDT); - UDTSOCKET getUSocket() {return _fdu;} -#endif - OnelabLocalNetworkClient(std::string name, Socket fd, unsigned int ip, unsigned short port); - virtual ~OnelabLocalNetworkClient(){} - void sendto(UInt8 *buff, unsigned int len); - int recvfrom(UInt8 *buff, unsigned int maxlen); - int recvmsg(OnelabProtocol &msg); - Socket getSSocket() {return _fds;} - std::string getName() {return _name;} - void updateParameter(onelab::parameter *); - unsigned int getIp() {return _ip.address;} - unsigned short getPort() {return _ip.port;} - - void run(std::string action); -}; -#endif diff --git a/contrib/onelab2/OnelabNetworkClient.cpp b/contrib/onelab2/OnelabNetworkClient.cpp deleted file mode 100644 index 30aaed9717..0000000000 --- a/contrib/onelab2/OnelabNetworkClient.cpp +++ /dev/null @@ -1,244 +0,0 @@ -#include <iostream> - -#include "OnelabNetworkClient.h" - -#ifdef HAVE_UDT -OnelabNetworkClient::OnelabNetworkClient(std::string name, bool UDT) - : VirtualClient(name) -{ - _fds = 0; - _fdu = 0; - _ip.address = 0; - _ip.port = 0; - _connected = false; - - IPv4 local; - local.address = 0;// FIXME ip4_default_iface(); - local.port = 0; - UDT::startup(); - if(UDT) _fdu = udt_socket(local, SOCK_STREAM); - else _fds = ip4_socket(local, SOCK_STREAM); -} -OnelabNetworkClient::OnelabNetworkClient(std::string name, unsigned int ip, unsigned short port, bool UDT) - : VirtualClient(name) -{ - _fds = 0; - _fdu = 0; - _ip.address = ip; - _ip.port = port; - _connected = false; - - IPv4 local; - local.address = 0;//ip4_default_iface(); - local.port = 0; - UDT::startup(); - if(UDT) _fdu = udt_socket(local, SOCK_STREAM); - else _fds = ip4_socket(local, SOCK_STREAM); -} -#else -OnelabNetworkClient::OnelabNetworkClient(std::string name, unsigned int ip, unsigned short port) - : VirtualClient(name) -{ - _ip.address = ip; - _ip.port = port; - _connected = false; - - IPv4 local; - local.address = 0;//ip4_default_iface(); - local.port = 0; - _fds = ip4_socket(local, SOCK_STREAM); -} -#endif -OnelabNetworkClient::OnelabNetworkClient(std::string name, const char *sockname) - : VirtualClient(name) -{ - _ip.address = 0; - _ip.port = 0; - _connected = false; - - _sockname = std::string(sockname); - - _fds = unix_socket(SOCK_STREAM); -} -void OnelabNetworkClient::sendto(UInt8 *buff, UInt16 len) -{ -#ifndef HAVE_UDT - ip4_socket_send(_fds, buff, len); -#else - if(_fds) ip4_socket_send(_fds, buff, len); - else udt_socket_send(_fdu, buff, len); -#endif -} -int OnelabNetworkClient::recvfrom(UInt8 *buff, UInt16 maxlen) -{ - IPv4 unused; -#ifndef HAVE_UDT - return ip4_socket_recv(_fds, buff, maxlen, unused); // FIXME check unused == _ip ? -#else - if(_fds) return ip4_socket_recv(_fds, buff, maxlen); // FIXME check unused == _ip ? - return udt_socket_recv(_fdu, buff, maxlen); -#endif -} -int OnelabNetworkClient::recvfrom(OnelabProtocol &msg) -{ - UInt8 header[8]; - UInt8 *buff = NULL; - int recvlen = 0; - // recv the header - recvlen = recvfrom(header, 4); - if(recvlen != 4) return recvlen; - int msglen = msg.parseHeader(header, recvlen); - // then recv the message - if(msglen == 0) return 4; - buff = (UInt8 *) malloc(sizeof(UInt8)*msglen); - recvlen = recvfrom(buff, msglen); // recvlen should be equals to msglen - msg.parseMessage(buff, recvlen); - free(buff); - return recvlen + 4; -} -int OnelabNetworkClient::recvfrom() -{ - OnelabProtocol msg(-1); - int totalrecv = 0; - int recvlen = 0; - do { - ip4_socket_timeout(_fds, 0, 1000); - recvlen = recvfrom(msg); - ip4_socket_timeout(_fds, 0); - if(recv > 0) totalrecv+=recvlen; - - if(recv <= 0) return totalrecv; - - switch(msg.msgType()) { - case OnelabProtocol::OnelabResponse: - case OnelabProtocol::OnelabUpdate: - for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { - if((*it)->getAttributeType() == OnelabAttr::Number) { - onelab::number *attr = (onelab::number *)*it; - set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttr::String) { - onelab::string *attr = (onelab::string *)*it; - set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttr::Region) { - onelab::region *attr = (onelab::region *)*it; - set(*attr, false); - } - else if((*it)->getAttributeType() == OnelabAttr::Function) { - onelab::function *attr = (onelab::function *)*it; - set(*attr, false); - } - } - } - } while(recvlen > 0); - return totalrecv; -} -bool OnelabNetworkClient::connect() -{ - if(_connected) return true; - - UInt16 bufflen = 1024; - int recvlen = 0; - UInt8 buff[1024]; - OnelabProtocol msg(OnelabProtocol::OnelabStart); -#ifdef HAVE_UDT - if(_fds) { - if(_sockname.size()) - unix_socket_connect(_fds, _sockname.c_str()); - else - _connected = ip4_socket_connect(_fds, _ip) != -1; - } - else - udt_socket_connect(_fdu, _ip); -#else - if(_sockname.size()) - unix_socket_connect(_fds, _sockname.c_str()); - else - _connected = ip4_socket_connect(_fds, _ip) != -1; -#endif - - if(!_connected) return false; - - msg.attrs.push_back(new OnelabAttrStart(_name)); - recvlen = msg.encodeMsg(buff, bufflen); - sendto(buff, recvlen); -#ifdef HAVE_UDT - if(_fdu)udt_socket_timeout(_fdu, 3); - else -#endif - ip4_socket_timeout(_fds, 3); - recvlen = recvfrom(msg); - -#ifdef HAVE_UDT - if(_fdu)udt_socket_timeout(_fdu, -1); - else -#endif - ip4_socket_timeout(_fds, 0); - if(recvlen > 0 && msg.msgType() == OnelabProtocol::OnelabStart) _connected = true; - return _connected; -} - -void OnelabNetworkClient::disconnect(bool waitForServer) -{ - if(!_connected) return; - // Send a message to the server to say the client is going to stop (the server have to reply) - UInt8 buff[128]; - fd_set readfds; - struct timeval timeout; - OnelabProtocol msg(OnelabProtocol::OnelabStop); - int recvlen = msg.encodeMsg(buff, 128); - this->sendto(buff, recvlen); - if(waitForServer) { - timeout.tv_sec = 1; - timeout.tv_usec = 0; - FD_ZERO(&readfds); - FD_SET(_fds, &readfds); - while(select(_fds+1, &readfds, NULL, NULL, &timeout) > 0) { // Wait for the server to answer - recvlen = recvfrom(msg); - if(msg.msgType() == OnelabProtocol::OnelabStop) { - _connected = false; - closeSocket(); - break; - } - } - } - else { - _connected = false; - } -} - -void OnelabNetworkClient::closeSocket() -{ -#ifdef HAVE_UDT - if(_fds) - ip4_socket_close(_fds); - else - udt_socket_close(_fdu); -#else - ip4_socket_close(_fds); -#endif -} - -void OnelabNetworkClient::request(OnelabProtocol &msg) -{ - UInt16 bufflen = 1024, recvlen = 0; - UInt8 buff[1024]; - recvlen = msg.encodeMsg(buff, bufflen); - this->sendto(buff, recvlen); -} - -void OnelabNetworkClient::requestParameters() -{ - OnelabProtocol msg(OnelabProtocol::OnelabRequest); - this->request(msg); -} - -void OnelabNetworkClient::sendMessage(const int level, const std::string &message) -{ - OnelabProtocol msg(OnelabProtocol::OnelabMessage); - UInt8 buff[1024]; - msg.attrs.push_back(new OnelabAttrMessage(message, level)); - int recvlen = msg.encodeMsg(buff, 1024); - this->sendto(buff, recvlen); -} diff --git a/contrib/onelab2/OnelabNetworkClient.h b/contrib/onelab2/OnelabNetworkClient.h deleted file mode 100644 index 50c1a51af4..0000000000 --- a/contrib/onelab2/OnelabNetworkClient.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef _ONELABCLIENT_H_ -#define _ONELABCLIENT_H_ - -#include <vector> -#include <unistd.h> - -#include "VirtualClient.h" -#include "OnelabProtocol.h" -#ifdef HAVE_UDT -#include "UdtUtils.h" -#else -#include "NetworkUtils.h" -#endif - -class OnelabNetworkClient : public VirtualClient -{ -private: -#ifdef HAVE_UDT - UDTSOCKET _fdu; -#endif - std::string _sockname; - Socket _fds; - bool _connected; - IPv4 _ip; - - void request(OnelabProtocol &msg); - template <class T> bool requestParameter(std::vector<T> &ps, const std::string &name=""){ - OnelabProtocol msg(OnelabProtocol::OnelabRequest); - msg.attrs.push_back(new OnelabAttrParameterQuery(name.c_str(), T::attributeType())); - this->request(msg); - return true; - } - void requestParameters(); // request all parameter for this client -public: - OnelabNetworkClient(std::string name, const char *sockname); -#ifdef HAVE_UDT - OnelabNetworkClient(std::string name, bool UDT=false); - OnelabNetworkClient(std::string name, unsigned int ip, unsigned short port, bool UDT=false); - virtual ~OnelabNetworkClient() {UDT::cleanup();} -#else - OnelabNetworkClient(std::string name); - OnelabNetworkClient(std::string name, unsigned int ip, unsigned short port); - virtual ~OnelabNetworkClient() {} -#endif - template <class T> bool existInDatabase(const T p) { - std::vector<T> ps; - _parameterSpace->get(ps, p.getName(), _name); - return ps.size() > 0; - } - template <class T> bool set(const T &p, bool update=true){ - bool isInDatabase = existInDatabase(p); - if(_parameterSpace->set(p, _name)) { - T *pp; - _parameterSpace->getPtr(&pp, p.getName(), _name); - if(update) { - OnelabProtocol msg(OnelabProtocol::OnelabUpdate); - msg.attrs.push_back(pp); - request(msg); - } - if(!isInDatabase) onNewParameter(pp); - else onUpdateParameter(pp); - return true; - } - return false; - } - template <class T> bool get(std::vector<T> &ps, const std::string &name, bool needed=false){ - if(_parameterSpace->get(ps, name, this->_name) && ps.size() == 0) { - if(requestParameter(ps, name)) { - if(needed) {// wait for the answer - fd_set readfds; - struct timeval timeout; - timeout.tv_sec = 1; - timeout.tv_usec = 0; - FD_ZERO(&readfds); - FD_SET(_fds, &readfds); - int nfds = select(_fds+1, &readfds, NULL, NULL, &timeout); // Wait for the server to answer - if(nfds > 0) recvfrom(); - } - return _parameterSpace->get(ps, name, _name) && ps.size() == 0; - } - else - return false; - } - 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); - if(fp == NULL){ // File is not local, download it - OnelabProtocol msg(OnelabProtocol::OnelabUpdate); - msg.attrs.push_back(new OnelabAttrFileQuery(name)); - request(msg); - // TODO - } - return fp; - } - bool fromChar(const std::vector<std::string> &msg, const std::string &client="") - { - onelab::parameter *parameters[4]; - unsigned int pi = 0; - for(unsigned int i = 0; i < msg.size(); i++){ - std::string version, type, name; - onelab::parameter::getInfoFromChar(msg[i], version, type, name); - if(onelab::parameter::version() != version) return false; - if(type == "number"){ - onelab::number p; p.fromChar(msg[i]); set(p, false); - _parameterSpace->getPtr((onelab::number **)¶meters[pi++], p.getName()); - } - else if(type == "string"){ - onelab::string p; p.fromChar(msg[i]); set(p, false); - _parameterSpace->getPtr((onelab::string **)¶meters[pi++], p.getName()); - } - else if(type == "region"){ - onelab::region p; p.fromChar(msg[i]); set(p, false); - _parameterSpace->getPtr((onelab::region **)¶meters[pi++], p.getName()); - } - else if(type == "function"){ - onelab::function p; p.fromChar(msg[i]); set(p, false); - _parameterSpace->getPtr((onelab::function **)¶meters[pi++], p.getName()); - } - else - return false; - if(pi == 4 || i==msg.size()-1) { - OnelabProtocol msg(OnelabProtocol::OnelabUpdate); - for(unsigned int j = 0; j < pi; j++) - msg.attrs.push_back(parameters[j]); - request(msg); - pi=0; - } - } - return true; - } - bool fromFile(FILE *fp, const std::string &client="") - { - std::vector<std::string> msg; - if(onelab::parameter::fromFile(msg, fp)) return fromChar(msg, client); - return false; - } - virtual void onNewParameter(onelab::parameter *){} - virtual void onUpdateParameter(onelab::parameter *){} - virtual void onRemoveParameter(onelab::parameter *){} - void onMessage(const std::string &name, const std::string &message, int level) {} - // network specific method - bool connect(); - bool isConnected(){return _connected;} - int recvfrom(); // empty the buffer (useful when the client do not listen on another thread) - int recvfrom(OnelabProtocol &msg); - int recvfrom(UInt8 *buff, UInt16 maxlen); - void sendto(UInt8 *buff, UInt16 len); - void disconnect(bool waitForServer=false); - void closeSocket(); - void setRemoteIP(unsigned long ip){if(!_connected) _ip.address=ip;} - void setRemotePort(unsigned short port){if(!_connected) _ip.port=port;} - - void run(std::string action) {} - - void sendMessage(const int level, const std::string &message); - void sendInfo(const std::string &msg) - { - sendMessage(OnelabAttrMessage::Info, msg); - } - void sendWarning(const std::string &msg) - { - sendMessage(OnelabAttrMessage::Warning, msg); - } - void sendError(const std::string &msg) - { - sendMessage(OnelabAttrMessage::Error, msg); - } - void mergeFile(const std::string &filename) - { - OnelabProtocol msg(OnelabProtocol::OnelabUpdate); - UInt8 buff[1024]; - msg.attrs.push_back(new OnelabAttrMergeFile(filename)); - int recvlen = msg.encodeMsg(buff, 1024); - std::cout <<recvlen << std::endl; - sendto(buff, recvlen); - } -}; - -#endif diff --git a/contrib/onelab2/OnelabProtocol.cpp b/contrib/onelab2/OnelabProtocol.cpp deleted file mode 100644 index 93ee702773..0000000000 --- a/contrib/onelab2/OnelabProtocol.cpp +++ /dev/null @@ -1,162 +0,0 @@ -#include <iostream> - -#include "OnelabProtocol.h" -#include "onelab.h" -#include "NetworkUtils.h" - -OnelabProtocol::OnelabProtocol(UInt16 type) -{ - _type = type; - _size = 0; -} -void OnelabProtocol::clearAttrs() -{ - for (std::vector<OnelabAttr*>::iterator it = this->attrs.begin() ; it != this->attrs.end(); ++it) { - if((*it) != NULL && !(*it)->isInDatabase()) delete *it; - } - this->attrs.clear(); -} -unsigned short OnelabProtocol::encodeMsg(UInt8 *buff, UInt32 len) -{ - if(len < 4) throw ERROR_BUFFER_TOO_SMALL; - UInt8 *ptr = encode(buff, (UInt8)ONELAB_VERSION); - ptr = encode(ptr, _type); - UInt8 *sizeptr = ptr; - _size = 0; - ptr = encode(sizeptr, _size); - for (std::vector<OnelabAttr*>::iterator it = this->attrs.begin() ; it != this->attrs.end(); ++it) { - UInt16 attrLen = (*it)->getAttributeLength(); - if(4+_size+attrLen > len) { - encode(sizeptr, _size); - return (unsigned short)(ptr-buff); - } - ptr = (*it)->encodeAttribute(ptr); - _size+=attrLen+4; - } - - encode(sizeptr, _size); - return (unsigned short)(ptr-buff); -} -unsigned short OnelabProtocol::encodeMsgs(UInt8 *buff, UInt32 len) -{ - if(len < 4) throw ERROR_BUFFER_TOO_SMALL; - if(!attrs.size()) return 0; - UInt8 *ptr = encode(buff, (UInt8)ONELAB_VERSION); - ptr = encode(ptr, _type); - UInt8 *sizeptr = ptr; - _size = 0; - ptr = encode(sizeptr, _size); - while(attrs.size() > 0) { - OnelabAttr *attr = attrs.back(); - UInt16 attrLen = attr->getAttributeLength(); - if(4+_size+attrLen > len) { - encode(sizeptr, _size); - return (unsigned short)(ptr-buff); - } - ptr = attr->encodeAttribute(ptr); - if(!attr->isInDatabase()) delete attr; - attrs.pop_back(); - _size+=attrLen+4; - } - - encode(sizeptr, _size); - return (unsigned short)(ptr-buff); -} -int OnelabProtocol::parseHeader(UInt8 *buff, UInt32 len) -{ - this->clearAttrs(); - if(len < 4) throw ERROR_BUFFER_TOO_SMALL; - - UInt8 *ptr = buff; - UInt8 version = 0; - ptr = parse(ptr, version); - if(version != ONELAB_VERSION) throw ERROR_ONELAB_VERSION; - ptr = parse(ptr, _type); - ptr = parse(ptr, _size); - - //std::cout << "current version is " << (int)ONELAB_VERSION << ", message version is " << (int)version << "(length is " << len << ", size is "<< _size <<" )" << std::endl; - - return _size; -} -UInt32 OnelabProtocol::parseMessage(UInt8 *buff, UInt32 len) -{ - UInt8 *ptr = buff; - UInt8 *payload = ptr; - unsigned short parsed = 4; // header size - unsigned short size = _size; - while(size >= 4) { - UInt16 attrType = 0; - UInt16 attrSize = 0; - ptr = parse(ptr, attrType); - ptr = parse(ptr, attrSize); - size -= 4; - //std::cout << "Try to parse an attribute of type 0x" << std::hex << (UInt16)attrType << std::dec << " and size : " << attrSize << std::endl; - if(attrSize > size) throw ERROR_BUFFER_TOO_SMALL; - switch(attrType) { - case OnelabAttr::Message: - this->attrs.push_back(new OnelabAttrMessage()); - ((OnelabAttrMessage *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case OnelabAttr::Number: - this->attrs.push_back(new onelab::number()); - ((onelab::number *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case OnelabAttr::String: - this->attrs.push_back(new onelab::string()); - ((onelab::string *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case OnelabAttr::Region: - this->attrs.push_back(new onelab::region()); - ((onelab::region *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case OnelabAttr::Function: - this->attrs.push_back(new onelab::region()); - ((onelab::function *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case OnelabAttr::Start: - this->attrs.push_back(new OnelabAttrStart()); - ((onelab::string *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case OnelabAttr::Parameter: - this->attrs.push_back(new OnelabAttrParameterQuery()); - ((OnelabAttrParameterQuery *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case 0x10: - this->attrs.push_back(new OnelabAttrAction()); - ((OnelabAttrAction *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case 0x0b: - this->attrs.push_back(new OnelabAttrFileQuery()); - ((OnelabAttrFileQuery *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case 0x0c: - this->attrs.push_back(new OnelabAttrFile()); - ((OnelabAttrFile *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - case 0x0d: - this->attrs.push_back(new OnelabAttrMergeFile()); - ((OnelabAttrMergeFile *)this->attrs.back())->parseAttribute(ptr, attrSize); - break; - default: - // FIXME unknown attribute - //if(attrSize != 0) throw "Size of attr must be 0!"; - /*this->attrs.push_back(new OnelabAttr(attrType)); - this->attrs.back()->parseAttribute(ptr, &attrSize);*/ - break; - } - ptr += attrSize; - size -= attrSize; - parsed += (attrSize+4); - } - //if(parsed != len) {std::cout << "parse - size left:" << len-parsed << '-' << size << "(len is "<< len <<" and parsed is "<< parsed <<" )" << std::endl;} - - return len-parsed; -} -void OnelabProtocol::showMsg() -{ - std::cout << "\033[1m" << "\033[4m" << "Message type: 0x" << std::hex << (int)_type << "\033[0m" << std::endl - << "And have " << std::dec << this->attrs.size() << " attribute(s)" << std::endl; - for (std::vector<OnelabAttr*>::iterator it = this->attrs.begin() ; it != this->attrs.end(); ++it) - (*it)->showAttribute(); - std::cout << std::endl; -} diff --git a/contrib/onelab2/OnelabProtocol.h b/contrib/onelab2/OnelabProtocol.h deleted file mode 100644 index afd44943c4..0000000000 --- a/contrib/onelab2/OnelabProtocol.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _ONELAB_PROTOCOL_H -#define _ONELAB_PROTOCOL_H - -#define ERROR_ONELAB_VERSION 20 -#define ONELAB_VERSION 0x02 - -#include <vector> - -#include "OnelabAttributes.h" - -class OnelabProtocol -{ -private: - //UInt8 _version; - UInt8 _type; - UInt16 _size; -public: - std::vector<OnelabAttr*> attrs; - OnelabProtocol(UInt16 type); - ~OnelabProtocol() {clearAttrs();} - void clearAttrs(); - unsigned short encodeMsg(UInt8 *buff, UInt32 len); - unsigned short encodeMsgs(UInt8 *buff, UInt32 len); - UInt32 parseMsg(UInt8 *buff, UInt32 len); - int parseHeader(UInt8 *buff, UInt32 len); - UInt32 parseMessage(UInt8 *buff, UInt32 len); - void showMsg(); - - short msgType() {return _type;} - void msgType(short type) {this->clearAttrs(); _type = type;} - - static const UInt8 BindRequestMsg = 0x01; - static const UInt8 BindResponseMsg = 0x02; - static const UInt8 BindMessageMsg = 0x03; - - static const UInt8 OnelabStart = 0x10; // Client send his name to the server (first message) - static const UInt8 OnelabStop = 0x11; // Client say to the server he is going to stop / the server ask a client to stop - static const UInt8 OnelabMessage = 0x12; - static const UInt8 OnelabRequest = 0x13; - static const UInt8 OnelabResponse = 0x14; - static const UInt8 OnelabUpdate = 0x15; - static const UInt8 OnelabAction = 0x16; -}; -#endif diff --git a/contrib/onelab2/OnelabServer.cpp b/contrib/onelab2/OnelabServer.cpp deleted file mode 100644 index de47235eb9..0000000000 --- a/contrib/onelab2/OnelabServer.cpp +++ /dev/null @@ -1,884 +0,0 @@ -#include <cstdio> - -#ifndef WIN32 -#include <pthread.h> -#include <signal.h> -#else -#include <wspiapi.h> -#endif - -#include "NetworkUtils.h" -#include "OnelabServer.h" -#include "OnelabProtocol.h" -#include "OnelabAttributes.h" -#include "onelab.h" -#include "onelabUtils.h" -#include "OnelabException.h" - -// FIXME no Gmsh specific header ? -#include "StringUtils.h" -#include "GmshMessage.h" -#include "OS.h" -#include "GModel.h" -#include "Options.h" - -#ifndef WIN32 -void *OnelabServer_run(void *param); -void *listenOnClients(void *param); -void *acceptTcpClient(void *param); -void *acceptUnixClient(void *param); -void *acceptUdtClient(void *param); -#else -DWORD WINAPI OnelabServer_run(LPVOID param); -#endif - -OnelabServer::OnelabServer() -{ - _running = false; - _udtServer = false; - _tcpServer = false; - _unixServer = false; - _ipu.address = _ip.address = 0; - _ipu.port = _ip.port = 0; - UDT::startup(); - - _eid = UDT::epoll_create(); -} - -void OnelabServer::listenOnTcp(unsigned int iface, unsigned short port) -{ - if(_tcpServer) return; - - IPv4 ip = {iface, port}; - _fds = ip4_socket(ip, SOCK_STREAM); - ip4_socket_ip(_fds, _ip); - ip4_socket_listen(_fds); - - std::clog << "\033[0;31m" << "listen on TCP - " << ip4_inet_ntop(_ip.address) << ":" << _ip.port << "\033[0m" << std::endl; - - pthread_create(&_tcpThread, NULL, acceptTcpClient, NULL); - _tcpServer = true; -} - -void OnelabServer::listenOnUnix(const char *sockname) -{ -#if !defined(WIN32) || defined(__CYGWIN__) - if(_unixServer) return; - - _fdx = unix_socket(SOCK_STREAM); - unix_socket_listen(_fdx, sockname); - - std::clog << "\033[0;31m" << "listen on UNIX - " << sockname << "\033[0m" << std::endl; - _sockname = std::string(sockname); - - pthread_create(&_unixThread, NULL, acceptUnixClient, NULL); - _unixServer = true; -#else - throw NetworkException(NetworkException::nUnix); -#endif -} -void OnelabServer::acceptTcp() -{ - IPv4 ip; - while(Socket newcli = ip4_socket_accept(_fds, ip)) { - std::clog << "\033[0;31m" << "accept TCP peer : " << ip4_inet_ntop(ip.address)<< ':' << ip.port << "\033[0m" << std::endl; - UDT::epoll_add_ssock(_eid, newcli); - if(_clients.size() == 0) -#ifndef WIN32 - pthread_create(&_listenThread, NULL, listenOnClients, NULL); -#else - listenThread = CreateThread(NULL, 0, listenOnClients, NULL, 0, NULL); -#endif - } -} -void OnelabServer::acceptUnix() -{ - while(Socket newcli = unix_socket_accept(_fdx)) { - std::clog << "\033[0;31m" << "accept peer on UNIX socket : " << _sockname << "\033[0m" << std::endl; - UDT::epoll_add_ssock(_eid, newcli); - if(_clients.size() == 0) -#ifndef WIN32 - pthread_create(&_listenThread, NULL, listenOnClients, NULL); -#else - listenThread = CreateThread(NULL, 0, listenOnClients, NULL, 0, NULL); -#endif - } -} -void OnelabServer::stopTcp() -{ - if(!_tcpServer) return; - - pthread_cancel(_tcpThread); - close(_fds); - - _tcpServer = false; -} -void OnelabServer::stopUnix() -{ - if(!_unixServer) return; - - pthread_cancel(_unixThread); - unlink(_sockname.c_str()); - - _unixServer = false; -} -#ifdef HAVE_UDT -void OnelabServer::listenOnUdt(unsigned int iface, unsigned short port) -{ - if(_udtServer) return; - - IPv4 ip = {iface, port}; - _fdu = udt_socket(ip, SOCK_STREAM); - udt_socket_listen(_fdu); - - std::clog << "\033[0;31m" << "listen on UDT - " << ip4_inet_ntop(iface) << ":" << port << "\033[0m" << std::endl; - - pthread_create(&_udtThread, NULL, acceptUdtClient, NULL); - _udtServer = true; -} -void OnelabServer::acceptUdt() -{ - IPv4 ip; - while(Socket newcli = udt_socket_accept(_fdu, ip)) { - std::clog << "\033[0;31m" << "accept peer on UNIX socket\033[0m" << std::endl; - UDT::epoll_add_usock(_eid, newcli); - if(_clients.size() == 0) -#ifndef WIN32 - pthread_create(&_listenThread, NULL, listenOnClients, NULL); -#else - listenThread = CreateThread(NULL, 0, listenOnClients, NULL, 0, NULL); -#endif - } -} -void OnelabServer::stopUdt() -{ - if(!_udtServer) return; - - pthread_cancel(_udtThread); - - _udtServer = false; -} -#endif - -OnelabLocalNetworkClient *OnelabServer::getClient(Socket fd) -{ - for(std::vector<OnelabLocalNetworkClient>::iterator it = _clients.begin(); it != _clients.end(); ++it) { -#ifdef HAVE_UDT - if(it->getUSocket() == fd) return &(*it); -#endif - if(it->getSSocket() == fd) return &(*it); - } - return NULL; -} - -void OnelabServer::addClient(std::string name, Socket fd, UInt32 ip, UInt16 port) -{ - this->_clients.push_back(OnelabLocalNetworkClient(name, fd, ip, port)); -} - -int OnelabServer::launchClient(const std::string &client, bool blocking) -{ - // launch a new client with a system call - std::string command = ""; - if(getClient(client) != NULL || getLocalClient(client) != NULL) return -1; // client already exist - - std::vector<onelab::string> s; - get(s, client + "/CommandLine"); - if(s.size()) { - command.assign(s[0].getValue()); - } - else if(client == "Gmsh") { - command.assign(Msg::GetExecutableName()); - } - else { - int num = 0; - while(num < 10/*NUM_SOLVERS*/){ - if(opt_solver_name(num, GMSH_GET, "") == client) break; - num++; - } - if(num >= 10/*NUM_SOLVERS*/) { - std::cout << "Unable to find " << client << std::endl; - return -1; - } - - //std::string name = opt_solver_name(num, GMSH_GET, ""); - std::string exe = opt_solver_executable(num, GMSH_GET, ""); - command.assign(exe); - } - - if(command.size()){ - std::vector<std::string> args = onelabUtils::getCommandLine(client); - for(unsigned int i = 0; i < args.size(); i++) - command.append(" " + args[i]); - } - command.append(" -onelab" - " \"" + client + "\" %s"); - - char cmd[1024]; - // UNIX socket - if(_sockname.size()) - sprintf(cmd, command.c_str(), _sockname.c_str()); - // TCP socket - else if(_ip.port > 0) { - sprintf(cmd, command.c_str(), " %s:%d"); - command.assign(cmd); - if(_ip.address > 0) sprintf(cmd, command.c_str(), ip4_inet_ntop(_ip.address).c_str(), _ip.port); - else sprintf(cmd, command.c_str(), "127.0.0.1", _ip.port); - } - // UDP (UDT) socket - else if(_ipu.port > 0){ - sprintf(cmd, command.c_str(), " u%s:%d"); - command.assign(cmd); - sprintf(cmd, command.c_str(), ip4_inet_ntop(_ipu.address).c_str(), _ipu.port); - } - else { - // unknown.... - return 1; - } - - std::cout << "launch " << client << " with command: " << cmd << std::endl; - SystemCall(cmd, blocking); - - return 0; -} - -void OnelabServer::sendto(std::string client, UInt8 *buff, UInt32 len) -{ - for(std::vector<OnelabLocalNetworkClient>::iterator it = this->_clients.begin() ; it != this->_clients.end(); ++it) { - if((*it).getName() != client) continue; - (*it).sendto(buff, len); - return; - } -} - -OnelabLocalNetworkClient *OnelabServer::getClient(const UInt32 ip, const UInt16 port) -{ - for(std::vector<OnelabLocalNetworkClient>::iterator it = _clients.begin(); it != _clients.end(); ++it) { - if((*it).getIp() == ip && (*it).getPort() == port) - return &(*it); - } - return NULL; -} - -OnelabLocalNetworkClient *OnelabServer::getClient(const std::string &name) -{ - for(std::vector<OnelabLocalNetworkClient>::iterator it = _clients.begin(); it != _clients.end(); ++it) { - if((*it).getName() == name) - return &(*it); - } - return NULL; -} -OnelabLocalClient *OnelabServer::getLocalClient(const std::string &name) -{ - for(std::vector<OnelabLocalClient *>::iterator it = _localClients.begin(); it != _localClients.end(); ++it) { - if((*it)->getName() == name) - return (*it); - } - return NULL; - -} - -void OnelabServer::removeClient(OnelabLocalNetworkClient *client) -{ - for(std::vector<OnelabLocalNetworkClient>::iterator it = _clients.begin(); it != _clients.end(); ++it) { - if(&(*it) == client) { - _clients.erase(it); - return; - } - } -} - -void OnelabServer::stopClient(OnelabLocalNetworkClient *cli) -{ - // FIXME check if listenOnClients does not perform action on this client - UInt8 buff[16]; -#ifdef HAVE_UDT - bool isUDT = cli->getSSocket() == 0; - Socket fd = (!isUDT)? cli->getSSocket() : cli->getUSocket(); -#else - Socket fd = cli->getSSocket(); -#endif - OnelabProtocol msg(OnelabProtocol::OnelabStop); - int recvlen = msg.encodeMsg(buff, 16); - onelab::string o(cli->getName() + "/Action", "stop"); - o.setVisible(false); - o.setNeverChanged(true); - set(o); - cli->sendto(buff, recvlen); -#ifdef HAVE_UDT - if(isUDT) { - UDT::epoll_remove_usock(_eid, fd); - UDT::close(fd); - } - else { - UDT::epoll_remove_ssock(_eid, fd); - close(fd); - } -#else - UDT::epoll_remove_ssock(_eid, fd); - close(fd); -#endif - removeClient(cli); -} - -void OnelabServer::stopClients() -{ - std::cout << _clients.size() << std::endl; - for(int i=0; i < _clients.size(); i++) { - stopClient(&_clients[i]); - } -} - -void OnelabServer::waitOnClients() -{ - if(_running) pthread_join(_runningThread, NULL); -} - -bool OnelabServer::performNextAction() -{ - if(_todoClient.size() == 0 || _todoAction.size() == 0) return false; - - std::string client = _todoClient.front(), - action = _todoAction.front(); - performAction(action, client, true); - pthread_mutex_lock(&_mutex_todo); - _todoAction.pop(); - _todoClient.pop(); - pthread_mutex_unlock(&_mutex_todo); - - return true; -} -void OnelabServer::performAction(const std::string &action, const std::string &client, bool blocking) -{ - if(blocking) { - if(client.size()) { - onelabUtils::guessModelName(client); - OnelabLocalNetworkClient *cli = getClient(client); - OnelabLocalClient *localcli = getLocalClient(client); - if(action.size() > 0) { - std::cout << "set " << client << "/Action to" << action << std::endl; - 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); - } - else if(localcli != NULL){ // client is local (in the same memory space than this server) - std::cout << action << " on " << client << "(client is local)" << std::endl; - localcli->run(action); - } - else { // client does not exist (Gmsh is used as a server), launch the client - std::cout << action << " on " << client << "(launch a new remote client)" << std::endl; - launchClient(client, blocking); - } - } - else { - // run all non Gmsh clients - for(std::vector<OnelabLocalNetworkClient>::iterator it = _clients.begin(); it != _clients.end(); ++it) { - if((*it).getName() == "Gmsh" || (*it).getName() == "GUI") continue; - std::cout << action << " on " << (*it).getName() << "(remote)" << std::endl; - onelab::string o((*it).getName() + "/Action", action); - o.setVisible(false); - o.setNeverChanged(true); - set(o, (*it).getName()); - (*it).run(action); // FIXME Block - } - - for(std::vector<OnelabLocalClient *>::iterator it = _localClients.begin(); it != _localClients.end(); ++it) { - if((*it)->getName() == "Gmsh") continue; - onelab::string o((*it)->getName() + "/Action", action); - o.setVisible(false); - o.setNeverChanged(true); - set(o); - std::cout << action << " on " << (*it)->getName() << "(local)" << std::endl; - (*it)->run(action); - } - } - } - else { - if(_running) { - pthread_mutex_lock(&_mutex_todo); - _todoClient.push(client); - _todoAction.push(action); - pthread_mutex_unlock(&_mutex_todo); - } - else { - _running = true; - _mutex_todo = PTHREAD_MUTEX_INITIALIZER; - _todoClient.push(std::string(client)); - _todoAction.push(std::string(action)); - pthread_create(&_runningThread, NULL, OnelabServer_run, NULL); - } - } -} - -void *acceptTcpClient(void *param) -{ - OnelabServer::instance()->acceptTcp(); -} -void *acceptUnixClient(void *param) -{ - OnelabServer::instance()->acceptUnix(); -} -void *acceptUdtClient(void *param) -{ -#ifdef HAVE_UDT - OnelabServer::instance()->acceptUdt(); -#endif -} - -#ifndef WIN32 -void *OnelabServer_run(void *param) -#else -DWORD WINAPI OnelabServer_run(LPVOID param) -#endif -{ - OnelabServer::instance()->running(true); - - while(OnelabServer::instance()->performNextAction()); - - OnelabServer::instance()->running(false); -} - -#ifndef WIN32 -void *listenOnClients(void *param) -#else - DWORD WINAPI listenOnClients(LPVOID param) -#endif -{ - IPv4 ip; - int recvlen = 0; - UInt8 buff[1024]; - OnelabProtocol msg(-1), rep(-1); - int eid = OnelabServer::instance()->getEID(); - std::set<Socket> fdss; -#ifdef HAVE_UDT - std::set<UDTSOCKET> fdus; - while(UDT::ERROR != UDT::epoll_wait(eid, &fdus, NULL, -1, &fdss, NULL)) { - /* - for(std::set<UDTSOCKET>::iterator it = fdus.begin(); it != fdus.end(); ++it) { - OnelabLocalNetworkClient *cli = OnelabServer::instance()->getClient(*it); - if(cli == NULL) { // Client is not in the list (it must be a Start message) - IPv4 ip; - recvlen = udt_socket_recv(*it, buff, 4); - if(recvlen != 4) { - // invalid message header - UDT::epoll_remove_usock(eid, *it); - UDT::close(*it); - continue; - } - int msglen = msg.parseHeader(buff, recvlen); - if(msglen > 1024) { - // buffer size is too small - UDT::epoll_remove_ssock(eid, *it); - UDT::close(*it); - continue; - } - recvlen = udt_socket_recv(*it, buff, msglen); - msg.parseMessage(buff, recvlen); - if(msg.msgType() == OnelabProtocol::OnelabStart && msg.attrs.size() > 0 && msg.attrs[0]->getAttributeType() == OnelabAttr::Start) { - std::string name = std::string(((OnelabAttrStart *)msg.attrs[0])->name()); - if(OnelabServer::instance()->getClient(name) != NULL) { - std::cout << "A client exist with this name !" << std::endl; - rep.msgType(OnelabProtocol::OnelabMessage); - rep.attrs.push_back(new OnelabAttrMessage("A client exist with this name !", OnelabAttrMessage::Fatal)); - recvlen = rep.encodeMsg(buff, 1024); - //TODO ip4_socket_send(*it, buff, recvlen); - UDT::epoll_remove_usock(eid, *it); - UDT::close(*it); - continue; - } - // Add a new remote client - OnelabServer::instance()->addClient(name, *it, ip.address, ip.port); - std::clog << "\033[0;31m" << "Add a new (UDT) client: " << name << "\033[0m" << std::endl; - OnelabProtocol rep(OnelabProtocol::OnelabStart); - recvlen = rep.encodeMsg(buff, 1024); - cli = OnelabServer::instance()->getClient(*it); - cli->sendto(buff, recvlen); - OnelabServer::instance()->sendAllParameter(cli); - continue; - } - else { - // cli shoud send a name first - UDT::epoll_remove_usock(eid, *it); - UDT::close(*it); - continue; - } - } - else { - try { - recvlen = cli->recvmsg(msg); - } - catch(int &e) { - if(UDT::getlasterror().getErrorCode() == 2001 || e == 50) { // ECONNLOST - std::cout << "\033[0;31m" << "Connection with (UDT) client \"" << cli->getName() << "\" was broken, removing the client." << "\033[0m" << std::endl; // DEBUG - UDT::epoll_remove_usock(eid, *it); - OnelabServer::instance()->removeClient(cli); - UDT::close(*it); - } - } - switch (msg.msgType()) { - case OnelabProtocol::OnelabStop: - std::cout << "\033[0;31m" << "Client \"" << cli->getName() << "\" is going to stop" << "\033[0m" << std::endl; // DEBUG - rep.msgType(OnelabProtocol::OnelabStop); - recvlen = rep.encodeMsg(buff, 1024); - if(ip4_socket_connected(cli->getUSocket())) // FIXME cli can close socket before send - cli->sendto(buff, recvlen); - UDT::epoll_remove_usock(eid, *it); - OnelabServer::instance()->removeClient(cli); - UDT::close(*it); - break; - case OnelabProtocol::OnelabMessage: - if(msg.attrs.size()==1 && msg.attrs[0]->getAttributeType() == OnelabAttrMessage::attributeType()) { - OnelabLocalClient *localgui = OnelabServer::instance()->getLocalClient("localGUI"); - OnelabLocalNetworkClient *gui = OnelabServer::instance()->getClient("GUI"); - if(gui) { - recvlen = msg.encodeMsg(buff, 1024); - gui->sendto(buff, recvlen); - } - if(localgui) localgui->onMessage(cli->getName(), ((OnelabAttrMessage *)msg.attrs[0])->getMessage(), ((OnelabAttrMessage *)msg.attrs[0])->getLevel()); - } - break; - case OnelabProtocol::OnelabRequest: - rep.msgType(OnelabProtocol::OnelabResponse); - if(msg.attrs.size() == 0) OnelabServer::instance()->sendAllParameter(cli); - else for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { - if((*it)->getAttributeType() == OnelabAttr::Parameter) { - OnelabAttrParameterQuery *attr = (OnelabAttrParameterQuery *)*it; - std::cout << "\033[0;31m" << "Client \"" << cli->getName() << " ask for parameter \"" << attr->getName() << " (type=" << (int)attr->paramType() << ")\"\033[0m" << std::endl; // DEBUG - onelab::parameter *p; - switch(attr->paramType()) { - case OnelabAttr::Number: - OnelabServer::instance()->getPtr((onelab::number **)&p, attr->getName(), cli->getName()); - break; - case OnelabAttr::String: - OnelabServer::instance()->getPtr((onelab::string **)&p, attr->getName(), cli->getName()); - break; - case OnelabAttr::Region: - OnelabServer::instance()->getPtr((onelab::region **)&p, attr->getName(), cli->getName()); - break; - case OnelabAttr::Function: - OnelabServer::instance()->getPtr((onelab::function **)&p, attr->getName(), cli->getName()); - break; - } - if(p != NULL) rep.attrs.push_back(p); - else rep.attrs.push_back(new OnelabAttrMessage("Unable to find the request parameter.", OnelabAttrMessage::Error)); - } - // else ?? - } - recvlen = rep.encodeMsg(buff, 1024); - cli->sendto(buff, recvlen); - break; - case OnelabProtocol::OnelabUpdate: - for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { - if((*it)->getAttributeType() >= OnelabAttr::Number && (*it)->getAttributeType() <= OnelabAttr::Function) { - onelab::parameter *attr = (onelab::parameter *)*it; - std::cout << "\033[0;31m" << "Client \"" << cli->getName() << " update parameter \"" << attr->getName() << "\"\033[0m" << std::endl; // DEBUG - onelab::parameter *parameter = NULL; - switch(attr->getAttributeType()) { - case OnelabAttr::Number: - OnelabServer::instance()->set(*(onelab::number *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::number **)¶meter, attr->getName(), cli->getName()); - break; - case OnelabAttr::String: - OnelabServer::instance()->set(*(onelab::string *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::string **)¶meter, attr->getName(), cli->getName()); - if(((onelab::string *)parameter)->getName() == "Gmsh/Action") { - OnelabLocalClient *localgui = OnelabServer::instance()->getLocalClient("localGUI"); - if(((onelab::string *)parameter)->getValue() == "refresh") localgui->refresh(); - } - break; - case OnelabAttr::Region: - OnelabServer::instance()->set(*(onelab::region *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::region **)¶meter, attr->getName(), cli->getName()); - break; - case OnelabAttr::Function: - OnelabServer::instance()->set(*(onelab::function *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::function **)¶meter, attr->getName(), cli->getName()); - break; - } - } - else - switch((*it)->getAttributeType()) { - case 0x0B: - { - // TODO - break; - } - case 0x0C: - { - // TODO - break; - } - case 0x0D: - { - // merge file only if the GUI and the server are local - OnelabLocalClient *gui = OnelabServer::instance()->getLocalClient("localGUI"); - if(gui) gui->mergeFile(((OnelabAttrMergeFile *)*it)->getFilename()); - } - } - } - break; - case OnelabProtocol::OnelabAction: - { - if(msg.attrs.size()==1 && msg.attrs[0]->getAttributeType() == OnelabAttrAction::attributeType()) { - std::clog << "\033[0;31m" << "Client " << cli->getName() << " ask " << ((OnelabAttrAction *)msg.attrs[0])->getClient() << " to " << ((OnelabAttrAction *)msg.attrs[0])->getAction() << "\033[0m" << std::endl; - OnelabServer::instance()->performAction(((OnelabAttrAction *)msg.attrs[0])->getAction(), ((OnelabAttrAction *)msg.attrs[0])->getClient()); - } - } - break; - } - } - } - */ -#else - while(UDT::ERROR != UDT::epoll_wait(eid, NULL, NULL, -1, &fdss, NULL)) { -#endif - for(std::set<Socket>::iterator it = fdss.begin(); it != fdss.end(); ++it) { // For TCP and UNIX - OnelabLocalNetworkClient *cli = OnelabServer::instance()->getClient(*it); - if(cli == NULL) { // Client is not in the list (we should get a Start message) - IPv4 ip; - // recv the header - recvlen = ip4_socket_recv(*it, buff, 4); - if(recvlen != 4) { - // invalid message header - UDT::epoll_remove_ssock(eid, *it); - close(*it); - continue; - } - int msglen = msg.parseHeader(buff, recvlen); - if(msglen > 1024) { - // FIXME? buffer is too small - UDT::epoll_remove_ssock(eid, *it); - close(*it); - continue; - } - // then recv the message - recvlen = ip4_socket_recv(*it, buff, msglen); - msg.parseMessage(buff, recvlen); - if(msg.msgType() == OnelabProtocol::OnelabStart && msg.attrs.size() > 0 && msg.attrs[0]->getAttributeType() == OnelabAttr::Start) { - std::string name = std::string(((OnelabAttrStart *)msg.attrs[0])->name()); - if(OnelabServer::instance()->getClient(name) != NULL) { - std::cout << "A client exist with this name !" << std::endl; - rep.msgType(OnelabProtocol::OnelabMessage); - rep.attrs.push_back(new OnelabAttrMessage("A client exist with this name !", OnelabAttrMessage::Fatal)); - recvlen = rep.encodeMsg(buff, 1024); - ip4_socket_send(*it, buff, recvlen); - UDT::epoll_remove_ssock(eid, *it); - close(*it); - continue; - } - // Add a new remote client - OnelabServer::instance()->addClient(name, *it, ip.address, ip.port); - std::clog << "\033[0;31m" << "Add a new client: " << name << "\033[0m" << std::endl; - OnelabProtocol rep(OnelabProtocol::OnelabStart); - recvlen = rep.encodeMsg(buff, 1024); - cli = OnelabServer::instance()->getClient(*it); - cli->sendto(buff, recvlen); - OnelabServer::instance()->sendAllParameter(cli); - continue; - } - else { - // cli shoud send a name first - UDT::epoll_remove_ssock(eid, *it); - close(*it); - continue; - } - } - else { - try { - recvlen = cli->recvmsg(msg); - } - catch(int &e) { - if(e == 50) { // Recv error (TCP) - std::cout << "\033[0;31m" << "Connection with client \"" << cli->getName() << "\" was broken, removing the client." << "\033[0m" << std::endl; // DEBUG - UDT::epoll_remove_ssock(eid, *it); - OnelabServer::instance()->removeClient(cli); - close(*it); - } - std::cerr << "Error while recv message." << std::endl; - continue; - } - if(recvlen == 0) { // for TCP - std::cout << "\033[0;31m" << "Connection with client \"" << cli->getName() << "\" was broken, removing the client." << "\033[0m" << std::endl; // DEBUG - UDT::epoll_remove_ssock(eid, *it); - OnelabServer::instance()->removeClient(cli); - close(*it); - continue; - } - switch (msg.msgType()) { - case OnelabProtocol::OnelabStop: - std::cout << "\033[0;31m" << "Client \"" << cli->getName() << "\" is going to stop" << "\033[0m" << std::endl; // DEBUG - OnelabServer::instance()->stopClient(cli); - break; - case OnelabProtocol::OnelabMessage: - if(msg.attrs.size()==1 && msg.attrs[0]->getAttributeType() == OnelabAttrMessage::attributeType()) { - OnelabLocalClient *localgui = OnelabServer::instance()->getLocalClient("localGUI"); - OnelabLocalNetworkClient *gui = OnelabServer::instance()->getClient("GUI"); - if(gui) { - recvlen = msg.encodeMsg(buff, 1024); - gui->sendto(buff, recvlen); - } - if(localgui) localgui->onMessage(cli->getName(), ((OnelabAttrMessage *)msg.attrs[0])->getMessage(), ((OnelabAttrMessage *)msg.attrs[0])->getLevel()); - } - break; - case OnelabProtocol::OnelabRequest: - rep.msgType(OnelabProtocol::OnelabResponse); - if(msg.attrs.size() == 0) OnelabServer::instance()->sendAllParameter(cli); - else for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { - if((*it)->getAttributeType() == OnelabAttr::Parameter) { - OnelabAttrParameterQuery *attr = (OnelabAttrParameterQuery *)*it; - std::cout << "\033[0;31m" << "Client \"" << cli->getName() << " ask for parameter \"" << attr->getName() << " (type=" << (int)attr->paramType() << ")\"\033[0m" << std::endl; // DEBUG - onelab::parameter *p; - switch(attr->paramType()) { - case OnelabAttr::Number: - OnelabServer::instance()->getPtr((onelab::number **)&p, attr->getName(), cli->getName()); - break; - case OnelabAttr::String: - OnelabServer::instance()->getPtr((onelab::string **)&p, attr->getName(), cli->getName()); - break; - case OnelabAttr::Region: - OnelabServer::instance()->getPtr((onelab::region **)&p, attr->getName(), cli->getName()); - break; - case OnelabAttr::Function: - OnelabServer::instance()->getPtr((onelab::function **)&p, attr->getName(), cli->getName()); - break; - } - if(p != NULL) rep.attrs.push_back(p); - else rep.attrs.push_back(new OnelabAttrMessage("Unable to find the request parameter.", OnelabAttrMessage::Error)); - } - // else ?? - } - recvlen = rep.encodeMsg(buff, 1024); - cli->sendto(buff, recvlen); - break; - case OnelabProtocol::OnelabUpdate: - for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { - if((*it)->getAttributeType() >= OnelabAttr::Number && (*it)->getAttributeType() <= OnelabAttr::Function) { - onelab::parameter *attr = (onelab::parameter *)*it; - std::cout << "\033[0;31m" << "Client \"" << cli->getName() << " update parameter \"" << attr->getName() << "\"\033[0m" << std::endl; // DEBUG - onelab::parameter *parameter = NULL; - switch(attr->getAttributeType()) { - case OnelabAttr::Number: - OnelabServer::instance()->set(*(onelab::number *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::number **)¶meter, attr->getName(), cli->getName()); - break; - case OnelabAttr::String: - OnelabServer::instance()->set(*(onelab::string *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::string **)¶meter, attr->getName(), cli->getName()); - if(((onelab::string *)parameter)->getName() == "Gmsh/Action") { - OnelabLocalClient *localgui = OnelabServer::instance()->getLocalClient("localGUI"); - if(((onelab::string *)parameter)->getValue() == "refresh") localgui->refresh(); - } - break; - case OnelabAttr::Region: - OnelabServer::instance()->set(*(onelab::region *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::region **)¶meter, attr->getName(), cli->getName()); - break; - case OnelabAttr::Function: - OnelabServer::instance()->set(*(onelab::function *)attr, cli->getName()); - OnelabServer::instance()->getPtr((onelab::function **)¶meter, attr->getName(), cli->getName()); - break; - } - } - else - switch((*it)->getAttributeType()) { - case 0x0B: - { - // TODO check if file is on a specific client - const char *filename = ((OnelabAttrFileQuery *)*it)->getFilename(); - // FIXME path/filename ? - std::clog << "try to open " << filename << " to read" << std::endl; - FILE *fp = fopen(filename, "rb"); - if(fp != NULL){ - std::clog << "file open" << std::endl; - rep.msgType(OnelabProtocol::OnelabUpdate); - rep.attrs.push_back(new OnelabAttrFile(std::string(filename), fp)); - recvlen = rep.encodeMsg(buff, 1024); - cli->sendto(buff, recvlen); - while((recvlen = fread(buff, 1, 1024, fp)) > 0){ - cli->sendto(buff, recvlen); - } - } - std::clog << "file ok" << std::endl; - break; - } - case 0x0C: - { - const char *filename = ((OnelabAttrFile *)*it)->getFilename(); - std::clog << "try to open " << filename << " to write" << std::endl; - FILE *fp = fopen(filename, "wb"); - if(fp != NULL){ - std::clog << "file open" << std::endl; - int filesize = ((OnelabAttrFile *)*it)->getFileSize(); - int downloadsize = 0; - while(downloadsize < filesize) { - recvlen = cli->recvfrom(buff, 1024); - fwrite(buff, 1, recvlen, fp); - } - } - std::clog << "file ok" << std::endl; - break; - } - case 0x0D: - { - // merge file only if the GUI and the server are local - OnelabLocalClient *gui = OnelabServer::instance()->getLocalClient("localGUI"); - if(gui) gui->mergeFile(((OnelabAttrMergeFile *)*it)->getFilename()); - } - } - } - break; - case OnelabProtocol::OnelabAction: - { - if(msg.attrs.size()==1 && msg.attrs[0]->getAttributeType() == OnelabAttrAction::attributeType()) { - std::clog << "\033[0;31m" << "Client " << cli->getName() << " ask " << ((OnelabAttrAction *)msg.attrs[0])->getClient() << " to " << ((OnelabAttrAction *)msg.attrs[0])->getAction() << "\033[0m" << std::endl; - //FIXME you may want to run the solver (see OnelabDatabase) - OnelabServer::instance()->performAction(((OnelabAttrAction *)msg.attrs[0])->getAction(), ((OnelabAttrAction *)msg.attrs[0])->getClient()); - } - } - break; - } - } - } - } -} - -void OnelabServer::sendAllParameter(OnelabLocalNetworkClient *cli) -{ - std::set<onelab::parameter*, onelab::parameterLessThan> ps; - OnelabProtocol msg = OnelabProtocol(OnelabProtocol::OnelabUpdate); - UInt32 bufflen = 1024, recvlen = 0; - UInt8 buff[1024]; - _parameterSpace.getAllParameters(ps); - if(ps.size() == 0) return; - for(std::set<onelab::parameter*, onelab::parameterLessThan>::iterator it = ps.begin(); it != ps.end(); it++) - if((*it)->hasClient(cli->getName())) msg.attrs.push_back(*it); - while(recvlen = msg.encodeMsgs(buff, bufflen)) - { - cli->sendto(buff, recvlen); - } -} - -void OnelabServer::finalize() -{ - stopClients(); -#if !defined(WIN32) || defined(__CYGWIN__) - if(_sockname.size()) { - unlink(_sockname.c_str()); - } -#endif -} -void OnelabServer::running(bool running) -{ - _running = running; - if(!_running){ - OnelabLocalClient *localgui = OnelabServer::instance()->getLocalClient("localGUI"); - OnelabLocalNetworkClient *gui = OnelabServer::instance()->getClient("GUI"); - if(localgui) localgui->onStop(); - if(gui) ;// TODO - } -} diff --git a/contrib/onelab2/OnelabServer.h b/contrib/onelab2/OnelabServer.h deleted file mode 100644 index a1789672b8..0000000000 --- a/contrib/onelab2/OnelabServer.h +++ /dev/null @@ -1,171 +0,0 @@ -#ifndef _ONELABSERVER_H_ -#define _ONELABSERVER_H_ - -#include <vector> -#include <string> -#include <queue> - -#include "onelab.h" -#include "GmshSocket.h" -#include "NetworkUtils.h" -#ifdef HAVE_UDT -#include "UdtUtils.h" -#endif -#include "OnelabLocalNetworkClient.h" -#include "OnelabLocalClient.h" - -class OnelabLocalClient; - -class OnelabServer -{ -private: - static OnelabServer *_server; - std::string _sockname; - IPv4 _ip, // TCP - _ipu; // UDT - std::vector<OnelabLocalNetworkClient> _clients; - std::vector<OnelabLocalClient *> _localClients; -#ifndef WIN32 - pthread_t _runningThread, - _listenThread, // thread to listen on connected clients - _tcpThread, _udtThread, _unixThread; // thread to accept new clients - pthread_mutex_t _mutex_todo; -#else - HANDLER _runningThread, - _listenThread, - _tcpThread, _udtThread, _unixThread; -#endif - bool _running, - _tcpServer, _udtServer, _unixServer; - std::queue<std::string> _todoClient; - std::queue<std::string> _todoAction; - onelab::parameterSpace _parameterSpace; - Socket _fds, _fdx; // system socket (TCP and UNIX) - int _eid; -#ifdef HAVE_UDT - UDTSOCKET _fdu; -#endif - void sendto(std::string client, UInt8 *buff, UInt32 len); - -public: - OnelabServer(); - static OnelabServer *instance() { - if(!_server) _server = new OnelabServer(); - return _server; - } - static void setInstance(OnelabServer *s) { _server = s; } - void listenOnTcp(unsigned int iface=0, unsigned short port=0); - void listenOnUnix(const char *sockname); - void acceptTcp(); - void acceptUnix(); - void stopTcp(); - void stopUnix(); - onelab::parameterSpace *getParameterSpace() {return &_parameterSpace;} - UInt16 getPort() { return _ip.port;} -#ifdef HAVE_UDT - ~OnelabServer(){UDT::cleanup();} - void listenOnUdt(unsigned int iface=0, unsigned short port=0); - void acceptUdt(); - void stopUdt(); -#else - ~OnelabServer(){} -#endif - void finalize(); - bool isRunning() const {return _running;} - void running(bool running); - // Client methods - inline int getEID() const {return _eid;} - OnelabLocalNetworkClient *getClient(Socket fd); - void addClient(std::string name, UInt32 ip, UInt16 port); - void addClient(OnelabLocalClient *cli) {_localClients.push_back(cli);} - void addClient(std::string name, Socket fd, UInt32 ip, UInt16 port); - int launchClient(const std::string &, bool blocking=false); - void removeClient(OnelabLocalNetworkClient *client); - void stopClient(OnelabLocalNetworkClient *cli); - void stopClients(); - std::vector<OnelabLocalNetworkClient> &getClients() {return _clients;} - std::vector<OnelabLocalClient *> &getLocalClients() {return _localClients;} - OnelabLocalNetworkClient *getClient(const UInt32 ip, const UInt16 port); - OnelabLocalNetworkClient *getClient(const std::string &name); - OnelabLocalClient *getLocalClient(const std::string &name); - void waitForClient(const std::string &name); - void sendAllParameter(OnelabLocalNetworkClient *cli); - // Parameters methods - void clear(const std::string &name="", const std::string &client="") { - _parameterSpace.clear(name, client); - } - template <class T> bool existInDatabase(const T &p) { - std::vector<T> ps; - _parameterSpace.get(ps, p.getName()); - return ps.size() > 0; - } - template <class T> bool set(const T &p, const std::string &client="") { - bool isNew = !existInDatabase(p); - _parameterSpace.set(p, client); - T *pp; - _parameterSpace.getPtr(&pp, p.getName()); - if(pp->getVisible()) { - pp->addClient("GUI", true); - pp->addClient("localGUI", true); - } - for(std::vector<OnelabLocalClient *>::iterator it = _localClients.begin() ; it != _localClients.end(); ++it) { - if((*it)->getName() != client) { - if(isNew)(*it)->onNewParameter(pp); - else (*it)->onUpdateParameter(pp); - } - } - std::map<std::string, bool> clients = pp->getClients(); - for(std::map<std::string, bool>::const_iterator it = clients.begin(); it != clients.end(); it++) { - if(it->first == client) continue; - OnelabLocalNetworkClient *tmp = getClient(it->first); - if(tmp == NULL) continue; - tmp->updateParameter(pp); - } - return true; - } - template <class T> bool get(std::vector<T> &ps, const std::string &name="", const std::string &client="") { - return _parameterSpace.get(ps, name, client); - } - template <class T> void getPtr(T **ptr, const std::string &name="", const std::string &client="") { - _parameterSpace.getPtr(ptr, name, client); - } - bool fromChar(const std::vector<std::string> &msg, const std::string &client="") - { - for(unsigned int i = 0; i < msg.size(); i++){ - std::string version, type, name; - onelab::parameter::getInfoFromChar(msg[i], version, type, name); - if(onelab::parameter::version() != version) return false; - if(type == "number"){ - onelab::number p; p.fromChar(msg[i]); set(p, client); - } - else if(type == "string"){ - onelab::string p; p.fromChar(msg[i]); set(p, client); - } - else if(type == "region"){ - onelab::region p; p.fromChar(msg[i]); set(p, client); - } - else if(type == "function"){ - onelab::function p; p.fromChar(msg[i]); set(p, client); - } - else - return false; - } - return true; - } - bool fromFile(FILE *fp, const std::string &client="") - { - std::vector<std::string> msg; - if(onelab::parameter::fromFile(msg, fp)) return fromChar(msg, client); - return false; - } - bool getChanged(const std::string &client="") const { - return _parameterSpace.getChanged(client); - } - void setChanged(bool changed, const std::string &client="") { - _parameterSpace.setChanged(changed, client); - } - void performAction(const std::string &action, const std::string &client="", bool blocking=false); - bool performNextAction(); - void waitOnClients(); -}; -#endif diff --git a/contrib/onelab2/OnelabWindow.cpp b/contrib/onelab2/OnelabWindow.cpp deleted file mode 100644 index c2a8198f6e..0000000000 --- a/contrib/onelab2/OnelabWindow.cpp +++ /dev/null @@ -1,239 +0,0 @@ -#include <FL/Fl.H> -#include <FL/Fl_Tabs.H> -#include <FL/Fl_Check_Button.H> -#include <FL/Fl_Button.H> -#include <FL/Fl_Input_Choice.H> -#include <FL/Fl_Choice.H> -#include <FL/Fl_Browser.H> -#include <FL/Fl_Scroll.H> -#include <iostream> - -#include "OnelabWindow.h" -#include "OnelabDatabase.h" -#include "OnelabServer.h" -#include "FlGui.h" -#include "paletteWindow.h" -#include "Context.h" -#include "Options.h" - -void onelab_listen_tcp_cb(Fl_Widget *w, void *data); -void onelab_listen_unix_cb(Fl_Widget *w, void *data); -#ifdef HAVE_UDT -void onelab_listen_udt_cb(Fl_Widget *w, void *data); -#endif -void onelab_connect_remote_server_cb(Fl_Widget *w, void *data); - -onelabWindow::onelabWindow(int deltaFontSize) -{ - FL_NORMAL_SIZE -= deltaFontSize; - - int width = 34 * FL_NORMAL_SIZE + WB; - int height = 12 * BH + 4 * WB; - - win = new paletteWindow(width, height, CTX::instance()->nonModalWindows ? true : false); - win->box(GMSH_WINDOW_BOX); - win->label("ONELAB2"); - - Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); - { - Fl_Group *o = new Fl_Group( - WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Network (server)"); - _listenOnUNIX = new Fl_Check_Button(2*WB, 2*WB + 1*BH, width-2*WB, BH, "Listen on UNIX socket"); - _sockUNIX = new Fl_Input(2*WB, 2*WB + 2*BH, width/2-2*WB, BH, "UNIX base socket name"); - _listenOnUNIX->callback(onelab_listen_unix_cb, _sockUNIX); - _sockUNIX->align(FL_ALIGN_RIGHT); - _listenOnTCP = new Fl_Check_Button(2*WB, 2*WB + 3*BH, width-2*WB, BH, "Listen on TCP socket"); - _sockTCP = new Fl_Input(2*WB, 2*WB + 4*BH, width/2-2*WB, BH, "TCP port (0 to let the system choose)"); - _listenOnTCP->callback(onelab_listen_tcp_cb, _sockTCP); - _sockTCP->align(FL_ALIGN_RIGHT); -#ifdef HAVE_UDT - _listenOnUDT = new Fl_Check_Button(2*WB, 2*WB + 5*BH, width-2*WB, BH, "Listen on UDT (UDP) socket"); - _sockUDT = new Fl_Input(2*WB, 2*WB + 6*BH, width/2-2*WB, BH, "UDP port (0 to let the system choose)"); - _listenOnUDT->callback(onelab_listen_udt_cb, _sockUDT); - _sockUDT->align(FL_ALIGN_RIGHT); -#else - _listenOnUDT = new Fl_Check_Button(2*WB, 2*WB + 5*BH, width-2*WB, BH, "Listen on UDT (UDP) socket"); - _sockUDT = new Fl_Input(2*WB, 2*WB + 6*BH, width/2-2*WB, BH, "UDP port (0 to let the system choose)"); - _sockUDT->align(FL_ALIGN_RIGHT); -#endif - refreshServers(); - o->end(); - } - { - Fl_Group *o = new Fl_Group( - 0, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Clients (server)"); - _solvers = new Fl_Choice(2*WB, 2*WB + 1*BH, width/2-2*WB, BH, "Solver"); - _solvers->align(FL_ALIGN_RIGHT); - rebuildSolverList(); - _clients = new Fl_Browser(2*WB, 2*WB + 3*BH, width/2-2*WB, 5*BH, "Connected clients"); - _clients->align(FL_ALIGN_RIGHT); - o->end(); - } - { - Fl_Group *o = new Fl_Group( - WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Network (client)"); - _remoteServer = new Fl_Input(2*WB, 2*WB + 1*BH, width/2-2*WB, BH, "Server address (IPv4:port)"); - _remoteServer->align(FL_ALIGN_RIGHT); - _connectRemoteServer = new Fl_Button(2*WB, 3*WB + 2*BH, width/2-2*WB, BH, "Connect"); - _connectRemoteServer->callback(onelab_connect_remote_server_cb, _remoteServer); - } -} - -void onelabWindow::refresh(){ - refreshServers(); - rebuildSolverList(); - refreshRemoteServer(); -} - -void onelabWindow::refreshServers() -{ - if(OnelabDatabase::instance()->isNetworkClient()) { - _listenOnUNIX->deactivate(); - _listenOnTCP->deactivate(); - _listenOnUDT->deactivate(); - _sockUNIX->deactivate(); - _sockUDT->deactivate(); - _sockTCP->deactivate(); - return; - } - - _sockUNIX->value(CTX::instance()->onelab.unixSock.c_str()); - _sockTCP->value(CTX::instance()->onelab.tcpSock.c_str()); -#ifdef HAVE_UDT - _sockUDT->value(CTX::instance()->onelab.udtSock.c_str()); -#else - _sockUDT->value("Not compiled with UDT library"); -#endif - if(CTX::instance()->onelab.unixConnected) { - _listenOnUNIX->value(1); - _sockUNIX->deactivate(); - } - else { - _listenOnUNIX->value(0); - _sockUNIX->activate(); - } - - if(CTX::instance()->onelab.tcpConnected) { - _listenOnTCP->value(1); - _sockTCP->deactivate(); - } - else { - _listenOnTCP->value(0); - _sockTCP->activate(); - } - - if(CTX::instance()->onelab.udtConnected) { - _listenOnUDT->value(1); - _sockUDT->deactivate(); - } - else { - _listenOnUDT->value(0); - _sockUDT->activate(); - } -} - -void onelabWindow::rebuildSolverList() -{ - _solvers->clear(); - for(int i = 0; i < NUM_SOLVERS; i++){ - if(opt_solver_name(i, GMSH_GET, "").size()) - _solvers->add(opt_solver_name(i, GMSH_GET, "").c_str()); - } - if(CTX::instance()->solverToRun >= 0) _solvers->value(CTX::instance()->solverToRun); -} - -void onelabWindow::refreshRemoteServer() -{ - if(OnelabDatabase::instance()->isNetworkClient()) { - _remoteServer->value(); - //TODO 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, name); - //if(c == NULL) { - // Error("Unable to connect ONELAB server (%s)", sockname.c_str()); - // Exit(1); - //} - } -} - -void onelab_listen_tcp_cb(Fl_Widget *w, void *data) -{ - Fl_Check_Button *checkbutton = (Fl_Check_Button *)w; - Fl_Input *sockTCP = (Fl_Input *)data; - if(checkbutton->value() == 1) { - sockTCP->deactivate(); - CTX::instance()->onelab.tcpSock = sockTCP->value(); - std::size_t colon = CTX::instance()->onelab.tcpSock.find(":"); - OnelabServer::instance()->listenOnTcp( - ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()), - atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str())); - } - else { - sockTCP->activate(); - OnelabServer::instance()->stopTcp(); - } -} - -void onelab_listen_unix_cb(Fl_Widget *w, void *data) -{ - Fl_Check_Button *checkbutton = (Fl_Check_Button *)w; - Fl_Input *sockUNIX = (Fl_Input *)data; - if(checkbutton->value() == 1) { - sockUNIX->deactivate(); - CTX::instance()->onelab.unixSock = sockUNIX->value(); - std::size_t colon = CTX::instance()->onelab.unixSock.find(":"); - std::ostringstream tmp; - tmp << CTX::instance()->homeDir << CTX::instance()->onelab.unixSock; - OnelabServer::instance()->listenOnUnix(tmp.str().c_str()); - } - else { - sockUNIX->activate(); - OnelabServer::instance()->stopUnix(); - } -} - -#ifdef HAVE_UDT -void onelab_listen_udt_cb(Fl_Widget *w, void *data) -{ - Fl_Check_Button *checkbutton = (Fl_Check_Button *)w; - Fl_Input *sockUDT = (Fl_Input *)data; - if(checkbutton->value() == 1) { - sockUDT->deactivate(); - CTX::instance()->onelab.udtSock = sockUDT->value(); - std::size_t colon = CTX::instance()->onelab.udtSock.find(":"); - OnelabServer::instance()->listenOnTcp( - ip4_inet_pton(CTX::instance()->onelab.udtSock.substr(0, colon).c_str()), - atoi(CTX::instance()->onelab.udtSock.substr(colon+1, CTX::instance()->onelab.udtSock.size()-colon-1).c_str())); - } - else { - sockUDT->activate(); - OnelabServer::instance()->stopUdt(); - } -} -#endif - -void onelab2_cb(Fl_Widget *w, void *data) -{ - FlGui::instance()->onelab2->refresh(); - FlGui::instance()->onelab2->win->show(); -} - -void onelab_connect_remote_server_cb(Fl_Widget *w, void *data) -{ - Fl_Input *serverAddr = (Fl_Input *)data; - std::string address = serverAddr->value(); - std::size_t colon = address.find(":"); - GmshNetworkClient *c = OnelabDatabase::instance()->useAsNetworkClient( - ip4_inet_pton(address.substr(0, colon).c_str()), - atoi(address.substr(colon+1, address.size()-colon-1).c_str()), - "GUI"); - if(c == NULL) { - Msg::Error("Unable to connect ONELAB server (%s)", address.c_str()); - Msg::Exit(1); - } - else if(FlGui::available()) // FIXME - c->setCallback(FlGui::instance()->onelab); -} diff --git a/contrib/onelab2/OnelabWindow.h b/contrib/onelab2/OnelabWindow.h deleted file mode 100644 index 3a68f637fe..0000000000 --- a/contrib/onelab2/OnelabWindow.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _ONELAB_WINDOW_H_ -#define _ONELAB_WINDOW_H_ - -class Fl_Window; -class Fl_Check_Button; -class Fl_Input; -class Fl_Choice; -class Fl_Browser; -class Fl_Button; - -class onelabWindow{ - private: - Fl_Check_Button *_listenOnUNIX, *_listenOnTCP, *_listenOnUDT; - Fl_Input *_sockUNIX, *_sockTCP, *_sockUDT; - - Fl_Choice *_solvers; - Fl_Browser *_clients; - - Fl_Check_Button *_useRemoteServer; - Fl_Input *_remoteServer; - Fl_Button *_connectRemoteServer; - - public: - Fl_Window *win; - - onelabWindow(int deltaFontSize=0); - void refresh(); - void refreshServers(); - void rebuildSolverList(); - void refreshRemoteServer(); -}; - -void onelab2_cb(Fl_Widget *w, void *data); -#endif diff --git a/contrib/onelab2/UdtUtils.h b/contrib/onelab2/UdtUtils.h deleted file mode 100644 index b6f67e842e..0000000000 --- a/contrib/onelab2/UdtUtils.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef _UDTUTILS_H_ -#define _UDTUTILS_H_ -#include <iostream> -#include "NetworkUtils.h" -#include <udt.h> - -inline UDTSOCKET udt_socket(IPv4 ip, int socketType) -{ - UDTSOCKET fd; - struct sockaddr_in addr; - - memset(&addr, 0, sizeof(struct sockaddr_in)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = hton32((ip.address==0)? INADDR_ANY : ip.address); - addr.sin_port = hton16(ip.port); - - if(UDT::ERROR == (fd = UDT::socket(AF_INET, socketType, 0))) throw ERROR_SOCKET_CREATE; - - if(UDT::ERROR == UDT::bind(fd, (struct sockaddr*)&addr, sizeof(addr))) {std::cout << UDT::getlasterror().getErrorMessage() << std::endl; throw ERROR_SOCKET_BIND;} - - bool otrue = true; - UDT::setsockopt(fd, 0, UDT_REUSEADDR, &otrue, sizeof(bool)); - - return fd; -} - -inline void udt_socket_timeout(UDTSOCKET fd, long ms) -{ - setsockopt(fd, 0, UDT_SNDTIMEO, &ms, sizeof(long)); - setsockopt(fd, 0, UDT_RCVTIMEO, &ms, sizeof(long)); -} - -inline void udt_socket_listen(UDTSOCKET fd, int maxconnection=1024) -{ - if(UDT::ERROR == UDT::listen(fd, maxconnection)) throw ERROR_SOCKET_LISTEN; -} - -inline UDTSOCKET udt_socket_accept(UDTSOCKET fd, IPv4 &ip) -{ - UDTSOCKET cli; - struct sockaddr_in addr; - int addrl = sizeof(addr); - - cli = UDT::accept(fd, (struct sockaddr*)&addr, &addrl); - ip.address = ntoh32(addr.sin_addr.s_addr); - ip.port = ntoh16(addr.sin_port); - - return cli; -} - -inline void udt_socket_connect(UDTSOCKET fd, IPv4 ip) -{ - struct sockaddr_in addr; - socklen_t addrl = sizeof(addr); - memset(&addr, 0, addrl); - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = hton32(ip.address); - addr.sin_port = hton16(ip.port); - if(UDT::ERROR == UDT::connect(fd, (struct sockaddr *)&addr, addrl)) { std::cout << UDT::getlasterror().getErrorMessage() << std::endl; throw ERROR_SOCKET_CONNECT;} -} - -inline int udt_socket_send(UDTSOCKET fd, UInt8 *src, int length) -{ - return UDT::send(fd, (char *)src, length, 0); -} - -inline int udt_socket_recv(UDTSOCKET fd, UInt8 *dst, int maxlength) -{ - int recvlen = 0; - if(UDT::ERROR == (recvlen = UDT::recv(fd, (char *)dst, maxlength, 0))) { std::cout << UDT::getlasterror().getErrorMessage() << std::endl; throw ERROR_SOCKET_RECV;} - return recvlen; -} - -inline void udt_socket_close(UDTSOCKET fd) -{ - UDT::close(fd); -} - -#endif diff --git a/contrib/onelab2/VirtualClient.h b/contrib/onelab2/VirtualClient.h deleted file mode 100644 index a664d44d8a..0000000000 --- a/contrib/onelab2/VirtualClient.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _VIRTUALCLIENT_H_ -#define _VIRTUALCLIENT_H_ - -#include <string> - -#include "onelab.h" - -class VirtualClient -{ -protected: - std::string _name; - onelab::parameterSpace *_parameterSpace; -private: - bool _parameterSpaceShouldBeDeleted; -public: - VirtualClient(std::string name, onelab::parameterSpace *parameterSpace=NULL){ - _name = name; - _parameterSpaceShouldBeDeleted = (parameterSpace==NULL); - if(_parameterSpaceShouldBeDeleted)_parameterSpace = new onelab::parameterSpace; - else _parameterSpace = parameterSpace; - } - virtual ~VirtualClient(){ - if(_parameterSpaceShouldBeDeleted && _parameterSpace != NULL) delete _parameterSpace; - } - std::string &getName() {return _name;} - template <class T> bool existInDatabase(const T p) const { - std::vector<T> ps; - _parameterSpace->get(ps, p.getName(), this->_name); - return ps.size() > 0; - } - template <class T> bool set(const T &p){ - return _parameterSpace->set(p, this->_name); - } - template <class T> bool get(std::vector<T> &ps, const std::string &name=""){ - return _parameterSpace->get(ps, this->_name); - } - virtual void onNewParameter(onelab::parameter *) = 0; - virtual void onUpdateParameter(onelab::parameter *) = 0; - virtual void onRemoveParameter(onelab::parameter *) = 0; - - virtual void run(std::string action) = 0; -}; - -#endif diff --git a/contrib/onelab2/noudt.cpp b/contrib/onelab2/noudt.cpp deleted file mode 100644 index b59ab6e902..0000000000 --- a/contrib/onelab2/noudt.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "noudt.h" - -#include <sys/select.h> -#include <sys/types.h> - -namespace UDT { - - class Epoll - { - private: - std::set<SYSSOCKET> _fds; - static Epoll *_instance; - - public: - Epoll() {} - static Epoll* epoll() { - if(!_instance) _instance = new Epoll(); - return _instance; - } - - void add_ssock(SYSSOCKET s) {_fds.insert(s);} - void remove_ssock(SYSSOCKET s) { - _fds.erase(s); - } - std::set<int>::iterator begin() {return _fds.begin();} - std::set<int>::iterator end() {return _fds.end();} - }; - - Epoll *Epoll::_instance = NULL; - - int startup() - { - return 1; - } - - int cleanup() - { - return 1; - } - - int epoll_create() - { - return 1; - } - - int epoll_add_ssock(int eid, SYSSOCKET s) - { - Epoll::epoll()->add_ssock(s); - return 1; - } - - int epoll_remove_ssock(int eid, SYSSOCKET s) - { - Epoll::epoll()->remove_ssock(s); - return 1; - } - int epoll_wait(int eid, void* readfds, void* writefds, long msTimeOut, - std::set<SYSSOCKET>* lrfds, std::set<SYSSOCKET>* wrfds) - { - fd_set fds; - FD_ZERO(&fds); - for(std::set<SYSSOCKET>::const_iterator i = Epoll::epoll()->begin(); i != Epoll::epoll()->end(); i++) - FD_SET(*i, &fds); - struct timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - if(select(*Epoll::epoll()->begin()+1, &fds, NULL, NULL, /*&timeout*/NULL) > 0) { - for(std::set<SYSSOCKET>::const_iterator i = Epoll::epoll()->begin(); i != Epoll::epoll()->end(); i++) { - lrfds->insert(*i); - } - } - return 1; - } -} diff --git a/contrib/onelab2/noudt.h b/contrib/onelab2/noudt.h deleted file mode 100644 index 82f4fee7f2..0000000000 --- a/contrib/onelab2/noudt.h +++ /dev/null @@ -1,25 +0,0 @@ -#include <set> -#include <cstddef> - -#ifdef WIN32 - #ifndef __MINGW__ - typedef SOCKET SYSSOCKET; - #else - typedef int SYSSOCKET; - #endif -#else - typedef int SYSSOCKET; -#endif - - -namespace UDT { - const int ERROR = -1; - - int startup(); - int cleanup(); - int epoll_create(); - int epoll_add_ssock(int eid, SYSSOCKET s); - int epoll_remove_ssock(int eid, SYSSOCKET s); - int epoll_wait(int eid, void* readfds, void* writefds, long msTimeOut, - std::set<SYSSOCKET>* lrfds = NULL, std::set<SYSSOCKET>* wrfds = NULL); -} diff --git a/contrib/onelab2/python/onelab2.py b/contrib/onelab2/python/onelab2.py deleted file mode 100755 index b97ac7e5e9..0000000000 --- a/contrib/onelab2/python/onelab2.py +++ /dev/null @@ -1,458 +0,0 @@ -""" -OneLab - Copyright (C) 2011-2014 ULg-UCL - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, copy, -modify, merge, publish, distribute, and/or sell copies of the -Software, and to permit persons to whom the Software is furnished -to do so, provided that the above copyright notice(s) and this -permission notice appear in all copies of the Software and that -both the above copyright notice(s) and this permission notice -appear in supporting documentation. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE -COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR -ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY -DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS -ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE -OF THIS SOFTWARE. - -Please report all bugs and problems to the public mailing list -<gmsh@onelab.info>. -""" - -import socket, struct, os, sys, subprocess -_VERSION = 2 -_ONELAB_PARAMETER = { - 'number' : 0x06, - 'string' : 0x07} - -def file_exist(filename): - try: - with open(filename) as f: - return True - except IOError: - return False - -def path(dirname, inp): - # dirname is a directory, can be empty - # inp is an optional file or subdirectory name - # returns the path to 'inp' in the same directory as 'ref' - if not inp: - return dirname - if inp[0] == '/' or inp[0] == '\\' or (len(inp) > 2 and inp[1] == '\:'): - return inp # do nothing, inp is an absolute path - if inp[0] == '.' : - inp = inp[2:] # cut off heading './' or '.\' - if dirname: - return dirname + os.sep + inp # append inp to the path of the reference file - else: - return inp - -class _parameter() : - _membersbase = [ - ('name', 'string'), ('label', 'string', ''), ('help', 'string', ''), - ('readOnly', 'bool', 0), ('neverChanged', 'bool', 0), ('visible', 'bool', 1), - ('attributes', ('dict', 'string', 'string'), {}), - ('clients', ('dict', 'string', 'bool'), {}) - ] - _members = { - 'string' : _membersbase + [ - ('value', 'string',''), ('kind', 'string', 'generic'), - ('choices', ('list', 'string'), []) - ], - 'number' : _membersbase + [ - ('value', 'float',0), - ('min', 'float', -sys.float_info.max), ('max', 'float', sys.float_info.max), - ('step', 'float', 0.), ('index', 'int', -1), ('choices', ('list', 'float'), []), - ('labels', ('dict', 'float', 'string'), {}) - ] - } - - def __init__(self, type, **values) : - self.type = type - for i in _parameter._members[self.type] : - setattr(self, i[0], values[i[0]] if i[0] in values else i[2]) - - def tochar(self) : - def tocharitem(l, t, v) : - if t=='string' : l.append(v) - elif t =='int': l.append(str(v)) - elif t=='float' : l.append('%.16g' % v) - elif t[0]=='list' : - l.append(str(len(v))) - for i in v : tocharitem(l, t[1], i) - elif t[0]=='dict' : - l.append(str(len(v))) - for i, j in v.items() : - tocharitem(l, t[1], i) - tocharitem(l, t[2], j) - msg = [_VERSION, self.type] - for i in _parameter._members[self.type] : - tocharitem(msg, i[1], getattr(self, i[0])) - return '\0'.join(msg) - - def tobytes(self): - def tobytesitem(t, v): - val = None - if t=='string': - val = v+'\0' - elif t=='bool': - val = struct.pack('!B', v) - elif t=='int': - val = struct.pack('!i', v) - elif t=='float': - val = struct.pack('!d', v) - elif t[0]=='list': - val = struct.pack('!H', len(v)) - for i in v: - val += tobytesitem(t[1], i) - elif t[0]=='dict': - val = struct.pack('!H', len(v)) - for i, j in v.items(): - val += tobytesitem(t[1], i) - val += tobytesitem(t[2], j) - return val - msg = '' - for i in _parameter._members[self.type]: - msg += tobytesitem(i[1], getattr(self, i[0])) - return struct.pack('!HH', _ONELAB_PARAMETER[self.type], len(msg)) + msg - - def frombytes(self, b): - def frombytesitem(p_w, t): - p = p_w[0] - val = None - if t=='string': - val = p[:p.index('\0')] - p_w[0] = p[p.index('\0')+1:] - elif t=='bool': - val = struct.unpack('!B', p[:1])[0] - p_w[0] = p[1:] - elif t=='int': - val = struct.unpack('!i', p[:4])[0] - p_w[0] = p[4:] - elif t=='float': - val = struct.unpack('!d', p[:8])[0] - p_w[0] = p[8:] - elif t[0]=='list': - l = struct.unpack('!H', p[:2])[0] - p_w[0] = p[2:] - val = [frombytesitem(p_w, t[1]) for i in range(l)] - elif t[0]=='dict': - l = struct.unpack('!H', p[:2])[0] - p_w[0] = p[2:] - val = dict([(frombytesitem(p_w, t[1]), frombytesitem(p_w, t[2])) for i in range(l)]) - return val - tmp = [b[4:]] - for p in _parameter._members[self.type]: - setattr(self, p[0], frombytesitem(tmp, p[1])) - return self - - def fromchar(self, msg) : - def fromcharitem(l, t) : - if t=='string' : return l.pop() - elif t =='int': return int(l.pop()) - elif t=='float' : return float(l.pop()) - elif t[0]=='list' : return [fromcharitem(l, t[1]) for i in range(int(l.pop()))] - elif t[0]=='dict' : return dict([(fromcharitem(l, t[1]),fromcharitem(l, t[2])) for i in range(int(l.pop()))]) - l = msg.split('\0') - l.reverse() - if l.pop() != _VERSION : - print('onelab version mismatch') - if l.pop() != self.type : - print('onelab parameter type mismatch') - for p in _parameter._members[self.type]: - setattr(self, p[0], fromcharitem(l, p[1])) - return self - - def modify(self, **param) : - ## updates the parameter with the content of param, attributes are merged - for i in _parameter._members[self.type] : - if i[0] in param : - if i[0] == 'attributes' : - self.attributes.update(param['attributes']) - else : - setattr(self, i[0], param[i[0]]) - -class client : - _ONELAB_START = 0x10 - _ONELAB_STOP = 0x11 - _ONELAB_MESSAGE = 0x12 - _ONELAB_REQUEST = 0x13 - _ONELAB_RESPONSE= 0x14 - _ONELAB_UPDATE = 0x15 - - - def _createSocket(self) : - addr = self.addr - if '/' in addr or '\\' in addr or ':' not in addr : - self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - self.socket.connect(addr) - else : - self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s = addr.split(':') - self.socket.connect((s[0], int(s[1]))) - - def _send(self, t, m=''): - if not self.socket : - return - - try: - if self.socket.send(struct.pack('!BBH', _VERSION, t, len(m))+m) == 0 : - RuntimeError('onelab socket closed') - except socket.error: - self.socket.close() - self._createSocket() - #self.socket.send(struct.pack('ii%is' %len(m), t, len(m), m)) - - def _clearbuffer(self): - self.socket.settimeout(0.) - try: - msg = self.socket.recv(1024) - except socket.error: - self.socket.settimeout(None) - return - self.socket.settimeout(None) - if len(msg) >= 4: - v, t, l = struct.unpack('!BBH', msg[:4]) - if t == self._ONELAB_MESSAGE : - print('onelab info : %s' % msg) - elif t == self._ONELAB_STOP : - print('server ask to stop') - os._exit(1) - - def _receive(self) : - def buffered_receive(l) : - msg = b'' - while len(msg) < l: - chunk = self.socket.recv(l - len(msg)) - if not chunk : - RuntimeError('onelab socket closed') - msg += chunk - return msg - msg = buffered_receive(struct.calcsize('BBH')) - v, t, l = struct.unpack('!BBH', msg) - if v != _VERSION : - RuntimeError('onelab version mismatch') - msg = buffered_receive(l) - if t == self._ONELAB_MESSAGE : - print('onelab info : %s' % msg) - elif t == self._ONELAB_STOP: - print('server ask to stop') - os._exit(1) - return t, msg - - def _parseParameter(msg): - def extract_attr(b): - t, l = struct.unpack('!HH', b[:4]) - if l+4 > len(b): - RuntimeError('onelab invalid parameter') - return t ,b[4:] - - ptype, p = extract_attr(msg) - if ptype == 0x06: - param = _parameter('number') - param.frombytes(msg) - return param - elif ptype == 0x07: - param = _parameter('string') - param.frombytes(msg) - return param - else: - return None - - def _defineParameter(self, p) : - if not self.socket : - return p.value - self._send(self._ONELAB_UPDATE, p.tobytes()) - return p.value - - def _getParameter(self, param, warn_if_not_found=True) : - def extract_attr(b): - t, l = struct.unpack('!HH', b[:4]) - if l+4 > len(b): - RuntimeError('onelab invalid parameter') - return t ,b[4:] - - if not self.socket : - return - self._send(self._ONELAB_REQUEST, struct.pack('!HHB', 0x05, len(param.name)+1, _ONELAB_PARAMETER[param.type])+param.name) - (t, msg) = self._receive() - if t == self._ONELAB_RESPONSE : - ptype, p = extract_attr(msg) - if ptype == 0x06 or ptype == 0x07: - param.frombytes(msg) - elif ptype == 0x0A and warn_if_not_found: - print('Unknown parameter %s' %(param.name)) - self._clearbuffer() - - def defineNumber(self, name, **param): - if 'labels' in param : - param["choices"] = param["labels"].keys() - p = _parameter('number', name=name, **param) - value = self._defineParameter(p) - return value - - def defineString(self, name, **param): - p = _parameter('string', name=name, **param) - value = self._defineParameter(p) - return value - - def getString(self, name, warn_if_not_found=True): - param = _parameter('string', name=name) - self._getParameter(param, warn_if_not_found) - return param.value - - def getNumber(self, name, warn_if_not_found=True): - param = _parameter('number', name=name) - self._getParameter(param, warn_if_not_found) - return param.value - - def setNumber(self, name, **param): - if not self.socket : - return - p = _parameter('number', name=name) - self._getParameter(p, False) - p.modify(**param) - self._send(self._ONELAB_UPDATE, p.tobytes()) - - def setString(self, name, **param): - if not self.socket : - return - p = _parameter('string', name=name) - self._getParameter(p, False) - p.modify(**param) - self._send(self._ONELAB_UPDATE, p.tobytes()) - - def _sendMessage(self, msg, lvl=5): - if not self.socket : - print (msg) - return - self._send(self._ONELAB_MESSAGE, struct.pack("!HHB", 0x0A, len(msg)+1, lvl)+msg) - - def sendFatal(self, msg) : - self._sendMessage(msg+'\0', 1) - def sendError(self, msg) : - self._sendMessage(msg+'\0', 2) - def sendWarning(self, msg) : - self._sendMessage(msg+'\0', 3) - def sendInfo(self, msg) : - self._sendMessage(msg+'\0', 5) - def sendDebug(self, msg) : - self._sendMessage(msg+'\0', 99) - - def mergeFile(self, filename) : - if not self.socket or not filename : - return - self._send(self._ONELAB_UPDATE, struct.pack("!HH", 0x0D, len(filename))+filename) - - def waitOnSubClient(self, name): - if not self.socket : - return - while self._numSubClients > 0: - (t, msg) = self._receive() - if t == _ONELAB_UPDATE: - param = _parseParameter(msg) - if param.type=='string' and param.name[-7:]=='/Action' and param.value=='stop': - if param.name[-7:] == name: return - self._numSubClients -= 1 # FIXME check that the client is a subclient ? - - - def waitOnSubClients(self): - if not self.socket : - return - while self._numSubClients > 0: - (t, msg) = self._receive() - if t == _ONELAB_UPDATE: - param = _parseParameter(msg) - if param.type=='string' and param.name[:-7]=='/Action' and param.value=='stop': - self._numSubClients -= 1 # FIXME check that the client is a subclient ? - - def runNonBlockingSubClient(self, name, command, arguments=''): - if self.action == 'check': - cmd = command - else: - cmd = command + ' ' + arguments - os.system(cmd); - self._numSubClients += 1 - self.getString(name+'/Action', False) - - def runSubClient(self, name, command, arguments=''): - self.runNonBlockingSubClient(name, command, arguments) - self.waitOnSubClient(name) # makes the subclient blocking - #if self.action == 'compute': - #TODO self.setChanged(name, False) - - def __init__(self, ref=''): - self.socket = None - self.name = "" - self.addr = "" - self.wdir = os.path.dirname(ref) - self._numSubClients = 0 - for i, v in enumerate(sys.argv) : - if v == '-onelab': - self.name = sys.argv[i + 1] - self.addr = sys.argv[i + 2] - self._createSocket() - self._send(self._ONELAB_START, struct.pack('!HH', 0x04, len(self.name))+self.name) - (t, msg) = self._receive() # wait for the server to reply - if t != self._ONELAB_START: - print("unable to connect the server") - exit(1) - self._clearbuffer() - self.action = "compute" # default (subclients have no client.Action defined) - self.action = self.getString(self.name + '/Action', False) - self.setNumber('IsPyMetamodel',value=1,visible=0) - self.loop = self.getNumber('0Metamodel/Loop', warn_if_not_found=False) - self.batch = self.getNumber('0Metamodel/Batch', warn_if_not_found=False) - self.sendInfo("Performing OneLab '" + self.action + "'") - if self.action == "initialize": - self.finalize() - exit(0) - - def finalize(self): - # code aster python interpreter does not call the destructor at exit, it is - # necessary to call finalize() epxlicitely - if self.socket : - self.waitOnSubClients() - self._send(self._ONELAB_STOP) - self._receive() - self.socket.close() - self.socket = None - - def getPath(self, inp='') : - return path(self.wdir,inp) - - def fileExists(self, p) : - return os.path.exists(p) - - def checkFile(self, p) : - if not self.fileExists(p): - self.sendError('path error: %s' %(p)) - exit(0) - return True - - def checkPath(self, inp='') : - p = path(self.wdir,inp) - self.checkFile(p) - return p - - def __del__(self): - self.finalize() - -# tool to extract the (i, j)th element in an array file -#from rlcompleter import readline -def extract(filename,i,j): - input = open(filename,'r') - all_lines = input.readlines() - input.close() - if i == -1: - i = len(all_lines) # last line - items = all_lines[i-1].split() - return float(items[j-1]) diff --git a/utils/solvers/c++/onelab.h b/utils/solvers/c++/onelab.h index e5c92260a3..adffa0d5ac 100644 --- a/utils/solvers/c++/onelab.h +++ b/utils/solvers/c++/onelab.h @@ -1,4 +1,4 @@ -// ONELAB - Copyright (C) 2011-2014 ULg-UCL +// ONELAB - Copyright (C) 2011-2016 ULg-UCL // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -38,19 +38,10 @@ #include <sstream> #include "GmshSocket.h" -#ifdef HAVE_ONELAB2 -#include "NetworkUtils.h" -#include "OnelabAttributes.h" -#endif - namespace onelab{ // The base parameter class. -#ifdef HAVE_ONELAB2 - class parameter : public OnelabAttr{ -#else class parameter { -#endif private: // the name of the parameter, including its '/'-separated path in the // parameter hierarchy. Parameters or subpaths can start with numbers to @@ -140,7 +131,15 @@ namespace onelab{ std::string::size_type last = _name.find_last_of('/'); if(last != std::string::npos) s = _name.substr(last + 1); - // remove starting numbers + // remove starting white space + while(s.size() && s[0] == ' ') + s = s.substr(1); + // remove starting braces: can be used to order parameters 'from the end', + // as the ASCII code is after numbers and letters + while(s.size() && (s[0] == '}' || s[0] == '{')) + s = s.substr(1); + // remove starting numbers: can be used to order parameters 'from the + // start' while(s.size() && s[0] >= '0' && s[0] <= '9') s = s.substr(1); return s; @@ -301,86 +300,6 @@ namespace onelab{ } return true; } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x05;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = _name.length()+_label.length()+_help.length()+10; - for(std::map<std::string, bool>::const_iterator it = getClients().begin(); it != getClients().end(); it++) - len += it->first.size()+2; - for(std::map<std::string, std::string>::const_iterator it = _attributes.begin(); it != _attributes.end(); it++) - len += it->first.size()+it->second.size()+2; - return len; - } - virtual UInt8 *encodeAttribute(UInt8 *dst) - { - dst = encode(dst, getAttributeType()); - dst = encode(dst, getAttributeLength()); - - dst = encode(dst, (UInt8 *)_name.c_str(), this->_name.length()+1); - dst = encode(dst, (UInt8 *)_label.c_str(), this->_label.length()+1); - dst = encode(dst, (UInt8 *)_help.c_str(), this->_help.length()+1); - dst = encode(dst, (UInt8)_readOnly); - dst = encode(dst, (UInt8)_neverChanged); - dst = encode(dst, (UInt8)_visible); - - dst = encode(dst, (UInt16)_attributes.size()); - for(std::map<std::string, std::string>::const_iterator it = _attributes.begin(); it != _attributes.end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - - dst = encode(dst, (UInt16)_clients.size()); - for(std::map<std::string, bool>::const_iterator it = getClients().begin(); it != getClients().end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8)it->second); - } - - return dst; - } - virtual UInt8 *parseAttribute(UInt8 *src, UInt32 length) - { - UInt8 tmp; - UInt16 n; - - src = parse(src, _name, '\0'); - src = parse(src, _label, '\0'); - src = parse(src, _help, '\0'); - src = parse(src, tmp); - this->_readOnly = (bool)tmp; - src = parse(src, tmp); - this->_neverChanged = (bool)tmp; - src = parse(src, tmp); - this->_visible = (bool)tmp; - - src = parse(src, n); - for(int i=0; i<n; i++) { - std::string key, value; - src = parse(src, key, '\0'); - src = parse(src, value, '\0'); - setAttribute(key, value); - } - - src = parse(src, n); - for(int i=0; i<n; i++) { - std::string client; - src = parse(src, client, '\0'); - src = parse(src, tmp); - addClient(client, (bool)tmp); - } - - return src; - } - void showAttribute() const - { - std::cout << "Name: " << getName() << std::endl - << "Label: " << getLabel() << std::endl - << "Help: " << getHelp() << std::endl - << "Never changed: " << getNeverChanged() << std::endl - << "Changed: " << getChanged() << std::endl - << "Visible: " << getVisible() << std::endl; - } -#endif }; class parameterLessThan{ @@ -392,8 +311,8 @@ namespace onelab{ }; // The number class. Numbers are stored internally as double precision real - // numbers. All more complicated types (complex numbers, vectors, etc.) are - // supposed to be either exchanged as strings or encapsulated in functions. + // numbers. All more complicated types (complex numbers, vectors, expressions, + // functions, etc.) are supposed to be exchanged as strings. class number : public parameter{ private: double _value, _min, _max, _step; @@ -501,73 +420,6 @@ namespace onelab{ } return pos; } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x06;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = parameter::getAttributeLength()+sizeof(double)*4+8+sizeof(double)*_choices.size(); - for(std::map<double, std::string>::const_iterator it = _valueLabels.begin(); it != _valueLabels.end(); it++) - len += it->second.size()+1+sizeof(double); - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst); - - dst = encode(dst, _value); - dst = encode(dst, _min); - dst = encode(dst, _max); - dst = encode(dst, _step); - dst = encode(dst, (UInt32)_index); - - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++) - dst = encode(dst, _choices[i]); - - dst = encode(dst, (UInt16)_valueLabels.size()); - for(std::map<double, std::string>::const_iterator it = _valueLabels.begin(); it != _valueLabels.end(); it++) { - dst = encode(dst, it->first); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 length) - { - UInt16 n; - - src = parameter::parseAttribute(src, length); - - src = parse(src, _value); - src = parse(src, _min); - src = parse(src, _max); - src = parse(src, _step); - src = parse(src, *(UInt32 *)&_index); - - src = parse(src, n); - _choices.resize(n); - for(unsigned int i = 0; i < n; i++) - src = parse(src, _choices[i]); - - src = parse(src, n); - for(int i=0; i<n; i++) { - double value; - std::string label; - src = parse(src, value); - src = parse(src, label, '\0'); - setValueLabel(value, label); - } - - return src; - } - void showAttribute() const - { - parameter::showAttribute(); - std::cout << "Value: " << this->_value << std::endl - << "Min: " << this->_min << std::endl - << "Max: " << this->_max << std::endl; - } -#endif }; // The string class. A string has a mutable "kind": we do not derive @@ -632,337 +484,6 @@ namespace onelab{ _choices[i] = getNextToken(msg, pos); return pos; } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x07;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const - { - UInt16 len = parameter::getAttributeLength(); - len += _value.size()+_kind.size()+4; - for(unsigned int i = 0; i < _choices.size(); i++) - len += _choices[i].size()+1; - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst); - - dst = encode(dst, (UInt8 *)_value.c_str(), _value.size()+1); - dst = encode(dst, (UInt8 *)_kind.c_str(), _kind.size()+1); - - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++) - dst = encode(dst, (UInt8 *)_choices[i].c_str(), _choices[i].size()+1); - - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 length) - { - UInt16 n; - src = parameter::parseAttribute(src, length); - src = parse(src, _value, '\0'); - src = parse(src, _kind, '\0'); - - src = parse(src, n); - _choices.resize(n); - for(unsigned int i=0; i<n; i++) { - src = parse(src, _choices[i], '\0'); - } - - return src; - } - void showAttribute() const - { - parameter::showAttribute(); - std::cout << "Value: " << this->_value << std::endl; - } -#endif - }; - - // The region class. A region can be any kind of geometrical entity, - // represented as identifiers of physical regions. Operations on regions will - // include union, intersection, etc. - class region : public parameter{ - private: - std::set<std::string> _value; - // optional geometrical dimension - int _dimension; - std::vector<std::set<std::string> > _choices; - public: - region(const std::string &name="", - const std::set<std::string> &value = std::set<std::string>(), - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _value(value), _dimension(-1) {} - region(const std::string &name, const std::string &value, - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _dimension(-1) - { - if(value.size()) _value.insert(value); - } - void setValue(const std::set<std::string> &value){ _value = value; } - void setDimension(int dim){ _dimension = dim; } - void setChoices(const std::vector<std::set<std::string> > &choices) - { - _choices = choices; - } - std::string getType() const { return "region"; } - const std::set<std::string> &getValue() const { return _value; } - int getDimension() const { return _dimension; } - const std::vector<std::set<std::string> > &getChoices() const - { - return _choices; - } - void update(const region &p) - { - addClients(p.getClients()); - setLabel(p.getLabel()); - setHelp(p.getHelp()); - setAttributes(p.getAttributes()); - if(p.getValue() != getValue()){ - setValue(p.getValue()); - setChanged(true); - } - setDimension(p.getDimension()); - setChoices(p.getChoices()); - if(getNeverChanged()) setChanged(false); - } - std::string toChar() const - { - std::ostringstream sstream; - sstream << parameter::toChar() << _value.size() << charSep(); - for(std::set<std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) - sstream << sanitize(*it) << charSep(); - sstream << _dimension << charSep(); - sstream << _choices.size() << charSep(); - for(unsigned int i = 0; i < _choices.size(); i++){ - sstream << _choices[i].size() << charSep(); - for(std::set<std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) - sstream << sanitize(*it) << charSep(); - } - return sstream.str(); - } - std::string::size_type fromChar(const std::string &msg) - { - std::string::size_type pos = parameter::fromChar(msg); - if(!pos) return 0; - int n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++) - _value.insert(getNextToken(msg, pos)); - setDimension(atoi(getNextToken(msg, pos).c_str())); - _choices.resize(atoi(getNextToken(msg, pos).c_str())); - for(unsigned int i = 0; i < _choices.size(); i++){ - n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++) - _choices[i].insert(getNextToken(msg, pos)); - } - return pos; - } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x08;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = parameter::getAttributeLength(); - len += 2; - for(std::set<std::string>::const_iterator it = _value.begin(); it != _value.end(); it++) - len += it->size()+1; - len += 4; - len += 2; - for(unsigned int i = 0; i < _choices.size(); i++){ - len += 2; - for(std::set<std::string>::const_iterator it = _choices[i].begin(); it != _choices[i].end(); it++) - len += it->size()+1; - } - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst); - dst = encode(dst, (UInt16)this->_value.size()); - for(std::set<std::string>::const_iterator it = _value.begin(); it != _value.end(); it++) - dst = encode(dst, (UInt8 *)it->c_str(), it->size()+1); - dst = encode(dst, (UInt32)_dimension); - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++){ - dst = encode(dst, (UInt16)_choices[i].size()); - for(std::set<std::string>::const_iterator it = _choices[i].begin(); it != _choices[i].end(); it++) - dst = encode(dst, (UInt8 *)it->c_str(), it->size()+1); - } - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 len) - { - src = parameter::parseAttribute(src, len); - UInt16 m = 0, n = 0; - std::string value; - src = parse(src, n); - for(int i=0; i<n; i++) { - src = parse(src, value, '\0'); - _value.insert(value); - } - src = parse(src, *(UInt32 *)&_dimension); - src = parse(src, n); - _choices.resize(n); - for(int i=0; i<n; i++) { - src = parse(src, m); - for(int j=0; j<m; j++) { - src = parse(src, value, '\0'); - _choices[i].insert(value); - } - } - return src; - } - void showAttribute() const {} -#endif - - }; - - // The (possibly piece-wise defined on regions) function class. Functions are - // entirely client-dependent: they are just represented internally as onelab - // strings, defined on onelab regions. - class function : public parameter{ - private: - std::map<std::string, std::string> _value; - std::vector<std::map<std::string, std::string> > _choices; - public: - function(const std::string &name="") : parameter(name, "", "") {} - function(const std::string &name, const std::map<std::string, std::string> &value, - const std::string &label="", const std::string &help="") - : parameter(name, label, help), _value(value) {} - void setValue(const std::map<std::string, std::string> &value) - { - _value = value; - } - void setChoices(const std::vector<std::map<std::string, std::string> > &choices) - { - _choices = choices; - } - std::string getType() const { return "function"; } - const std::map<std::string, std::string> &getValue() const { return _value; } - const std::string getValue(const std::string ®ion) const - { - std::map<std::string, std::string>::const_iterator it = _value.find(region); - if(it != _value.end()) return it->second; - return ""; - } - const std::vector<std::map<std::string, std::string> > &getChoices() const - { - return _choices; - } - void update(const function &p) - { - addClients(p.getClients()); - setLabel(p.getLabel()); - setHelp(p.getHelp()); - setAttributes(p.getAttributes()); - if(p.getValue() != getValue()){ - setValue(p.getValue()); - setChanged(true); - } - setChoices(p.getChoices()); - if(getNeverChanged()) setChanged(false); - } - std::string toChar() const - { - std::ostringstream sstream; - sstream << parameter::toChar() << _value.size() << charSep(); - for(std::map<std::string, std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) - sstream << sanitize(it->first) << charSep() - << sanitize(it->second) << charSep(); - sstream << _choices.size() << charSep(); - for(unsigned int i = 0; i < _choices.size(); i++){ - sstream << _choices[i].size() << charSep(); - for(std::map<std::string, std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) - sstream << sanitize(it->first) << charSep() - << sanitize(it->second) << charSep(); - } - return sstream.str(); - } - std::string::size_type fromChar(const std::string &msg) - { - std::string::size_type pos = parameter::fromChar(msg); - if(!pos) return 0; - int n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++){ - std::string key = getNextToken(msg, pos); - _value[key] = getNextToken(msg, pos); - } - _choices.resize(atoi(getNextToken(msg, pos).c_str())); - for(unsigned int i = 0; i < _choices.size(); i++){ - n = atoi(getNextToken(msg, pos).c_str()); - for(int i = 0; i < n; i++){ - std::string key = getNextToken(msg, pos); - _choices[i][key] = getNextToken(msg, pos); - } - } - return pos; - } -#ifdef HAVE_ONELAB2 - static UInt16 attributeType() {return 0x09;} - virtual inline UInt16 getAttributeType() const {return this->attributeType();} - virtual inline UInt16 getAttributeLength() const { - UInt16 len = parameter::getAttributeLength(); - len += 2; - for(std::map<std::string, std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) - len += 2+it->first.size()+it->second.size(); - for(unsigned int i = 0; i < _choices.size(); i++){ - len += 2; - for(std::map<std::string, std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) { - len += 2+it->first.size()+it->second.size(); - } - } - return len; - } - UInt8 *encodeAttribute(UInt8 *dst) - { - dst = parameter::encodeAttribute(dst), - dst = encode(dst, (UInt16)this->_value.size()); - for(std::map<std::string, std::string>::const_iterator it = _value.begin(); - it != _value.end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - dst = encode(dst, (UInt16)_choices.size()); - for(unsigned int i = 0; i < _choices.size(); i++){ - dst = encode(dst, (UInt16)_choices[i].size()); - for(std::map<std::string, std::string>::const_iterator it = _choices[i].begin(); - it != _choices[i].end(); it++) { - dst = encode(dst, (UInt8 *)it->first.c_str(), it->first.size()+1); - dst = encode(dst, (UInt8 *)it->second.c_str(), it->second.size()+1); - } - } - return dst; - } - UInt8 *parseAttribute(UInt8 *src, UInt32 len) - { - src = parameter::parseAttribute(src, len); - UInt16 m = 0, n = 0; - std::string key, value; - src = parse(src, n); - for(int i=0; i<n; i++) { - src = parse(src, key, '\0'); - src = parse(src, value, '\0'); - _value[key] = value; - } - src = parse(src, n); - _choices.resize(n); - for(int i=0; i<n; i++) { - src = parse(src, m); - for(int j=0; j<m; j++) { - src = parse(src, key, '\0'); - src = parse(src, value, '\0'); - _choices[i][key] = value; - } - } - return src; - } - void showAttribute() const {} -#endif }; // The parameter space, i.e., the set of parameters stored and handled by the @@ -971,21 +492,23 @@ namespace onelab{ private: std::set<number*, parameterLessThan> _numbers; std::set<string*, parameterLessThan> _strings; - std::set<region*, parameterLessThan> _regions; - std::set<function*, parameterLessThan> _functions; // delete a parameter from the parameter space template <class T> bool _clear(const std::string &name, const std::string &client, std::set<T*, parameterLessThan> &ps) { if(name.empty() && client.size()){ + std::vector<T*> toDelete; for(typename std::set<T*, parameterLessThan>::iterator it = ps.begin(); - it != ps.end(); it++){ + it != ps.end(); ){ T *p = *it; if(p->hasClient(client)){ - ps.erase(it); + ps.erase(it++); // to avoid invalid iterator delete p; } + else{ + it++; + } } } else{ @@ -1016,9 +539,6 @@ namespace onelab{ } else{ T* newp = new T(p); -#ifdef HAVE_ONELAB2 - newp->isInDatabase(true); -#endif if(client.size()) newp->addClient(client, true); ps.insert(newp); } @@ -1062,8 +582,6 @@ namespace onelab{ { ps.insert(_numbers.begin(), _numbers.end()); ps.insert(_strings.begin(), _strings.end()); - ps.insert(_regions.begin(), _regions.end()); - ps.insert(_functions.begin(), _functions.end()); } public: parameterSpace(){} @@ -1078,50 +596,32 @@ namespace onelab{ delete *it; _numbers.clear(); _strings.clear(); - _regions.clear(); - _functions.clear(); } else{ bool done = _clear(name, client, _numbers); if(!done) done = _clear(name, client, _strings); - if(!done) done = _clear(name, client, _regions); - if(!done) done = _clear(name, client, _functions); } } bool set(const number &p, const std::string &client=""){ return _set(p, client, _numbers); } bool set(const string &p, const std::string &client=""){ return _set(p, client, _strings); } - bool set(const region &p, - const std::string &client=""){ return _set(p, client, _regions); } - bool set(const function &p, - const std::string &client=""){ return _set(p, client, _functions); } bool get(std::vector<number> &ps, const std::string &name="", const std::string &client=""){ return _get(ps, name, client, _numbers); } bool get(std::vector<onelab::string> &ps, const std::string &name="", const std::string &client=""){ return _get(ps, name, client, _strings); } - bool get(std::vector<region> &ps, const std::string &name="", - const std::string &client=""){ return _get(ps, name, client, _regions); } - bool get(std::vector<function> &ps, const std::string &name="", - const std::string &client=""){ return _get(ps, name, client, _functions); } void getPtr(number **ptr, const std::string name, const std::string client="") {*ptr = _getPtr(name, client, _numbers);} void getPtr(string **ptr, const std::string name, const std::string client="") {*ptr = _getPtr(name, client, _strings);} - void getPtr(region **ptr, const std::string name, const std::string client="") - {*ptr = _getPtr(name, client, _regions);} - void getPtr(function **ptr, const std::string name, const std::string client="") - {*ptr = _getPtr(name, client, _functions);} void getAllParameters(std::set<parameter*, parameterLessThan> &ps) const { ps.insert(_numbers.begin(), _numbers.end()); ps.insert(_strings.begin(), _strings.end()); - ps.insert(_regions.begin(), _regions.end()); - ps.insert(_functions.begin(), _functions.end()); } unsigned int getNumParameters() { - return (int)(_numbers.size() + _strings.size() + _regions.size() + _functions.size()); + return (int)(_numbers.size() + _strings.size()); } // check if at least one parameter depends on the given client bool hasClient(const std::string &client) const @@ -1185,12 +685,6 @@ namespace onelab{ else if(type == "string"){ onelab::string p; p.fromChar(msg[i]); set(p, client); } - else if(type == "region"){ - onelab::region p; p.fromChar(msg[i]); set(p, client); - } - else if(type == "function"){ - onelab::function p; p.fromChar(msg[i]); set(p, client); - } else return false; } @@ -1231,23 +725,15 @@ namespace onelab{ virtual bool clear(const std::string &name) = 0; virtual bool set(const number &p) = 0; virtual bool set(const string &p) = 0; - virtual bool set(const region &p) = 0; - virtual bool set(const function &p) = 0; virtual bool get(std::vector<number> &ps, const std::string &name="") = 0; virtual bool get(std::vector<onelab::string> &ps, const std::string &name="") = 0; - virtual bool get(std::vector<region> &ps, const std::string &name="") = 0; - virtual bool get(std::vector<function> &ps, const std::string &name="") = 0; std::vector<std::string> toChar() { std::vector<std::string> out; std::vector<number> n; get(n); for(unsigned int i = 0; i < n.size(); i++) out.push_back(n[i].toChar()); - std::vector<number> s; get(s); + std::vector<string> s; get(s); for(unsigned int i = 0; i < s.size(); i++) out.push_back(s[i].toChar()); - std::vector<region> r; get(r); - for(unsigned int i = 0; i < r.size(); i++) out.push_back(r[i].toChar()); - std::vector<region> f; get(f); - for(unsigned int i = 0; i < f.size(); i++) out.push_back(f[i].toChar()); return out; } bool fromChar(const std::vector<std::string> &msg) @@ -1262,12 +748,6 @@ namespace onelab{ else if(type == "string"){ onelab::string p; p.fromChar(msg[i]); set(p); } - else if(type == "region"){ - onelab::region p; p.fromChar(msg[i]); set(p); - } - else if(type == "function"){ - onelab::function p; p.fromChar(msg[i]); set(p); - } else return false; } @@ -1292,8 +772,8 @@ namespace onelab{ static server *_server; // the address of the server std::string _address; - // the connected clients, indexed by name - std::map<std::string, client*> _clients; + // the connected clients + std::set<client*> _clients; // the parameter space parameterSpace _parameterSpace; public: @@ -1318,17 +798,22 @@ namespace onelab{ { return _parameterSpace.get(ps, name, client); } - typedef std::map<std::string, client*>::iterator citer; + typedef std::set<client*>::iterator citer; citer firstClient(){ return _clients.begin(); } citer lastClient(){ return _clients.end(); } int getNumClients() { return (int)_clients.size(); }; - citer findClient(const std::string &name){ return _clients.find(name); } + citer findClient(const std::string &name) + { + for(citer it = _clients.begin(); it != _clients.end(); it++) + if((*it)->getName() == name) return it; + return _clients.end(); + } void registerClient(client *c) { - _clients[c->getName()] = c; + _clients.insert(c); c->setId(_clients.size()); } - void unregisterClient(client *c){ _clients.erase(c->getName()); } + void unregisterClient(client *c){ _clients.erase(c); } void setChanged(bool changed, const std::string &client="") { _parameterSpace.setChanged(changed, client); @@ -1337,10 +822,6 @@ namespace onelab{ { return _parameterSpace.getChanged(client); } - bool isRegistered(const std::string &client) - { - return _clients.count(client); - } unsigned int getNumParameters(){ return _parameterSpace.getNumParameters(); } std::vector<std::string> toChar(const std::string &client="") { @@ -1392,16 +873,10 @@ namespace onelab{ } virtual bool set(const number &p){ return _set(p); } virtual bool set(const string &p){ return _set(p); } - virtual bool set(const function &p){ return _set(p); } - virtual bool set(const region &p){ return _set(p); } virtual bool get(std::vector<number> &ps, const std::string &name=""){ return _get(ps, name); } virtual bool get(std::vector<onelab::string> &ps, const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<function> &ps, - const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<region> &ps, - const std::string &name=""){ return _get(ps, name); } }; // The local part of a network client. @@ -1434,7 +909,7 @@ namespace onelab{ const std::string &getExecutable(){ return _executable; } void setExecutable(const std::string &s){ _executable = s; } const std::string &getRemoteLogin(){ return _remoteLogin; } - const bool treatExecutableAsFullCommandLine() + bool treatExecutableAsFullCommandLine() const { return _treatExecutableAsFullCommandLine; } @@ -1591,16 +1066,10 @@ namespace onelab{ } virtual bool set(const number &p){ return _set(p); } virtual bool set(const string &p){ return _set(p); } - virtual bool set(const function &p){ return _set(p); } - virtual bool set(const region &p){ return _set(p); } virtual bool get(std::vector<number> &ps, const std::string &name=""){ return _get(ps, name); } virtual bool get(std::vector<onelab::string> &ps, const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<function> &ps, - const std::string &name=""){ return _get(ps, name); } - virtual bool get(std::vector<region> &ps, - const std::string &name=""){ return _get(ps, name); } void sendInfo(const std::string &msg) { if(_gmshClient) _gmshClient->Info(msg.c_str()); -- GitLab