diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 156efc3f408fce0b67e3ee07d8bd51f13238b7c4..489b67f2cf7c13beab1b38ea8cec3ef7fa89a082 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -1177,6 +1177,7 @@ void Msg::FinalizeOnelab() #ifdef HAVE_ONELAB2 if(_onelabClient) { _onelabClient->disconnect(); + OnelabDatabase::instance()->wait(); delete _onelabClient; _onelabClient = 0; } diff --git a/Fltk/onelab2Group.cpp b/Fltk/onelab2Group.cpp index 0b1a7c9fa70af76a31418e373b7acdfce7d91e21..ceb13b8e68c5e5db1e2ec0c9991b60c341a747a3 100644 --- a/Fltk/onelab2Group.cpp +++ b/Fltk/onelab2Group.cpp @@ -328,7 +328,6 @@ void onelabGroup::useServer(bool use=false) void onelabGroup::addParameter(onelab::parameter &p) { - std::cout << "add " << p.getName() << " to the tree (visible = " << p.getVisible() << ", changed = " << p.getChanged() << ")" << std::endl; if(!p.getVisible() || CTX::instance()->solver.showInvisibleParameters) return; bool highlight = false; Fl_Color c; @@ -680,7 +679,6 @@ Fl_Widget *onelabGroup::_addParameterWidget(onelab::function &p, int ww, int hh, void onelabGroup::updateParameter(onelab::parameter &p) { - std::cout << "update " << p.getName() << " to the tree (visible = " << p.getVisible() << ", changed = " << p.getChanged() << ")" << std::endl; int type = p.getAttributeType(); if(type == onelab::number::attributeType()) return updateParameter(*(onelab::number *)&p); diff --git a/contrib/onelab2/NetworkUtils.h b/contrib/onelab2/NetworkUtils.h index 21cf19df5eb2637b0d79df3ff32e4fb9c2a81282..3b44e30008687ad919aeae17ea22d5aa9855a73c 100644 --- a/contrib/onelab2/NetworkUtils.h +++ b/contrib/onelab2/NetworkUtils.h @@ -141,6 +141,13 @@ inline int ip4_socket_connect(Socket fd, IPv4 &ip) addr.sin_port = hton16(ip.port); return connect(fd, (struct sockaddr*)&addr, addrl); } +inline bool ip4_socket_connected(Socket fd) +{ + int error_code; + unsigned int optlen = sizeof(error_code); + getsockopt(fd, SOL_SOCKET, SO_ERROR, &error_code, &optlen); + return (error_code == 0); +} bool ip4_socket_get_local_address(Socket fd, IPv4 &ip); void ip4_socket_timeout(Socket d, long tos, long tous=0); inline void ip4_socket_reuse_address(Socket fd, bool reuse=true) {setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof reuse);} diff --git a/contrib/onelab2/OnelabAttributes.h b/contrib/onelab2/OnelabAttributes.h index a591d9d783d0a81ad6cefc4d0fc62ce26cf9592b..cd8532e781f6ef00744be328a879edc845b5f830 100644 --- a/contrib/onelab2/OnelabAttributes.h +++ b/contrib/onelab2/OnelabAttributes.h @@ -111,9 +111,8 @@ public: inline UInt16 getAttributeLength() const {return 1+_messageLength;} void setMessage(const std::string &message, const int level=OnelabAttrMessage::Debug) { - _messageLength = message.size()+1; - if(_messageLength == 0) return; _level = level; + _messageLength = message.size()+1; if(_message != NULL) free(_message); _message = (UInt8 *)strndup(message.c_str(), _messageLength); } diff --git a/contrib/onelab2/OnelabDatabase.cpp b/contrib/onelab2/OnelabDatabase.cpp index 34314b9bba0f3c6b648d51e8614a144a1fe50a4a..63e54290f70ecf27977d374d41f42211a78b3807 100644 --- a/contrib/onelab2/OnelabDatabase.cpp +++ b/contrib/onelab2/OnelabDatabase.cpp @@ -26,8 +26,9 @@ DWORD WINAPI OnelabDatabase_listen(LPVOID arg) break; case OnelabProtocol::OnelabResponse: case OnelabProtocol::OnelabUpdate: - std::clog << "\033[0;35m" << "Update parameter on client" << "\033[0;0m" << std::endl; + std::clog << "\033[0;35m" << "Update " << msg.attrs.size() << " parameter(s) on client:" << "\033[0;0m" << std::endl; for(std::vector<OnelabAttr *>::iterator it = msg.attrs.begin() ; it != msg.attrs.end(); ++it) { + std::clog << " - " << ((onelab::parameter *)*it)->getName() << std::endl; // FIXME if((*it)->getAttributeType() == OnelabAttr::Number) { onelab::number *attr = (onelab::number *)*it; OnelabDatabase::instance()->set(*attr, false); @@ -79,16 +80,7 @@ DWORD WINAPI OnelabDatabase_listen(LPVOID arg) case OnelabProtocol::OnelabAction: { std::clog << "\033[0;35m" << "Client have to perform an action" << "\033[0;0m" << std::endl; - std::cout << "nb attr: " << msg.attrs.size() << std::endl;//" attr type: " << msg.attrs[0]->getAttributeType() << " and must be " << OnelabAttrAction::attributeType() << std::endl; - if(msg.attrs.size()==1 && msg.attrs[0]->getAttributeType() == OnelabAttrAction::attributeType()) { - OnelabAttrAction *attr = (OnelabAttrAction *)msg.attrs[0]; - std::cout << attr->getAction() << " on " << attr->getClient() << "( i'm " << ((client)?*client:"nobody") << ") ?" << std::endl; - if(client && client->size() && *client == attr->getClient()) { - OnelabDatabase::instance()->haveToDo(attr->getAction()); - return NULL; - } - } - break; + // nothing to do ? } } } diff --git a/contrib/onelab2/OnelabDatabase.h b/contrib/onelab2/OnelabDatabase.h index f0c9af615b358ccba39057f21138a460ed410585..78f3dab21b1f752460ddfe72e57a9c71f98a2327 100644 --- a/contrib/onelab2/OnelabDatabase.h +++ b/contrib/onelab2/OnelabDatabase.h @@ -139,12 +139,10 @@ public: return _localGUI; } template <class T> bool set(const T &p, const std::string &client) { - std::cout<<"set "<<p.getName()<<" from "<<client<<std::endl; if(_client) return _client->set(p, true); return OnelabServer::instance()->set(p, client); } template <class T> bool set(const T &p, bool update=true) { - std::cout<<"set "<<p.getName()<<std::endl; if(_client) return _client->set(p, update); //if(_localGUI) return _localGUI->set(p); return OnelabServer::instance()->set(p); diff --git a/contrib/onelab2/OnelabLocalClient.cpp b/contrib/onelab2/OnelabLocalClient.cpp index 1ae1fc4068cd8e17389f5f53a8ed6612403ed4a6..13be1125fb4178edb2548e690986ab8242c7d84b 100644 --- a/contrib/onelab2/OnelabLocalClient.cpp +++ b/contrib/onelab2/OnelabLocalClient.cpp @@ -1 +1,12 @@ #include "OnelabLocalClient.h" +#include "OnelabServer.h" + + +template <class T> bool OnelabLocalClient::set(const T &p) +{ + return OnelabServer::instance->set(p, _name); +} +template <class T> bool OnelabLocalClient::get(std::vector<T> &ps, const std::string &name) +{ + return OnelabServer::instance->get(ps, name, _name); +} diff --git a/contrib/onelab2/OnelabLocalClient.h b/contrib/onelab2/OnelabLocalClient.h index fd82ccab9c45bca90766d2aa92142b9f496566c7..18a7f8f184723023b068cb6cf44761a5569cde52 100644 --- a/contrib/onelab2/OnelabLocalClient.h +++ b/contrib/onelab2/OnelabLocalClient.h @@ -16,12 +16,8 @@ public: : VirtualClient(name, parameterSpace){ } virtual ~OnelabLocalClient(){} - template <class T> bool set(const T &p){ - return _parameterSpace->set(p, this->_name); - } - template <class T> bool get(std::vector<T> &ps, const std::string &name){ - return _parameterSpace->get(ps, name, _name); - } + template <class T> bool set(const T &p); + template <class T> bool get(std::vector<T> &ps, const std::string &name); virtual void onNewParameter(onelab::parameter *p){} virtual void onUpdateParameter(onelab::parameter *p){} virtual void onRemoveParameter(onelab::parameter *p){} diff --git a/contrib/onelab2/OnelabLocalNetworkClient.cpp b/contrib/onelab2/OnelabLocalNetworkClient.cpp index 69cdd39d76e2295f3b93ff4d44b5bdc9b34b0c34..7e40893ffb57255e70fbededdda8096d563cacdf 100644 --- a/contrib/onelab2/OnelabLocalNetworkClient.cpp +++ b/contrib/onelab2/OnelabLocalNetworkClient.cpp @@ -57,6 +57,7 @@ int OnelabLocalNetworkClient::recvmsg(OnelabProtocol &msg) } void OnelabLocalNetworkClient::updateParameter(onelab::parameter *p) { + if(p == NULL) return; OnelabProtocol msg(OnelabProtocol::OnelabUpdate); msg.attrs.push_back(p); UInt8 buff[1024]; diff --git a/contrib/onelab2/OnelabLocalNetworkClient.h b/contrib/onelab2/OnelabLocalNetworkClient.h index 17f94a471c7cebe5bc2bd6ff5fc93e253e804f23..f9707c0393179abdb9515c7efe56688709e8760b 100644 --- a/contrib/onelab2/OnelabLocalNetworkClient.h +++ b/contrib/onelab2/OnelabLocalNetworkClient.h @@ -24,12 +24,12 @@ public: OnelabLocalNetworkClient(std::string name, UDTSOCKET fd, unsigned int ip, unsigned short port, bool UDT); //#endif OnelabLocalNetworkClient(std::string name, Socket fd, unsigned int ip, unsigned short port); + virtual ~OnelabLocalNetworkClient(){} void sendto(UInt8 *buff, unsigned int len); int recvfrom(UInt8 *buff, unsigned int maxlen); int recvmsg(OnelabProtocol &msg); UDTSOCKET getSSocket() {return _fds;} UDTSOCKET getUSocket() {return _fdu;} - virtual ~OnelabLocalNetworkClient(){} std::string getName() {return _name;} void updateParameter(onelab::parameter *); unsigned int getIp() {return _ip.address;} diff --git a/contrib/onelab2/OnelabNetworkClient.cpp b/contrib/onelab2/OnelabNetworkClient.cpp index ea90b879d0ec9576462597c85205f666b532f500..3b32ec31abc8610a8190b9b64c3dcfb8bf3d99c6 100644 --- a/contrib/onelab2/OnelabNetworkClient.cpp +++ b/contrib/onelab2/OnelabNetworkClient.cpp @@ -170,16 +170,31 @@ bool OnelabNetworkClient::connect() return _connected; } -void OnelabNetworkClient::disconnect() +void OnelabNetworkClient::disconnect(bool waitForServer) { - // Send a message to the server to say the client stop (the server have to reply) - UInt16 bufflen = 1024, recvlen = 0; - UInt8 buff[1024]; - OnelabProtocol msg(OnelabProtocol::OnelabStop); if(!_connected) return; - recvlen = msg.encodeMsg(buff, bufflen); + // Send a message to the server to say the client is going to stop (the server have to reply) + UInt8 buff[128]; + fd_set readfds; + struct timeval timeout; + OnelabProtocol msg(OnelabProtocol::OnelabStop); + int recvlen = msg.encodeMsg(buff, 128); this->sendto(buff, recvlen); - _connected = false; + if(waitForServer) { + timeout.tv_sec = 1; + timeout.tv_usec = 0; + FD_ZERO(&readfds); + FD_SET(_fds, &readfds); + while(select(_fds+1, &readfds, NULL, NULL, &timeout) > 0) { // Wait for the server to answer + recvlen = recvfrom(msg); + if(msg.msgType() == OnelabProtocol::OnelabStop) { + _connected = false; + break; + } + } + } + else + _connected = false; } void OnelabNetworkClient::request(OnelabProtocol &msg) diff --git a/contrib/onelab2/OnelabNetworkClient.h b/contrib/onelab2/OnelabNetworkClient.h index 6a20005bf2d9f85c0996bd2bd08f33a22e92f93b..08474840e49bb2db9dec20d3ad78440ece840718 100644 --- a/contrib/onelab2/OnelabNetworkClient.h +++ b/contrib/onelab2/OnelabNetworkClient.h @@ -74,7 +74,7 @@ public: int nfds = select(_fds+1, &readfds, NULL, NULL, &timeout); // Wait for the server to answer if(nfds > 0) recvfrom(); } - return _parameterSpace->get(ps, name, this->_name) && ps.size() == 0; + return _parameterSpace->get(ps, name, _name) && ps.size() == 0; } else return false; @@ -148,7 +148,7 @@ public: int recvfrom(OnelabProtocol &msg); int recvfrom(UInt8 *buff, UInt16 maxlen); void sendto(UInt8 *buff, UInt16 len); - void disconnect(); + void disconnect(bool waitForServer=false); void setRemoteIP(unsigned long ip){if(!_connected) _ip.address=ip;} void setRemotePort(unsigned short port){if(!_connected) _ip.port=port;} diff --git a/contrib/onelab2/OnelabServer.cpp b/contrib/onelab2/OnelabServer.cpp index b057dee1c3a8dd0ed563855a0b1dd9a61c066da5..a8a938fdb09617aba717a753ad74e13076a991ed 100644 --- a/contrib/onelab2/OnelabServer.cpp +++ b/contrib/onelab2/OnelabServer.cpp @@ -337,13 +337,7 @@ void *listenOnClients(void *param) std::cout << "\033[0;31m" << "Client \"" << cli->getName() << "\" is going to stop" << "\033[0m" << std::endl; // DEBUG rep.msgType(OnelabProtocol::OnelabStop); recvlen = rep.encodeMsg(buff, 1024); - fd_set writefds; - struct timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = 5000; - FD_ZERO(&writefds); - FD_SET(cli->getSSocket(), &writefds); - if(select(cli->getSSocket()+1, NULL, writefds, NULL, timeout) > 0) + if(ip4_socket_connected(cli->getSSocket())) // FIXME cli can close socket before send cli->sendto(buff, recvlen); //UDT::epoll_remove_usock(eid, *it); UDT::epoll_remove_ssock(eid, *it); diff --git a/contrib/onelab2/OnelabServer.h b/contrib/onelab2/OnelabServer.h index 22c82499942ce75e141fe4b853392b2d0fb9ccf8..c188676894283b4b13b20a3847f9c33af5c2cd35 100644 --- a/contrib/onelab2/OnelabServer.h +++ b/contrib/onelab2/OnelabServer.h @@ -77,7 +77,10 @@ public: _parameterSpace.set(p, client); T *pp; _parameterSpace.getPtr(&pp, p.getName()); - if(pp->getVisible()) pp->addClient("GUI", true); + if(pp->getVisible()) { + pp->addClient("GUI", true); + pp->addClient("localGUI", true); + } for(std::vector<OnelabLocalClient *>::iterator it = _localClients.begin() ; it != _localClients.end(); ++it) { std::cout << (*it)->getName() << " and is " << ((isNew)?"new ":"updated ") << " from " << client << std::endl; if((*it)->getName() != client) { @@ -85,10 +88,9 @@ public: else (*it)->onUpdateParameter(pp); } } - std::map<std::string, bool> clients = p.getClients(); + std::map<std::string, bool> clients = pp->getClients(); for(std::map<std::string, bool>::const_iterator it = clients.begin(); it != clients.end(); it++) { if(it->first == client) continue; - std::cout << "send " << p.getName() << " to " << it->first << " from " << client << std::endl; OnelabLocalNetworkClient *tmp = getClient(it->first); if(tmp == NULL) continue; tmp->updateParameter(pp); @@ -135,8 +137,6 @@ public: } void setChanged(bool changed, const std::string &client="") { _parameterSpace.setChanged(changed, client); - std::cout << "set " << client << ((changed)?" changed ":" unchanged ") << std::endl - << "get " << getChanged(client) << std::endl; } void performAction(const std::string action, const std::string client=""); };