Skip to content
Snippets Groups Projects
Commit 3db9df87 authored by Francois Henrotte's avatar Francois Henrotte
Browse files

revision of the ReadOnly principle, elimination of warnings

parent 0c946d56
No related branches found
No related tags found
No related merge requests found
......@@ -733,8 +733,24 @@ void Msg::ExchangeOnelabParameter(const std::string &key,
bool noRange = true, noChoices = true, noLoop = true;
bool noGraph = true, noClosed = true;
if(ps.size()){
if(!ps[0].getReadOnly())
// modified implementation of ReadOnly
if(fopt.count("ReadOnly")) {
ps[0].setReadOnly(fopt["ReadOnly"][0] ? true : false);
if(ps[0].getReadOnly())
// If the parameter is set "read-only" in this statement
// use local value
ps[0].setValue(val[0]);
else
// use value from server
val[0] = ps[0].getValue();
}
else
val[0] = ps[0].getValue(); // use value from server
// if(!ps[0].getReadOnly())
// val[0] = ps[0].getValue(); // use value from server
// keep track of these attributes, which can be changed server-side
if(ps[0].getMin() != -onelab::parameter::maxNumber() ||
ps[0].getMax() != onelab::parameter::maxNumber() ||
......@@ -790,12 +806,6 @@ void Msg::ExchangeOnelabParameter(const std::string &key,
if(copt.count("Choices")) ps[0].setChoiceLabels(copt["Choices"]);
}
if(fopt.count("Visible")) ps[0].setVisible(fopt["Visible"][0] ? true : false);
if(fopt.count("ReadOnly")) {
ps[0].setReadOnly(fopt["ReadOnly"][0] ? true : false);
// If the parameter is set "read-only" here, the local value is used instead
// of that from the server
if(ps[0].getReadOnly()) ps[0].setValue(val[0]);
}
if(copt.count("Help")) ps[0].setHelp(copt["Help"][0]);
if(copt.count("Label")) ps[0].setLabel(copt["Label"][0]);
if(copt.count("ShortHelp")) ps[0].setLabel(copt["ShortHelp"][0]);
......
......@@ -32,7 +32,7 @@ class onelabMetaModelServer : public GmshServer{
return 1;
}
std::string cmd(command);
int pos;
size_t pos;
if((pos=cmd.find("incomp_ssh ")) != std::string::npos){
cmd.assign(cmd.substr(pos+7)); // remove "incomp_"
cmd.append(" & '");
......@@ -59,6 +59,17 @@ class onelabMetaModelServer : public GmshServer{
// return immediately, i.e., do polling)
int ret = Select(0, 0, socket);
if(ret == 0){ // nothing available
// if asked, refresh the onelab GUI
// std::vector<onelab::string> ps;
// onelab::server::instance()->get(ps, "Gmsh/Action");
// if(ps.size() && ps[0].getValue() == "refresh"){
// ps[0].setVisible(false);
// ps[0].setValue("");
// onelab::server::instance()->set(ps[0]);
// onelab_cb(0, (void*)"refresh");
//}
// wait at most waitint seconds and respond to FLTK events
//FlGui::instance()->wait(waitint);
void (*waitFct)(double) = OLMsg::GetGuiWaitFunction();
if(waitFct) waitFct(waitint);
......@@ -316,8 +327,6 @@ bool localNetworkSolverClient::run()
OLMsg::Fatal("%-8.8s: %s", _name.c_str(), message.c_str());
break;
case GmshSocket::GMSH_MERGE_FILE:
OLMsg::Info("Merge Post-Processing File %s",message.c_str());
SystemCall("gmsh "+ message);
break;
default:
OLMsg::Warning("Received unknown message type (%d)", type);
......@@ -390,7 +399,7 @@ bool localSolverClient::checkCommandLine(){
OLMsg::Info("Check command line for <%s>",getName().c_str());
if(getCommandLine().empty())
OLMsg::Fatal("No commandline for client <%s>", getName().c_str());
OLMsg::Warning("No commandline for client <%s>", getName().c_str());
if(!isActive()) return true;
......@@ -399,6 +408,7 @@ bool localSolverClient::checkCommandLine(){
run(); // does nothing for Interfaced clients, initializes native clients
}
else{
std::cout << "FHF hasGmsh=" << OLMsg::hasGmsh << std::endl;
if(OLMsg::hasGmsh) {
// exits metamodel and restores control to the onelab window
OLMsg::Error("The command line of client <%s> is undefined.",
......@@ -431,11 +441,12 @@ bool localSolverClient::buildRmCommand(std::string &cmd){
#else
cmd.append("rm -rf ");
#endif
if(choices.size()){
for(unsigned int i = 0; i < choices.size(); i++)
cmd.append(choices[i]+" ");
return true;
}
else
}
return false;
}
......@@ -462,18 +473,17 @@ void localSolverClient::addNumberChoice(std::string name, double val)
void localSolverClient::PostArray(std::vector<std::string> choices)
{
int nb=0;
while( 4*(nb+1) <= choices.size()){
//std::cout << "Nb Choices" << choices.size() << std::endl;
int lin= atof(choices[4*nb+1].c_str());
int col= atof(choices[4*nb+2].c_str());
std::string fileName = getWorkingDir()+choices[4*nb];
unsigned int i=0;
while( 4*(i+1) <= choices.size()){
int lin= atof(choices[4*i+1].c_str())-1;
int col= atof(choices[4*i+2].c_str())-1;
std::string fileName = getWorkingDir()+choices[4*i];
//checkIfPresent or make available locally
double val=find_in_array(lin,col,read_array(fileName,' '));
addNumberChoice(choices[4*nb+3],val);
addNumberChoice(choices[4*i+3],val);
OLMsg::Info("Upload parameter <%s>=%e from file <%s>",
choices[4*nb+3].c_str(),val,fileName.c_str());
nb++;
choices[4*i+3].c_str(),val,fileName.c_str());
i++;
}
}
......@@ -490,7 +500,6 @@ void localSolverClient::GmshMerge(std::vector<std::string> choices)
// REMOTE CLIENT
bool remoteClient::checkCommandLine(const std::string &commandLine){
struct stat buf;
std::string cmd;
char cbuf [1024];
FILE *fp;
......@@ -513,7 +522,6 @@ bool remoteClient::checkCommandLine(const std::string &commandLine){
}
bool remoteClient::checkIfPresentRemote(const std::string &fileName){
struct stat buf;
std::string cmd;
char cbuf [1024];
FILE *fp;
......@@ -532,7 +540,7 @@ bool remoteClient::checkIfPresentRemote(const std::string &fileName){
}
bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fileName){
int pos;
size_t pos;
std::string cmd;
if((pos=fileName.find(onelabExtension)) != std::string::npos){
// .ol file => local
......@@ -542,6 +550,7 @@ 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);
sleep(OLMsg::GetOnelabNumber("RSYNCDELAY"));
return mySystem(cmd);
}
else{
......@@ -555,6 +564,7 @@ bool remoteClient::syncInputFile(const std::string &wdir, const std::string &fil
std::string fullName = wdir+fileName;
if(checkIfPresent(fullName)){
cmd.assign("rsync -e ssh -auv "+fullName+" "+_remoteHost+":"+_remoteDir+"/"+fileName);
sleep(OLMsg::GetOnelabNumber("RSYNCDELAY"));
return mySystem(cmd);
}
else{
......@@ -577,16 +587,17 @@ bool remoteClient::syncOutputFile(const std::string &wdir, const std::string &fi
std::string cmd;
if(checkIfPresentRemote(fileName)){
int pos=fileName.find_first_not_of(" ");
if(!fileName.compare(pos,1,".")){ // the file must be copied back locally
size_t pos=fileName.find_first_not_of(" ");
if(!fileName.compare(pos,1,".")){
// the file must be copied back on local host
cmd.assign("rsync -e ssh -auv "+_remoteHost+":"+_remoteDir+dirSep
+fileName.substr(pos,std::string::npos)+" .");
if(!wdir.empty())
cmd.append(dirSep+wdir);
sleep(OLMsg::GetOnelabNumber("RSYNCDELAY"));
return mySystem(cmd);
}
}
else
return false;
}
......@@ -623,16 +634,6 @@ void MetaModel::construct()
closeOnelabBlock();
}
// void MetaModel::initialize()
// {
// OLMsg::Info("Metamodel now INITIALIZING");
// OLMsg::Info("Initialize Metamodel by the loader");
// OLMsg::SetOnelabString(clientName + "/9CheckCommand","-a",false);
// OLMsg::SetOnelabNumber(clientName + "/UseCommandLine",1,false);
// OLMsg::SetOnelabNumber(clientName + "/Initialized",1,false);
// }
void MetaModel::analyze() {
OLMsg::Info("Metamodel now ANALYZING");
std::string fileName = genericNameFromArgs + onelabExtension;
......@@ -670,8 +671,8 @@ void MetaModel::registerClient(const std::string &name, const std::string &type,
c= new RemoteInterfacedClient(name,cmdl,getWorkingDir(),host,rdir);
else if(!type.compare(0,6,"native"))
c= new RemoteNativeClient(name,cmdl,getWorkingDir(),host,rdir);
// else if(!type.compare(0,6,"encaps"))
// c= new RemoteEncapsulatedClient(name,cmdl,getWorkingDir(),host,rdir);
else if(!type.compare(0,6,"encaps"))
c= new RemoteEncapsulatedClient(name,cmdl,getWorkingDir(),host,rdir);
else
OLMsg::Fatal("Unknown remote client type", type.c_str());
}
......@@ -680,24 +681,23 @@ void MetaModel::registerClient(const std::string &name, const std::string &type,
void MetaModel::PostArray(std::vector<std::string> choices)
{
int nb=0;
//onelab::number o;
while( 4*(nb+1) <= choices.size()){
int lin= atof(choices[4*nb+1].c_str());
int col= atof(choices[4*nb+2].c_str());
unsigned int i=0;
while( 4*(i+1) <= choices.size()){
int lin= atof(choices[4*i+1].c_str())-1;
int col= atof(choices[4*i+2].c_str())-1;
std::string fileName =
OLMsg::GetOnelabString("Arguments/WorkingDir")+choices[4*nb];
OLMsg::GetOnelabString("Arguments/WorkingDir")+choices[4*i];
double val=find_in_array(lin,col,read_array(fileName,' '));
addNumberChoice(choices[4*nb+3],val);
OLMsg::Info("PostArray <%s>=%e",choices[4*nb+3].c_str(),val);
nb++;
addNumberChoice(choices[4*i+3],val);
OLMsg::Info("PostArray <%s>=%e",choices[4*i+3].c_str(),val);
i++;
}
}
// INTERFACED client
void InterfacedClient::analyze() {
int pos;
size_t pos;
std::vector<std::string> choices;
setAction("check");
......@@ -715,7 +715,7 @@ void InterfacedClient::analyze() {
}
void InterfacedClient::convert() {
int pos;
size_t pos;
std::vector<std::string> choices;
getList("InputFiles", choices);
for(unsigned int i = 0; i < choices.size(); i++){
......@@ -737,11 +737,11 @@ void InterfacedClient::compute(){
std::string cmd;
std::vector<std::string> choices;
OLMsg::Info("Computes <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
OLMsg::Info("Computes <%s>", getName().c_str());
if(getActive() && onelab::server::instance()->getChanged(getName())){
analyze();
setAction("compute");
if(getList("InputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++){
//remove .ol ext
......@@ -750,11 +750,7 @@ void InterfacedClient::compute(){
}
}
setAction("compute");
if(buildRmCommand(cmd)){
OLMsg::Info("Calling <%s>",cmd.c_str());
SystemCall(cmd,true);
}
if(buildRmCommand(cmd)) mySystem(cmd);
cmd.assign("");
if(!getWorkingDir().empty())
......@@ -762,18 +758,14 @@ void InterfacedClient::compute(){
cmd.append(FixWindowsPath(getCommandLine()));
cmd.append(" " + getString("Arguments"));
if(cmd.size()){
OLMsg::Info("Calling <%s>",cmd.c_str());
SystemCall(cmd.c_str(),true);
}
if(cmd.size()) mySystem(cmd.c_str());
if(getList("OutputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++){
checkIfPresentLocal(choices[i]);
}
}
}
OLMsg::Info("Client %s completed",_name.c_str());
OLMsg::Info("Client %s completed",getName().c_str());
}
// NATIVE Client
......@@ -789,14 +781,11 @@ void NativeClient::compute() {
std::string cmd;
std::vector<std::string> choices;
OLMsg::Info("Computes <%s>", getName().c_str());
analyze();
setAction("compute");
OLMsg::Info("Computes <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
if(getActive() && onelab::server::instance()->getChanged(getName())){
if(buildRmCommand(cmd)){
OLMsg::Info("Calling <%s>",cmd.c_str());
SystemCall(cmd,true);
}
if(buildRmCommand(cmd)) mySystem(cmd);
if(getList("InputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++){
......@@ -810,17 +799,15 @@ void NativeClient::compute() {
checkIfPresentLocal(choices[i]);
}
}
}
OLMsg::Info("Client %s completed",getName().c_str());
}
// ENCAPSULATED Client
// bool EncapsulatedClient::checkCommandLine(){
// return localSolverClient::checkCommandLine(getCommandLine());
// }
// EncapsulatedClient's are InterfacedClient's called via the loader
// so that Gmsh sees them as a localNetworkClient
void EncapsulatedClient::analyze() {
int pos;
size_t pos;
std::vector<std::string> choices;
setAction("check");
......@@ -838,7 +825,7 @@ void EncapsulatedClient::analyze() {
}
void EncapsulatedClient::convert() {
int pos;
size_t pos;
std::vector<std::string> choices;
getList("InputFiles", choices);
for(unsigned int i = 0; i < choices.size(); i++){
......@@ -866,13 +853,11 @@ void EncapsulatedClient::compute(){
std::string cmd;
std::vector<std::string> choices;
//setAction("compute");
std::string name=getName();
OLMsg::Info("Computes <%s> changed=%d", name.c_str(),
onelab::server::instance()->getChanged(name));
OLMsg::Info("Computes <%s>", getName().c_str());
if(getActive() && onelab::server::instance()->getChanged(name)){
analyze();
setAction("compute");
if(getList("InputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++){
//remove .ol ext
......@@ -882,10 +867,7 @@ void EncapsulatedClient::compute(){
}
setAction("compute");
if(buildRmCommand(cmd)){
OLMsg::Info("Calling <%s>",cmd.c_str());
SystemCall(cmd,true);
}
if(buildRmCommand(cmd)) mySystem(cmd);
cmd.assign("");
if(!getWorkingDir().empty())
......@@ -893,7 +875,7 @@ void EncapsulatedClient::compute(){
cmd.append(FixWindowsPath(getCommandLine()));
cmd.append(" " + getString("Arguments"));
OLMsg::SetOnelabString(name+"/FullCmdLine",cmd,false);
OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false);
run();
if(getList("OutputFiles",choices)){
......@@ -901,8 +883,7 @@ void EncapsulatedClient::compute(){
checkIfPresentLocal(choices[i]);
}
}
}
OLMsg::Info("Client %s completed",name.c_str());
OLMsg::Info("Client %s completed",getName().c_str());
}
// REMOTE INTERFACED Client
......@@ -915,11 +896,11 @@ void RemoteInterfacedClient::compute(){
std::string cmd,rmcmd;
std::vector<std::string> choices;
OLMsg::Info("Computes <%s>", getName().c_str());
analyze();
setAction("compute");
OLMsg::Info("Computes <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
if(getActive() && onelab::server::instance()->getChanged(getName())){
if(getList("InputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++)
syncInputFile(getWorkingDir(),choices[i]);
......@@ -939,11 +920,12 @@ void RemoteInterfacedClient::compute(){
syncOutputFile(getWorkingDir(),choices[i]);
}
if(getList("PostArray",choices))
PostArray(choices);
}
// if(getList("PostArray",choices))
// PostArray(choices);
OLMsg::Info("Client %s completed",getName().c_str());
}
// REMOTE NATIVE Client
std::string RemoteNativeClient::buildCommandLine(){
......@@ -978,11 +960,10 @@ void RemoteNativeClient::compute(){
std::string cmd,rmcmd;
std::vector<std::string> choices;
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str());
analyze();
setAction("compute");
OLMsg::Info("Analyze <%s> changed=%d", getName().c_str(),
onelab::server::instance()->getChanged(getName()));
if(getActive() && onelab::server::instance()->getChanged(getName())){
if(getList("InputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++)
syncInputFile(getWorkingDir(),choices[i]);
......@@ -1000,9 +981,48 @@ void RemoteNativeClient::compute(){
syncOutputFile(getWorkingDir(),choices[i]);
}
if(getList("PostArray",choices))
PostArray(choices);
// if(getList("PostArray",choices))
// PostArray(choices);
OLMsg::Info("Client %s completed",getName().c_str());
}
// REMOTE ENCAPSULATED Client
bool RemoteEncapsulatedClient::checkCommandLine(){
return remoteClient::checkCommandLine(getCommandLine());
}
void RemoteEncapsulatedClient::compute(){
std::string cmd,rmcmd;
std::vector<std::string> choices;
OLMsg::Info("Computes <%s> changed=%d", getName().c_str());
analyze();
setAction("compute");
if(getList("InputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++)
syncInputFile(getWorkingDir(),choices[i]);
}
if(buildRmCommand(rmcmd)){
cmd.assign("ssh "+getRemoteHost()+" 'cd "+getRemoteDir()+"; "+rmcmd+"'");
mySystem(cmd);
}
cmd.assign("ssh "+getRemoteHost()+" 'cd "+getRemoteDir()+"; "
+getCommandLine()+" "+getString("Arguments")+"'");
mySystem(cmd);
if(getList("OutputFiles",choices)){
for(unsigned int i = 0; i < choices.size(); i++)
syncOutputFile(getWorkingDir(),choices[i]);
}
// if(getList("PostArray",choices))
// PostArray(choices);
OLMsg::Info("Client %s completed",getName().c_str());
}
// ONELAB additional TOOLS (no access to server in tools)
......@@ -1052,6 +1072,7 @@ int getOptions(int argc, char *argv[], parseMode &todo, std::string &commandLine
i++;
}
}
return(1);
}
std::string itoa(const int i){
......@@ -1067,7 +1088,7 @@ std::string ftoa(const double x){
}
int mySystem(std::string commandLine){
//std::cout << "mySystem<" << commandLine << ">" << std::endl;
OLMsg::Info("Calling <%s>", commandLine.c_str());
return SystemCall(commandLine.c_str(), true);
}
......@@ -1113,8 +1134,8 @@ std::string sanitize(const std::string &in)
}
std::string removeBlanks(const std::string &in)
{
int pos0=in.find_first_not_of(" ");
int pos=in.find_last_not_of(" ");
size_t pos0=in.find_first_not_of(" ");
size_t pos=in.find_last_not_of(" ");
if( (pos0 != std::string::npos) && (pos != std::string::npos))
return in.substr(pos0,pos-pos0+1);
else
......@@ -1122,38 +1143,37 @@ std::string removeBlanks(const std::string &in)
}
bool isPath(const std::string &in)
{
int pos=in.find_last_not_of(" 0123456789");
size_t pos=in.find_last_not_of(" 0123456789");
if(in.compare(pos,1,dirSep))
OLMsg::Fatal("The argument <%s> is not a valid path (must end with '/')",in.c_str());
return true;
}
std::vector <double> extract_column(const int col, array data){
std::vector<double> column;
for ( int i=0; i<data.size(); i++)
if ( col>0 && col<=data[i].size())
column.push_back(data[i][col-1]);
else
OLMsg::Fatal("Column number (%d) out of range.",col);
return column;
}
// std::vector <double> extract_column(const unsigned int col, const array data){
// std::vector<double> column;
// for(unsigned int i=0; i<data.size(); i++)
// if(col<=data[i].size())
// column.push_back(data[i][col-1]);
// else
// OLMsg::Fatal("Column number (%d) out of range.",col);
// return column;
// }
double find_in_array(int lin, int col, const std::vector <std::vector <double> > &data){
if ( lin<0 ) {
lin=data.size();
}
if ( lin>=1 && lin<=data.size()){
if ( col>=1 && col<=data[lin-1].size() )
return data[lin-1][col-1];
if(lin<0) lin=(int)data.size()-1;
if(lin<(int)data.size()){
if ( col>=0 && col<(int)data[lin].size() )
return data[lin][col];
}
OLMsg::Fatal("The value has not been calculated: (%d,%d) out of range",lin,col);
return(0);
}
array read_array(std::string fileName, char sep){
std::ifstream infile(sanitize(fileName).c_str());
std::vector <std::vector <double> > array;
int deb,end;
size_t deb,end;
double temp;
while (infile){
std::string s;
......
......@@ -20,7 +20,6 @@ static std::string onelabExtension(".ol");
// Possible actions for clients
enum parseMode {INITIALIZE, REGISTER, ANALYZE, COMPUTE, EXIT, STOP};
static char charSep() { return '\0'; }
#if defined(WIN32)
static std::string dirSep("\\");
static std::string cmdSep(" & ");
......@@ -42,7 +41,7 @@ std::string removeBlanks(const std::string &in);
bool isPath(const std::string &in);
// Parser TOOLS
int enclosed(const std::string &in, std::vector<std::string> &arguments);
int enclosed(const std::string &in, std::vector<std::string> &arguments, size_t &end);
int extract(const std::string &in, std::string &paramName, std::string &action, std::vector<std::string> &arguments);
bool extractRange(const std::string &in, std::vector<double> &arguments);
std::string extractExpandPattern(const std::string& str);
......@@ -51,7 +50,7 @@ std::string extractExpandPattern(const std::string& str);
typedef std::vector <std::vector <double> > array;
array read_array(std::string fileName, char sep);
double find_in_array(int i, int j, const std::vector <std::vector <double> > &data);
std::vector<double> extract_column(const int j, array data);
//std::vector<double> extract_column(const int j, array data);
static std::string getShortName(const std::string &name) {
std::string s = name;
......@@ -219,8 +218,12 @@ class remoteClient {
class MetaModel : public localSolverClient {
private:
// clients in order of appearance in the metamodel
std::vector<localSolverClient *> _clients;
// action performed at this metamodel call
parseMode _todo;
// remains false as long as the clients do not need recomputation
bool _started;
public:
MetaModel(const std::string &cmdl, const std::string &wdir, const std::string &cname, const std::string &fname)
: localSolverClient(cname,cmdl,wdir){
......@@ -228,6 +231,7 @@ class MetaModel : public localSolverClient {
genericNameFromArgs = fname.size() ? fname : cmdl;
setWorkingDir(wdir); // wdir from args
_todo=REGISTER;
_started=false;
construct();
}
~MetaModel(){}
......@@ -235,6 +239,7 @@ class MetaModel : public localSolverClient {
void setTodo(const parseMode x) { _todo=x; }
parseMode getTodo() { return _todo; }
bool isTodo(const parseMode x) { return (_todo==x);}
bool isStarted(bool x) { _started = _started || x; return _started; }
citer firstClient(){ return _clients.begin(); }
citer lastClient(){ return _clients.end(); }
int getNumClients() { return _clients.size(); };
......@@ -253,7 +258,7 @@ class MetaModel : public localSolverClient {
std::string genericNameFromArgs, clientName;
void client_sentence(const std::string &name, const std::string &action,
const std::vector<std::string> &arguments);
std::string toChar(){}
std::string toChar(){ return "";}
void PostArray(std::vector<std::string> choices);
void construct();
void analyze();
......@@ -320,6 +325,15 @@ public:
void compute() ;
};
class RemoteEncapsulatedClient : public EncapsulatedClient, public remoteClient {
public:
RemoteEncapsulatedClient(const std::string &name, const std::string &cmdl, const std::string &wdir, const std::string &host, const std::string &rdir)
: EncapsulatedClient(name,cmdl,wdir), remoteClient(host,rdir) {}
~RemoteEncapsulatedClient(){}
bool checkCommandLine();
void compute() ;
};
#endif
......@@ -24,10 +24,10 @@ namespace olkey{
}
int enclosed(const std::string &in, std::vector<std::string> &arguments,
int &end){
size_t &end){
// syntax: (arguments[Ø], arguments[1], ... , arguments[n])
// arguments[i] may contain parenthesis
int pos, cursor;
size_t pos, cursor;
arguments.resize(0);
cursor=0;
if ( (pos=in.find("(",cursor)) == std::string::npos )
......@@ -66,7 +66,7 @@ int enclosed(const std::string &in, std::vector<std::string> &arguments,
int extractLogic(const std::string &in, std::vector<std::string> &arguments){
// syntax: ( argument[0], argument[1]\in{<,>,<=,>=,==,!=}, arguments[2])
int pos, cursor;
size_t pos, cursor;
arguments.resize(0);
cursor=0;
if ( (pos=in.find("(",cursor)) == std::string::npos )
......@@ -109,7 +109,7 @@ int extractLogic(const std::string &in, std::vector<std::string> &arguments){
int extract(const std::string &in, std::string &paramName,
std::string &action, std::vector<std::string> &arguments){
// syntax: paramName.action( arg1, arg2, ... )
int pos, cursor;
size_t pos, cursor;
cursor=0;
if ( (pos=in.find(".",cursor)) == std::string::npos )
OLMsg::Fatal("Syntax error: <%s>",in.c_str());
......@@ -126,7 +126,7 @@ int extract(const std::string &in, std::string &paramName,
bool extractRange(const std::string &in, std::vector<double> &arguments){
// syntax: a:b:c or a:b#n
int pos, cursor;
size_t pos, cursor;
arguments.resize(0);
cursor=0;
if ( (pos=in.find(":",cursor)) == std::string::npos )
......@@ -150,7 +150,7 @@ bool extractRange(const std::string &in, std::vector<double> &arguments){
}
std::string extractExpandPattern(const std::string& str){
int posa,posb;
size_t posa, posb;
posa=str.find_first_of("\"\'<");
posb=str.find_last_of("\"\'>");
std::string pattern=str.substr(posa+1,posb-posa-1);
......@@ -170,7 +170,6 @@ std::string localSolverClient::longName(const std::string name){
fullName.assign(OLMsg::obtainFullName(*it));
else
fullName.assign(OLMsg::obtainFullName(name));
//std::cout << "Full name=<" << name << "> => <" << fullName << ">" << std::endl;
return fullName;
}
......@@ -179,7 +178,7 @@ std::string localSolverClient::resolveGetVal(std::string line) {
std::vector<onelab::string> strings;
std::vector<std::string> arguments;
std::string buff;
int pos,pos0,cursor;
size_t pos, pos0, cursor;
cursor=0;
while ( (pos=line.find(olkey::getValue,cursor)) != std::string::npos){
......@@ -214,7 +213,7 @@ std::string localSolverClient::resolveGetVal(std::string line) {
}
else if(!action.compare("comp")) {
int i=atoi(args[0].c_str());
if( (i>=0) && (i<choices.size()) )
if( (i>=0) && (i<(int)choices.size()) )
Num << choices[i];
buff.assign(ftoa(choices[i]));
}
......@@ -241,10 +240,13 @@ std::string localSolverClient::resolveGetVal(std::string line) {
action.c_str(),olkey::getValue.c_str());
}
else if(!name.compare("range")) {
double stp, min, max;
if( ((stp=numbers[0].getStep()) == 0) ||
((min=numbers[0].getMin()) ==-onelab::parameter::maxNumber()) ||
((max=numbers[0].getMax()) ==onelab::parameter::maxNumber()) )
double stp=numbers[0].getStep();
double min=numbers[0].getMin();
double max=numbers[0].getMax();
if( (stp == 0) ||
(min == -onelab::parameter::maxNumber()) ||
(max == onelab::parameter::maxNumber()) )
OLMsg::Fatal("Invalid range description for parameter <%s>",
paramName.c_str());
if(!action.compare("size")) {
......@@ -279,7 +281,7 @@ std::string localSolverClient::resolveGetVal(std::string line) {
// Check now wheter the line contains OL.mathex and resolve them
cursor=0;
while ( (pos=line.find(olkey::mathex,cursor)) != std::string::npos){
int pos0=pos;
size_t pos0=pos;
cursor=pos+olkey::mathex.length();
if(enclosed(line.substr(cursor),arguments,pos) != 1)
OLMsg::Fatal("Misformed %s statement: <%s>",
......@@ -302,13 +304,12 @@ std::string localSolverClient::resolveGetVal(std::string line) {
bool localSolverClient::resolveLogicExpr(std::vector<std::string> arguments) {
std::vector<onelab::number> numbers;
double val1, val2;
bool condition;
bool condition=false;
val1 = atof( resolveGetVal(arguments[0]).c_str() );
if(arguments.size()==1)
return (bool)val1;
if(arguments.size()==3){
condition=(bool)val1;
else if(arguments.size()==3){
val2=atof( resolveGetVal(arguments[2]).c_str() );
if(!arguments[1].compare("<"))
condition = (val1<val2);
......@@ -322,13 +323,16 @@ bool localSolverClient::resolveLogicExpr(std::vector<std::string> arguments) {
condition = (val1==val2);
else if (!arguments[1].compare("!="))
condition = (val1!=val2);
else
OLMsg::Fatal("Unknown logical operator <%s>", arguments[1].c_str());
}
else
OLMsg::Fatal("Invalid logical expression");
return condition;
}
void localSolverClient::parse_sentence(std::string line) {
int pos,cursor,NumArg;
size_t pos,cursor;
std::string name,action,path;
std::vector<std::string> arguments;
std::vector<onelab::number> numbers;
......@@ -535,7 +539,7 @@ void localSolverClient::parse_sentence(std::string line) {
strings[0].setValue("");
else
strings[0].setValue(arguments[0]);
numbers[0].setReadOnly(1);
strings[0].setReadOnly(1);
set(strings[0]);
}
else{
......@@ -665,7 +669,7 @@ void localSolverClient::modify_tags(const std::string lab, const std::string com
}
void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
int pos,cursor;
size_t pos,cursor;
std::vector<std::string> arguments;
std::vector<onelab::number> numbers;
std::vector<onelab::string> strings;
......@@ -742,7 +746,7 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) {
// onelab.ifcond
cursor = pos+olkey::ifcond.length();
int NumArgs=extractLogic(line.substr(cursor),arguments);
extractLogic(line.substr(cursor),arguments);
bool condition= resolveLogicExpr(arguments);
if (!parse_ifstatement(infile,condition)){
OLMsg::Fatal("Misformed %s statement: <%s>",
......@@ -814,7 +818,8 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
// either any other line within a onelabBlock or a line
// introduced by a "onelab.line" tag not within a onelabBlock
std::string cmds="",cmd;
int posa, posb, NbLines=1;
size_t posa, posb;
int NbLines=1;
do{
if( (pos=line.find(olkey::line)) != std::string::npos)
posa=pos + olkey::line.size();
......@@ -872,7 +877,7 @@ void localSolverClient::parse_oneline(std::string line, std::ifstream &infile) {
}
bool localSolverClient::parse_block(std::ifstream &infile) {
int pos;
size_t pos;
std::string line;
openOnelabBlock();
while (infile.good()){
......@@ -888,7 +893,8 @@ bool localSolverClient::parse_block(std::ifstream &infile) {
bool localSolverClient::parse_ifstatement(std::ifstream &infile,
bool condition) {
int level, pos;
int level;
size_t pos;
std::string line;
bool trueclause=true;
......@@ -914,7 +920,6 @@ bool localSolverClient::parse_ifstatement(std::ifstream &infile,
}
void localSolverClient::parse_onefile(std::string fileName, bool mandatory) {
int pos;
std::string fullName=getWorkingDir()+fileName;
std::ifstream infile(fullName.c_str());
if (infile.is_open()){
......@@ -934,7 +939,8 @@ void localSolverClient::parse_onefile(std::string fileName, bool mandatory) {
}
bool localSolverClient::convert_ifstatement(std::ifstream &infile, std::ofstream &outfile, bool condition) {
int level, pos;
int level;
size_t pos;
std::string line;
bool trueclause=true;
......@@ -960,7 +966,7 @@ bool localSolverClient::convert_ifstatement(std::ifstream &infile, std::ofstream
}
void localSolverClient::convert_oneline(std::string line, std::ifstream &infile, std::ofstream &outfile) {
int pos,cursor;
size_t pos,cursor;
std::vector<std::string> arguments;
std::vector<onelab::number> numbers;
std::vector<onelab::string> strings;
......@@ -1044,7 +1050,7 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
else if ( (pos=line.find(olkey::ifcond)) != std::string::npos) {
// onelab.ifcond
cursor = pos+olkey::ifcond.length();
int NumArgs=extractLogic(line.substr(cursor),arguments);
extractLogic(line.substr(cursor),arguments);
bool condition= resolveLogicExpr(arguments);
if (!convert_ifstatement(infile,outfile,condition))
OLMsg::Fatal("Misformed %s statement: <%s>", line.c_str());
......@@ -1133,7 +1139,6 @@ void localSolverClient::convert_oneline(std::string line, std::ifstream &infile,
}
void localSolverClient::convert_onefile(std::string fileName, std::ofstream &outfile) {
int pos;
std::string fullName=getWorkingDir()+fileName;
std::ifstream infile(fullName.c_str());
if (infile.is_open()){
......@@ -1197,15 +1202,6 @@ void MetaModel::client_sentence(const std::string &name,
if(isTodo(REGISTER)){
if(arguments[0].size()){
OLMsg::SetOnelabString(name + "/CommandLine",arguments[0],false);
// get(strings, name);
// if(strings.empty()){
// strings.resize(1);
// strings[0].setName(name + "/CommandLine");
// strings[0].setValue(arguments[0]);
// strings[0].setKind("file");
// strings[0].setVisible(false);
// set(strings[0]);
// }
}
else
OLMsg::Error("No pathname given for client <%s>", name.c_str());
......@@ -1213,7 +1209,7 @@ void MetaModel::client_sentence(const std::string &name,
}
else if(!action.compare("workingDir")){
localSolverClient *c;
if(c=findClientByName(name))
if((c=findClientByName(name)))
c->setWorkingDir(c->getWorkingDir()+arguments[0]);
else
OLMsg::Fatal("Unknown client <%s>", name.c_str());
......@@ -1221,7 +1217,7 @@ void MetaModel::client_sentence(const std::string &name,
else if(!action.compare("active")){
localSolverClient *c;
if(arguments[0].size()){
if(c=findClientByName(name))
if((c=findClientByName(name)))
c->setActive(atof( resolveGetVal(arguments[0]).c_str() ));
else
OLMsg::Fatal("Unknown client <%s>", name.c_str());
......@@ -1288,13 +1284,19 @@ void MetaModel::client_sentence(const std::string &name,
}
else if(isTodo(ANALYZE)){
localSolverClient *c;
if(c=findClientByName(name)) c->analyze();
if((c=findClientByName(name))) c->analyze();
}
else if(isTodo(COMPUTE)){
localSolverClient *c;
if(c=findClientByName(name)){
c->analyze();
c->compute();
if((c=findClientByName(name))){
if(c->getActive()){
bool changed = onelab::server::instance()->getChanged(c->getName());
bool started = isStarted(changed);
std::cout << c->getName() << " active=" << c->getActive() << " changed=" << changed << " started=" << started << std::endl;
if(started) c->compute();
}
}
}
}
......@@ -1325,7 +1327,7 @@ void MetaModel::client_sentence(const std::string &name,
choices.push_back(str);
}
localSolverClient *c;
if(c=findClientByName(name)) c->PostArray(choices);
if((c=findClientByName(name))) c->PostArray(choices);
}
}
else
......@@ -1334,7 +1336,7 @@ void MetaModel::client_sentence(const std::string &name,
}
else if(!action.compare("check")){
localSolverClient *c;
if(c=findClientByName(name)){
if((c=findClientByName(name))){
c->checkCommandLine();
c->analyze();
}
......@@ -1343,7 +1345,7 @@ void MetaModel::client_sentence(const std::string &name,
}
else if(!action.compare("compute")){
localSolverClient *c;
if(c=findClientByName(name)){
if((c=findClientByName(name))){
c->checkCommandLine();
if(isTodo(REGISTER))
c->analyze(); // computes nothing at registration
......@@ -1362,7 +1364,7 @@ void MetaModel::client_sentence(const std::string &name,
choices.push_back(resolveGetVal(arguments[i]));
}
localSolverClient *c;
if(c=findClientByName(name)) {
if((c=findClientByName(name))) {
OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false);
c->GmshMerge(choices);
}
......@@ -1374,7 +1376,7 @@ void MetaModel::client_sentence(const std::string &name,
choices.push_back(resolveGetVal(arguments[i]));
}
localSolverClient *c;
if(c=findClientByName(name)) {
if((c=findClientByName(name))) {
c->checkCommandLine();
if(isTodo(REGISTER))
c->analyze(); // computes nothing at registration
......
......@@ -16,6 +16,7 @@ void initializeMetamodel(onelab::client *client, void (*gui_wait_fct)(double tim
int metamodel(const std::string &action){
OLMsg::Info("Start metamodel");
OLMsg::hasGmsh = OLMsg::GetOnelabNumber("IsMetamodel");
parseMode todo;
if(action == "initialize")
......@@ -33,9 +34,6 @@ int metamodel(const std::string &action){
std::string workingDir = OLMsg::GetOnelabString("Arguments/WorkingDir");
std::string clientName = "meta";
std::cout << "FHF ModelName=" << modelName << std::endl;
std::cout << "FHF WorkingDir=" << workingDir << std::endl;
MetaModel *myModel =
new MetaModel(clientName, workingDir, clientName, modelName);
myModel->setTodo(todo);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment