6 #include "GmshConfig.h"
7 #if !defined(HAVE_NO_STDINT_H)
9 #elif defined(HAVE_NO_INTPTR_T)
10 typedef unsigned long intptr_t;
21 #if defined(HAVE_ONELAB)
26 #if defined(HAVE_FLTK)
28 #include "onelabGroup.h"
32 #if defined(HAVE_POST)
36 #if defined(HAVE_ONELAB_METAMODEL)
37 #include "OnelabClients.h"
38 #include "metamodel.h"
50 ~onelabGmshServer() {}
59 if(timeout > 0 &&
TimeOfDay() - start > timeout)
61 if(_client->
getPid() < 0 ||
65 #if defined(HAVE_FLTK)
66 if(FlGui::available()) {
69 ret =
Select(0, 0, socket);
72 ret =
Select(0, waitint * 1e6, socket);
75 ret =
Select(0, waitint * 1e6, socket);
78 #if defined(HAVE_FLTK)
79 if(FlGui::available()) {
83 static double lastRefresh = 0.;
84 if(start - lastRefresh > 0.25) {
85 std::vector<onelab::string> ps;
87 if(ps.size() && ps[0].getValue() ==
"refresh") {
88 ps[0].setVisible(
false);
91 if(FlGui::available()) onelab_cb(
nullptr, (
void *)
"refresh");
97 if(Fl::ready()) FlGui::wait(waitint);
101 if(timeout < 0)
return 3;
115 std::string sockname;
116 std::ostringstream tmp;
117 static bool first =
true;
138 tmp << _client->
getId();
142 sockname = tmp.str();
154 for(std::size_t i = 0; i < cl.size(); i++) args.append(
" " + cl[i]);
160 Msg::Info(
"Listening on socket '%s'", sockname.c_str());
166 }
catch(std::runtime_error &e) {
167 Msg::Error(
"Abnormal server termination (%s on socket %s)",
168 e.what(), sockname.c_str());
176 static std::string tryToGetGmshNumberOption(
const std::string &name)
179 std::string::size_type
dot = name.find(
'.');
180 if(
dot != std::string::npos) {
184 reply = par.toChar();
190 static std::string tryToGetGmshStringOption(
const std::string &name)
193 std::string::size_type
dot = name.find(
'.');
194 if(
dot != std::string::npos) {
198 reply = par.toChar();
206 const std::string &name = p.
getName();
207 std::string::size_type
dot = name.find(
'.');
208 if(
dot != std::string::npos) {
217 const std::string &name = p.
getName();
218 std::string::size_type
dot = name.find(
'.');
219 if(
dot != std::string::npos) {
220 const std::string &val = p.
getValue();
226 bool gmshLocalNetworkClient::receiveMessage(gmshLocalNetworkClient *master)
233 if(!getGmshServer()) {
234 Msg::Error(
"Abnormal server termination (no valid server)");
239 if(!getGmshServer()->ReceiveHeader(&type, &
length, &
swap)) {
240 Msg::Error(
"Abnormal server termination (did not receive message header)");
244 std::string message(
length,
' '), blank = message;
245 if(!getGmshServer()->ReceiveMessage(
length, &message[0])) {
246 Msg::Error(
"Abnormal server termination (did not receive message body)");
250 if(message == blank &&
255 "Abnormal server termination (blank message: client not stopped?)");
264 std::string reply = getName();
266 (
int)reply.size(), &reply[0]);
272 std::string version, ptype, name;
275 Msg::Error(
"ONELAB version mismatch (server: %s / client: %s)",
278 else if(ptype ==
"number") {
281 if(!tryToSetGmshNumberOption(p)) {
284 std::vector<onelab::number> par;
286 std::vector<double>
c;
287 if(par.size())
c = par[0].getChoices();
292 std::vector<onelab::number> par;
301 if(p.
getName() == getName() +
"/Progress") {
302 #if defined(HAVE_FLTK)
303 if(FlGui::available())
310 else if(ptype ==
"string") {
313 if(!tryToSetGmshStringOption(p)) {
316 std::vector<onelab::string> par;
318 std::vector<std::string>
c;
319 if(par.size())
c = par[0].getChoices();
324 std::vector<onelab::string> par;
336 Msg::Error(
"Unknown ONELAB parameter type: %s", ptype.c_str());
340 std::string version, ptype, name, reply;
343 Msg::Error(
"ONELAB version mismatch (server: %s / client: %s)",
346 else if(ptype ==
"number") {
347 std::vector<onelab::number> par;
349 getWithoutChoices(par, name);
353 reply = tryToGetGmshNumberOption(name);
355 reply = par[0].toChar();
357 else if(ptype ==
"string") {
358 std::vector<onelab::string> par;
360 getWithoutChoices(par, name);
364 reply = tryToGetGmshStringOption(name);
366 reply = par[0].toChar();
369 Msg::Error(
"Unknown ONELAB parameter type in query: %s", ptype.c_str());
373 (
int)reply.size(), &reply[0]);
378 (
int)reply.size(), &reply[0]);
382 std::string version, ptype, name, reply;
383 std::vector<std::string> replies;
386 Msg::Error(
"ONELAB version mismatch (server: %s / client: %s)",
389 else if(ptype ==
"number") {
390 std::vector<onelab::number> numbers;
392 for(
auto it = numbers.begin();
393 it != numbers.end(); it++)
394 replies.push_back((*it).toChar());
396 else if(ptype ==
"string") {
397 std::vector<onelab::string> strings;
399 for(
auto it = strings.begin();
400 it != strings.end(); it++)
401 replies.push_back((*it).toChar());
404 Msg::Error(
"Unknown ONELAB parameter type in query: %s", ptype.c_str());
406 for(std::size_t i = 0; i < replies.size(); i++)
408 (
int)replies[i].size(), &replies[i][0]);
409 reply =
"Sent all ONELAB " + ptype +
"s";
411 (
int)reply.size(), &reply[0]);
414 clear(message ==
"*" ?
"" : message);
420 Msg::Direct(
"Info : %s - %s", _name.c_str(), message.c_str());
423 Msg::Warning(
"%s - %s", _name.c_str(), message.c_str());
426 Msg::Error(
"%s - %s", _name.c_str(), message.c_str());
430 #if defined(HAVE_FLTK)
437 #if defined(HAVE_FLTK)
439 if(FlGui::available() && n !=
PView::list.size()) {
440 FlGui::instance()->rebuildTree(
true);
441 FlGui::instance()->openModule(
"Post-processing");
447 #if defined(HAVE_FLTK)
452 #if defined(HAVE_FLTK)
461 #if defined(HAVE_FLTK)
464 #if defined(HAVE_POST)
467 #if defined(HAVE_FLTK)
468 if(FlGui::available())
469 FlGui::instance()->updateViews(n != (
int)
PView::list.size(),
true);
474 std::string::size_type first = 0;
477 gmshLocalNetworkClient *subClient =
478 new gmshLocalNetworkClient(clientName, command,
"",
true);
479 onelabGmshServer *server =
new onelabGmshServer(subClient);
480 subClient->setPid(0);
483 o.setNeverChanged(
true);
485 int sock = server->LaunchClient();
489 Msg::Error(
"Could not connect client '%s'", subClient->getName().c_str());
492 Msg::StatusBar(
true,
"Running '%s'...", subClient->getName().c_str());
493 subClient->setGmshServer(server);
494 subClient->setFather(
this);
495 master->addClient(subClient);
499 std::string reply =
"unavailable";
500 #if defined(HAVE_ONELAB_METAMODEL)
501 std::string::size_type first = 0;
504 preProcess(clientName, fullName);
505 Msg::Info(
"Done preprocessing file '%s'", fullName.c_str());
510 (
int)reply.size(), &reply[0]);
513 std::string::size_type first = 0;
516 if(command ==
"get") {
520 (
int)reply.size(), &reply[0]);
522 else if(command ==
"set") {
528 Msg::Warning(
"Received unknown message type (%d)", type);
536 bool gmshLocalNetworkClient::run()
541 onelabGmshServer *server =
new onelabGmshServer(
this);
543 int sock = server->LaunchClient();
554 setGmshServer(server);
564 bool stop =
false, haveData =
false;
565 gmshLocalNetworkClient *
c =
nullptr;
566 std::vector<gmshLocalNetworkClient *> toDelete;
567 for(
int i = 0; i < getNumClients(); i++) {
569 if(
c->getPid() < 0) {
578 c->setGmshServer(
nullptr);
579 c->setFather(
nullptr);
584 toDelete.push_back(
c);
590 Msg::Error(
"Abnormal server termination (no valid server)");
609 for(std::size_t i = 0; i < toDelete.size(); i++) {
610 removeClient(toDelete[i]);
620 if(haveData && !
c->receiveMessage(
this))
break;
623 if(
c ==
this &&
c->getPid() < 0)
break;
628 std::vector<gmshLocalNetworkClient *> toDelete;
629 for(
int i = 0; i < getNumClients(); i++) {
630 gmshLocalNetworkClient *
c = getClient(i);
632 c->setGmshServer(
nullptr);
633 c->setFather(
nullptr);
640 Msg::Error(
"Subclient %s was not stopped correctly",
641 c->getName().c_str());
642 toDelete.push_back(
c);
645 for(std::size_t i = 0; i < toDelete.size(); i++) {
646 removeClient(toDelete[i]);
652 if(getExecutable().empty()) {
653 Msg::Info(
"Client disconnected: starting new connection");
660 bool gmshLocalNetworkClient::kill()
665 Msg::Info(
"Killed '%s' (pid %d)", _name.c_str(), getPid());
666 #if defined(HAVE_FLTK)
667 if(FlGui::available()) FlGui::instance()->setProgress(
"Killed", 0, 0, 0);