gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
gmshLocalNetworkClient.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef GMSH_LOCAL_NETWORK_CLIENT_H
7 #define GMSH_LOCAL_NETWORK_CLIENT_H
8 
9 #include <vector>
10 #include <algorithm>
11 #include "GmshConfig.h"
12 
13 #if defined(HAVE_ONELAB)
14 
15 #include "onelab.h"
16 
17 class gmshLocalNetworkClient : public onelab::localNetworkClient {
18 private:
19  // a gmsh local network client can launch subclients (this is typical for a
20  // metamodel that calls several underlying models); _clients keeps track of
21  // the master (this) and the subclients.
22  std::vector<gmshLocalNetworkClient *> _clients;
23  // client that launched this one (with GMSH_CONNECT); _father is zero for the
24  // master client (the one created by Gmsh).
25  gmshLocalNetworkClient *_father;
26 
27 public:
28  gmshLocalNetworkClient(const std::string &name, const std::string &executable,
29  const std::string &remoteLogin = "",
30  bool treatExecutableAsFullCommandLine = false)
31  : onelab::localNetworkClient(name, executable, remoteLogin,
32  treatExecutableAsFullCommandLine),
33  _father(nullptr)
34  {
35  addClient(this);
36  }
37  void setFather(gmshLocalNetworkClient *father) { _father = father; }
38  gmshLocalNetworkClient *getFather() { return _father; }
39  void addClient(gmshLocalNetworkClient *client) { _clients.push_back(client); }
40  void removeClient(gmshLocalNetworkClient *client)
41  {
42  auto it = std::find(_clients.begin(), _clients.end(), client);
43  if(it != _clients.end()) _clients.erase(it);
44  }
45  int getNumClients() { return _clients.size(); }
46  gmshLocalNetworkClient *getClient(int i)
47  {
48  if(i >= 0 && i < getNumClients()) return _clients[i];
49  return nullptr;
50  }
51  int getNumConnectedClients()
52  {
53  int n = 0;
54  for(int i = 0; i < getNumClients(); i++) {
55  if(_clients[i]->getPid() != -1) n++;
56  }
57  return n;
58  }
59  bool receiveMessage(gmshLocalNetworkClient *master);
60  bool run();
61  bool kill();
62 };
63 
64 #endif
65 
66 #endif
onelab::localNetworkClient::run
virtual bool run()=0
onelab::localNetworkClient::kill
virtual bool kill()=0
onelab
Definition: GmshMessage.h:18
onelab.h
onelab::localNetworkClient
Definition: onelab.h:1471
onelab::localNetworkClient::getPid
int getPid()
Definition: onelab.h:1510