diff --git a/src/common/GmshSocket.h b/src/common/GmshSocket.h index ee83be3ded14460695b216e38c6eb7e68b9ba53d..2ccbc0e868bc246f182d2f1b83c1f199e6dc098f 100644 --- a/src/common/GmshSocket.h +++ b/src/common/GmshSocket.h @@ -55,42 +55,44 @@ typedef int socklen_t; typedef int socklen_t; #endif -class GmshSocket{ - public: +class GmshSocket { +public: // types of messages that can be exchanged (never use values greater // that 65535: if we receive a type > 65535 we assume that we // receive data from a machine with a different byte ordering, and // we swap the bytes in the payload) - enum MessageType{ - GMSH_START = 1, - GMSH_STOP = 2, - GMSH_INFO = 10, - GMSH_WARNING = 11, - GMSH_ERROR = 12, - GMSH_PROGRESS = 13, - GMSH_MERGE_FILE = 20, - GMSH_PARSE_STRING = 21, - GMSH_VERTEX_ARRAY = 22, - GMSH_PARAMETER = 23, - GMSH_PARAMETER_QUERY = 24, + enum MessageType { + GMSH_START = 1, + GMSH_STOP = 2, + GMSH_INFO = 10, + GMSH_WARNING = 11, + GMSH_ERROR = 12, + GMSH_PROGRESS = 13, + GMSH_MERGE_FILE = 20, + GMSH_PARSE_STRING = 21, + GMSH_VERTEX_ARRAY = 22, + GMSH_PARAMETER = 23, + GMSH_PARAMETER_QUERY = 24, GMSH_PARAMETER_QUERY_ALL = 25, GMSH_PARAMETER_QUERY_END = 26, - GMSH_CONNECT = 27, - GMSH_OLPARSE = 28, + GMSH_CONNECT = 27, + GMSH_OLPARSE = 28, GMSH_PARAMETER_NOT_FOUND = 29, - GMSH_SPEED_TEST = 30, - GMSH_PARAMETER_CLEAR = 31, - GMSH_PARAMETER_UPDATE = 32, - GMSH_OPEN_PROJECT = 33, - GMSH_CLIENT_CHANGED = 34, + GMSH_SPEED_TEST = 30, + GMSH_PARAMETER_CLEAR = 31, + GMSH_PARAMETER_UPDATE = 32, + GMSH_OPEN_PROJECT = 33, + GMSH_CLIENT_CHANGED = 34, GMSH_PARAMETER_WITHOUT_CHOICES = 35, GMSH_PARAMETER_QUERY_WITHOUT_CHOICES = 36, - GMSH_OPTION_1 = 100, - GMSH_OPTION_2 = 101, - GMSH_OPTION_3 = 102, - GMSH_OPTION_4 = 103, - GMSH_OPTION_5 = 104}; - protected: + GMSH_OPTION_1 = 100, + GMSH_OPTION_2 = 101, + GMSH_OPTION_3 = 102, + GMSH_OPTION_4 = 103, + GMSH_OPTION_5 = 104 + }; + +protected: // the socket descriptor int _sock; // the socket name @@ -135,10 +137,9 @@ class GmshSocket{ for(int i = 0; i < n; i++) { char *a = &array[i * size]; memcpy(x, a, size); - for(int c = 0; c < size; c++) - a[size - 1 - c] = x[c]; + for(int c = 0; c < size; c++) a[size - 1 - c] = x[c]; } - delete [] x; + delete[] x; } // sleep for some milliseconds void _sleep(int ms) @@ -149,7 +150,8 @@ class GmshSocket{ Sleep(ms); #endif } - public: + +public: GmshSocket() : _sock(0), _sent(0), _received(0) { #if defined(WIN32) && !defined(__CYGWIN__) @@ -167,7 +169,7 @@ class GmshSocket{ // we check for available data and return immediately, i.e., we do // polling). Returns 1 when data is available, 0 when nothing happened before // the time delay, -1 on error. - int Select(int seconds, int microseconds, int socket=-1) + int Select(int seconds, int microseconds, int socket = -1) { int s = (socket < 0) ? _sock : socket; struct timeval tv; @@ -192,14 +194,14 @@ class GmshSocket{ { SendMessage(type, (int)strlen(str), str); } - void Info(const char *str){ SendString(GMSH_INFO, str); } - void Warning(const char *str){ SendString(GMSH_WARNING, str); } - void Error(const char *str){ SendString(GMSH_ERROR, str); } - void Progress(const char *str){ SendString(GMSH_PROGRESS, str); } - void MergeFile(const char *str){ SendString(GMSH_MERGE_FILE, str); } - void OpenProject(const char *str){ SendString(GMSH_OPEN_PROJECT, str); } - void ParseString(const char *str){ SendString(GMSH_PARSE_STRING, str); } - void SpeedTest(const char *str){ SendString(GMSH_SPEED_TEST, str); } + void Info(const char *str) { SendString(GMSH_INFO, str); } + void Warning(const char *str) { SendString(GMSH_WARNING, str); } + void Error(const char *str) { SendString(GMSH_ERROR, str); } + void Progress(const char *str) { SendString(GMSH_PROGRESS, str); } + void MergeFile(const char *str) { SendString(GMSH_MERGE_FILE, str); } + void OpenProject(const char *str) { SendString(GMSH_OPEN_PROJECT, str); } + void ParseString(const char *str) { SendString(GMSH_PARSE_STRING, str); } + void SpeedTest(const char *str) { SendString(GMSH_SPEED_TEST, str); } void Option(int num, const char *str) { if(num < 1) num = 1; @@ -209,15 +211,15 @@ class GmshSocket{ int ReceiveHeader(int *type, int *len, int *swap) { *swap = 0; - if(_receiveData(type, sizeof(int)) > 0){ - if(*type > 65535){ + if(_receiveData(type, sizeof(int)) > 0) { + if(*type > 65535) { // the data comes from a machine with different endianness and // we must swap the bytes *swap = 1; - _swapBytes((char*)type, sizeof(int), 1); + _swapBytes((char *)type, sizeof(int), 1); } - if(_receiveData(len, sizeof(int)) > 0){ - if(*swap) _swapBytes((char*)len, sizeof(int), 1); + if(_receiveData(len, sizeof(int)) > 0) { + if(*swap) _swapBytes((char *)len, sizeof(int), 1); return 1; } } @@ -251,24 +253,25 @@ class GmshSocket{ shutdown(s, SHUT_RDWR); #endif } - unsigned long int SentBytes(){ return _sent; } - unsigned long int ReceivedBytes(){ return _received; } + unsigned long int SentBytes() { return _sent; } + unsigned long int ReceivedBytes() { return _received; } }; class GmshClient : public GmshSocket { - public: +public: GmshClient() : GmshSocket() {} - ~GmshClient(){} + ~GmshClient() {} int Connect(const char *sockname) { - if(strstr(sockname, "/") || strstr(sockname, "\\") || !strstr(sockname, ":")){ + if(strstr(sockname, "/") || strstr(sockname, "\\") || + !strstr(sockname, ":")) { #if !defined(WIN32) || defined(__CYGWIN__) // UNIX socket (testing ":" is not enough with Windows paths) _sock = socket(PF_UNIX, SOCK_STREAM, 0); if(_sock < 0) return -1; // try to connect socket to given name struct sockaddr_un addr_un; - memset((char *) &addr_un, 0, sizeof(addr_un)); + memset((char *)&addr_un, 0, sizeof(addr_un)); addr_un.sun_family = AF_UNIX; strcpy(addr_un.sun_path, sockname); for(int tries = 0; tries < 5; tries++) { @@ -280,7 +283,7 @@ class GmshClient : public GmshSocket { return -1; // Unix sockets are not available on Windows #endif } - else{ + else { // TCP/IP socket _sock = socket(AF_INET, SOCK_STREAM, 0); if(_sock < 0) return -1; @@ -292,26 +295,25 @@ class GmshClient : public GmshSocket { int portno = atoi(port + 1); char *remote = strdup(sockname); int remotelen = (int)(strlen(remote) - strlen(port)); - if(remotelen > 0) - strncpy(remote, sockname, remotelen); - if(remotelen >= 0) - remote[remotelen] = '\0'; + if(remotelen > 0) strncpy(remote, sockname, remotelen); + if(remotelen >= 0) remote[remotelen] = '\0'; struct hostent *server; - if(!(server = gethostbyname(remote))){ + if(!(server = gethostbyname(remote))) { CloseSocket(_sock); free(remote); return -3; // no such host } free(remote); struct sockaddr_in addr_in; - memset((char *) &addr_in, 0, sizeof(addr_in)); + memset((char *)&addr_in, 0, sizeof(addr_in)); addr_in.sin_family = AF_INET; - memcpy((char *)&addr_in.sin_addr.s_addr, (char *)server->h_addr, server->h_length); + memcpy((char *)&addr_in.sin_addr.s_addr, (char *)server->h_addr, + server->h_length); addr_in.sin_port = htons(portno); for(int tries = 0; tries < 5; tries++) { - if(connect(_sock, (struct sockaddr *)&addr_in, sizeof(addr_in)) >= 0){ + if(connect(_sock, (struct sockaddr *)&addr_in, sizeof(addr_in)) >= 0) { return _sock; - } + } _sleep(100); } } @@ -328,27 +330,30 @@ class GmshClient : public GmshSocket { #endif SendString(GMSH_START, tmp); } - void Stop(){ SendString(GMSH_STOP, "Goodbye!"); } - void Disconnect(){ CloseSocket(_sock); } + void Stop() { SendString(GMSH_STOP, "Goodbye!"); } + void Disconnect() { CloseSocket(_sock); } }; -class GmshServer : public GmshSocket{ - private: +class GmshServer : public GmshSocket { +private: int _portno; - public: + +public: GmshServer() : GmshSocket(), _portno(-1) {} - virtual ~GmshServer(){} - virtual int NonBlockingSystemCall(const std::string &exe, const std::string &args) = 0; - virtual int NonBlockingWait(double waitint, double timeout, int socket=-1) = 0; + virtual ~GmshServer() {} + virtual int NonBlockingSystemCall(const std::string &exe, + const std::string &args) = 0; + virtual int NonBlockingWait(double waitint, double timeout, + int socket = -1) = 0; // start the client by launching "exe args" (args is supposed to contain // '%s' where the socket name should appear) - int Start(const std::string &exe, const std::string &args, const std::string &sockname, - double timeout) + int Start(const std::string &exe, const std::string &args, + const std::string &sockname, double timeout) { _sockname = sockname; int tmpsock; if(strstr(_sockname.c_str(), "/") || strstr(_sockname.c_str(), "\\") || - !strstr(_sockname.c_str(), ":")){ + !strstr(_sockname.c_str(), ":")) { // UNIX socket (testing ":" is not enough with Windows paths) _portno = -1; #if !defined(WIN32) || defined(__CYGWIN__) @@ -359,10 +364,10 @@ class GmshServer : public GmshSocket{ if(tmpsock < 0) throw "Couldn't create socket"; // bind the socket to its name struct sockaddr_un addr_un; - memset((char *) &addr_un, 0, sizeof(addr_un)); + memset((char *)&addr_un, 0, sizeof(addr_un)); strcpy(addr_un.sun_path, _sockname.c_str()); addr_un.sun_family = AF_UNIX; - if(bind(tmpsock, (struct sockaddr *)&addr_un, sizeof(addr_un)) < 0){ + if(bind(tmpsock, (struct sockaddr *)&addr_un, sizeof(addr_un)) < 0) { CloseSocket(tmpsock); throw "Couldn't bind socket to name"; } @@ -372,7 +377,7 @@ class GmshServer : public GmshSocket{ throw "Unix sockets not available on Windows"; #endif } - else{ + else { // TCP/IP socket: valid names are either explicit ("hostname:12345") // or implicit ("hostname:", "hostname: ", "hostname:0") in which case // the system attributes at random an available port @@ -391,62 +396,60 @@ class GmshServer : public GmshSocket{ throw "Couldn't create socket"; // bind the socket to its name struct sockaddr_in addr_in; - memset((char *) &addr_in, 0, sizeof(addr_in)); + memset((char *)&addr_in, 0, sizeof(addr_in)); addr_in.sin_family = AF_INET; addr_in.sin_addr.s_addr = INADDR_ANY; addr_in.sin_port = htons(_portno); // random assign if _portno == 0 - if(bind(tmpsock, (struct sockaddr *)&addr_in, sizeof(addr_in)) < 0){ + if(bind(tmpsock, (struct sockaddr *)&addr_in, sizeof(addr_in)) < 0) { CloseSocket(tmpsock); throw "Couldn't bind socket to name"; } - if(!_portno){ // retrieve name if randomly assigned port + if(!_portno) { // retrieve name if randomly assigned port socklen_t addrlen = sizeof(addr_in); getsockname(tmpsock, (struct sockaddr *)&addr_in, &addrlen); _portno = ntohs(addr_in.sin_port); - int pos = (int)_sockname.find(':'); // remove trailing ' ' or '0' + int pos = (int)_sockname.find(':'); // remove trailing ' ' or '0' char tmp[256]; - sprintf(tmp, "%s:%d", _sockname.substr(0, pos).c_str(), _portno); + sprintf(tmp, "%s:%d", _sockname.substr(0, pos).c_str(), _portno); _sockname.assign(tmp); } } - if(exe.size() || args.size()){ + if(exe.size() || args.size()) { char s[1024]; sprintf(s, args.c_str(), _sockname.c_str()); NonBlockingSystemCall(exe, s); // starts the solver } - else{ + else { timeout = 0.; // no command launched: don't set a timeout } // listen on socket (queue up to 20 connections before having // them automatically rejected) - if(listen(tmpsock, 20)){ + if(listen(tmpsock, 20)) { CloseSocket(tmpsock); throw "Socket listen failed"; } // wait until we get data int ret = NonBlockingWait(0.001, timeout, tmpsock); - if(ret){ + if(ret) { CloseSocket(tmpsock); - if(ret == 2){ - throw "Socket listening timeout"; - } - else{ + if(ret == 2) { throw "Socket listening timeout"; } + else { return -1; // stopped listening } } // accept connection request - if(_portno < 0){ + if(_portno < 0) { #if !defined(WIN32) || defined(__CYGWIN__) struct sockaddr_un from_un; socklen_t len = sizeof(from_un); _sock = accept(tmpsock, (struct sockaddr *)&from_un, &len); #endif } - else{ + else { struct sockaddr_in from_in; socklen_t len = sizeof(from_in); _sock = accept(tmpsock, (struct sockaddr *)&from_in, &len); @@ -454,15 +457,13 @@ class GmshServer : public GmshSocket{ setsockopt(_sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); } CloseSocket(tmpsock); - if(_sock < 0) - throw "Socket accept failed"; + if(_sock < 0) throw "Socket accept failed"; return _sock; } int Shutdown() { #if !defined(WIN32) || defined(__CYGWIN__) - if(_portno < 0) - unlink(_sockname.c_str()); + if(_portno < 0) unlink(_sockname.c_str()); #endif ShutdownSocket(_sock); CloseSocket(_sock); diff --git a/src/common/onelab.h b/src/common/onelab.h index 2e21e91b537f68c9f40613aff09a7dbde63d3986..e7b5a783f88e99b543e6ba509d44bd100b13d7f2 100644 --- a/src/common/onelab.h +++ b/src/common/onelab.h @@ -97,8 +97,7 @@ namespace onelab { if(it != _clients.end()) it->second = changed; } else { - for(auto it = _clients.begin(); - it != _clients.end(); it++) + for(auto it = _clients.begin(); it != _clients.end(); it++) it->second = changed; } } @@ -180,8 +179,7 @@ namespace onelab { } else { int changed = 0; - for(auto it = _clients.begin(); - it != _clients.end(); it++) { + for(auto it = _clients.begin(); it != _clients.end(); it++) { changed = std::max(changed, it->second); } return changed; @@ -193,8 +191,7 @@ namespace onelab { bool getReadOnly() const { return _readOnly; } std::string getAttribute(const std::string &key) const { - auto it = - _attributes.find(key); + auto it = _attributes.find(key); if(it != _attributes.end()) return it->second; return ""; } @@ -262,14 +259,11 @@ namespace onelab { << getChangedValue() << charSep() << (getVisible() ? 1 : 0) << charSep() << (getReadOnly() ? 1 : 0) << charSep() << _attributes.size() << charSep(); - for(auto it = - _attributes.begin(); - it != _attributes.end(); it++) + for(auto it = _attributes.begin(); it != _attributes.end(); it++) sstream << sanitize(it->first) << charSep() << sanitize(it->second) << charSep(); sstream << getClients().size() << charSep(); - for(auto it = getClients().begin(); - it != getClients().end(); it++) + for(auto it = getClients().begin(); it != getClients().end(); it++) sstream << sanitize(it->first) << charSep() << (it->second ? 1 : 0) << charSep(); return sstream.str(); @@ -354,9 +348,7 @@ namespace onelab { << ", \"readOnly\":" << (getReadOnly() ? "true" : "false"); if(_attributes.size()) { sstream << ", \"attributes\":{ "; - for(auto it = - _attributes.begin(); - it != _attributes.end(); it++) { + for(auto it = _attributes.begin(); it != _attributes.end(); it++) { if(it != _attributes.begin()) sstream << ", "; sstream << "\"" << sanitizeJSON(it->first) << "\":\"" << sanitizeJSON(it->second) << "\""; @@ -365,9 +357,7 @@ namespace onelab { } if(getClients().size()) { sstream << ", \"clients\":{ "; - for(auto it = - getClients().begin(); - it != getClients().end(); it++) { + for(auto it = getClients().begin(); it != getClients().end(); it++) { if(it != getClients().begin()) sstream << ", "; sstream << "\"" << sanitizeJSON(it->first) << "\":" << it->second; } @@ -378,8 +368,7 @@ namespace onelab { #if defined(HAVE_PICOJSON) virtual bool fromJSON(const picojson::value::object &par) { - for(auto it = par.begin(); - it != par.end(); ++it) { + for(auto it = par.begin(); it != par.end(); ++it) { if(it->first == "name") { if(!it->second.is<std::string>()) return false; setName(it->second.get<std::string>()); @@ -408,8 +397,7 @@ namespace onelab { if(!it->second.is<picojson::object>()) return false; const picojson::value::object &obj = it->second.get<picojson::object>(); - for(auto i = obj.begin(); - i != obj.end(); ++i) { + for(auto i = obj.begin(); i != obj.end(); ++i) { std::string key(i->first); if(!i->second.is<std::string>()) return false; setAttribute(key, i->second.get<std::string>()); @@ -419,8 +407,7 @@ namespace onelab { if(!it->second.is<picojson::object>()) return false; const picojson::value::object &obj = it->second.get<picojson::object>(); - for(auto i = obj.begin(); - i != obj.end(); ++i) { + for(auto i = obj.begin(); i != obj.end(); ++i) { std::string client(i->first); if(!i->second.is<double>()) return false; addClient(client, (int)i->second.get<double>()); @@ -515,8 +502,7 @@ namespace onelab { } std::string getValueLabel(double value) const { - auto it = - _valueLabels.find(value); + auto it = _valueLabels.find(value); if(it != _valueLabels.end()) return it->second; return ""; } @@ -559,9 +545,7 @@ namespace onelab { for(std::size_t i = 0; i < _choices.size(); i++) sstream << _choices[i] << charSep(); sstream << _valueLabels.size() << charSep(); - for(auto it = - _valueLabels.begin(); - it != _valueLabels.end(); it++) { + for(auto it = _valueLabels.begin(); it != _valueLabels.end(); it++) { sstream << it->first << charSep() << sanitize(it->second) << charSep(); } return sstream.str(); @@ -609,9 +593,7 @@ namespace onelab { } if(_valueLabels.size()) { sstream << ", \"valueLabels\":{ "; - for(auto it = - _valueLabels.begin(); - it != _valueLabels.end(); it++) { + for(auto it = _valueLabels.begin(); it != _valueLabels.end(); it++) { if(it != _valueLabels.begin()) sstream << ", "; sstream << "\"" << sanitizeJSON(it->second) << "\":" << it->first; } @@ -641,8 +623,7 @@ namespace onelab { bool fromJSON(const picojson::value::object &par) { if(!parameter::fromJSON(par)) return false; - for(auto it = par.begin(); - it != par.end(); ++it) { + for(auto it = par.begin(); it != par.end(); ++it) { if(it->first == "values") { if(!it->second.is<picojson::array>()) return false; const picojson::value::array &arr = it->second.get<picojson::array>(); @@ -681,8 +662,7 @@ namespace onelab { if(!it->second.is<picojson::object>()) return false; const picojson::value::object &obj = it->second.get<picojson::object>(); - for(auto i = obj.begin(); - i != obj.end(); ++i) { + for(auto i = obj.begin(); i != obj.end(); ++i) { if(!i->second.is<double>()) return false; _valueLabels[i->second.get<double>()] = i->first; } @@ -730,10 +710,7 @@ namespace onelab { if(_values.empty()) return n; return _values[0]; } - std::string getValueAsString() const - { - return getValue(); - } + std::string getValueAsString() const { return getValue(); } const std::vector<std::string> &getValues() const { return _values; } int getNumValues() const { return (int)_values.size(); } const std::string &getKind() const { return _kind; } @@ -831,8 +808,7 @@ namespace onelab { bool fromJSON(const picojson::value::object &par) { if(!parameter::fromJSON(par)) return false; - for(auto it = par.begin(); - it != par.end(); ++it) { + for(auto it = par.begin(); it != par.end(); ++it) { if(it->first == "values") { if(!it->second.is<picojson::array>()) return false; const picojson::value::array &arr = it->second.get<picojson::array>(); @@ -876,8 +852,7 @@ namespace onelab { { if(name.empty() && client.size()) { std::vector<T *> toDelete; - for(auto it = ps.begin(); - it != ps.end();) { + for(auto it = ps.begin(); it != ps.end();) { T *p = *it; if(p->hasClient(client)) { ps.erase(it++); // to avoid invalid iterator @@ -936,15 +911,13 @@ namespace onelab { { p.clear(); if(name.empty()) { - for(auto it = ps.begin(); - it != ps.end(); it++) - p.push_back(**it); + for(auto it = ps.begin(); it != ps.end(); it++) p.push_back(**it); } else { T tmp(name); auto it = ps.find(&tmp); if(it != ps.end()) { - if(client.size()){ + if(client.size()) { _mutex.lock(); (*it)->addClient(client, parameter::defaultChangedValue()); _mutex.unlock(); @@ -961,7 +934,7 @@ namespace onelab { T tmp(name); auto it = ps.find(&tmp); if(it != ps.end()) { - if(client.size()){ + if(client.size()) { _mutex.lock(); (*it)->addClient(client, parameter::defaultChangedValue()); _mutex.unlock(); @@ -979,9 +952,7 @@ namespace onelab { if(name.empty() && client.empty()) { std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(auto it = ps.begin(); - it != ps.end(); it++) - delete *it; + for(auto it = ps.begin(); it != ps.end(); it++) delete *it; _numbers.clear(); _strings.clear(); } @@ -1023,10 +994,7 @@ namespace onelab { ps.insert(_numbers.begin(), _numbers.end()); ps.insert(_strings.begin(), _strings.end()); } - int getNumParameters() - { - return (int)(_numbers.size() + _strings.size()); - } + int getNumParameters() { return (int)(_numbers.size() + _strings.size()); } void getParameterNames(std::vector<std::string> &names, const std::string &search = "") const { @@ -1035,8 +1003,8 @@ namespace onelab { for(auto &p : _numbers) names.push_back(p->getName()); for(auto &p : _strings) names.push_back(p->getName()); } - else{ - try{ + else { + try { for(auto &p : _numbers) { if(std::regex_search(p->getName(), std::regex(search))) names.push_back(p->getName()); @@ -1045,8 +1013,7 @@ namespace onelab { if(std::regex_search(p->getName(), std::regex(search))) names.push_back(p->getName()); } - } - catch(...) { + } catch(...) { } } } @@ -1055,8 +1022,7 @@ namespace onelab { { std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(auto it = ps.begin(); - it != ps.end(); it++) + for(auto it = ps.begin(); it != ps.end(); it++) if((*it)->hasClient(client)) return true; return false; } @@ -1067,8 +1033,7 @@ namespace onelab { std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); int changed = 0; - for(auto it = ps.begin(); - it != ps.end(); it++) { + for(auto it = ps.begin(); it != ps.end(); it++) { changed = std::max(changed, (*it)->getChanged(client)); } return changed; @@ -1079,16 +1044,14 @@ namespace onelab { { std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(auto it = ps.begin(); - it != ps.end(); it++) + for(auto it = ps.begin(); it != ps.end(); it++) (*it)->setChanged(changed, client); } void thresholdChanged(int threshold, const std::string &client = "") { std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(auto it = ps.begin(); - it != ps.end(); it++) { + for(auto it = ps.begin(); it != ps.end(); it++) { int changed = (*it)->getChanged(client); if(changed > threshold) (*it)->setChanged(threshold, client); } @@ -1100,9 +1063,7 @@ namespace onelab { std::vector<std::string> s; std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(auto it = - ps.begin(); - it != ps.end(); it++) + for(auto it = ps.begin(); it != ps.end(); it++) if(client.empty() || (*it)->hasClient(client)) { if((*it)->getAttribute("NotInDb") != "True") s.push_back((*it)->toChar()); @@ -1147,9 +1108,7 @@ namespace onelab { json += " \"parameters\":[\n"; std::set<parameter *, parameterLessThan> ps; getAllParameters(ps); - for(auto it = - ps.begin(); - it != ps.end(); it++) { + for(auto it = ps.begin(); it != ps.end(); it++) { if(it != ps.begin()) json += ",\n"; if(client.empty() || (*it)->hasClient(client)) { if((*it)->getAttribute("NotInDb") != "True") { @@ -1166,12 +1125,13 @@ namespace onelab { picojson::value v; std::string err = picojson::parse(v, json); if(err.size()) return false; - if(v.is<picojson::object>()){ // full database or single parameter + if(v.is<picojson::object>()) { // full database or single parameter const picojson::value::object &obj = v.get<picojson::object>(); auto it = obj.find("onelab"); - if(it != obj.end()){ // full database + if(it != obj.end()) { // full database if(!it->second.is<picojson::object>()) return false; - const picojson::value::object &db = it->second.get<picojson::object>(); + const picojson::value::object &db = + it->second.get<picojson::object>(); for(auto j = db.begin(); j != db.end(); ++j) { if(j->first == "version") { if(!j->second.is<std::string>()) return false; @@ -1180,21 +1140,23 @@ namespace onelab { } else if(j->first == "parameters") { if(!j->second.is<picojson::array>()) return false; - const picojson::value::array &arr = j->second.get<picojson::array>(); + const picojson::value::array &arr = + j->second.get<picojson::array>(); for(std::size_t k = 0; k < arr.size(); k++) { if(!arr[k].is<picojson::object>()) return false; - const picojson::value::object &par = arr[k].get<picojson::object>(); + const picojson::value::object &par = + arr[k].get<picojson::object>(); if(!fromJSON(par, client)) return false; } } } return true; } - else{ // single parameter + else { // single parameter return fromJSON(obj, client); } } - else if(v.is<picojson::array>()){ // array of parameters + else if(v.is<picojson::array>()) { // array of parameters const picojson::value::array &arr = v.get<picojson::array>(); for(std::size_t k = 0; k < arr.size(); k++) { if(!arr[k].is<picojson::object>()) return false; @@ -1203,7 +1165,7 @@ namespace onelab { } return true; } - else{ + else { return false; } #else @@ -1211,7 +1173,8 @@ namespace onelab { #endif } #if defined(HAVE_PICOJSON) - bool fromJSON(const picojson::value::object &par, const std::string &client = "") + bool fromJSON(const picojson::value::object &par, + const std::string &client = "") { auto it = par.find("type"); if(it == par.end()) return false; @@ -1391,10 +1354,7 @@ namespace onelab { { _parameterSpace.thresholdChanged(value, client); } - int getNumParameters() - { - return _parameterSpace.getNumParameters(); - } + int getNumParameters() { return _parameterSpace.getNumParameters(); } void getParameterNames(std::vector<std::string> &names, const std::string &search = "") const { @@ -1706,8 +1666,8 @@ namespace onelab { if(!_gmshClient) return false; std::string msg = name; if(msg.empty()) msg = "*"; - _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_CLEAR, (int)msg.size(), - &msg[0]); + _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER_CLEAR, + (int)msg.size(), &msg[0]); return true; } virtual bool set(const number &p) { return _set(p); } @@ -1783,7 +1743,8 @@ namespace onelab { } #endif std::string msg = name + parameter::charSep() + command; - _gmshClient->SendMessage(GmshSocket::GMSH_CONNECT, (int)msg.size(), &msg[0]); + _gmshClient->SendMessage(GmshSocket::GMSH_CONNECT, (int)msg.size(), + &msg[0]); _numSubClients += 1; } void runSubClient(const std::string &name, const std::string &command)