Skip to content
Snippets Groups Projects
Commit c44e54c3 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better handling of .pro + refactor server start

parent 83a9d4f7
No related branches found
No related tags found
No related merge requests found
...@@ -405,8 +405,8 @@ int MergeFile(const std::string &fileName, bool warnIfMissing) ...@@ -405,8 +405,8 @@ int MergeFile(const std::string &fileName, bool warnIfMissing)
#if defined(HAVE_ONELAB) && defined(HAVE_FLTK) #if defined(HAVE_ONELAB) && defined(HAVE_FLTK)
else if(ext == ".pro" && opt_solver_name(0, GMSH_GET, "") == "GetDP"){ else if(ext == ".pro" && opt_solver_name(0, GMSH_GET, "") == "GetDP"){
std::vector<std::string> split = SplitFileName(fileName); std::vector<std::string> split = SplitFileName(fileName);
GModel::current()->setName(""); GModel::current()->setName(split[1] + ".geo");
status = MergeFile(split[0] + split[1] + ".geo"); GModel::current()->setFileName(split[0] + split[1] + ".geo");
CTX::instance()->launchSolverAtStartup = 0; CTX::instance()->launchSolverAtStartup = 0;
return status; return status;
} }
...@@ -417,6 +417,7 @@ int MergeFile(const std::string &fileName, bool warnIfMissing) ...@@ -417,6 +417,7 @@ int MergeFile(const std::string &fileName, bool warnIfMissing)
status = metamodel_cb(fileName); status = metamodel_cb(fileName);
} }
else if(ext == ".py"){ else if(ext == ".py"){
// FIXME: should use launchSolverAtStartup
FlGui::instance()->onelab->addSolver("python", fileName, "", 1); FlGui::instance()->onelab->addSolver("python", fileName, "", 1);
onelab_cb(0, (void*)"check"); onelab_cb(0, (void*)"check");
status = 1; status = 1;
......
...@@ -97,6 +97,50 @@ class onelabGmshServer : public GmshServer{ ...@@ -97,6 +97,50 @@ class onelabGmshServer : public GmshServer{
} }
} }
} }
int LaunchClient()
{
std::string sockname;
std::ostringstream tmp;
if(!strstr(CTX::instance()->solver.socketName.c_str(), ":")){
// Unix socket
tmp << CTX::instance()->homeDir << CTX::instance()->solver.socketName
<< _client->getId();
sockname = FixWindowsPath(tmp.str());
}
else{
// TCP/IP socket
if(CTX::instance()->solver.socketName.size() &&
CTX::instance()->solver.socketName[0] == ':')
tmp << GetHostName(); // prepend hostname if only the port number is given
tmp << CTX::instance()->solver.socketName << _client->getId();
sockname = tmp.str();
}
std::string command = FixWindowsPath(_client->getExecutable());
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(" " + _client->getSocketSwitch() +
" \"" + _client->getName() + "\" %s");
}
else{
Msg::Info("Listening on socket '%s'", sockname.c_str());
}
int sock;
try{
sock = Start(command.c_str(), sockname.c_str(),
CTX::instance()->solver.timeout);
}
catch(const char *err){
Msg::Error("Abnormal server termination (%s on socket %s)", err,
sockname.c_str());
sock = -1;
}
return sock;
}
}; };
bool gmshLocalNetworkClient::receiveMessage() bool gmshLocalNetworkClient::receiveMessage()
...@@ -339,46 +383,10 @@ bool gmshLocalNetworkClient::run() ...@@ -339,46 +383,10 @@ bool gmshLocalNetworkClient::run()
onelabGmshServer *server = new onelabGmshServer(this); onelabGmshServer *server = new onelabGmshServer(this);
std::string sockname; int sock = server->LaunchClient();
std::ostringstream tmp;
if(!strstr(CTX::instance()->solver.socketName.c_str(), ":")){
// Unix socket
tmp << CTX::instance()->homeDir << CTX::instance()->solver.socketName << getId();
sockname = FixWindowsPath(tmp.str());
}
else{
// TCP/IP socket
if(CTX::instance()->solver.socketName.size() &&
CTX::instance()->solver.socketName[0] == ':')
tmp << GetHostName(); // prepend hostname if only the port number is given
tmp << CTX::instance()->solver.socketName << getId();
sockname = tmp.str();
}
std::string command = FixWindowsPath(getExecutable());
if(command.size()){
std::vector<std::string> args = onelabUtils::getCommandLine(this);
for(unsigned int i = 0; i < args.size(); i++)
command.append(" " + args[i]);
command.append(" " + getSocketSwitch() + " \"" + getName() + "\" %s");
}
else{
Msg::Info("Listening on socket '%s'", sockname.c_str());
}
int sock;
try{
sock = server->Start(command.c_str(), sockname.c_str(),
CTX::instance()->solver.timeout);
}
catch(const char *err){
Msg::Error("Abnormal server termination (%s on socket %s)", err,
sockname.c_str());
sock = -1;
}
if(sock < 0){ if(sock < 0){
// could not start the server: aborting // could not establish the connection: aborting
server->Shutdown(); server->Shutdown();
delete server; delete server;
return false; return false;
...@@ -395,7 +403,7 @@ bool gmshLocalNetworkClient::run() ...@@ -395,7 +403,7 @@ bool gmshLocalNetworkClient::run()
bool stop = false, haveData = false; bool stop = false, haveData = false;
onelab::localNetworkClient *c = 0; onelab::localNetworkClient *c = 0;
for(int i = 0; i < getNumClients(); i++){ for(int i = 0; i < getNumClients(); i++){
if(command.empty() && !CTX::instance()->solver.listen){ if(getExecutable().empty() && !CTX::instance()->solver.listen){
// we stopped listening to the special "Listen" client // we stopped listening to the special "Listen" client
stop = true; stop = true;
break; break;
...@@ -450,7 +458,7 @@ bool gmshLocalNetworkClient::run() ...@@ -450,7 +458,7 @@ bool gmshLocalNetworkClient::run()
Msg::StatusBar(true, "Done running '%s'", _name.c_str()); Msg::StatusBar(true, "Done running '%s'", _name.c_str());
if(command.empty()){ if(getExecutable().empty()){
Msg::Info("Client disconnected: starting new connection"); Msg::Info("Client disconnected: starting new connection");
goto new_connection; goto new_connection;
} }
...@@ -1759,8 +1767,10 @@ void solver_cb(Fl_Widget *w, void *data) ...@@ -1759,8 +1767,10 @@ void solver_cb(Fl_Widget *w, void *data)
if(FlGui::instance()->onelab->isBusy()) if(FlGui::instance()->onelab->isBusy())
FlGui::instance()->onelab->show(); FlGui::instance()->onelab->show();
else{ else{
if(CTX::instance()->launchSolverAtStartup >= 0) if(CTX::instance()->launchSolverAtStartup >= 0){
onelab_cb(0, (void*)"reset"); onelab_cb(0, (void*)"reset");
onelabUtils::setFirstComputationFlag(true);
}
else if(num >= 0) else if(num >= 0)
onelab_cb(0, (void*)"check"); onelab_cb(0, (void*)"check");
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment