gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
onelab.h
Go to the documentation of this file.
1 // ONELAB - Copyright (C) 2011-2022 Universite de Liege - Universite catholique
2 // de Louvain
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, and/or sell copies of the
8 // Software, and to permit persons to whom the Software is furnished to do so,
9 // provided that the above copyright notice(s) and this permission notice appear
10 // in all copies of the Software and that both the above copyright notice(s) and
11 // this permission notice appear in supporting documentation.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
16 // RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
17 // NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
18 // DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
19 // PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 // ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21 // SOFTWARE.
22 
23 #ifndef ONELAB_H
24 #define ONELAB_H
25 
26 #include <time.h>
27 #include <stdio.h>
28 #include <string>
29 #include <vector>
30 #include <set>
31 #include <map>
32 #include <iostream>
33 #include <algorithm>
34 #include <sstream>
35 #include <mutex>
36 #include <regex>
37 
38 #include "GmshSocket.h"
39 
40 #define HAVE_PICOJSON
41 #if defined(HAVE_PICOJSON)
42 #include "picojson.h"
43 #endif
44 
45 namespace onelab {
46 
47  // The base parameter class.
48  class parameter {
49  private:
50  // the name of the parameter, including its '/'-separated path in the
51  // parameter hierarchy. Subpaths can start with white space, numbers or
52  // braces (in that order) to force their relative ordering; getShortName()
53  // can be used to remove these prefixes automatically. All strings in ONELAB
54  // are supposed to be UTF8-encoded.
55  std::string _name;
56  // the parameter label: if provided it serves as a better way to display the
57  // parameter in the interface
58  std::string _label;
59  // a help string
60  std::string _help;
61  // map of clients that use this parameter, associated with a "changed" flag
62  // (set to 0 if the client has already been run with the current value of
63  // the parameter; set to defaultChangedValue() when the value of a parameter
64  // has been changed; values between 1 and defaultChangedValue() can be used
65  // to "modulate" the degree of change, e.g. to change the action to be
66  // performed depending on the "severity" of the change)
67  std::map<std::string, int> _clients;
68  // flag indicating what the "changed" value should be set to when a
69  // parameter is updated to a different value (if set to 0, the parameter
70  // will appear as never being changed)
72  // should the parameter be visible in the interface?
73  bool _visible;
74  // sould the paramete be "read-only" (not settable by the user)
75  bool _readOnly;
76 
77  protected:
78  // optional additional attributes
79  std::map<std::string, std::string> _attributes;
80 
81  public:
82  parameter(const std::string &name = "", const std::string &label = "",
83  const std::string &help = "")
84  : _name(name), _label(label), _help(help), _visible(true),
85  _readOnly(false)
86  {
88  }
89  virtual ~parameter() {}
90  void setName(const std::string &name) { _name = name; }
91  void setLabel(const std::string &label) { _label = label; }
92  void setHelp(const std::string &help) { _help = help; }
93  void setChanged(int changed, const std::string &client = "")
94  {
95  if(client.size()) {
96  auto it = _clients.find(client);
97  if(it != _clients.end()) it->second = changed;
98  }
99  else {
100  for(auto it = _clients.begin(); it != _clients.end(); it++)
101  it->second = changed;
102  }
103  }
104  void setChangedValue(int value) { _changedValue = value; }
105  void setNeverChanged(bool never)
106  {
107  _changedValue = never ? 0 : defaultChangedValue();
108  }
109  void setVisible(bool visible) { _visible = visible; }
110  void setReadOnly(bool readOnly) { _readOnly = readOnly; }
111  void setAttribute(const std::string &key, const std::string &value)
112  {
113  _attributes[key] = value;
114  }
115  void setAttributes(const std::map<std::string, std::string> &attributes)
116  {
117  _attributes = attributes;
118  }
119  void setClients(const std::map<std::string, int> &clients)
120  {
121  _clients = clients;
122  }
123  void addClient(const std::string &client, int changed)
124  {
125  if(_clients.find(client) == _clients.end()) _clients[client] = changed;
126  }
127  void addClients(const std::map<std::string, int> &clients)
128  {
129  _clients.insert(clients.begin(), clients.end());
130  }
131  bool hasClient(const std::string &client)
132  {
133  return (_clients.find(client) != _clients.end());
134  }
135  int getNumClients() { return (int)_clients.size(); };
136  virtual std::string getType() const = 0;
137  const std::string &getName() const { return _name; }
138  const std::string &getLabel() const { return _label; }
139  const std::string &getHelp() const { return _help; }
140  std::string getPath() const
141  {
142  std::string::size_type last = _name.find_last_of('/');
143  return _name.substr(0, last);
144  }
145  std::string getShortName() const
146  {
147  std::string units = getAttribute("Units");
148  if(_label.size()) {
149  if(units.empty())
150  return _label;
151  else
152  return _label + " [" + units + "]";
153  }
154  std::string s = _name;
155  // remove path
156  std::string::size_type last = _name.find_last_of('/');
157  if(last != std::string::npos) s = _name.substr(last + 1);
158  // remove starting white space
159  while(s.size() && s[0] == ' ') s = s.substr(1);
160  // remove starting braces: can be used to order parameters 'from the end',
161  // as the ASCII code is after numbers and letters
162  while(s.size() && (s[0] == '}' || s[0] == '{')) s = s.substr(1);
163  // remove starting numbers: can be used to order parameters 'from the
164  // start'
165  while(s.size() && s[0] >= '0' && s[0] <= '9') s = s.substr(1);
166  if(units.empty())
167  return s;
168  else
169  return s + " [" + units + "]";
170  }
171  int getChanged(const std::string &client = "") const
172  {
173  if(client.size()) {
174  auto it = _clients.find(client);
175  if(it != _clients.end())
176  return it->second;
177  else
178  return 0;
179  }
180  else {
181  int changed = 0;
182  for(auto it = _clients.begin(); it != _clients.end(); it++) {
183  changed = std::max(changed, it->second);
184  }
185  return changed;
186  }
187  }
188  int getChangedValue() const { return _changedValue; }
189  bool getNeverChanged() const { return _changedValue ? false : true; }
190  bool getVisible() const { return _visible; }
191  bool getReadOnly() const { return _readOnly; }
192  std::string getAttribute(const std::string &key) const
193  {
194  auto it = _attributes.find(key);
195  if(it != _attributes.end()) return it->second;
196  return "";
197  }
198  const std::map<std::string, std::string> &getAttributes() const
199  {
200  return _attributes;
201  }
202  const std::map<std::string, int> &getClients() const { return _clients; }
203  static char charSep() { return '\0'; }
204  static double maxNumber() { return 1e200; }
205  static std::string version() { return "1.3"; }
206  static int defaultChangedValue() { return 31; }
207  static std::string getNextToken(const std::string &msg,
208  std::string::size_type &first,
209  char separator = charSep())
210  {
211  if(first == std::string::npos) return "";
212  std::string::size_type last = msg.find_first_of(separator, first);
213  std::string next("");
214  if(last == std::string::npos) {
215  next = msg.substr(first);
216  first = last;
217  }
218  else if(first == last) {
219  next = "";
220  first = last + 1;
221  }
222  else {
223  next = msg.substr(first, last - first);
224  first = last + 1;
225  }
226  return next;
227  }
228  static std::vector<std::string> split(const std::string &msg,
229  char separator = charSep())
230  {
231  std::vector<std::string> out;
232  std::string::size_type first = 0;
233  while(first != std::string::npos)
234  out.push_back(getNextToken(msg, first, separator));
235  return out;
236  }
237  static std::string trim(const std::string &str,
238  const std::string &whitespace = " \t\n")
239  {
240  std::string::size_type strBegin = str.find_first_not_of(whitespace);
241  if(strBegin == std::string::npos) return ""; // no content
242  std::string::size_type strEnd = str.find_last_not_of(whitespace);
243  std::string::size_type strRange = strEnd - strBegin + 1;
244  return str.substr(strBegin, strRange);
245  }
246  std::string sanitize(const std::string &in) const
247  {
248  std::string out(in);
249  for(std::size_t i = 0; i < in.size(); i++)
250  if(out[i] == charSep()) out[i] = ' ';
251  return out;
252  }
253  virtual std::string toChar() const
254  {
255  std::ostringstream sstream;
256  sstream << version() << charSep() << getType() << charSep()
257  << sanitize(getName()) << charSep() << sanitize(getLabel())
258  << charSep() << sanitize(getHelp()) << charSep()
259  << getChangedValue() << charSep() << (getVisible() ? 1 : 0)
260  << charSep() << (getReadOnly() ? 1 : 0) << charSep()
261  << _attributes.size() << charSep();
262  for(auto it = _attributes.begin(); it != _attributes.end(); it++)
263  sstream << sanitize(it->first) << charSep() << sanitize(it->second)
264  << charSep();
265  sstream << getClients().size() << charSep();
266  for(auto it = getClients().begin(); it != getClients().end(); it++)
267  sstream << sanitize(it->first) << charSep() << (it->second ? 1 : 0)
268  << charSep();
269  return sstream.str();
270  }
271  virtual std::string::size_type fromChar(const std::string &msg)
272  {
273  std::string::size_type pos = 0;
274  if(getNextToken(msg, pos) != version()) return 0;
275  if(getNextToken(msg, pos) != getType()) return 0;
276  setName(getNextToken(msg, pos));
277  setLabel(getNextToken(msg, pos));
278  setHelp(getNextToken(msg, pos));
279  setChangedValue(atoi(getNextToken(msg, pos).c_str()));
280  setVisible(atoi(getNextToken(msg, pos).c_str()));
281  setReadOnly(atoi(getNextToken(msg, pos).c_str()));
282  int numAttributes = atoi(getNextToken(msg, pos).c_str());
283  for(int i = 0; i < numAttributes; i++) {
284  std::string key(getNextToken(msg, pos));
285  setAttribute(key, getNextToken(msg, pos));
286  }
287  int numClients = atoi(getNextToken(msg, pos).c_str());
288  for(int i = 0; i < numClients; i++) {
289  std::string client(getNextToken(msg, pos));
290  int changed = atoi(getNextToken(msg, pos).c_str());
291  addClient(client, changed);
292  }
293  return pos;
294  }
295  static void getInfoFromChar(const std::string &msg, std::string &version,
296  std::string &type, std::string &name)
297  {
298  std::string::size_type first = 0;
299  version = getNextToken(msg, first);
300  type = getNextToken(msg, first);
301  name = getNextToken(msg, first);
302  }
303  static bool fromFile(std::vector<std::string> &msg, FILE *fp)
304  {
305  msg.clear();
306  char tmp[1000];
307  if(!fgets(tmp, sizeof(tmp), fp)) return false; // first line is comment
308  while(!feof(fp)) {
309  int numc = 0;
310  if(!fscanf(fp, "%d ", &numc)) break; // space is important
311  if(!numc) break;
312  msg.push_back("");
313  for(int i = 0; i < numc; i++) msg.back() += fgetc(fp);
314  if(!fgets(tmp, sizeof(tmp), fp)) break; // end of line
315  }
316  return true;
317  }
318  static bool toFile(const std::vector<std::string> &msg, FILE *fp,
319  const std::string &creator)
320  {
321  time_t now;
322  time(&now);
323  fprintf(fp, "ONELAB database created by %s on %s", creator.c_str(),
324  ctime(&now));
325  for(std::size_t i = 0; i < msg.size(); i++) {
326  fprintf(fp, "%d ", (int)msg[i].size());
327  for(std::size_t j = 0; j < msg[i].size(); j++) fputc(msg[i][j], fp);
328  fputc('\n', fp);
329  }
330  return true;
331  }
332  std::string sanitizeJSON(const std::string &in) const
333  {
334  // FIXME: replace \n with \\n, \t with \\t, etc.
335  return in;
336  }
337  virtual std::string toJSON() const
338  {
339  std::ostringstream sstream;
340  sstream << "\"type\":\"" << getType() << "\""
341  << ", \"name\":\"" << sanitizeJSON(getName()) << "\"";
342  if(getLabel().size())
343  sstream << ", \"label\":\"" << sanitizeJSON(getLabel()) << "\"";
344  if(getHelp().size())
345  sstream << ", \"help\":\"" << sanitizeJSON(getHelp()) << "\"";
346  sstream << ", \"changedValue\":" << getChangedValue()
347  << ", \"visible\":" << (getVisible() ? "true" : "false")
348  << ", \"readOnly\":" << (getReadOnly() ? "true" : "false");
349  if(_attributes.size()) {
350  sstream << ", \"attributes\":{ ";
351  for(auto it = _attributes.begin(); it != _attributes.end(); it++) {
352  if(it != _attributes.begin()) sstream << ", ";
353  sstream << "\"" << sanitizeJSON(it->first) << "\":\""
354  << sanitizeJSON(it->second) << "\"";
355  }
356  sstream << " }";
357  }
358  if(getClients().size()) {
359  sstream << ", \"clients\":{ ";
360  for(auto it = getClients().begin(); it != getClients().end(); it++) {
361  if(it != getClients().begin()) sstream << ", ";
362  sstream << "\"" << sanitizeJSON(it->first) << "\":" << it->second;
363  }
364  sstream << " }";
365  }
366  return sstream.str();
367  }
368 #if defined(HAVE_PICOJSON)
369  virtual bool fromJSON(const picojson::value::object &par)
370  {
371  for(auto it = par.begin(); it != par.end(); ++it) {
372  if(it->first == "name") {
373  if(!it->second.is<std::string>()) return false;
374  setName(it->second.get<std::string>());
375  }
376  else if(it->first == "label") {
377  if(!it->second.is<std::string>()) return false;
378  setLabel(it->second.get<std::string>());
379  }
380  else if(it->first == "help") {
381  if(!it->second.is<std::string>()) return false;
382  setHelp(it->second.get<std::string>());
383  }
384  else if(it->first == "changedValue") {
385  if(!it->second.is<double>()) return false;
386  setChangedValue((int)it->second.get<double>());
387  }
388  else if(it->first == "visible") {
389  if(!it->second.is<bool>()) return false;
390  setVisible(it->second.get<bool>());
391  }
392  else if(it->first == "readOnly") {
393  if(!it->second.is<bool>()) return false;
394  setReadOnly(it->second.get<bool>());
395  }
396  else if(it->first == "attributes") {
397  if(!it->second.is<picojson::object>()) return false;
398  const picojson::value::object &obj =
399  it->second.get<picojson::object>();
400  for(auto i = obj.begin(); i != obj.end(); ++i) {
401  std::string key(i->first);
402  if(!i->second.is<std::string>()) return false;
403  setAttribute(key, i->second.get<std::string>());
404  }
405  }
406  else if(it->first == "clients") {
407  if(!it->second.is<picojson::object>()) return false;
408  const picojson::value::object &obj =
409  it->second.get<picojson::object>();
410  for(auto i = obj.begin(); i != obj.end(); ++i) {
411  std::string client(i->first);
412  if(!i->second.is<double>()) return false;
413  addClient(client, (int)i->second.get<double>());
414  }
415  }
416  }
417  return true;
418  }
419 #endif
420  };
421 
423  public:
424  bool operator()(const parameter *p1, const parameter *p2) const
425  {
426  return p1->getName() < p2->getName();
427  }
428  };
429 
430  // The number class. Numbers are stored internally as double precision real
431  // numbers.
432  class number : public parameter {
433  private:
434  std::vector<double> _values, _choices;
435  double _min, _max, _step;
436  // when in a loop, indicates current index in the vector _choices; is -1
437  // when not in a loop
438  int _index;
439  std::map<double, std::string> _valueLabels;
440 
441  public:
442  number(const std::string &name = "", double value = 0.,
443  const std::string &label = "", const std::string &help = "")
444  : parameter(name, label, help), _values(std::vector<double>(1, value)),
445  _min(-maxNumber()), _max(maxNumber()), _step(0.), _index(-1)
446  {
447  }
448  number(const std::string &name, const std::vector<double> &values,
449  const std::string &label = "", const std::string &help = "")
450  : parameter(name, label, help), _values(values), _min(-maxNumber()),
451  _max(maxNumber()), _step(0.), _index(-1)
452  {
453  }
454  void setValue(double value)
455  {
456  _values.resize(1);
457  _values[0] = value;
458  }
459  void setValues(const std::vector<double> &values) { _values = values; }
460  void setMin(double min) { _min = min; }
461  void setMax(double max) { _max = max; }
462  void setStep(double step) { _step = step; }
463  void setIndex(int index) { _index = index; }
464  void setChoices(const std::vector<double> &choices) { _choices = choices; }
465  void setChoiceLabels(const std::vector<std::string> &labels)
466  {
467  if(labels.size() != _choices.size()) return;
468  if(_valueLabels.size()) _valueLabels.clear();
469  for(std::size_t i = 0; i < _choices.size(); i++)
470  _valueLabels[_choices[i]] = labels[i];
471  }
472  void setValueLabels(const std::map<double, std::string> &valueLabels)
473  {
474  _valueLabels = valueLabels;
475  }
476  void setValueLabel(double value, const std::string &label)
477  {
478  _valueLabels[value] = label;
479  }
480  std::string getType() const { return "number"; }
481  double getValue() const
482  {
483  if(_values.empty()) return 0.;
484  return _values[0];
485  }
486  std::string getValueAsString() const
487  {
488  std::ostringstream sstream;
489  sstream << getValue();
490  return sstream.str();
491  }
492  const std::vector<double> &getValues() const { return _values; }
493  int getNumValues() const { return (int)_values.size(); }
494  double getMin() const { return _min; }
495  double getMax() const { return _max; }
496  double getStep() const { return _step; }
497  int getIndex() const { return _index; }
498  const std::vector<double> &getChoices() const { return _choices; }
499  const std::map<double, std::string> &getValueLabels() const
500  {
501  return _valueLabels;
502  }
503  std::string getValueLabel(double value) const
504  {
505  auto it = _valueLabels.find(value);
506  if(it != _valueLabels.end()) return it->second;
507  return "";
508  }
509  void update(const number &p)
510  {
511  addClients(p.getClients());
512  setLabel(p.getLabel());
513  setHelp(p.getHelp());
514  setVisible(p.getVisible());
517  bool changed = false;
518  for(std::size_t i = 0; i < p.getValues().size(); i++) {
519  if(p.getValues()[i] != getValues()[i]) {
520  changed = true;
521  break;
522  }
523  }
524  if(changed) {
525  setValues(p.getValues());
527  }
528  setMin(p.getMin());
529  setMax(p.getMax());
530  setStep(p.getStep());
531  setIndex(p.getIndex());
532  setChoices(p.getChoices());
534  if(getNeverChanged()) setChanged(0);
535  }
536  std::string toChar() const
537  {
538  std::ostringstream sstream;
539  sstream.precision(16);
540  sstream << parameter::toChar() << _values.size() << charSep();
541  for(std::size_t i = 0; i < _values.size(); i++)
542  sstream << _values[i] << charSep();
543  sstream << _min << charSep() << _max << charSep() << _step << charSep()
544  << _index << charSep() << _choices.size() << charSep();
545  for(std::size_t i = 0; i < _choices.size(); i++)
546  sstream << _choices[i] << charSep();
547  sstream << _valueLabels.size() << charSep();
548  for(auto it = _valueLabels.begin(); it != _valueLabels.end(); it++) {
549  sstream << it->first << charSep() << sanitize(it->second) << charSep();
550  }
551  return sstream.str();
552  }
553  std::string::size_type fromChar(const std::string &msg)
554  {
555  std::string::size_type pos = parameter::fromChar(msg);
556  if(!pos) return 0;
557  _values.resize(atoi(getNextToken(msg, pos).c_str()));
558  for(std::size_t i = 0; i < _values.size(); i++)
559  _values[i] = atof(getNextToken(msg, pos).c_str());
560  setMin(atof(getNextToken(msg, pos).c_str()));
561  setMax(atof(getNextToken(msg, pos).c_str()));
562  setStep(atof(getNextToken(msg, pos).c_str()));
563  setIndex(atoi(getNextToken(msg, pos).c_str()));
564  _choices.resize(atoi(getNextToken(msg, pos).c_str()));
565  for(std::size_t i = 0; i < _choices.size(); i++)
566  _choices[i] = atof(getNextToken(msg, pos).c_str());
567  int numValueLabels = atoi(getNextToken(msg, pos).c_str());
568  for(int i = 0; i < numValueLabels; i++) {
569  double value = atof(getNextToken(msg, pos).c_str());
570  _valueLabels[value] = getNextToken(msg, pos);
571  }
572  return pos;
573  }
574  std::string toJSON() const
575  {
576  std::ostringstream sstream;
577  sstream.precision(16);
578  sstream << "{ " << parameter::toJSON() << ", \"values\":[ ";
579  for(std::size_t i = 0; i < _values.size(); i++) {
580  if(i) sstream << ", ";
581  sstream << _values[i];
582  }
583  sstream << " ]"
584  << ", \"min\":" << _min << ", \"max\":" << _max
585  << ", \"step\":" << _step << ", \"index\":" << _index;
586  if(_choices.size()) {
587  sstream << ", \"choices\":[ ";
588  for(std::size_t i = 0; i < _choices.size(); i++) {
589  if(i) sstream << ", ";
590  sstream << _choices[i];
591  }
592  sstream << " ]";
593  }
594  if(_valueLabels.size()) {
595  sstream << ", \"valueLabels\":{ ";
596  for(auto it = _valueLabels.begin(); it != _valueLabels.end(); it++) {
597  if(it != _valueLabels.begin()) sstream << ", ";
598  sstream << "\"" << sanitizeJSON(it->second) << "\":" << it->first;
599  }
600  sstream << " }";
601  }
602  sstream << " }";
603  return sstream.str();
604  }
605  bool fromJSON(const std::string &json)
606  {
607 #if defined(HAVE_PICOJSON)
608  picojson::value v;
609  std::string err = picojson::parse(v, json);
610  if(err.size()) return false;
611  if(!v.is<picojson::object>()) return false;
612  const picojson::value::object &par = v.get<picojson::object>();
613  auto it = par.find("type");
614  if(it == par.end()) return false;
615  if(it->second.to_str() == "number") {
616  fromJSON(par);
617  return true;
618  }
619 #endif
620  return false;
621  }
622 #if defined(HAVE_PICOJSON)
624  {
625  if(!parameter::fromJSON(par)) return false;
626  for(auto it = par.begin(); it != par.end(); ++it) {
627  if(it->first == "values") {
628  if(!it->second.is<picojson::array>()) return false;
629  const picojson::value::array &arr = it->second.get<picojson::array>();
630  _values.resize(arr.size());
631  for(std::size_t i = 0; i < arr.size(); i++) {
632  if(!arr[i].is<double>()) return false;
633  _values[i] = arr[i].get<double>();
634  }
635  }
636  else if(it->first == "min") {
637  if(!it->second.is<double>()) return false;
638  setMin(it->second.get<double>());
639  }
640  else if(it->first == "max") {
641  if(!it->second.is<double>()) return false;
642  setMax(it->second.get<double>());
643  }
644  else if(it->first == "step") {
645  if(!it->second.is<double>()) return false;
646  setStep(it->second.get<double>());
647  }
648  else if(it->first == "index") {
649  if(!it->second.is<double>()) return false;
650  setIndex((int)it->second.get<double>());
651  }
652  else if(it->first == "choices") {
653  if(!it->second.is<picojson::array>()) return false;
654  const picojson::value::array &arr = it->second.get<picojson::array>();
655  _choices.resize(arr.size());
656  for(std::size_t i = 0; i < arr.size(); i++) {
657  if(!arr[i].is<double>()) return false;
658  _choices[i] = arr[i].get<double>();
659  }
660  }
661  else if(it->first == "valueLabels") {
662  if(!it->second.is<picojson::object>()) return false;
663  const picojson::value::object &obj =
664  it->second.get<picojson::object>();
665  for(auto i = obj.begin(); i != obj.end(); ++i) {
666  if(!i->second.is<double>()) return false;
667  _valueLabels[i->second.get<double>()] = i->first;
668  }
669  }
670  }
671  return true;
672  }
673 #endif
674  };
675 
676  // The string class. A string has a mutable "kind", that can be changed at
677  // runtime. Kinds leading to specific behavior in Gmsh are: "file".
678  class string : public parameter {
679  private:
680  std::vector<std::string> _values, _choices;
681  std::string _kind;
682 
683  public:
684  string(const std::string &name = "", const std::string &value = "",
685  const std::string &label = "", const std::string &help = "")
686  : parameter(name, label, help),
687  _values(std::vector<std::string>(1, value)), _kind("generic")
688  {
689  }
690  string(const std::string &name, const std::vector<std::string> &values,
691  const std::string &label = "", const std::string &help = "")
692  : parameter(name, label, help), _values(values), _kind("generic")
693  {
694  }
695  void setValue(const std::string &value)
696  {
697  _values.resize(1);
698  _values[0] = value;
699  }
700  void setValues(const std::vector<std::string> &values) { _values = values; }
701  void setKind(const std::string &kind) { _kind = kind; }
702  void setChoices(const std::vector<std::string> &choices)
703  {
704  _choices = choices;
705  }
706  std::string getType() const { return "string"; }
707  const std::string &getValue() const
708  {
709  static std::string n("");
710  if(_values.empty()) return n;
711  return _values[0];
712  }
713  std::string getValueAsString() const { return getValue(); }
714  const std::vector<std::string> &getValues() const { return _values; }
715  int getNumValues() const { return (int)_values.size(); }
716  const std::string &getKind() const { return _kind; }
717  const std::vector<std::string> &getChoices() const { return _choices; }
718  void update(const string &p)
719  {
720  addClients(p.getClients());
721  setLabel(p.getLabel());
722  setHelp(p.getHelp());
723  setVisible(p.getVisible());
726  bool changed = false;
727  for(std::size_t i = 0; i < p.getValues().size(); i++) {
728  if(p.getValues()[i] != getValues()[i]) {
729  changed = true;
730  break;
731  }
732  }
733  if(changed) {
734  setValues(p.getValues());
736  }
737  if(p.getKind() != getKind()) {
738  setKind(p.getKind());
740  }
741  setChoices(p.getChoices());
742  if(getNeverChanged()) setChanged(0);
743  }
744  std::string toChar() const
745  {
746  std::ostringstream sstream;
747  sstream << parameter::toChar() << _values.size() << charSep();
748  for(std::size_t i = 0; i < _values.size(); i++)
749  sstream << sanitize(_values[i]) << charSep();
750  sstream << sanitize(_kind) << charSep() << _choices.size() << charSep();
751  for(std::size_t i = 0; i < _choices.size(); i++)
752  sstream << sanitize(_choices[i]) << charSep();
753  return sstream.str();
754  }
755  std::string::size_type fromChar(const std::string &msg)
756  {
757  std::string::size_type pos = parameter::fromChar(msg);
758  if(!pos) return 0;
759  _values.resize(atoi(getNextToken(msg, pos).c_str()));
760  for(std::size_t i = 0; i < _values.size(); i++)
761  _values[i] = getNextToken(msg, pos);
762  setKind(getNextToken(msg, pos));
763  _choices.resize(atoi(getNextToken(msg, pos).c_str()));
764  for(std::size_t i = 0; i < _choices.size(); i++)
765  _choices[i] = getNextToken(msg, pos);
766  return pos;
767  }
768  std::string toJSON() const
769  {
770  std::ostringstream sstream;
771  sstream << "{ " << parameter::toJSON() << ", \"values\":[ ";
772  for(std::size_t i = 0; i < _values.size(); i++) {
773  if(i) sstream << ", ";
774  sstream << "\"" << sanitizeJSON(_values[i]) << "\"";
775  }
776  sstream << " ] ";
777  if(_kind.size())
778  sstream << ", \"kind\":\"" << sanitizeJSON(_kind) << "\"";
779  if(_choices.size()) {
780  sstream << ", \"choices\":[ ";
781  for(std::size_t i = 0; i < _choices.size(); i++) {
782  if(i) sstream << ", ";
783  sstream << "\"" << sanitizeJSON(_choices[i]) << "\"";
784  }
785  sstream << " ]";
786  }
787  sstream << " }";
788  return sstream.str();
789  }
790  bool fromJSON(const std::string &json)
791  {
792 #if defined(HAVE_PICOJSON)
793  picojson::value v;
794  std::string err = picojson::parse(v, json);
795  if(err.size()) return false;
796  if(!v.is<picojson::object>()) return false;
797  const picojson::value::object &par = v.get<picojson::object>();
798  auto it = par.find("type");
799  if(it == par.end()) return false;
800  if(it->second.to_str() == "string") {
801  fromJSON(par);
802  return true;
803  }
804 #endif
805  return false;
806  }
807 #if defined(HAVE_PICOJSON)
809  {
810  if(!parameter::fromJSON(par)) return false;
811  for(auto it = par.begin(); it != par.end(); ++it) {
812  if(it->first == "values") {
813  if(!it->second.is<picojson::array>()) return false;
814  const picojson::value::array &arr = it->second.get<picojson::array>();
815  _values.resize(arr.size());
816  for(std::size_t i = 0; i < arr.size(); i++) {
817  if(!arr[i].is<std::string>()) return false;
818  _values[i] = arr[i].get<std::string>();
819  }
820  }
821  else if(it->first == "kind") {
822  if(!it->second.is<std::string>()) return false;
823  setKind(it->second.get<std::string>());
824  }
825  else if(it->first == "choices") {
826  if(!it->second.is<picojson::array>()) return false;
827  const picojson::value::array &arr = it->second.get<picojson::array>();
828  _choices.resize(arr.size());
829  for(std::size_t i = 0; i < arr.size(); i++) {
830  if(!arr[i].is<std::string>()) return false;
831  _choices[i] = arr[i].get<std::string>();
832  }
833  }
834  }
835  return true;
836  }
837 #endif
838  };
839 
840  // The parameter space, i.e., the set of parameters stored and handled by the
841  // ONELAB server.
843  private:
844  std::set<number *, parameterLessThan> _numbers;
845  std::set<string *, parameterLessThan> _strings;
846  std::mutex _mutex;
847 
848  // delete a parameter from the parameter space
849  template <class T>
850  bool _clear(const std::string &name, const std::string &client,
851  std::set<T *, parameterLessThan> &ps)
852  {
853  if(name.empty() && client.size()) {
854  std::vector<T *> toDelete;
855  for(auto it = ps.begin(); it != ps.end();) {
856  T *p = *it;
857  if(p->hasClient(client)) {
858  ps.erase(it++); // to avoid invalid iterator
859  delete p;
860  }
861  else {
862  it++;
863  }
864  }
865  }
866  else {
867  T tmp(name);
868  auto it = ps.find(&tmp);
869  if(it != ps.end()) {
870  T *p = *it;
871  if(client.empty() || p->hasClient(client)) {
872  ps.erase(it);
873  delete p;
874  return true;
875  }
876  }
877  }
878  return false;
879  }
880  // set a parameter in the parameter space; if it already exists, update it
881  // (adding new clients if necessary). This would need to be locked to avoid
882  // race conditions when several clients try to set a parameter at the same
883  // time.
884  template <class T>
885  bool _set(const T &p, const std::string &client,
886  std::set<T *, parameterLessThan> &ps)
887  {
888  _mutex.lock();
889  auto it = ps.find((T *)&p);
890  if(it != ps.end()) {
891  (*it)->update(p);
892  if(client.size())
893  (*it)->addClient(client, parameter::defaultChangedValue());
894  }
895  else {
896  T *newp = new T(p);
897  if(client.size())
898  newp->addClient(client, parameter::defaultChangedValue());
899  ps.insert(newp);
900  }
901  _mutex.unlock();
902  return true;
903  }
904  // get the parameter matching the given name, or all the parameters in the
905  // category if no name is given. If we find a given parameter by name, we
906  // add the client requesting the parameter to the list of clients for this
907  // parameter. This would also need to be locked.
908  template <class T>
909  bool _get(std::vector<T> &p, const std::string &name,
910  const std::string &client, std::set<T *, parameterLessThan> &ps)
911  {
912  p.clear();
913  if(name.empty()) {
914  for(auto it = ps.begin(); it != ps.end(); it++) p.push_back(**it);
915  }
916  else {
917  T tmp(name);
918  auto it = ps.find(&tmp);
919  if(it != ps.end()) {
920  if(client.size()) {
921  _mutex.lock();
922  (*it)->addClient(client, parameter::defaultChangedValue());
923  _mutex.unlock();
924  }
925  p.push_back(**it);
926  }
927  }
928  return true;
929  }
930  template <class T>
931  T *_getPtr(std::string name, const std::string client,
932  std::set<T *, parameterLessThan> ps)
933  {
934  T tmp(name);
935  auto it = ps.find(&tmp);
936  if(it != ps.end()) {
937  if(client.size()) {
938  _mutex.lock();
939  (*it)->addClient(client, parameter::defaultChangedValue());
940  _mutex.unlock();
941  }
942  return *it;
943  }
944  return nullptr;
945  }
946 
947  public:
950  void clear(const std::string &name = "", const std::string &client = "")
951  {
952  if(name.empty() && client.empty()) {
953  std::set<parameter *, parameterLessThan> ps;
954  getAllParameters(ps);
955  for(auto it = ps.begin(); it != ps.end(); it++) delete *it;
956  _numbers.clear();
957  _strings.clear();
958  }
959  else {
960  bool done = _clear(name, client, _numbers);
961  if(!done) done = _clear(name, client, _strings);
962  }
963  }
964  bool set(const number &p, const std::string &client = "")
965  {
966  return _set(p, client, _numbers);
967  }
968  bool set(const string &p, const std::string &client = "")
969  {
970  return _set(p, client, _strings);
971  }
972  bool get(std::vector<number> &ps, const std::string &name = "",
973  const std::string &client = "")
974  {
975  return _get(ps, name, client, _numbers);
976  }
977  bool get(std::vector<string> &ps, const std::string &name = "",
978  const std::string &client = "")
979  {
980  return _get(ps, name, client, _strings);
981  }
982  void getPtr(number **ptr, const std::string &name,
983  const std::string &client = "")
984  {
985  *ptr = _getPtr(name, client, _numbers);
986  }
987  void getPtr(string **ptr, const std::string &name,
988  const std::string &client = "")
989  {
990  *ptr = _getPtr(name, client, _strings);
991  }
992  void getAllParameters(std::set<parameter *, parameterLessThan> &ps) const
993  {
994  ps.insert(_numbers.begin(), _numbers.end());
995  ps.insert(_strings.begin(), _strings.end());
996  }
997  int getNumParameters() { return (int)(_numbers.size() + _strings.size()); }
998  void getParameterNames(std::vector<std::string> &names,
999  const std::string &search = "") const
1000  {
1001  names.clear();
1002  if(search.empty()) {
1003  for(auto &p : _numbers) names.push_back(p->getName());
1004  for(auto &p : _strings) names.push_back(p->getName());
1005  }
1006  else {
1007  try {
1008  for(auto &p : _numbers) {
1009  if(std::regex_search(p->getName(), std::regex(search)))
1010  names.push_back(p->getName());
1011  }
1012  for(auto &p : _strings) {
1013  if(std::regex_search(p->getName(), std::regex(search)))
1014  names.push_back(p->getName());
1015  }
1016  } catch(...) {
1017  }
1018  }
1019  }
1020  // check if at least one parameter depends on the given client
1021  bool hasClient(const std::string &client) const
1022  {
1023  std::set<parameter *, parameterLessThan> ps;
1024  getAllParameters(ps);
1025  for(auto it = ps.begin(); it != ps.end(); it++)
1026  if((*it)->hasClient(client)) return true;
1027  return false;
1028  }
1029  // check if some parameters have changed (optionnally only check the
1030  // parameters that depend on a given client)
1031  int getChanged(const std::string &client = "") const
1032  {
1033  std::set<parameter *, parameterLessThan> ps;
1034  getAllParameters(ps);
1035  int changed = 0;
1036  for(auto it = ps.begin(); it != ps.end(); it++) {
1037  changed = std::max(changed, (*it)->getChanged(client));
1038  }
1039  return changed;
1040  }
1041  // set the changed flag for all the parameters that depend on the given
1042  // client (or for all parameters if no client name is provided)
1043  void setChanged(int changed, const std::string &client = "")
1044  {
1045  std::set<parameter *, parameterLessThan> ps;
1046  getAllParameters(ps);
1047  for(auto it = ps.begin(); it != ps.end(); it++)
1048  (*it)->setChanged(changed, client);
1049  }
1050  void thresholdChanged(int threshold, const std::string &client = "")
1051  {
1052  std::set<parameter *, parameterLessThan> ps;
1053  getAllParameters(ps);
1054  for(auto it = ps.begin(); it != ps.end(); it++) {
1055  int changed = (*it)->getChanged(client);
1056  if(changed > threshold) (*it)->setChanged(threshold, client);
1057  }
1058  }
1059  // serialize the parameter space (optionally only serialize those parameters
1060  // that depend on the given client)
1061  std::vector<std::string> toChar(const std::string &client = "") const
1062  {
1063  std::vector<std::string> s;
1064  std::set<parameter *, parameterLessThan> ps;
1065  getAllParameters(ps);
1066  for(auto it = ps.begin(); it != ps.end(); it++)
1067  if(client.empty() || (*it)->hasClient(client)) {
1068  if((*it)->getAttribute("NotInDb") != "True")
1069  s.push_back((*it)->toChar());
1070  }
1071  return s;
1072  }
1073  // unserialize the parameter space
1074  bool fromChar(const std::vector<std::string> &msg,
1075  const std::string &client = "")
1076  {
1077  for(std::size_t i = 0; i < msg.size(); i++) {
1078  std::string version, type, name;
1079  onelab::parameter::getInfoFromChar(msg[i], version, type, name);
1080  if(onelab::parameter::version() != version) return false;
1081  if(type == "number") {
1082  number p;
1083  p.fromChar(msg[i]);
1084  set(p, client);
1085  }
1086  else if(type == "string") {
1087  string p;
1088  p.fromChar(msg[i]);
1089  set(p, client);
1090  }
1091  else
1092  return false;
1093  }
1094  return true;
1095  }
1096  bool toJSON(std::string &json, const std::string &creator = "",
1097  const std::string &client = "") const
1098  {
1099  time_t now;
1100  time(&now);
1101  std::string t(ctime(&now));
1102  t.resize(t.size() - 1);
1103  json.clear();
1104  json += "{ \"onelab\":{\n";
1105  json += " \"creator\":\"" + creator + "\",\n";
1106  json += " \"date\":\"" + t + "\",\n";
1107  json += " \"version\":\"" + parameter::version() + "\",\n";
1108  json += " \"parameters\":[\n";
1109  std::set<parameter *, parameterLessThan> ps;
1110  getAllParameters(ps);
1111  for(auto it = ps.begin(); it != ps.end(); it++) {
1112  if(it != ps.begin()) json += ",\n";
1113  if(client.empty() || (*it)->hasClient(client)) {
1114  if((*it)->getAttribute("NotInDb") != "True") {
1115  json += " " + (*it)->toJSON();
1116  }
1117  }
1118  }
1119  json += "\n ] }\n}\n";
1120  return true;
1121  }
1122  bool fromJSON(const std::string &json, const std::string &client = "")
1123  {
1124 #if defined(HAVE_PICOJSON)
1125  picojson::value v;
1126  std::string err = picojson::parse(v, json);
1127  if(err.size()) return false;
1128  if(v.is<picojson::object>()) { // full database or single parameter
1129  const picojson::value::object &obj = v.get<picojson::object>();
1130  auto it = obj.find("onelab");
1131  if(it != obj.end()) { // full database
1132  if(!it->second.is<picojson::object>()) return false;
1133  const picojson::value::object &db =
1134  it->second.get<picojson::object>();
1135  for(auto j = db.begin(); j != db.end(); ++j) {
1136  if(j->first == "version") {
1137  if(!j->second.is<std::string>()) return false;
1138  if(j->second.get<std::string>() != parameter::version())
1139  return false;
1140  }
1141  else if(j->first == "parameters") {
1142  if(!j->second.is<picojson::array>()) return false;
1143  const picojson::value::array &arr =
1144  j->second.get<picojson::array>();
1145  for(std::size_t k = 0; k < arr.size(); k++) {
1146  if(!arr[k].is<picojson::object>()) return false;
1147  const picojson::value::object &par =
1148  arr[k].get<picojson::object>();
1149  if(!fromJSON(par, client)) return false;
1150  }
1151  }
1152  }
1153  return true;
1154  }
1155  else { // single parameter
1156  return fromJSON(obj, client);
1157  }
1158  }
1159  else if(v.is<picojson::array>()) { // array of parameters
1160  const picojson::value::array &arr = v.get<picojson::array>();
1161  for(std::size_t k = 0; k < arr.size(); k++) {
1162  if(!arr[k].is<picojson::object>()) return false;
1163  const picojson::value::object &par = arr[k].get<picojson::object>();
1164  if(!fromJSON(par, client)) return false;
1165  }
1166  return true;
1167  }
1168  else {
1169  return false;
1170  }
1171 #else
1172  return false;
1173 #endif
1174  }
1175 #if defined(HAVE_PICOJSON)
1177  const std::string &client = "")
1178  {
1179  auto it = par.find("type");
1180  if(it == par.end()) return false;
1181  if(it->second.to_str() == "number") {
1182  number p;
1183  p.fromJSON(par);
1184  set(p, client);
1185  return true;
1186  }
1187  else if(it->second.to_str() == "string") {
1188  string p;
1189  p.fromJSON(par);
1190  set(p, client);
1191  return true;
1192  }
1193  return false;
1194  }
1195 #endif
1196  };
1197 
1198  // The ONELAB client: a class that communicates with the ONELAB server. Each
1199  // client should be derived from this one. A client can be understood as "one
1200  // simulation step in a complex computation".
1201  class client {
1202  protected:
1203  // the name of the client
1204  std::string _name;
1205  // the id of the client, used to create a unique socket for this client
1206  int _id;
1207  // the index of the client in an external client list (if any)
1208  int _index;
1209 
1210  public:
1211  client(const std::string &name) : _name(name), _id(0), _index(-1) {}
1212  virtual ~client() {}
1213  std::string getName() { return _name; }
1214  void setId(int id) { _id = id; }
1215  int getId() { return _id; }
1216  void setIndex(int index) { _index = index; }
1217  int getIndex() { return _index; }
1218  virtual bool run() { return false; }
1219  virtual bool isNetworkClient() { return false; }
1220  virtual bool kill() { return false; }
1221  virtual void sendInfo(const std::string &msg)
1222  {
1223  std::cout << msg << std::endl;
1224  }
1225  virtual void sendWarning(const std::string &msg)
1226  {
1227  std::cerr << msg << std::endl;
1228  }
1229  virtual void sendError(const std::string &msg)
1230  {
1231  std::cerr << msg << std::endl;
1232  }
1233  virtual void sendProgress(const std::string &msg)
1234  {
1235  std::cout << msg << std::endl;
1236  }
1237  virtual void sendMergeFileRequest(const std::string &msg) {}
1238  virtual void sendOpenProjectRequest(const std::string &msg) {}
1239  virtual void sendParseStringRequest(const std::string &msg) {}
1240  virtual void sendVertexArray(const std::string &msg) {}
1241  virtual bool clear(const std::string &name) = 0;
1242  virtual bool set(const number &p) = 0;
1243  virtual bool set(const string &p) = 0;
1244  virtual bool get(std::vector<number> &ps, const std::string &name = "") = 0;
1245  virtual bool get(std::vector<string> &ps, const std::string &name = "") = 0;
1246  virtual bool setAndAppendChoices(const number &p) = 0;
1247  virtual bool setAndAppendChoices(const string &p) = 0;
1248  virtual bool getWithoutChoices(std::vector<number> &ps,
1249  const std::string &name = "") = 0;
1250  virtual bool getWithoutChoices(std::vector<string> &ps,
1251  const std::string &name = "") = 0;
1252  std::vector<std::string> toChar()
1253  {
1254  std::vector<std::string> out;
1255  std::vector<number> n;
1256  get(n);
1257  for(std::size_t i = 0; i < n.size(); i++) out.push_back(n[i].toChar());
1258  std::vector<string> s;
1259  get(s);
1260  for(std::size_t i = 0; i < s.size(); i++) out.push_back(s[i].toChar());
1261  return out;
1262  }
1263  bool fromChar(const std::vector<std::string> &msg)
1264  {
1265  for(std::size_t i = 0; i < msg.size(); i++) {
1266  std::string version, type, name;
1267  onelab::parameter::getInfoFromChar(msg[i], version, type, name);
1268  if(onelab::parameter::version() != version) return false;
1269  if(type == "number") {
1270  number p;
1271  p.fromChar(msg[i]);
1272  set(p);
1273  }
1274  else if(type == "string") {
1275  string p;
1276  p.fromChar(msg[i]);
1277  set(p);
1278  }
1279  else
1280  return false;
1281  }
1282  return true;
1283  }
1284  bool toFile(FILE *fp) { return parameter::toFile(toChar(), fp, getName()); }
1285  bool fromFile(FILE *fp)
1286  {
1287  std::vector<std::string> msg;
1288  if(parameter::fromFile(msg, fp)) return fromChar(msg);
1289  return false;
1290  }
1291  };
1292 
1293  // The ONELAB server: a singleton that stores the parameter space and
1294  // interacts with ONELAB clients.
1295  class server {
1296  private:
1297  // the unique server (singleton behaviour due to the "static" specifier)
1298  static server *_server;
1299  // the address of the server
1300  std::string _address;
1301  // the connected clients
1302  std::set<client *> _clients;
1303  // the parameter space
1305 
1306  public:
1307  server(const std::string &address = "") : _address(address) {}
1308  ~server() {}
1309  static server *instance(const std::string &address = "")
1310  {
1311  if(!_server) _server = new server(address);
1312  return _server;
1313  }
1314  static void setInstance(server *s) { _server = s; }
1315  void clear(const std::string &name = "", const std::string &client = "")
1316  {
1317  _parameterSpace.clear(name, client);
1318  }
1319  template <class T> bool set(const T &p, const std::string &client = "")
1320  {
1321  return _parameterSpace.set(p, client);
1322  }
1323  template <class T>
1324  bool get(std::vector<T> &ps, const std::string &name = "",
1325  const std::string &client = "")
1326  {
1327  return _parameterSpace.get(ps, name, client);
1328  }
1329  typedef std::set<client *>::iterator citer;
1330  citer firstClient() { return _clients.begin(); }
1331  citer lastClient() { return _clients.end(); }
1332  int getNumClients() { return (int)_clients.size(); };
1333  citer findClient(const std::string &name)
1334  {
1335  for(auto it = _clients.begin(); it != _clients.end(); it++)
1336  if((*it)->getName() == name) return it;
1337  return _clients.end();
1338  }
1340  {
1341  _clients.insert(c);
1342  c->setId((int)_clients.size());
1343  }
1344  void unregisterClient(client *c) { _clients.erase(c); }
1345  void setChanged(int changed, const std::string &client = "")
1346  {
1347  _parameterSpace.setChanged(changed, client);
1348  }
1349  int getChanged(const std::string &client = "")
1350  {
1352  }
1353  void thresholdChanged(int value, const std::string &client = "")
1354  {
1356  }
1358  void getParameterNames(std::vector<std::string> &names,
1359  const std::string &search = "") const
1360  {
1361  _parameterSpace.getParameterNames(names, search);
1362  }
1363  std::vector<std::string> toChar(const std::string &client = "")
1364  {
1365  return _parameterSpace.toChar(client);
1366  }
1367  bool fromChar(const std::vector<std::string> &msg,
1368  const std::string &client = "")
1369  {
1370  return _parameterSpace.fromChar(msg, client);
1371  }
1372  bool toFile(FILE *fp, const std::string &client = "")
1373  {
1374  return parameter::toFile(toChar(client), fp, "onelab server");
1375  }
1376  bool fromFile(FILE *fp, const std::string &client = "")
1377  {
1378  std::vector<std::string> msg;
1379  if(parameter::fromFile(msg, fp)) return fromChar(msg, client);
1380  return false;
1381  }
1382  bool toJSON(std::string &json, const std::string &client = "")
1383  {
1384  return _parameterSpace.toJSON(json, client);
1385  }
1386  bool fromJSON(const std::string &json, const std::string &client = "")
1387  {
1388  return _parameterSpace.fromJSON(json, client);
1389  }
1390  };
1391 
1392  // A local client, which lives in the same memory space as the server.
1393  class localClient : public client {
1394  private:
1395  template <class T> bool _set(const T &p)
1396  {
1397  server::instance()->set(p, _name);
1398  return true;
1399  }
1400  template <class T>
1401  bool _get(std::vector<T> &ps, const std::string &name = "")
1402  {
1403  server::instance()->get(ps, name, _name);
1404  return true;
1405  }
1406 
1407  public:
1408  localClient(const std::string &name) : client(name)
1409  {
1411  }
1413  virtual bool clear(const std::string &name = "")
1414  {
1415  server::instance()->clear(name);
1416  return true;
1417  }
1418  virtual bool set(const number &p) { return _set(p); }
1419  virtual bool set(const string &p) { return _set(p); }
1420  virtual bool get(std::vector<number> &ps, const std::string &name = "")
1421  {
1422  return _get(ps, name);
1423  }
1424  virtual bool get(std::vector<string> &ps, const std::string &name = "")
1425  {
1426  return _get(ps, name);
1427  }
1428  virtual bool setAndAppendChoices(const number &p)
1429  {
1430  std::vector<number> ps;
1431  _get(ps, _name);
1432  std::vector<double> choices;
1433  if(ps.size()) choices = ps[0].getChoices();
1434  choices.insert(choices.end(), p.getChoices().begin(),
1435  p.getChoices().end());
1436  number p2(p);
1437  p2.setChoices(choices);
1438  return _set(p2);
1439  }
1440  virtual bool setAndAppendChoices(const string &p)
1441  {
1442  std::vector<string> ps;
1443  _get(ps, _name);
1444  std::vector<std::string> choices;
1445  if(ps.size()) choices = ps[0].getChoices();
1446  choices.insert(choices.end(), p.getChoices().begin(),
1447  p.getChoices().end());
1448  string p2(p);
1449  p2.setChoices(choices);
1450  return _set(p2);
1451  }
1452  virtual bool getWithoutChoices(std::vector<number> &ps,
1453  const std::string &name = "")
1454  {
1455  bool ret = _get(ps, name);
1456  for(std::size_t i = 0; i < ps.size(); i++)
1457  ps[i].setChoices(std::vector<double>());
1458  return ret;
1459  }
1460  virtual bool getWithoutChoices(std::vector<string> &ps,
1461  const std::string &name = "")
1462  {
1463  bool ret = _get(ps, name);
1464  for(std::size_t i = 0; i < ps.size(); i++)
1465  ps[i].setChoices(std::vector<std::string>());
1466  return ret;
1467  }
1468  };
1469 
1470  // The local part of a network client.
1472  private:
1473  // executable of the client (including filesystem path, if necessary)
1474  std::string _executable;
1475  // treat the executable name as a full command line (will prevent the
1476  // escaping of the exe name, and will assume that the command line has been
1477  // correcly escaped)
1479  // command to login to a remote host (if necessary)
1480  std::string _remoteLogin;
1481  // command line option to specify socket
1482  std::string _socketSwitch;
1483  // pid of the remote network client while it is running (-1 otherwise)
1484  int _pid;
1485  // underlying GmshServer
1487 
1488  public:
1489  localNetworkClient(const std::string &name, const std::string &executable,
1490  const std::string &remoteLogin = "",
1491  bool treatExecutableAsFullCommandLine = false)
1492  : localClient(name), _executable(executable),
1494  _remoteLogin(remoteLogin), _socketSwitch("-onelab"), _pid(-1),
1495  _gmshServer(nullptr)
1496  {
1497  }
1498  virtual ~localNetworkClient() {}
1499  virtual bool isNetworkClient() { return true; }
1500  const std::string &getExecutable() { return _executable; }
1501  void setExecutable(const std::string &s) { _executable = s; }
1502  const std::string &getRemoteLogin() { return _remoteLogin; }
1504  {
1506  }
1507  void setRemoteLogin(const std::string &s) { _remoteLogin = s; }
1508  const std::string &getSocketSwitch() { return _socketSwitch; }
1509  void setSocketSwitch(const std::string &s) { _socketSwitch = s; }
1510  int getPid() { return _pid; }
1511  void setPid(int pid) { _pid = pid; }
1514  virtual bool run() = 0;
1515  virtual bool kill() = 0;
1516  };
1517 
1518  // The remote part of a network client.
1519  class remoteNetworkClient : public client {
1520  private:
1521  // address (inet:port or unix socket) of the server
1522  std::string _serverAddress;
1523  // underlying GmshClient
1525  // number of subclients
1527  template <class T> bool _set(const T &p, bool withChoices = true)
1528  {
1529  if(!_gmshClient) return false;
1530  std::string msg = p.toChar();
1531  _gmshClient->SendMessage(withChoices ?
1534  (int)msg.size(), &msg[0]);
1535  return true;
1536  }
1537  template <class T>
1538  bool _get(std::vector<T> &ps, const std::string &name = "",
1539  bool withChoices = true)
1540  {
1541  ps.clear();
1542  if(!_gmshClient) return false;
1543  T p(name);
1544  std::string msg = p.toChar();
1545  if(name.size())
1547  withChoices ? GmshSocket::GMSH_PARAMETER_QUERY :
1549  (int)msg.size(), &msg[0]);
1550  else // get all parameters
1552  (int)msg.size(), &msg[0]);
1553 
1554  while(1) {
1555  // stop if we have no communications for 5 minutes
1556  int ret = _gmshClient->Select(500, 0);
1557  if(!ret) {
1558  _gmshClient->Info("Timeout: aborting remote get");
1559  return false;
1560  }
1561  else if(ret < 0) {
1562  _gmshClient->Error("Error on select: aborting remote get");
1563  return false;
1564  }
1565  int type, length, swap;
1566  if(!_gmshClient->ReceiveHeader(&type, &length, &swap)) {
1567  _gmshClient->Error(
1568  "Did not receive message header: aborting remote get");
1569  return false;
1570  }
1571  std::string msg(length, ' ');
1572  if(!_gmshClient->ReceiveMessage(length, &msg[0])) {
1573  _gmshClient->Error(
1574  "Did not receive message body: aborting remote get");
1575  return false;
1576  }
1577  if(type == GmshSocket::GMSH_PARAMETER) {
1578  T p;
1579  p.fromChar(msg);
1580  ps.push_back(p);
1581  return true;
1582  }
1584  T p;
1585  p.fromChar(msg);
1586  ps.push_back(p);
1587  // do NOT return until all parameters have been downloaded
1588  }
1589  else if(type == GmshSocket::GMSH_PARAMETER_QUERY_END) {
1590  // all parameters have been sent
1591  return true;
1592  }
1593  else if(type == GmshSocket::GMSH_PARAMETER_NOT_FOUND) {
1594  // parameter not found
1595  return true;
1596  }
1597  else if(type == GmshSocket::GMSH_INFO) {
1598  return true;
1599  }
1600  else {
1601  _gmshClient->Error("Unknown message type: aborting remote get");
1602  return false;
1603  }
1604  }
1605  return true;
1606  }
1607 
1608  public:
1610  {
1611  if(!_gmshClient) return;
1612  while(_numSubClients > 0) {
1613  int ret = _gmshClient->Select(500, 0);
1614  if(!ret) {
1615  _gmshClient->Info("Timeout: aborting wait on subclients");
1616  return;
1617  }
1618  else if(ret < 0) {
1619  _gmshClient->Error("Error on select: aborting wait on subclients");
1620  return;
1621  }
1622  int type, length, swap;
1623  if(!_gmshClient->ReceiveHeader(&type, &length, &swap)) {
1624  _gmshClient->Error(
1625  "Did not receive message header: aborting wait on subclients");
1626  return;
1627  }
1628  std::string msg(length, ' ');
1629  if(!_gmshClient->ReceiveMessage(length, &msg[0])) {
1630  _gmshClient->Error(
1631  "Did not receive message body: aborting wait on subclients");
1632  return;
1633  }
1634  if(type == GmshSocket::GMSH_STOP) _numSubClients -= 1;
1635  }
1636  }
1637 
1638  public:
1639  remoteNetworkClient(const std::string &name,
1640  const std::string &serverAddress)
1641  : client(name), _serverAddress(serverAddress), _numSubClients(0)
1642  {
1643  _gmshClient = new GmshClient();
1644  if(_gmshClient->Connect(_serverAddress.c_str()) < 0) {
1645  delete _gmshClient;
1646  _gmshClient = nullptr;
1647  }
1648  else {
1649  _gmshClient->Start();
1650  }
1651  }
1653  {
1654  if(_gmshClient) {
1655  waitOnSubClients();
1656  _gmshClient->Stop();
1658  delete _gmshClient;
1659  _gmshClient = nullptr;
1660  }
1661  }
1663  virtual bool isNetworkClient() { return true; }
1664  virtual bool clear(const std::string &name = "")
1665  {
1666  if(!_gmshClient) return false;
1667  std::string msg = name;
1668  if(msg.empty()) msg = "*";
1670  (int)msg.size(), &msg[0]);
1671  return true;
1672  }
1673  virtual bool set(const number &p) { return _set(p); }
1674  virtual bool set(const string &p) { return _set(p); }
1675  virtual bool get(std::vector<number> &ps, const std::string &name = "")
1676  {
1677  return _get(ps, name);
1678  }
1679  virtual bool get(std::vector<string> &ps, const std::string &name = "")
1680  {
1681  return _get(ps, name);
1682  }
1683  virtual bool setAndAppendChoices(const number &p)
1684  {
1685  // this will send the parameter without choices, using
1686  // GMSH_PARAMETER_WITHOUT_CHOICES instead of GMSH_PARAMETER; the ONELAB
1687  // server will then append the value to the choices server-side.
1688  return _set(p, false);
1689  }
1690  virtual bool setAndAppendChoices(const string &p)
1691  {
1692  // idem
1693  return _set(p, false);
1694  }
1695  virtual bool getWithoutChoices(std::vector<number> &ps,
1696  const std::string &name = "")
1697  {
1698  return _get(ps, name, false);
1699  }
1700  virtual bool getWithoutChoices(std::vector<string> &ps,
1701  const std::string &name = "")
1702  {
1703  return _get(ps, name, false);
1704  }
1705  void sendInfo(const std::string &msg)
1706  {
1707  if(_gmshClient) _gmshClient->Info(msg.c_str());
1708  }
1709  void sendWarning(const std::string &msg)
1710  {
1711  if(_gmshClient) _gmshClient->Warning(msg.c_str());
1712  }
1713  void sendError(const std::string &msg)
1714  {
1715  if(_gmshClient) _gmshClient->Error(msg.c_str());
1716  }
1717  void sendProgress(const std::string &msg)
1718  {
1719  if(_gmshClient) _gmshClient->Progress(msg.c_str());
1720  }
1721  void sendMergeFileRequest(const std::string &msg)
1722  {
1723  if(_gmshClient) _gmshClient->MergeFile(msg.c_str());
1724  }
1725  void sendOpenProjectRequest(const std::string &msg)
1726  {
1727  if(_gmshClient) _gmshClient->OpenProject(msg.c_str());
1728  }
1729  void sendParseStringRequest(const std::string &msg)
1730  {
1731  if(_gmshClient) _gmshClient->ParseString(msg.c_str());
1732  }
1733  void runNonBlockingSubClient(const std::string &name,
1734  const std::string &command)
1735  {
1736 #if !defined(BUILD_IOS)
1737  if(!_gmshClient) {
1738  int res = system(command.c_str());
1739  if(res) {
1740  // report error
1741  }
1742  return;
1743  }
1744 #endif
1745  std::string msg = name + parameter::charSep() + command;
1747  &msg[0]);
1748  _numSubClients += 1;
1749  }
1750  void runSubClient(const std::string &name, const std::string &command)
1751  {
1752  runNonBlockingSubClient(name, command);
1753  waitOnSubClients();
1754  }
1755  };
1756 
1757 } // namespace onelab
1758 
1759 #endif
onelab::number::fromJSON
bool fromJSON(const std::string &json)
Definition: onelab.h:605
onelab::parameter::sanitize
std::string sanitize(const std::string &in) const
Definition: onelab.h:246
onelab::number::toChar
std::string toChar() const
Definition: onelab.h:536
onelab::parameterSpace::set
bool set(const number &p, const std::string &client="")
Definition: onelab.h:964
onelab::server::instance
static server * instance(const std::string &address="")
Definition: onelab.h:1309
onelab::client::sendVertexArray
virtual void sendVertexArray(const std::string &msg)
Definition: onelab.h:1240
onelab::string
Definition: onelab.h:678
onelab::server::getNumParameters
int getNumParameters()
Definition: onelab.h:1357
onelab::number::getValueLabel
std::string getValueLabel(double value) const
Definition: onelab.h:503
onelab::string::toChar
std::string toChar() const
Definition: onelab.h:744
onelab::localNetworkClient::_treatExecutableAsFullCommandLine
bool _treatExecutableAsFullCommandLine
Definition: onelab.h:1478
onelab::remoteNetworkClient::setAndAppendChoices
virtual bool setAndAppendChoices(const number &p)
Definition: onelab.h:1683
onelab::parameter::_help
std::string _help
Definition: onelab.h:60
onelab::string::setValue
void setValue(const std::string &value)
Definition: onelab.h:695
onelab::parameter::addClients
void addClients(const std::map< std::string, int > &clients)
Definition: onelab.h:127
onelab::client::_index
int _index
Definition: onelab.h:1208
onelab::parameter::fromFile
static bool fromFile(std::vector< std::string > &msg, FILE *fp)
Definition: onelab.h:303
GmshSocket::SendMessage
void SendMessage(int type, int length, const void *msg)
Definition: GmshSocket.h:186
onelab::localClient
Definition: onelab.h:1393
onelab::parameterSpace::_mutex
std::mutex _mutex
Definition: onelab.h:846
onelab::client::getWithoutChoices
virtual bool getWithoutChoices(std::vector< string > &ps, const std::string &name="")=0
onelab::remoteNetworkClient::sendWarning
void sendWarning(const std::string &msg)
Definition: onelab.h:1709
onelab::parameterSpace::set
bool set(const string &p, const std::string &client="")
Definition: onelab.h:968
onelab::parameter::toFile
static bool toFile(const std::vector< std::string > &msg, FILE *fp, const std::string &creator)
Definition: onelab.h:318
onelab::server::server
server(const std::string &address="")
Definition: onelab.h:1307
onelab::parameter::getInfoFromChar
static void getInfoFromChar(const std::string &msg, std::string &version, std::string &type, std::string &name)
Definition: onelab.h:295
picojson::value
Definition: picojson.h:122
onelab::parameterSpace::getAllParameters
void getAllParameters(std::set< parameter *, parameterLessThan > &ps) const
Definition: onelab.h:992
GmshSocket::Warning
void Warning(const char *str)
Definition: GmshSocket.h:199
onelab::localClient::_set
bool _set(const T &p)
Definition: onelab.h:1395
picojson::value::array
std::vector< value > array
Definition: picojson.h:124
onelab::number::toJSON
std::string toJSON() const
Definition: onelab.h:574
onelab::number::fromChar
std::string::size_type fromChar(const std::string &msg)
Definition: onelab.h:553
onelab::localClient::getWithoutChoices
virtual bool getWithoutChoices(std::vector< number > &ps, const std::string &name="")
Definition: onelab.h:1452
onelab::remoteNetworkClient::sendParseStringRequest
void sendParseStringRequest(const std::string &msg)
Definition: onelab.h:1729
onelab::parameter::setLabel
void setLabel(const std::string &label)
Definition: onelab.h:91
onelab::number::setValueLabel
void setValueLabel(double value, const std::string &label)
Definition: onelab.h:476
GmshSocket::ReceiveHeader
int ReceiveHeader(int *type, int *len, int *swap)
Definition: GmshSocket.h:212
onelab::parameter::fromJSON
virtual bool fromJSON(const picojson::value::object &par)
Definition: onelab.h:369
onelab::server::thresholdChanged
void thresholdChanged(int value, const std::string &client="")
Definition: onelab.h:1353
onelab::parameterSpace::thresholdChanged
void thresholdChanged(int threshold, const std::string &client="")
Definition: onelab.h:1050
onelab::remoteNetworkClient::isNetworkClient
virtual bool isNetworkClient()
Definition: onelab.h:1663
onelab::server::clear
void clear(const std::string &name="", const std::string &client="")
Definition: onelab.h:1315
onelab::client::getId
int getId()
Definition: onelab.h:1215
onelab::remoteNetworkClient::runSubClient
void runSubClient(const std::string &name, const std::string &command)
Definition: onelab.h:1750
onelab::parameterSpace::hasClient
bool hasClient(const std::string &client) const
Definition: onelab.h:1021
onelab::number::setStep
void setStep(double step)
Definition: onelab.h:462
onelab::string::_values
std::vector< std::string > _values
Definition: onelab.h:680
onelab::localClient::set
virtual bool set(const number &p)
Definition: onelab.h:1418
onelab::parameterSpace::get
bool get(std::vector< number > &ps, const std::string &name="", const std::string &client="")
Definition: onelab.h:972
onelab::client::get
virtual bool get(std::vector< number > &ps, const std::string &name="")=0
onelab::localClient::set
virtual bool set(const string &p)
Definition: onelab.h:1419
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition: discreteFrechetDistance.cpp:15
onelab::number::_values
std::vector< double > _values
Definition: onelab.h:434
onelab::number::number
number(const std::string &name, const std::vector< double > &values, const std::string &label="", const std::string &help="")
Definition: onelab.h:448
GmshSocket::GMSH_PARAMETER_QUERY_ALL
@ GMSH_PARAMETER_QUERY_ALL
Definition: GmshSocket.h:77
onelab::localNetworkClient::setGmshServer
void setGmshServer(GmshServer *server)
Definition: onelab.h:1513
GmshSocket::ParseString
void ParseString(const char *str)
Definition: GmshSocket.h:204
onelab::parameter::toJSON
virtual std::string toJSON() const
Definition: onelab.h:337
onelab::client::client
client(const std::string &name)
Definition: onelab.h:1211
onelab::parameter::version
static std::string version()
Definition: onelab.h:205
onelab::parameterSpace::getNumParameters
int getNumParameters()
Definition: onelab.h:997
onelab::localNetworkClient::getRemoteLogin
const std::string & getRemoteLogin()
Definition: onelab.h:1502
onelab::parameterLessThan::operator()
bool operator()(const parameter *p1, const parameter *p2) const
Definition: onelab.h:424
onelab::number::getValues
const std::vector< double > & getValues() const
Definition: onelab.h:492
onelab::number::setMin
void setMin(double min)
Definition: onelab.h:460
onelab::string::getType
std::string getType() const
Definition: onelab.h:706
onelab::parameter::_clients
std::map< std::string, int > _clients
Definition: onelab.h:67
onelab::client::setIndex
void setIndex(int index)
Definition: onelab.h:1216
onelab::string::setKind
void setKind(const std::string &kind)
Definition: onelab.h:701
GmshSocket::GMSH_PARAMETER
@ GMSH_PARAMETER
Definition: GmshSocket.h:75
onelab::number::update
void update(const number &p)
Definition: onelab.h:509
onelab::parameter::setVisible
void setVisible(bool visible)
Definition: onelab.h:109
onelab::parameter::getShortName
std::string getShortName() const
Definition: onelab.h:145
onelab::parameter::getNextToken
static std::string getNextToken(const std::string &msg, std::string::size_type &first, char separator=charSep())
Definition: onelab.h:207
GmshSocket::MergeFile
void MergeFile(const char *str)
Definition: GmshSocket.h:202
onelab::parameter::setNeverChanged
void setNeverChanged(bool never)
Definition: onelab.h:105
onelab::string::setValues
void setValues(const std::vector< std::string > &values)
Definition: onelab.h:700
onelab::number::_min
double _min
Definition: onelab.h:435
onelab::server::fromJSON
bool fromJSON(const std::string &json, const std::string &client="")
Definition: onelab.h:1386
onelab::parameter::getChangedValue
int getChangedValue() const
Definition: onelab.h:188
onelab::client::sendError
virtual void sendError(const std::string &msg)
Definition: onelab.h:1229
onelab::number::setMax
void setMax(double max)
Definition: onelab.h:461
onelab::parameterSpace::parameterSpace
parameterSpace()
Definition: onelab.h:948
GmshSocket.h
onelab::server::registerClient
void registerClient(client *c)
Definition: onelab.h:1339
onelab::string::getValue
const std::string & getValue() const
Definition: onelab.h:707
onelab::parameterSpace::fromJSON
bool fromJSON(const picojson::value::object &par, const std::string &client="")
Definition: onelab.h:1176
onelab::server::setInstance
static void setInstance(server *s)
Definition: onelab.h:1314
onelab::client::get
virtual bool get(std::vector< string > &ps, const std::string &name="")=0
onelab::parameter::getName
const std::string & getName() const
Definition: onelab.h:137
onelab::parameter::getAttributes
const std::map< std::string, std::string > & getAttributes() const
Definition: onelab.h:198
GmshSocket::ReceiveMessage
int ReceiveMessage(int len, void *buffer)
Definition: GmshSocket.h:229
onelab::parameterSpace::_clear
bool _clear(const std::string &name, const std::string &client, std::set< T *, parameterLessThan > &ps)
Definition: onelab.h:850
onelab::client::set
virtual bool set(const number &p)=0
onelab::remoteNetworkClient::_numSubClients
int _numSubClients
Definition: onelab.h:1526
onelab::parameter::maxNumber
static double maxNumber()
Definition: onelab.h:204
onelab::number::getValueLabels
const std::map< double, std::string > & getValueLabels() const
Definition: onelab.h:499
GmshServer
Definition: GmshSocket.h:338
GmshSocket::GMSH_CONNECT
@ GMSH_CONNECT
Definition: GmshSocket.h:79
onelab::parameterSpace::_strings
std::set< string *, parameterLessThan > _strings
Definition: onelab.h:845
onelab::remoteNetworkClient
Definition: onelab.h:1519
onelab::parameter::getClients
const std::map< std::string, int > & getClients() const
Definition: onelab.h:202
onelab::string::fromChar
std::string::size_type fromChar(const std::string &msg)
Definition: onelab.h:755
onelab::number::number
number(const std::string &name="", double value=0., const std::string &label="", const std::string &help="")
Definition: onelab.h:442
onelab::client::sendInfo
virtual void sendInfo(const std::string &msg)
Definition: onelab.h:1221
onelab::parameterSpace::_get
bool _get(std::vector< T > &p, const std::string &name, const std::string &client, std::set< T *, parameterLessThan > &ps)
Definition: onelab.h:909
onelab::localNetworkClient::run
virtual bool run()=0
onelab::client::toFile
bool toFile(FILE *fp)
Definition: onelab.h:1284
onelab::localClient::setAndAppendChoices
virtual bool setAndAppendChoices(const number &p)
Definition: onelab.h:1428
onelab::localNetworkClient::setPid
void setPid(int pid)
Definition: onelab.h:1511
onelab::remoteNetworkClient::_get
bool _get(std::vector< T > &ps, const std::string &name="", bool withChoices=true)
Definition: onelab.h:1538
onelab::localClient::clear
virtual bool clear(const std::string &name="")
Definition: onelab.h:1413
onelab::number::setValueLabels
void setValueLabels(const std::map< double, std::string > &valueLabels)
Definition: onelab.h:472
onelab::parameter::getPath
std::string getPath() const
Definition: onelab.h:140
onelab::number
Definition: onelab.h:432
onelab::parameter::getHelp
const std::string & getHelp() const
Definition: onelab.h:139
GmshClient
Definition: GmshSocket.h:261
onelab::server::_address
std::string _address
Definition: onelab.h:1300
onelab::server::get
bool get(std::vector< T > &ps, const std::string &name="", const std::string &client="")
Definition: onelab.h:1324
onelab::parameter::_name
std::string _name
Definition: onelab.h:55
onelab::localNetworkClient::setSocketSwitch
void setSocketSwitch(const std::string &s)
Definition: onelab.h:1509
onelab::parameter::defaultChangedValue
static int defaultChangedValue()
Definition: onelab.h:206
onelab::localClient::getWithoutChoices
virtual bool getWithoutChoices(std::vector< string > &ps, const std::string &name="")
Definition: onelab.h:1460
onelab::localNetworkClient::getSocketSwitch
const std::string & getSocketSwitch()
Definition: onelab.h:1508
onelab::client::kill
virtual bool kill()
Definition: onelab.h:1220
GmshSocket::GMSH_PARAMETER_QUERY_END
@ GMSH_PARAMETER_QUERY_END
Definition: GmshSocket.h:78
onelab::string::update
void update(const string &p)
Definition: onelab.h:718
onelab::client::setAndAppendChoices
virtual bool setAndAppendChoices(const string &p)=0
onelab::parameterSpace::_getPtr
T * _getPtr(std::string name, const std::string client, std::set< T *, parameterLessThan > ps)
Definition: onelab.h:931
onelab::server::_parameterSpace
parameterSpace _parameterSpace
Definition: onelab.h:1304
onelab::string::getKind
const std::string & getKind() const
Definition: onelab.h:716
onelab::parameter::getVisible
bool getVisible() const
Definition: onelab.h:190
onelab::parameter::_label
std::string _label
Definition: onelab.h:58
onelab::parameter::parameter
parameter(const std::string &name="", const std::string &label="", const std::string &help="")
Definition: onelab.h:82
GmshSocket::OpenProject
void OpenProject(const char *str)
Definition: GmshSocket.h:203
onelab::string::string
string(const std::string &name, const std::vector< std::string > &values, const std::string &label="", const std::string &help="")
Definition: onelab.h:690
onelab::remoteNetworkClient::~remoteNetworkClient
virtual ~remoteNetworkClient()
Definition: onelab.h:1652
onelab::server::getChanged
int getChanged(const std::string &client="")
Definition: onelab.h:1349
onelab::parameterSpace::getParameterNames
void getParameterNames(std::vector< std::string > &names, const std::string &search="") const
Definition: onelab.h:998
GmshClient::Disconnect
void Disconnect()
Definition: GmshSocket.h:335
picojson::value::get
const T & get() const
onelab::server::findClient
citer findClient(const std::string &name)
Definition: onelab.h:1333
onelab::client::getWithoutChoices
virtual bool getWithoutChoices(std::vector< number > &ps, const std::string &name="")=0
onelab::number::getValueAsString
std::string getValueAsString() const
Definition: onelab.h:486
onelab::remoteNetworkClient::get
virtual bool get(std::vector< number > &ps, const std::string &name="")
Definition: onelab.h:1675
onelab::remoteNetworkClient::get
virtual bool get(std::vector< string > &ps, const std::string &name="")
Definition: onelab.h:1679
onelab::server::_clients
std::set< client * > _clients
Definition: onelab.h:1302
onelab::number::getNumValues
int getNumValues() const
Definition: onelab.h:493
onelab::parameter::setChanged
void setChanged(int changed, const std::string &client="")
Definition: onelab.h:93
onelab::number::_max
double _max
Definition: onelab.h:435
onelab::string::getChoices
const std::vector< std::string > & getChoices() const
Definition: onelab.h:717
onelab::remoteNetworkClient::sendError
void sendError(const std::string &msg)
Definition: onelab.h:1713
onelab::number::getMax
double getMax() const
Definition: onelab.h:495
onelab::server::toChar
std::vector< std::string > toChar(const std::string &client="")
Definition: onelab.h:1363
onelab::server::citer
std::set< client * >::iterator citer
Definition: onelab.h:1329
onelab::number::_step
double _step
Definition: onelab.h:435
onelab::localNetworkClient::kill
virtual bool kill()=0
swap
void swap(double &a, double &b)
Definition: meshTriangulation.cpp:27
onelab::server
Definition: onelab.h:1295
onelab
Definition: GmshMessage.h:18
onelab::number::setChoiceLabels
void setChoiceLabels(const std::vector< std::string > &labels)
Definition: onelab.h:465
onelab::localClient::_get
bool _get(std::vector< T > &ps, const std::string &name="")
Definition: onelab.h:1401
onelab::parameter::getNeverChanged
bool getNeverChanged() const
Definition: onelab.h:189
onelab::parameter::setHelp
void setHelp(const std::string &help)
Definition: onelab.h:92
onelab::remoteNetworkClient::getWithoutChoices
virtual bool getWithoutChoices(std::vector< string > &ps, const std::string &name="")
Definition: onelab.h:1700
onelab::number::getValue
double getValue() const
Definition: onelab.h:481
onelab::string::fromJSON
bool fromJSON(const picojson::value::object &par)
Definition: onelab.h:808
onelab::remoteNetworkClient::clear
virtual bool clear(const std::string &name="")
Definition: onelab.h:1664
onelab::server::getParameterNames
void getParameterNames(std::vector< std::string > &names, const std::string &search="") const
Definition: onelab.h:1358
onelab::client::getName
std::string getName()
Definition: onelab.h:1213
onelab::number::getStep
double getStep() const
Definition: onelab.h:496
onelab::string::toJSON
std::string toJSON() const
Definition: onelab.h:768
onelab::number::_valueLabels
std::map< double, std::string > _valueLabels
Definition: onelab.h:439
picojson::value::is
bool is() const
onelab::number::setIndex
void setIndex(int index)
Definition: onelab.h:463
picojson::object
value::object object
Definition: picojson.h:195
onelab::localClient::get
virtual bool get(std::vector< string > &ps, const std::string &name="")
Definition: onelab.h:1424
onelab::server::getNumClients
int getNumClients()
Definition: onelab.h:1332
onelab::parameterSpace::clear
void clear(const std::string &name="", const std::string &client="")
Definition: onelab.h:950
GmshClient::Connect
int Connect(const char *sockname)
Definition: GmshSocket.h:265
GmshSocket::Info
void Info(const char *str)
Definition: GmshSocket.h:198
picojson::parse
std::string parse(value &out, Iter &pos, const Iter &last)
Definition: picojson.h:1058
picojson.h
picojson::value::object
std::map< std::string, value > object
Definition: picojson.h:125
onelab::parameter::trim
static std::string trim(const std::string &str, const std::string &whitespace=" \t\n")
Definition: onelab.h:237
onelab::parameter::_visible
bool _visible
Definition: onelab.h:73
onelab::number::getMin
double getMin() const
Definition: onelab.h:494
onelab::parameterSpace::~parameterSpace
~parameterSpace()
Definition: onelab.h:949
onelab::client::_name
std::string _name
Definition: onelab.h:1204
onelab::parameter
Definition: onelab.h:48
onelab::parameter::addClient
void addClient(const std::string &client, int changed)
Definition: onelab.h:123
onelab::parameterSpace::setChanged
void setChanged(int changed, const std::string &client="")
Definition: onelab.h:1043
GmshSocket::GMSH_STOP
@ GMSH_STOP
Definition: GmshSocket.h:67
onelab::remoteNetworkClient::_set
bool _set(const T &p, bool withChoices=true)
Definition: onelab.h:1527
onelab::localNetworkClient
Definition: onelab.h:1471
onelab::localNetworkClient::isNetworkClient
virtual bool isNetworkClient()
Definition: onelab.h:1499
onelab::parameterSpace::fromChar
bool fromChar(const std::vector< std::string > &msg, const std::string &client="")
Definition: onelab.h:1074
onelab::client::toChar
std::vector< std::string > toChar()
Definition: onelab.h:1252
onelab::localNetworkClient::_pid
int _pid
Definition: onelab.h:1484
onelab::parameter::getNumClients
int getNumClients()
Definition: onelab.h:135
onelab::parameter::getChanged
int getChanged(const std::string &client="") const
Definition: onelab.h:171
onelab::localNetworkClient::setExecutable
void setExecutable(const std::string &s)
Definition: onelab.h:1501
onelab::localNetworkClient::_remoteLogin
std::string _remoteLogin
Definition: onelab.h:1480
onelab::localNetworkClient::~localNetworkClient
virtual ~localNetworkClient()
Definition: onelab.h:1498
onelab::parameter::setAttributes
void setAttributes(const std::map< std::string, std::string > &attributes)
Definition: onelab.h:115
onelab::client::isNetworkClient
virtual bool isNetworkClient()
Definition: onelab.h:1219
onelab::client::sendProgress
virtual void sendProgress(const std::string &msg)
Definition: onelab.h:1233
onelab::server::toFile
bool toFile(FILE *fp, const std::string &client="")
Definition: onelab.h:1372
onelab::parameterSpace::get
bool get(std::vector< string > &ps, const std::string &name="", const std::string &client="")
Definition: onelab.h:977
GmshSocket::Select
int Select(int seconds, int microseconds, int socket=-1)
Definition: GmshSocket.h:173
GmshSocket::GMSH_INFO
@ GMSH_INFO
Definition: GmshSocket.h:68
onelab::client::clear
virtual bool clear(const std::string &name)=0
GmshSocket::GMSH_PARAMETER_CLEAR
@ GMSH_PARAMETER_CLEAR
Definition: GmshSocket.h:83
onelab::parameter::setAttribute
void setAttribute(const std::string &key, const std::string &value)
Definition: onelab.h:111
onelab::server::_server
static server * _server
Definition: onelab.h:1298
onelab::client::sendOpenProjectRequest
virtual void sendOpenProjectRequest(const std::string &msg)
Definition: onelab.h:1238
onelab::parameterSpace::_set
bool _set(const T &p, const std::string &client, std::set< T *, parameterLessThan > &ps)
Definition: onelab.h:885
onelab::number::getType
std::string getType() const
Definition: onelab.h:480
onelab::client::fromChar
bool fromChar(const std::vector< std::string > &msg)
Definition: onelab.h:1263
GmshSocket::Progress
void Progress(const char *str)
Definition: GmshSocket.h:201
onelab::parameter::setReadOnly
void setReadOnly(bool readOnly)
Definition: onelab.h:110
onelab::remoteNetworkClient::sendOpenProjectRequest
void sendOpenProjectRequest(const std::string &msg)
Definition: onelab.h:1725
length
double length(Quaternion &q)
Definition: Camera.cpp:346
onelab::server::firstClient
citer firstClient()
Definition: onelab.h:1330
onelab::remoteNetworkClient::_serverAddress
std::string _serverAddress
Definition: onelab.h:1522
onelab::client::sendMergeFileRequest
virtual void sendMergeFileRequest(const std::string &msg)
Definition: onelab.h:1237
GmshSocket::GMSH_PARAMETER_NOT_FOUND
@ GMSH_PARAMETER_NOT_FOUND
Definition: GmshSocket.h:81
onelab::client::fromFile
bool fromFile(FILE *fp)
Definition: onelab.h:1285
onelab::string::getValueAsString
std::string getValueAsString() const
Definition: onelab.h:713
onelab::remoteNetworkClient::setAndAppendChoices
virtual bool setAndAppendChoices(const string &p)
Definition: onelab.h:1690
onelab::number::setValue
void setValue(double value)
Definition: onelab.h:454
GmshSocket::GMSH_PARAMETER_QUERY_WITHOUT_CHOICES
@ GMSH_PARAMETER_QUERY_WITHOUT_CHOICES
Definition: GmshSocket.h:88
onelab::remoteNetworkClient::remoteNetworkClient
remoteNetworkClient(const std::string &name, const std::string &serverAddress)
Definition: onelab.h:1639
onelab::server::toJSON
bool toJSON(std::string &json, const std::string &client="")
Definition: onelab.h:1382
onelab::parameterSpace::fromJSON
bool fromJSON(const std::string &json, const std::string &client="")
Definition: onelab.h:1122
GmshClient::Start
void Start()
Definition: GmshSocket.h:324
onelab::localNetworkClient::setRemoteLogin
void setRemoteLogin(const std::string &s)
Definition: onelab.h:1507
onelab::client::setId
void setId(int id)
Definition: onelab.h:1214
onelab::remoteNetworkClient::getGmshClient
GmshClient * getGmshClient()
Definition: onelab.h:1662
onelab::client::~client
virtual ~client()
Definition: onelab.h:1212
onelab::client::sendParseStringRequest
virtual void sendParseStringRequest(const std::string &msg)
Definition: onelab.h:1239
onelab::string::string
string(const std::string &name="", const std::string &value="", const std::string &label="", const std::string &help="")
Definition: onelab.h:684
std
Definition: picojson.h:1135
onelab::parameter::getReadOnly
bool getReadOnly() const
Definition: onelab.h:191
onelab::parameter::_changedValue
int _changedValue
Definition: onelab.h:71
onelab::number::fromJSON
bool fromJSON(const picojson::value::object &par)
Definition: onelab.h:623
onelab::localNetworkClient::_executable
std::string _executable
Definition: onelab.h:1474
onelab::localClient::~localClient
virtual ~localClient()
Definition: onelab.h:1412
onelab::parameter::setClients
void setClients(const std::map< std::string, int > &clients)
Definition: onelab.h:119
onelab::client::sendWarning
virtual void sendWarning(const std::string &msg)
Definition: onelab.h:1225
onelab::string::_kind
std::string _kind
Definition: onelab.h:681
onelab::client::setAndAppendChoices
virtual bool setAndAppendChoices(const number &p)=0
picojson::array
value::array array
Definition: picojson.h:194
onelab::parameter::toChar
virtual std::string toChar() const
Definition: onelab.h:253
onelab::parameter::_attributes
std::map< std::string, std::string > _attributes
Definition: onelab.h:79
onelab::remoteNetworkClient::sendMergeFileRequest
void sendMergeFileRequest(const std::string &msg)
Definition: onelab.h:1721
onelab::server::fromFile
bool fromFile(FILE *fp, const std::string &client="")
Definition: onelab.h:1376
onelab::parameter::split
static std::vector< std::string > split(const std::string &msg, char separator=charSep())
Definition: onelab.h:228
onelab::remoteNetworkClient::runNonBlockingSubClient
void runNonBlockingSubClient(const std::string &name, const std::string &command)
Definition: onelab.h:1733
onelab::client::set
virtual bool set(const string &p)=0
onelab::server::lastClient
citer lastClient()
Definition: onelab.h:1331
onelab::parameter::charSep
static char charSep()
Definition: onelab.h:203
onelab::parameter::setName
void setName(const std::string &name)
Definition: onelab.h:90
onelab::string::getValues
const std::vector< std::string > & getValues() const
Definition: onelab.h:714
onelab::parameter::~parameter
virtual ~parameter()
Definition: onelab.h:89
onelab::parameter::getLabel
const std::string & getLabel() const
Definition: onelab.h:138
GmshClient::Stop
void Stop()
Definition: GmshSocket.h:334
onelab::parameterSpace
Definition: onelab.h:842
onelab::number::_choices
std::vector< double > _choices
Definition: onelab.h:434
onelab::localNetworkClient::localNetworkClient
localNetworkClient(const std::string &name, const std::string &executable, const std::string &remoteLogin="", bool treatExecutableAsFullCommandLine=false)
Definition: onelab.h:1489
onelab::localNetworkClient::treatExecutableAsFullCommandLine
bool treatExecutableAsFullCommandLine() const
Definition: onelab.h:1503
onelab::client::getIndex
int getIndex()
Definition: onelab.h:1217
onelab::parameterSpace::toJSON
bool toJSON(std::string &json, const std::string &creator="", const std::string &client="") const
Definition: onelab.h:1096
onelab::remoteNetworkClient::_gmshClient
GmshClient * _gmshClient
Definition: onelab.h:1524
onelab::string::setChoices
void setChoices(const std::vector< std::string > &choices)
Definition: onelab.h:702
onelab::parameter::fromChar
virtual std::string::size_type fromChar(const std::string &msg)
Definition: onelab.h:271
onelab::client
Definition: onelab.h:1201
onelab::string::fromJSON
bool fromJSON(const std::string &json)
Definition: onelab.h:790
onelab::parameter::_readOnly
bool _readOnly
Definition: onelab.h:75
onelab::remoteNetworkClient::sendInfo
void sendInfo(const std::string &msg)
Definition: onelab.h:1705
onelab::parameter::sanitizeJSON
std::string sanitizeJSON(const std::string &in) const
Definition: onelab.h:332
onelab::parameterSpace::_numbers
std::set< number *, parameterLessThan > _numbers
Definition: onelab.h:844
GmshSocket::GMSH_PARAMETER_WITHOUT_CHOICES
@ GMSH_PARAMETER_WITHOUT_CHOICES
Definition: GmshSocket.h:87
onelab::parameterSpace::getPtr
void getPtr(number **ptr, const std::string &name, const std::string &client="")
Definition: onelab.h:982
onelab::number::_index
int _index
Definition: onelab.h:438
onelab::parameter::setChangedValue
void setChangedValue(int value)
Definition: onelab.h:104
onelab::server::fromChar
bool fromChar(const std::vector< std::string > &msg, const std::string &client="")
Definition: onelab.h:1367
onelab::parameter::getType
virtual std::string getType() const =0
onelab::parameterLessThan
Definition: onelab.h:422
onelab::parameter::getAttribute
std::string getAttribute(const std::string &key) const
Definition: onelab.h:192
onelab::number::setValues
void setValues(const std::vector< double > &values)
Definition: onelab.h:459
onelab::localNetworkClient::_gmshServer
GmshServer * _gmshServer
Definition: onelab.h:1486
onelab::localClient::localClient
localClient(const std::string &name)
Definition: onelab.h:1408
onelab::remoteNetworkClient::waitOnSubClients
void waitOnSubClients()
Definition: onelab.h:1609
onelab::localClient::get
virtual bool get(std::vector< number > &ps, const std::string &name="")
Definition: onelab.h:1420
onelab::localNetworkClient::getGmshServer
GmshServer * getGmshServer()
Definition: onelab.h:1512
onelab::parameterSpace::toChar
std::vector< std::string > toChar(const std::string &client="") const
Definition: onelab.h:1061
onelab::remoteNetworkClient::sendProgress
void sendProgress(const std::string &msg)
Definition: onelab.h:1717
onelab::remoteNetworkClient::getWithoutChoices
virtual bool getWithoutChoices(std::vector< number > &ps, const std::string &name="")
Definition: onelab.h:1695
GmshSocket::GMSH_PARAMETER_QUERY
@ GMSH_PARAMETER_QUERY
Definition: GmshSocket.h:76
onelab::server::set
bool set(const T &p, const std::string &client="")
Definition: onelab.h:1319
onelab::parameterSpace::getChanged
int getChanged(const std::string &client="") const
Definition: onelab.h:1031
onelab::remoteNetworkClient::set
virtual bool set(const number &p)
Definition: onelab.h:1673
onelab::number::getChoices
const std::vector< double > & getChoices() const
Definition: onelab.h:498
onelab::localNetworkClient::getExecutable
const std::string & getExecutable()
Definition: onelab.h:1500
onelab::parameterSpace::getPtr
void getPtr(string **ptr, const std::string &name, const std::string &client="")
Definition: onelab.h:987
onelab::number::getIndex
int getIndex() const
Definition: onelab.h:497
GmshSocket::Error
void Error(const char *str)
Definition: GmshSocket.h:200
onelab::parameter::hasClient
bool hasClient(const std::string &client)
Definition: onelab.h:131
onelab::localClient::setAndAppendChoices
virtual bool setAndAppendChoices(const string &p)
Definition: onelab.h:1440
onelab::server::setChanged
void setChanged(int changed, const std::string &client="")
Definition: onelab.h:1345
onelab::server::unregisterClient
void unregisterClient(client *c)
Definition: onelab.h:1344
onelab::string::_choices
std::vector< std::string > _choices
Definition: onelab.h:680
onelab::localNetworkClient::_socketSwitch
std::string _socketSwitch
Definition: onelab.h:1482
onelab::remoteNetworkClient::set
virtual bool set(const string &p)
Definition: onelab.h:1674
onelab::client::_id
int _id
Definition: onelab.h:1206
onelab::number::setChoices
void setChoices(const std::vector< double > &choices)
Definition: onelab.h:464
onelab::localNetworkClient::getPid
int getPid()
Definition: onelab.h:1510
onelab::client::run
virtual bool run()
Definition: onelab.h:1218
onelab::string::getNumValues
int getNumValues() const
Definition: onelab.h:715
onelab::server::~server
~server()
Definition: onelab.h:1308