From 4156ea563f94cdaf516ab3f01fcda609f40ee676 Mon Sep 17 00:00:00 2001 From: Francois Henrotte <francois.henrotte@ulg.ac.be> Date: Fri, 2 Nov 2012 21:24:02 +0000 Subject: [PATCH] --- contrib/onelab/OnelabClients.cpp | 135 +++++++++++++++---------------- contrib/onelab/OnelabClients.h | 5 +- contrib/onelab/OnelabMessage.h | 11 +-- contrib/onelab/OnelabParser.cpp | 43 +++++----- contrib/onelab/loader.cpp | 17 +++- contrib/onelab/metamodel.cpp | 4 - 6 files changed, 106 insertions(+), 109 deletions(-) diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index 4bfc3241f9..1f86747b48 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -18,40 +18,41 @@ class onelabMetaModelServer : public GmshServer{ : GmshServer(), _client(client) {} ~onelabMetaModelServer(){} - int NonBlockingSystemCall(const char *command) - { -#if defined(WIN32) - STARTUPINFO suInfo; - PROCESS_INFORMATION prInfo; - memset(&suInfo, 0, sizeof(suInfo)); - suInfo.cb = sizeof(suInfo); - std::string cmd(command); - OLMsg::Info("Calling <%s>", cmd.c_str()); - // DETACHED_PROCESS removes the console (useful if the program to launch is - // a console-mode exe) - CreateProcess(NULL,(char *)cmd.c_str(), NULL, NULL, FALSE, - NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL, - &suInfo, &prInfo); - return 0; -#else - if(!system(NULL)) { - OLMsg::Error("Could not find /bin/sh: aborting system call"); - return 1; - } - std::string cmd(command); - size_t pos; - if((pos=cmd.find("incomp_ssh ")) != std::string::npos){ - cmd.assign(cmd.substr(pos+7)); // remove "incomp_" - cmd.append(" & '"); - } - else - cmd.append(" & "); +// int NonBlockingSystemCall(const char *command) +// { +// #if defined(WIN32) +// STARTUPINFO suInfo; +// PROCESS_INFORMATION prInfo; +// memset(&suInfo, 0, sizeof(suInfo)); +// suInfo.cb = sizeof(suInfo); +// std::string cmd(command); +// OLMsg::Info("Calling <%s>", cmd.c_str()); +// // DETACHED_PROCESS removes the console (useful if the program to launch is +// // a console-mode exe) +// CreateProcess(NULL,(char *)cmd.c_str(), NULL, NULL, FALSE, +// NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL, +// &suInfo, &prInfo); +// return 0; +// #else +// if(!system(NULL)) { +// OLMsg::Error("Could not find /bin/sh: aborting system call"); +// return 1; +// } +// std::string cmd(command); +// size_t pos; +// if((pos=cmd.find("incomp_ssh ")) != std::string::npos){ +// cmd.assign(cmd.substr(pos+7)); // remove "incomp_" +// cmd.append(" & '"); +// } +// else +// cmd.append(" & "); - OLMsg::Info("Calling <%s>", cmd.c_str()); - return system(cmd.c_str()); -#endif - }// non blocking +// OLMsg::Info("Calling <%s>", cmd.c_str()); +// return system(cmd.c_str()); +// #endif +// }// non blocking + int NonBlockingSystemCall(const char *str){ return SystemCall(str); } int NonBlockingWait(int socket, double waitint, double timeout) { double start = GetTimeInSeconds(); @@ -66,16 +67,6 @@ 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(); @@ -160,6 +151,7 @@ bool localNetworkSolverClient::run() sockname = tmp.str(); } + _socketMsg = OLMsg::GetOnelabNumber("SHOWSOCKETMESSAGES")?true:false; std::string command = buildCommandLine(); if(command.size()) command.append(appendArguments()); @@ -178,7 +170,7 @@ bool localNetworkSolverClient::run() return false; } - OLMsg::StatusBar(2, true, "Now running client <%s>", _name.c_str()); + //OLMsg::StatusBar(2, true, "Now running client <%s>", _name.c_str()); while(1) { if(_pid < 0) break; @@ -193,16 +185,16 @@ bool localNetworkSolverClient::run() OLMsg::Error("Did not receive message header: stopping server"); break; } - // else - // std::cout << "FHF: Received header=" << type << std::endl; + else if(_socketMsg) + OLMsg::Info("Received header <%d>",type); std::string message(length, ' '); if(!server->ReceiveMessage(length, &message[0])){ OLMsg::Error("Did not receive message body: stopping server"); break; } - //else - // std::cout << "FHF: Received message=" << message << std::endl; + else if(_socketMsg) + OLMsg::Info("Received message <%s>",message.c_str()); switch (type) { case GmshSocket::GMSH_START: @@ -405,6 +397,11 @@ const bool localSolverClient::getList(const std::string type, std::vector<std::s return false; } + +/* +si cmd est un path, vérifier la présence du fichier +sinon faire un which (n'existe pas sous WIN) + */ bool localSolverClient::checkCommandLine(){ OLMsg::Info("Check command line <%s> for client <%s>", getCommandLine().c_str(), getName().c_str()); @@ -437,7 +434,8 @@ bool localSolverClient::checkCommandLine(){ char cbuf [1024]; FILE *fp; commandLine.assign(FixExecPath(getCommandLine())); - cmd.assign(whichCmd + commandLine); +#if !defined(WIN32) + cmd.assign("which " + commandLine); fp = POPEN(cmd.c_str(), "r"); if(fgets(cbuf, 1024, fp) == NULL){ OLMsg::Error("The executable <%s> does not exist", @@ -445,8 +443,11 @@ bool localSolverClient::checkCommandLine(){ PCLOSE(fp); return false; } - OLMsg::Info("The executable <%s> exists", commandLine.c_str()); + else + commandLine.assign(cbuf); PCLOSE(fp); +#endif + return checkIfPresent(sanitizeString(commandLine,"\n")); } } return true; @@ -570,11 +571,6 @@ 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 SleepInSeconds(OLMsg::GetOnelabNumber("RSYNCDELAY")); return mySystem(cmd); } @@ -775,7 +771,6 @@ void InterfacedClient::compute(){ checkIfPresentLocal(choices[i]); } } - OLMsg::Info("Client %s completed",getName().c_str()); } // NATIVE Client @@ -815,7 +810,6 @@ void NativeClient::compute() { checkIfPresentLocal(choices[i]); } } - OLMsg::Info("Client %s completed",getName().c_str()); } // ENCAPSULATED Client @@ -863,7 +857,7 @@ void EncapsulatedClient::convert() { std::string EncapsulatedClient::buildCommandLine(){ std::string cmd= FixExecPath(OLMsg::GetOnelabString("LoaderPathName")); - OLMsg::Info("command line=<%s>",cmd.c_str()); + OLMsg::Info("Loader pathname=<%s>",cmd.c_str()); return cmd; } @@ -886,17 +880,16 @@ void EncapsulatedClient::compute(){ if(buildRmCommand(cmd)) mySystem(cmd); - // the client command line is buit and stored in a onelab parameter + // the client command line is built and stored in a onelab parameter cmd.assign(""); - if(!getWorkingDir().empty()) - cmd.append("cd " + getWorkingDir() + cmdSep); + // if(!getWorkingDir().empty()) + // cmd.append("cd " + getWorkingDir() + cmdSep); cmd.append(FixExecPath(getCommandLine())); cmd.append(" " + getString("Arguments")); OLMsg::SetOnelabString(getName()+"/FullCmdLine",cmd,false); - - // the encapsulating localNetworkClient is called OLMsg::Info("Command line=<%s>",cmd.c_str()); + // the encapsulating localNetworkClient is called if(!run()) OLMsg::Error("Invalid commandline <%s> for client <%s>", FixExecPath(getCommandLine()).c_str(), getName().c_str()); @@ -906,7 +899,6 @@ void EncapsulatedClient::compute(){ checkIfPresentLocal(choices[i]); } } - OLMsg::Info("Client %s completed",getName().c_str()); } // REMOTE INTERFACED Client @@ -942,8 +934,6 @@ void RemoteInterfacedClient::compute(){ for(unsigned int i = 0; i < choices.size(); i++) syncOutputFile(getWorkingDir(),choices[i]); } - - OLMsg::Info("Client %s completed",getName().c_str()); } @@ -1007,8 +997,6 @@ void RemoteNativeClient::compute(){ for(unsigned int i = 0; i < choices.size(); i++) syncOutputFile(getWorkingDir(),choices[i]); } - - OLMsg::Info("Client %s completed",getName().c_str()); } @@ -1056,8 +1044,6 @@ void RemoteEncapsulatedClient::compute(){ for(unsigned int i = 0; i < choices.size(); i++) syncOutputFile(getWorkingDir(),choices[i]); } - - OLMsg::Info("Client %s completed",getName().c_str()); } @@ -1170,9 +1156,18 @@ std::string getUserHomedir(){ // return str; // } +std::string sanitizeString(const std::string &in, const std::string &forbidden) +{ + std::string out; + for(unsigned int i = 0; i < in.size(); i++) + if ( forbidden.find(in[i]) == std::string::npos) + out.push_back(in[i]); + return out; +} + std::string sanitize(const std::string &in) { - std::string out, forbidden(" ();"); + std::string out, forbidden(" ();\n"); for(unsigned int i = 0; i < in.size(); i++) if ( forbidden.find(in[i]) == std::string::npos) out.push_back(in[i]); diff --git a/contrib/onelab/OnelabClients.h b/contrib/onelab/OnelabClients.h index 0679361d8a..0bed40f6f9 100644 --- a/contrib/onelab/OnelabClients.h +++ b/contrib/onelab/OnelabClients.h @@ -41,6 +41,7 @@ int mySystem(std::string commandLine); std::string getCurrentWorkdir(); std::string getUserHomedir(); std::string sanitize(const std::string &in); +std::string sanitizeString(const std::string &in, const std::string &forbidden); std::string removeBlanks(const std::string &in); bool isPath(const std::string &in); std::string FixWindowsQuotes(const std::string &in); @@ -186,10 +187,12 @@ class localNetworkSolverClient : public localSolverClient{ GmshServer *_gmshServer; // flag indicating if the client is a remote one bool _remote; + // flag indicating whether socket communication should be shown + bool _socketMsg; public: localNetworkSolverClient(const std::string &name, const std::string &cmdl, const std::string &wdir) : localSolverClient(name,cmdl,wdir), _socketSwitch("-onelab"), - _pid(-1), _gmshServer(0), _remote(false) {} + _pid(-1), _gmshServer(0), _remote(false), _socketMsg(false) {} virtual ~localNetworkSolverClient(){} virtual bool isNetworkClient(){ return true; } const std::string &getSocketSwitch(){ return _socketSwitch; } diff --git a/contrib/onelab/OnelabMessage.h b/contrib/onelab/OnelabMessage.h index 9ce6245fd6..079e570f7b 100644 --- a/contrib/onelab/OnelabMessage.h +++ b/contrib/onelab/OnelabMessage.h @@ -69,8 +69,8 @@ class OLMsg { /* static int GetNumThreads(); */ /* static int GetMaxThreads(); */ /* static int GetThreadNum(); */ - /* static void SetVerbosity(int val){ _verbosity = val; } */ - /* static int GetVerbosity(){ return _verbosity; } */ + static void SetVerbosity(int val){ _verbosity = val; } + static int GetVerbosity(){ return _verbosity; } /* static std::string GetLaunchDate(){ return _launchDate; } */ /* static std::string GetCommandLineArgs(){ return _commandLine; } */ static void Fatal(const char *fmt, ...); @@ -128,13 +128,6 @@ class OLMsg { std::map<std::string, std::vector<std::string> > &copt); static void MergeFile(const std::string &name); - - //static void AddOnelabNumberChoice(std::string name, double val); - // communication with loader - //static onelab::remoteNetworkClient *loader; - //static int Synchronize_Down(); - //static int Synchronize_Up(); - static bool hasGmsh; static void recordFullName(const std::string &name); static std::string obtainFullName(const std::string &name); diff --git a/contrib/onelab/OnelabParser.cpp b/contrib/onelab/OnelabParser.cpp index b7c1f8fb20..994c239b55 100644 --- a/contrib/onelab/OnelabParser.cpp +++ b/contrib/onelab/OnelabParser.cpp @@ -105,7 +105,7 @@ void MetaModel::saveCommandLines(const std::string fileName){ outfile << "(LoaderPathName) == "; outfile << loaderPathName << ")" << std::endl; for(citer it = _clients.begin(); it != _clients.end(); it++) - if((*it)->checkCommandLine()) + //if((*it)->checkCommandLine()) outfile << (*it)->toChar(); outfile << olkey::olendif << std::endl; @@ -1350,9 +1350,6 @@ void MetaModel::client_sentence(const std::string &name, set(str); } } - - if((!type.compare(0,6,"encaps")) && (!OLMsg::hasGmsh)) - type.assign("interf"); registerClient(name,type,cmdl,host,rdir); } else @@ -1377,8 +1374,10 @@ 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() )); + onelab::server::instance()->setChanged(true, c->getName()); + } else OLMsg::Error("Unknown client <%s>", name.c_str()); } @@ -1536,23 +1535,23 @@ void MetaModel::client_sentence(const std::string &name, } } else if(!action.compare("frontPage")){ - std::vector<std::string> choices; - for(unsigned int i = 0; i < arguments.size(); i++){ - choices.push_back(resolveGetVal(arguments[i])); - } - localSolverClient *c; - if((c=findClientByName(name))) { - if(isTodo(REGISTER) && !OLMsg::GetErrorCount()) - if(onelab::server::instance()->getChanged(c->getName())){ - c->compute(); - c->GmshMerge(choices); - OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false); - //onelab::server::instance()->setChanged(false, c->getName()); - } + if(OLMsg::hasGmsh){ + std::vector<std::string> choices; + for(unsigned int i = 0; i < arguments.size(); i++){ + choices.push_back(resolveGetVal(arguments[i])); + } + localSolverClient *c; + if((c=findClientByName(name))) { + if(isTodo(REGISTER) && !OLMsg::GetErrorCount()) + if(onelab::server::instance()->getChanged(c->getName())){ + c->compute(); + c->GmshMerge(choices); + OLMsg::SetOnelabNumber("Gmsh/NeedReloadGeom",1,false); + //onelab::server::instance()->setChanged(false, c->getName()); + } + } + else + OLMsg::Error("Unknown client <%s>", name.c_str()); } - else - OLMsg::Error("Unknown client <%s>", name.c_str()); } - else - OLMsg::Error("Unknown action <%s>",action.c_str()); } diff --git a/contrib/onelab/loader.cpp b/contrib/onelab/loader.cpp index c5fea65c0b..20112776f7 100644 --- a/contrib/onelab/loader.cpp +++ b/contrib/onelab/loader.cpp @@ -217,7 +217,7 @@ bool menu() { } void PrintUsage(const char *name){ - printf("\nUsage: %s [-a -i] modelName\n", name); + printf("\nUsage: %s [-a -i -h -v int] modelName\n", name); exit(1); } @@ -237,7 +237,7 @@ int main(int argc, char *argv[]){ i++; launchMenu=true; } - else if(!strcmp(argv[i] + 1, "onelab")) { + else if(!strcmp(argv[i] + 1, "lol")) { std::string clientName=argv[i+1]; client = new onelab::remoteNetworkClient(clientName,argv[i+2]); if(client){ @@ -261,12 +261,23 @@ int main(int argc, char *argv[]){ else OLMsg::Info("No full command line found for <%s>", clientName.c_str()); + //OLMsg::Info("Stopping client <%s>", clientName.c_str()); } - OLMsg::Info("Stopping client <%s>", clientName.c_str()); delete client; } exit(1); } + else if(!strcmp(argv[i] + 1, "v")) { + i++; + if(argv[i]) + OLMsg::SetVerbosity(atoi(argv[i++])); + else + OLMsg::Fatal("Missing number"); + } + else { + i++; + PrintUsage(argv[0]); + } } else { caseName=argv[i]; diff --git a/contrib/onelab/metamodel.cpp b/contrib/onelab/metamodel.cpp index 7777b50eb0..c2281ce8cd 100644 --- a/contrib/onelab/metamodel.cpp +++ b/contrib/onelab/metamodel.cpp @@ -11,7 +11,6 @@ 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); } @@ -24,9 +23,6 @@ int metamodel(const std::string &action){ OLMsg::ResetErrorCounter(); parseMode todo; - // if(action == "initialize") - // todo = INITIALIZE; - if(action == "compute") todo = COMPUTE; else{ -- GitLab