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

update

parent 61e28f1f
Branches
Tags
No related merge requests found
...@@ -73,6 +73,8 @@ class GmshSocket{ ...@@ -73,6 +73,8 @@ class GmshSocket{
GMSH_VERTEX_ARRAY = 22, GMSH_VERTEX_ARRAY = 22,
GMSH_PARAMETER = 23, GMSH_PARAMETER = 23,
GMSH_PARAMETER_QUERY = 24, GMSH_PARAMETER_QUERY = 24,
GMSH_PARAM_QUERY_ALL = 25,
GMSH_PARAM_QUERY_END = 26,
GMSH_SPEED_TEST = 30, GMSH_SPEED_TEST = 30,
GMSH_OPTION_1 = 100, GMSH_OPTION_1 = 100,
GMSH_OPTION_2 = 101, GMSH_OPTION_2 = 101,
......
...@@ -91,6 +91,19 @@ namespace onelab{ ...@@ -91,6 +91,19 @@ namespace onelab{
const std::string &getName() const { return _name; } const std::string &getName() const { return _name; }
const std::string &getShortHelp() const { return _shortHelp; } const std::string &getShortHelp() const { return _shortHelp; }
const std::string &getHelp() const { return _help; } const std::string &getHelp() const { return _help; }
std::string getShortName() const
{
if(_shortHelp.size()) return _shortHelp;
std::string s = _name;
// remove path
std::string::size_type last = _name.find_last_of('/');
if(last != std::string::npos)
s = _name.substr(last + 1);
// remove starting numbers
while(s.size() && s[0] >= '0' && s[0] <= '9')
s = s.substr(1);
return s;
}
bool getChanged() const { return _changed; } bool getChanged() const { return _changed; }
bool getVisible() const { return _visible; } bool getVisible() const { return _visible; }
std::string getAttribute(const std::string &key) const std::string getAttribute(const std::string &key) const
...@@ -110,6 +123,7 @@ namespace onelab{ ...@@ -110,6 +123,7 @@ namespace onelab{
static std::string getNextToken(const std::string &msg, static std::string getNextToken(const std::string &msg,
std::string::size_type &first) std::string::size_type &first)
{ {
if(first == std::string::npos) return "";
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);
first = (last == std::string::npos) ? last : last + 1; first = (last == std::string::npos) ? last : last + 1;
...@@ -311,15 +325,18 @@ namespace onelab{ ...@@ -311,15 +325,18 @@ namespace onelab{
// regions will include union, intersection, etc. // regions will include union, intersection, etc.
class region : public parameter{ class region : public parameter{
private: private:
std::string _value; // TODO: change this into std::set<std::string> std::set<std::string> _value;
std::vector<std::string> _choices; std::vector<std::set<std::string> > _choices;
// optional geometrical dimension
int _dimension;
public: public:
region(const std::string &name="", const std::string &value="", region(const std::string &name="",
const std::set<std::string> &value = std::set<std::string>(),
const std::string &shortHelp="", const std::string &help="") const std::string &shortHelp="", const std::string &help="")
: parameter(name, shortHelp, help), _value(value) {} : parameter(name, shortHelp, help), _value(value) {}
void setValue(const std::string &value){ _value = value; } void setValue(const std::set<std::string> &value){ _value = value; }
std::string getType() const { return "region"; } std::string getType() const { return "region"; }
const std::string &getValue() const { return _value; } const std::set<std::string> &getValue() const { return _value; }
void update(const region &p) void update(const region &p)
{ {
addClients(p.getClients()); addClients(p.getClients());
...@@ -333,12 +350,15 @@ namespace onelab{ ...@@ -333,12 +350,15 @@ namespace onelab{
} }
std::string toChar() const std::string toChar() const
{ {
/*
std::ostringstream sstream; std::ostringstream sstream;
sstream << parameter::toChar() << _value << charSep() sstream << parameter::toChar() << _value << charSep()
<< _choices.size() << charSep(); << _choices.size() << charSep();
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
sstream << sanitize(_choices[i]) << charSep(); sstream << sanitize(_choices[i]) << charSep();
return sstream.str(); return sstream.str();
*/
return "";
} }
}; };
...@@ -493,6 +513,10 @@ namespace onelab{ ...@@ -493,6 +513,10 @@ namespace onelab{
const std::string &client=""){ return _get(ps, name, client, _regions); } const std::string &client=""){ return _get(ps, name, client, _regions); }
bool get(std::vector<function> &ps, const std::string &name="", bool get(std::vector<function> &ps, const std::string &name="",
const std::string &client=""){ return _get(ps, name, client, _functions); } const std::string &client=""){ return _get(ps, name, client, _functions); }
unsigned int getNumParameters()
{
return _numbers.size() + _strings.size() + _regions.size() + _functions.size();
}
// check if at least one parameter depends on the given client // check if at least one parameter depends on the given client
bool hasClient(const std::string &client) const bool hasClient(const std::string &client) const
{ {
...@@ -556,7 +580,7 @@ namespace onelab{ ...@@ -556,7 +580,7 @@ namespace onelab{
int getId(){ return _id; } int getId(){ return _id; }
void setIndex(int index){ _index = index; } void setIndex(int index){ _index = index; }
int getIndex(){ return _index; } int getIndex(){ return _index; }
virtual bool run(const std::string &what){ return false; } virtual bool run(){ return false; }
virtual bool isNetworkClient(){ return false; } virtual bool isNetworkClient(){ return false; }
virtual bool kill(){ return false; } virtual bool kill(){ return false; }
virtual void sendInfo(const std::string &msg){ std::cout << msg << std::endl; } virtual void sendInfo(const std::string &msg){ std::cout << msg << std::endl; }
...@@ -580,7 +604,7 @@ namespace onelab{ ...@@ -580,7 +604,7 @@ namespace onelab{
// and interacts with onelab clients. // and interacts with onelab clients.
class server{ class server{
private: private:
// the unique server // the unique server (singleton behaviour due to the "static" specifier)
static server *_server; static server *_server;
// the address of the server // the address of the server
std::string _address; std::string _address;
...@@ -609,6 +633,7 @@ namespace onelab{ ...@@ -609,6 +633,7 @@ namespace onelab{
typedef std::map<std::string, client*>::iterator citer; typedef std::map<std::string, client*>::iterator citer;
citer firstClient(){ return _clients.begin(); } citer firstClient(){ return _clients.begin(); }
citer lastClient(){ return _clients.end(); } citer lastClient(){ return _clients.end(); }
int getNumClients() { return _clients.size(); };
citer findClient(const std::string &name){ return _clients.find(name); } citer findClient(const std::string &name){ return _clients.find(name); }
void registerClient(client *c) void registerClient(client *c)
{ {
...@@ -628,6 +653,7 @@ namespace onelab{ ...@@ -628,6 +653,7 @@ namespace onelab{
{ {
return _parameterSpace.toChar(client); return _parameterSpace.toChar(client);
} }
unsigned int getNumParameters(){ return _parameterSpace.getNumParameters(); }
}; };
class localClient : public client{ class localClient : public client{
...@@ -687,7 +713,7 @@ namespace onelab{ ...@@ -687,7 +713,7 @@ namespace onelab{
void setPid(int pid){ _pid = pid; } void setPid(int pid){ _pid = pid; }
GmshServer *getGmshServer(){ return _gmshServer; } GmshServer *getGmshServer(){ return _gmshServer; }
void setGmshServer(GmshServer *server){ _gmshServer = server; } void setGmshServer(GmshServer *server){ _gmshServer = server; }
virtual bool run(const std::string &what); virtual bool run();
virtual bool kill(); virtual bool kill();
}; };
...@@ -711,7 +737,11 @@ namespace onelab{ ...@@ -711,7 +737,11 @@ namespace onelab{
if(!_gmshClient) return false; if(!_gmshClient) return false;
T p(name); T p(name);
std::string msg = p.toChar(); std::string msg = p.toChar();
if (name.size())
_gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY, msg.size(), &msg[0]); _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_QUERY, msg.size(), &msg[0]);
else //get all parameters
_gmshClient->SendMessage(GmshSocket::GMSH_PARAM_QUERY_ALL, 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
int ret = _gmshClient->Select(10, 0); int ret = _gmshClient->Select(10, 0);
...@@ -739,8 +769,17 @@ namespace onelab{ ...@@ -739,8 +769,17 @@ namespace onelab{
ps.push_back(p); ps.push_back(p);
return true; return true;
} }
if(type == GmshSocket::GMSH_PARAM_QUERY_ALL){
T p;
p.fromChar(msg);
ps.push_back(p);
// do NOT return until all parameters have been downloaded
}
else if(type == GmshSocket::GMSH_PARAM_QUERY_END){
return true;
}
else if(type == GmshSocket::GMSH_INFO){ else if(type == GmshSocket::GMSH_INFO){
// parameter not found // parameter not found or all aparameters have been sent
return true; return true;
} }
else{ else{
......
...@@ -15,25 +15,27 @@ int main(int argc, char **argv) ...@@ -15,25 +15,27 @@ int main(int argc, char **argv)
onelab::remoteNetworkClient *client = 0; onelab::remoteNetworkClient *client = 0;
for(int i = 0; i < argc; i++){ for(int i = 0; i < argc; i++){
if(std::string(argv[i]) == "-onelab" && i < argc - 1) if(std::string(argv[i]) == "-onelab" && i + 2 < argc){
client = new onelab::remoteNetworkClient("My solver", argv[i + 1]); client = new onelab::remoteNetworkClient(argv[i + 1], argv[i + 2]);
break;
}
} }
if(!client){ if(!client){
printf("usage: %s -onelab socket\n", argv[0]); printf("usage: %s -onelab name socket\n", argv[0]);
exit(1); exit(1);
} }
std::vector<onelab::string> strings; std::vector<onelab::string> strings;
// try to get the string variable "My solver/My string" from the server // try to get the string variable "My solver/My string" from the server
client->get(strings, "My solver/My string"); client->get(strings, "My string");
if(strings.size()){ if(strings.size()){
std::cout << "Got string from server: '" << strings[0].getValue() << "'\n"; std::cout << "Got string from server: '" << strings[0].getValue() << "'\n";
} }
else{ else{
// send a value to the server // send a value to the server
onelab::string s("My solver/My string", "Hello!"); onelab::string s("My string", "Hello!");
client->set(s); client->set(s);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment