From e34780e7fa95cf628b0a04341ec38b568de29917 Mon Sep 17 00:00:00 2001 From: Francois Henrotte <francois.henrotte@ulg.ac.be> Date: Mon, 29 Oct 2012 21:26:36 +0000 Subject: [PATCH] --- contrib/onelab/OnelabClients.cpp | 30 +++++----- contrib/onelab/OnelabClients.h | 3 +- contrib/onelab/OnelabParser.cpp | 95 ++++++++++++++++++++++++-------- contrib/onelab/metamodel.cpp | 31 ++++------- 4 files changed, 100 insertions(+), 59 deletions(-) diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index 72a9220b3f..f72d2d8882 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -410,8 +410,6 @@ bool localSolverClient::checkCommandLine(){ getCommandLine().c_str(), getName().c_str()); if(!isActive()) return true; - //if(*getCommandLine().rbegin() != '=') return false; - if(!getCommandLine().empty()){ if(isNative()){ setAction("initialize"); @@ -578,11 +576,12 @@ bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fil std::string fullName = wdir+trueName; if(checkIfPresent(fullName)){ cmd.assign("rsync -e ssh -auv "+fullName+" "+_remoteHost+":"+_remoteDir+"/"+trueName); -#if defined(WIN32) - Sleep((int)(OLMsg::GetOnelabNumber("RSYNCDELAY")*1000)); -#else - sleep(OLMsg::GetOnelabNumber("RSYNCDELAY")); -#endif +// #if defined(WIN32) +// Sleep((int)(OLMsg::GetOnelabNumber("RSYNCDELAY")*1000)); +// #else +// sleep(OLMsg::GetOnelabNumber("RSYNCDELAY")); +// #endif + SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); return mySystem(cmd); } else{ @@ -595,8 +594,9 @@ bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fil //should be found local std::string fullName = wdir+fileName; if(checkIfPresent(fullName)){ - cmd.assign("rsync -e ssh -auv "+fullName+" "+_remoteHost+":"+_remoteDir+"/"+fileName); - //FIXME sleep(OLMsg::GetOnelabNumber("RSYNCDELAY")); + cmd.assign("rsync -e ssh -auv "+fullName+" " + _remoteHost); + cmd.append(":" + _remoteDir + "/"+fileName); + SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); return mySystem(cmd); } else{ @@ -626,7 +626,7 @@ bool remoteClient::syncOutputFile(const std::string &wdir, const std::string &fi +fileName.substr(pos,std::string::npos)+" ."); if(!wdir.empty()) cmd.append(dirSep+wdir); - //FIXME sleep(OLMsg::GetOnelabNumber("RSYNCDELAY")); + SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); return mySystem(cmd); } } @@ -1226,9 +1226,9 @@ std::string FixExecPath(const std::string &in) split0.assign(SplitFileName(cmd)[0]); split1.assign(SplitFileName(cmd)[1]); split2.assign(SplitFileName(cmd)[2]); - std::cout << "0=<" << split0 << ">" << std::endl; - std::cout << "1=<" << split1 << ">" << std::endl; - std::cout << "2=<" << split2 << ">" << std::endl; + // std::cout << "0=<" << split0 << ">" << std::endl; + // std::cout << "1=<" << split1 << ">" << std::endl; + // std::cout << "2=<" << split2 << ">" << std::endl; if(split2==".app") cmd.assign(cmd + "/Contents/MacOS/" + split1); @@ -1243,9 +1243,7 @@ std::string FixExecPath(const std::string &in) else if(cmd[0] != '\"') cmd.assign(quote(cmd)); - std::cout << "cmd=<" << cmd << ">" << std::endl; - - //exit(1); + //std::cout << "cmd=<" << cmd << ">" << std::endl; return cmd; } diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index d3edf7495f..435192230b 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -18,7 +18,7 @@ // Onelab file extension static std::string onelabExtension(".ol"); // Possible actions for clients -enum parseMode {INITIALIZE, REGISTER, ANALYZE, COMPUTE, EXIT, STOP}; +enum parseMode {REGISTER, ANALYZE, COMPUTE, EXIT}; #if defined(WIN32) static std::string dirSep("\\"); @@ -140,6 +140,7 @@ class localSolverClient : public onelab::localClient{ const bool isOnelabBlock() { return _onelabBlock; } const void openOnelabBlock() { _onelabBlock=true; } const void closeOnelabBlock() { _onelabBlock=false; } + std::string resolveString(const std::string &line); std::string resolveGetVal(std::string line); bool resolveLogicExpr(std::vector<std::string> arguments); bool resolveRange(const std::string &in, std::vector<double> &arguments); diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index 1d9352d1c7..3f2e6a35cf 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -168,7 +168,35 @@ std::string localSolverClient::longName(const std::string name){ return fullName; } +std::string localSolverClient::resolveString(const std::string &line) { + //looks for the first OL.get() statement, + //returns a onelab::string value from the server, if any, or "" otherwise + //if no OL.get() statement found, returns line unchanged. + std::vector<onelab::string> strings; + std::vector<std::string> arguments; + size_t pos,cursor; + + if((pos=line.find(olkey::getValue)) != std::string::npos){ + cursor = pos+olkey::getValue.length(); + int NumArg=enclosed(line.substr(cursor),arguments,pos); + if(NumArg<1){ + OLMsg::Error("Misformed %s statement: <%s>", + olkey::getValue.c_str(),line.c_str()); + return "??"; + } + std::string paramName=longName(arguments[0]); + get(strings,paramName); + if (strings.size()) + return strings[0].getValue(); + else + return ""; + } + return line; +} + std::string localSolverClient::resolveGetVal(std::string line) { + //looks for OL.get() statements, substitute the value from server + //then ealuate the resulting string with mathex. std::vector<onelab::number> numbers; std::vector<onelab::string> strings; std::vector<std::string> arguments; @@ -265,7 +293,7 @@ std::string localSolverClient::resolveGetVal(std::string line) { } } else{ - get(strings,longName(paramName)); + get(strings,paramName); if (strings.size()) buff.assign(strings[0].getValue()); else{ @@ -304,28 +332,49 @@ std::string localSolverClient::resolveGetVal(std::string line) { bool localSolverClient::resolveLogicExpr(std::vector<std::string> arguments) { std::vector<onelab::number> numbers; + double val1, val2; + std::string str1,str2; bool condition=false; - val1 = atof( resolveGetVal(arguments[0]).c_str() ); - if(arguments.size()==1) - condition=(bool)val1; + if(arguments.size()==1){ + str1.assign(resolveString(arguments[0])); + if(str1.size()) + return true; + val1 = atof( resolveGetVal(arguments[0]).c_str() ); + return (bool)val1; + } else if(arguments.size()==3){ - val2=atof( resolveGetVal(arguments[2]).c_str() ); - if(!arguments[1].compare("<")) - condition = (val1<val2); - else if (!arguments[1].compare("<=")) - condition = (val1<=val2); - else if (!arguments[1].compare(">")) - condition = (val1>val2); - else if (!arguments[1].compare(">=")) - condition = (val1>=val2); - else if (!arguments[1].compare("==")) - condition = (val1==val2); - else if (!arguments[1].compare("!=")) - condition = (val1!=val2); - else - OLMsg::Error("Unknown logical operator <%s>", arguments[1].c_str()); + + str1.assign(resolveString(arguments[0])); + str2.assign(resolveString(arguments[2])); + if(str1.size() && str2.size()){ + if (!arguments[1].compare("==")) + condition = !str1.compare(str2); + else if (!arguments[1].compare("!=")) + condition = str1.compare(str2); + else + OLMsg::Error("Unknown logical operator <%s> for strings", + arguments[1].c_str()); + } + else{ + val1 = atof( resolveGetVal(arguments[0]).c_str() ); + val2 = atof( resolveGetVal(arguments[2]).c_str() ); + if(!arguments[1].compare("<")) + condition = (val1<val2); + else if (!arguments[1].compare("<=")) + condition = (val1<=val2); + else if (!arguments[1].compare(">")) + condition = (val1>val2); + else if (!arguments[1].compare(">=")) + condition = (val1>=val2); + else if (!arguments[1].compare("==")) + condition = (val1==val2); + else if (!arguments[1].compare("!=")) + condition = (val1!=val2); + else + OLMsg::Error("Unknown logical operator <%s>", arguments[1].c_str()); + } } else OLMsg::Error("Invalid logical expression"); @@ -1358,10 +1407,10 @@ void MetaModel::client_sentence(const std::string &name, set(strings[0]); } localSolverClient *c; - if((c=findClientByName(name))){ - if(c->checkCommandLine() && !OLMsg::GetErrorNum()) - c->analyze(); - } + if(!OLMsg::GetErrorNum()) + if((c=findClientByName(name))) + if(c->checkCommandLine()) + c->analyze(); } else if(isTodo(ANALYZE)){ localSolverClient *c; diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index 4588bab57d..da73a4f2b4 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -11,6 +11,7 @@ void initializeMetamodel(const std::string &loaderName, onelab::client *olclient //Initilizes also the wait function the Gmsh Gui //so that Gmsh windows may remain active during client computations. OLMsg::SetOnelabClient(olclient); + OLMsg::Info("I can now communicate with gmsh"); OLMsg::SetOnelabString("LoaderPathName",loaderName,false); OLMsg::SetGuiWaitFunction(gui_wait_fct); } @@ -23,40 +24,32 @@ int metamodel(const std::string &action){ OLMsg::ResetErrorNum(); parseMode todo; - if(action == "initialize") - todo = INITIALIZE; - else if(action == "check") - todo = ANALYZE; - else if(action == "compute"){ + // if(action == "initialize") + // todo = INITIALIZE; + + if(action == "compute") todo = COMPUTE; - } else{ - todo = EXIT; - OLMsg::Error("Unknown action <%s>", action.c_str()); + todo = ANALYZE; } std::string modelName = OLMsg::GetOnelabString("Arguments/FileName"); std::string workingDir = OLMsg::GetOnelabString("Arguments/WorkingDir"); std::string clientName = "meta"; + MetaModel *myModel = + new MetaModel("meta", workingDir, "meta", modelName); + myModel->setTodo(todo); + if(OLMsg::GetOnelabNumber("LOGFILES")){ - if(workingDir.size()) workingDir.append(dirSep); std::string mystdout = FixWindowsQuotes(workingDir + "stdout.txt"); std::string mystderr = FixWindowsQuotes(workingDir + "stderr.txt"); - freopen(mystdout.c_str(),"w",stdout); - freopen(mystderr.c_str(),"w",stderr); OLMsg::Info("Redirecting stdout into <%s>",mystdout.c_str()); OLMsg::Info("Redirecting stderr into <%s>",mystderr.c_str()); + freopen(mystdout.c_str(),"w",stdout); + freopen(mystderr.c_str(),"w",stderr); } - MetaModel *myModel = - new MetaModel("meta", workingDir, "meta", modelName); - myModel->setTodo(todo); - - //if not all clients have valid commandlines -> exit metamodel - // if(!myModel->checkCommandLines()) - // myModel->setTodo(EXIT); - if(OLMsg::GetErrorNum()) myModel->setTodo(EXIT); if( myModel->isTodo(ANALYZE)){ -- GitLab