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

onelab work

parent c9d4d99f
Branches
Tags
No related merge requests found
...@@ -81,7 +81,8 @@ namespace onelab{ ...@@ -81,7 +81,8 @@ namespace onelab{
return sstream.str(); return sstream.str();
} }
virtual void fromChar(const std::string &msg){} virtual void fromChar(const std::string &msg){}
static std::string getNextToken(const std::string &msg, std::string::size_type &first) static std::string getNextToken(const std::string &msg,
std::string::size_type &first)
{ {
std::string::size_type last = msg.find_first_of(charSep(), first); std::string::size_type last = msg.find_first_of(charSep(), first);
std::string next = msg.substr(first, last - first); std::string next = msg.substr(first, last - first);
...@@ -285,34 +286,35 @@ namespace onelab{ ...@@ -285,34 +286,35 @@ namespace onelab{
// add new clients if necessary. This needs to be locked to avoid // add new clients if necessary. This needs to be locked to avoid
// race conditions when several clients try to set a parameter at // race conditions when several clients try to set a parameter at
// the same time // the same time
template <class T> bool _set(T &p, std::set<T*, parameterLessThan> &parameters, template <class T> bool _set(T &p, std::set<T*, parameterLessThan> &ps,
bool value=true) bool value=true)
{ {
typename std::set<T*, parameterLessThan>::iterator it = parameters.find(&p); typename std::set<T*, parameterLessThan>::iterator it = ps.find(&p);
if(it != parameters.end()){ if(it != ps.end()){
std::set<std::string> clients = p.getClients(); std::set<std::string> clients = p.getClients();
(*it)->addClients(clients); (*it)->addClients(clients);
if(value) (*it)->setValue(p.getValue()); if(value) (*it)->setValue(p.getValue());
} }
else{ else{
parameters.insert(new T(p)); ps.insert(new T(p));
} }
return true; return true;
} }
// get the parameter matching the given name, or all the // get the parameter matching the given name, or all the
// parameters in the category if no name is given // parameters in the category if no name is given
template <class T> bool _get(std::vector<T> &p, const std::string &name, template <class T> bool _get(std::vector<T> &p, const std::string &name,
std::set<T*, parameterLessThan> &parameters) std::set<T*, parameterLessThan> &ps)
{ {
p.clear();
if(name.empty()){ if(name.empty()){
for(typename std::set<T*, parameterLessThan>::iterator it = parameters.begin(); for(typename std::set<T*, parameterLessThan>::iterator it = ps.begin();
it != parameters.end(); it++) it != ps.end(); it++)
p.push_back(**it); p.push_back(**it);
} }
else{ else{
T tmp(name); T tmp(name);
typename std::set<T*, parameterLessThan>::iterator it = parameters.find(&tmp); typename std::set<T*, parameterLessThan>::iterator it = ps.find(&tmp);
if(it != parameters.end()) if(it != ps.end())
p.push_back(**it); p.push_back(**it);
} }
return true; return true;
...@@ -338,21 +340,21 @@ namespace onelab{ ...@@ -338,21 +340,21 @@ namespace onelab{
bool set(string &p, bool value=true){ return _set(p, _strings, value); } bool set(string &p, bool value=true){ return _set(p, _strings, value); }
bool set(region &p, bool value=true){ return _set(p, _regions, value); } bool set(region &p, bool value=true){ return _set(p, _regions, value); }
bool set(function &p, bool value=true){ return _set(p, _functions, value); } bool set(function &p, bool value=true){ return _set(p, _functions, value); }
bool get(std::vector<number> &p, const std::string &name="") bool get(std::vector<number> &ps, const std::string &name="")
{ {
return _get(p, name, _numbers); return _get(ps, name, _numbers);
} }
bool get(std::vector<string> &p, const std::string &name="") bool get(std::vector<string> &ps, const std::string &name="")
{ {
return _get(p, name, _strings); return _get(ps, name, _strings);
} }
bool get(std::vector<region> &p, const std::string &name="") bool get(std::vector<region> &ps, const std::string &name="")
{ {
return _get(p, name, _regions); return _get(ps, name, _regions);
} }
bool get(std::vector<function> &p, const std::string &name="") bool get(std::vector<function> &ps, const std::string &name="")
{ {
return _get(p, name, _functions); return _get(ps, name, _functions);
} }
void print() void print()
{ {
...@@ -386,14 +388,26 @@ namespace onelab{ ...@@ -386,14 +388,26 @@ namespace onelab{
virtual void sendProgress(const std::string &msg){ std::cout << msg << std::endl; } virtual void sendProgress(const std::string &msg){ std::cout << msg << std::endl; }
virtual void sendMergeFileRequest(const std::string &msg){} virtual void sendMergeFileRequest(const std::string &msg){}
virtual void sendParseStringRequest(const std::string &msg){} virtual void sendParseStringRequest(const std::string &msg){}
virtual bool set(number &parameter, bool value=true){ return false; } virtual bool set(number &p, bool value=true){ return false; }
virtual bool set(string &parameter, bool value=true){ return false; } virtual bool set(string &p, bool value=true){ return false; }
virtual bool set(region &parameter, bool value=true){ return false; } virtual bool set(region &p, bool value=true){ return false; }
virtual bool set(function &parameter, bool value=true){ return false; } virtual bool set(function &p, bool value=true){ return false; }
virtual bool get(std::vector<number> &parameters, const std::string &name=""){ return false; } virtual bool get(std::vector<number> &ps, const std::string &name="")
virtual bool get(std::vector<string> &parameters, const std::string &name=""){ return false; } {
virtual bool get(std::vector<region> &parameters, const std::string &name=""){ return false; } return false;
virtual bool get(std::vector<function> &parameters, const std::string &name=""){ return false; } }
virtual bool get(std::vector<string> &ps, const std::string &name="")
{
return false;
}
virtual bool get(std::vector<region> &ps, const std::string &name="")
{
return false;
}
virtual bool get(std::vector<function> &ps, const std::string &name="")
{
return false;
}
}; };
// The onelab server: a singleton that stores the parameter space // The onelab server: a singleton that stores the parameter space
...@@ -420,9 +434,9 @@ namespace onelab{ ...@@ -420,9 +434,9 @@ namespace onelab{
{ {
return _parameterSpace.set(p, value); return _parameterSpace.set(p, value);
} }
template <class T> bool get(std::vector<T> &p, const std::string &name="") template <class T> bool get(std::vector<T> &ps, const std::string &name="")
{ {
return _parameterSpace.get(p, name); return _parameterSpace.get(ps, name);
} }
bool registerClient(client *c) bool registerClient(client *c)
{ {
...@@ -442,16 +456,16 @@ namespace onelab{ ...@@ -442,16 +456,16 @@ namespace onelab{
protected: protected:
// the pointer to the server // the pointer to the server
server *_server; server *_server;
template <class T> bool _set(T &parameter, bool value=true) template <class T> bool _set(T &p, bool value=true)
{ {
parameter.addClient(_name); p.addClient(_name);
_server->set(parameter, value); _server->set(p, value);
return true; return true;
} }
template <class T> bool _get(std::vector<T> &parameters, template <class T> bool _get(std::vector<T> &ps,
const std::string &name="") const std::string &name="")
{ {
_server->get(parameters, name); _server->get(ps, name);
return true; return true;
} }
public: public:
...@@ -465,10 +479,22 @@ namespace onelab{ ...@@ -465,10 +479,22 @@ namespace onelab{
virtual bool set(string &p, bool value=true){ return _set(p, value); } virtual bool set(string &p, bool value=true){ return _set(p, value); }
virtual bool set(function &p, bool value=true){ return _set(p, value); } virtual bool set(function &p, bool value=true){ return _set(p, value); }
virtual bool set(region &p, bool value=true){ return _set(p, value); } virtual bool set(region &p, bool value=true){ return _set(p, value); }
virtual bool get(std::vector<number> &p, const std::string &name=""){ return _get(p, name); } virtual bool get(std::vector<number> &ps, const std::string &name="")
virtual bool get(std::vector<string> &p, const std::string &name=""){ return _get(p, name); } {
virtual bool get(std::vector<function> &p, const std::string &name=""){ return _get(p, name); } return _get(ps, name);
virtual bool get(std::vector<region> &p, const std::string &name=""){ return _get(p, name); } }
virtual bool get(std::vector<string> &ps, const std::string &name="")
{
return _get(ps, name);
}
virtual bool get(std::vector<function> &ps, const std::string &name="")
{
return _get(ps, name);
}
virtual bool get(std::vector<region> &ps, const std::string &name="")
{
return _get(ps, name);
}
virtual void print(){ _server->print(); } virtual void print(){ _server->print(); }
}; };
...@@ -493,21 +519,22 @@ namespace onelab{ ...@@ -493,21 +519,22 @@ namespace onelab{
std::string _serverAddress; std::string _serverAddress;
// underlying GmshClient // underlying GmshClient
GmshClient *_gmshClient; GmshClient *_gmshClient;
template <class T> bool _set(T &parameter) template <class T> bool _set(T &p)
{ {
if(!_gmshClient) return false; if(!_gmshClient) return false;
parameter.addClient(_name); p.addClient(_name);
std::string msg = parameter.toChar(); std::string msg = p.toChar();
_gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER, msg.size(), &msg[0]); _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER, msg.size(), &msg[0]);
return true; return true;
} }
template <class T> bool _get(std::vector<T> &parameters, template <class T> bool _get(std::vector<T> &ps,
const std::string &name="") const std::string &name="")
{ {
ps.clear();
if(!_gmshClient) return false; if(!_gmshClient) return false;
T parameter(name); T p(name);
parameter.addClient(_name); p.addClient(_name);
std::string msg = parameter.toChar(); std::string msg = p.toChar();
_gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY, msg.size(), &msg[0]); _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY, msg.size(), &msg[0]);
while(1){ while(1){
// stop if we have no communications for 10 secs // stop if we have no communications for 10 secs
...@@ -533,7 +560,7 @@ namespace onelab{ ...@@ -533,7 +560,7 @@ namespace onelab{
if(type == GmshSocket::GMSH_PARAMETER){ if(type == GmshSocket::GMSH_PARAMETER){
T p; T p;
p.fromChar(msg); p.fromChar(msg);
parameters.push_back(p); ps.push_back(p);
return true; return true;
} }
else if(type == GmshSocket::GMSH_INFO){ else if(type == GmshSocket::GMSH_INFO){
...@@ -573,16 +600,34 @@ namespace onelab{ ...@@ -573,16 +600,34 @@ namespace onelab{
virtual bool set(string &p, bool value=true){ return _set(p); } virtual bool set(string &p, bool value=true){ return _set(p); }
virtual bool set(function &p, bool value=true){ return _set(p); } virtual bool set(function &p, bool value=true){ return _set(p); }
virtual bool set(region &p, bool value=true){ return _set(p); } virtual bool set(region &p, bool value=true){ return _set(p); }
virtual bool get(std::vector<number> &p, const std::string &name=""){ return _get(p, name); } virtual bool get(std::vector<number> &ps, const std::string &name="")
virtual bool get(std::vector<string> &p, const std::string &name=""){ return _get(p, name); } {
virtual bool get(std::vector<function> &p, const std::string &name=""){ return _get(p, name); } return _get(ps, name);
virtual bool get(std::vector<region> &p, const std::string &name=""){ return _get(p, name); } }
virtual bool get(std::vector<string> &ps, const std::string &name="")
{
return _get(ps, name);
}
virtual bool get(std::vector<function> &ps, const std::string &name="")
{
return _get(ps, name);
}
virtual bool get(std::vector<region> &ps, const std::string &name="")
{
return _get(ps, name);
}
void sendInfo(const std::string &msg){ _gmshClient->Info(msg.c_str()); } void sendInfo(const std::string &msg){ _gmshClient->Info(msg.c_str()); }
void sendWarning(const std::string &msg){ _gmshClient->Warning(msg.c_str()); } void sendWarning(const std::string &msg){ _gmshClient->Warning(msg.c_str()); }
void sendError(const std::string &msg){ _gmshClient->Error(msg.c_str()); } void sendError(const std::string &msg){ _gmshClient->Error(msg.c_str()); }
void sendProgress(const std::string &msg){ _gmshClient->Progress(msg.c_str()); } void sendProgress(const std::string &msg){ _gmshClient->Progress(msg.c_str()); }
void sendMergeFileRequest(const std::string &msg){ _gmshClient->MergeFile(msg.c_str()); } void sendMergeFileRequest(const std::string &msg)
void sendParseStringRequest(const std::string &msg){ _gmshClient->ParseString(msg.c_str()); } {
_gmshClient->MergeFile(msg.c_str());
}
void sendParseStringRequest(const std::string &msg)
{
_gmshClient->ParseString(msg.c_str());
}
}; };
} }
......
...@@ -207,7 +207,7 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -207,7 +207,7 @@ void onelab_cb(Fl_Widget *w, void *data)
onelab::client *c = it->second; onelab::client *c = it->second;
c->run("/Users/geuzaine/src/getdp/demos/test.pro"); c->run("/Users/geuzaine/src/getdp/demos/test.pro");
} }
printf("**** ONELAB DB DUMP:\n"); printf("**** GMSH ONELAB DB DUMP:\n");
onelab::server::instance()->print(); onelab::server::instance()->print();
printf("**** \n"); printf("**** \n");
FlGui::instance()->onelab->rebuildTree(); FlGui::instance()->onelab->rebuildTree();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment