COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coSimLib.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef _CO_SIM_LIB_H_
9 #define _CO_SIM_LIB_H_
10 
11 // 11.06.99
12 
13 #include <sys/types.h>
14 #include <set>
15 #include <list>
17 #ifndef YAC
18 #include <api/coModule.h>
19 #include <covise/covise.h>
20 #else
21 #include <comm/logic/coSocketListener.h>
22 #endif
24 
29 namespace covise
30 {
31 
33 {
34 
35 public:
36  command_object(int type, char *port = 0, char *name = 0, char *data = 0, int length = 0, int numComp = 0, int actNode = 0)
37  : _type(type)
38  , _port(port)
42  , _numComp(numComp)
43  , _actNode(actNode)
44  {
45  }
46 
48  {
49  if (_port)
50  delete[] _port;
51  if (_name)
52  delete[] _name;
53  if (_data)
54  delete[] _data;
55  }
56 
57  // private:
58  int _type;
59  char *_port, *_name, *_data;
61 };
62 
63 #ifndef YAC
64 class APIEXPORT coSimLib : public coModule
65 #else
66 class APIEXPORT coSimLib : public coSimpleModule, public coSocketListener
67 #endif
68 {
69 public:
70  typedef int int32;
71 
72 // execute commands received from the simulation in sockData()
73 #ifndef YAC
74  void executeCommands();
75 #else
76  void executeCommands(std::set<coOutputPort *> *);
77 #endif
78 
79  // overload coModule sockData routine and make it private
80  virtual void sockData(int sockNo);
81 
82 private:
83  // ---------- Internal member functions ----------------------------
84 
86  uint32_t nslookup(const char *name);
87 
88  // Open a TCP server
89  int openServer();
90 
91  // Open a TCP client
92  int openClient();
93 
94  // Accept a TCP server
95  int acceptServer(float wait);
96 
97  // handle all Commands
98  int handleCommand(/*int fromWhere*/);
99 
100  // ---------- Class data -------------------------------------------
101 
102  // number of user-defined arguments in call and contents
103  char *d_userArg[10];
104 
105  // IP number of local and target machine, min/max port number
106  uint32_t d_localIP, d_targetIP, d_minPort, d_maxPort, d_usePort;
107 
108  // the socket the simulation connects to if COVISE is the server
110 
111  // Socket number =1 on error or not-yet-open
112  int d_socket;
113 
114  // Verbose level
116 
117  // do we have to byteswap incoming data ?
119 
120  // the name of the simulation
121  char *d_name;
122 
123  // active command: if a command is in the 'queue': sent for server, recv in main_loop
125 
126  // mapping for parallel data : only ONE mapping right now
127  // make better it with list and per-port mapping later!
128  int32 **d_cellMap, d_numCells;
129  int32 **d_vertMap, d_numVert;
132  {
133  const char *name; // name of the port
134  int ***map; // mapping for this port: either cell- or vertex
135  int numParts; // number of parts collected so far
136  coDistributedObject *openObj; // open Object to write into
137 
138  PortListElem *next; // chain...
139 
140  } *d_portList;
141 
142  // when going parallel: active node number. If not: -1;
144 
145  // all the startup lines we have
147  const char **d_startup_line;
148 
149  // and how many we have
151 
152  // Flag: The simulation requested an EXEC. Cleared by
153  // - C'tor
154  // - startSim
155  // - serverMode
156  // - resetSim
158 
159  // list of command objects that were sent during sockData
160  // the two pointers are swapped when the simulation sent COMM_QUIT
161  std::list<command_object *> *command_objects;
162  std::list<command_object *> *tmp_objects;
163 
164  // called from sockData when COMM_QUIT command is received
165  virtual int endIteration();
166 
167  void closeSocket(int socket);
168 
169 #ifdef YAC
170  coCommunicator *comm;
171  std::set<coOutputPort *> portList;
172 #endif
173 protected:
174 #include "coSimLibComm.h"
175 
177  coSimLib(const coSimLib &);
178 
180  coSimLib &operator=(const coSimLib &);
181 
183  coSimLib();
184 
185  // this allows to choose between the different start-ups
187 
188  int reAccept();
189 
190 public:
192  coSimLib(int argc, char *argv[], const char *moduleName, const char *desc);
193 
195  virtual ~coSimLib();
196 
198  int setTargetHost(const char *hostname);
199  int setLocalHost(const char *hostname);
200 
202  int setUserArg(int num, const char *data);
203 
205  int startSim(int reattach = 0);
206 
208  //int serverMode();
209 
212  void resetSimLib();
213 
215  int isConnected();
216 
218  int recvData(void *buffer, size_t length);
219  int sendData(const void *buffer, size_t length);
220 
223  int recvBS_Data(void *buffer, size_t length);
224  int sendBS_Data(void *buffer, size_t length);
225 
227  int coParallelInit(int numParts, int numPorts);
228 
230  int coParallelPort(const char *portName, int isCellData);
231 
233  // i.e. local COPCM or COPAVM
234  int setParaMap(int isCell, int isFortran, int nodeNo, int length,
235  int32 *nodeMap);
236 
238  void setVerbose(int level)
239  {
240  d_verbose = level;
241  }
242 
245  {
246  return d_verbose;
247  }
248 
251  {
252  return p_StartupSwitch;
253  }
254 
257  {
258  return d_simExec;
259  }
260 
261  void setPorts(int min, int max);
262 };
263 }
264 #endif
int32 d_actNode
Definition: coSimLib.h:143
int d_verbose
Definition: coSimLib.h:115
int d_numNodes
Definition: coSimLib.h:130
int d_simExec
Definition: coSimLib.h:157
bool d_byteswap
Definition: coSimLib.h:118
command_object(int type, char *port=0, char *name=0, char *data=0, int length=0, int numComp=0, int actNode=0)
Definition: coSimLib.h:36
int _actNode
Definition: coSimLib.h:60
char * _name
Definition: coSimLib.h:59
int min(int a, int b)
Definition: cutil_math.h:60
char * _data
Definition: coSimLib.h:59
int recvData(void *buffer, size_t length)
Definition: coSimClient.c:1474
int d_socket
Definition: coSimLib.h:112
int int32
Definition: coSimLib.h:70
int _numComp
Definition: coSimLib.h:60
int _length
Definition: coSimLib.h:60
coChoiceParam * p_StartupSwitch
Definition: coSimLib.h:186
int getVerboseLevel()
request verbose level
Definition: coSimLib.h:244
int32 d_command
Definition: coSimLib.h:124
Definition: coModule.h:47
static int openClient(unsigned long ip, int port, float timeout)
Definition: coSimClient.c:1579
int sendData(const void *buffer, size_t length)
Definition: coSimClient.c:1414
int numParts
Definition: coSimLib.h:135
coChoiceParam * getStartupChoice()
get the startup choice
Definition: coSimLib.h:250
static int acceptServer(float wait)
Definition: coSimClient.c:1628
char ** d_startup_label
Definition: coSimLib.h:146
GLenum type
Definition: khronos-glext.h:6279
int32 d_numCells
Definition: coSimLib.h:128
int *** map
Definition: coSimLib.h:134
Definition: coSimLib.h:32
Definition: coSimLib.h:131
char * d_name
Definition: coSimLib.h:121
Definition: coSimpleModule.h:26
int server_socket
Definition: coSimLib.h:109
parameter to choose values from a list
Definition: coChoiceParam.h:29
#define APIEXPORT
Definition: coExport.h:251
std::list< command_object * > * command_objects
Definition: coSimLib.h:161
GLuint GLuint num
Definition: khronos-glext.h:10593
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: khronos-glext.h:6354
const char * name
Definition: coSimLib.h:133
int _type
Definition: coSimLib.h:58
GLenum GLuint GLenum GLsizei length
Definition: khronos-glext.h:6279
int max(int a, int b)
Definition: cutil_math.h:55
GLuint buffer
Definition: khronos-glext.h:6606
Definition: coDistributedObject.h:294
coDistributedObject * openObj
Definition: coSimLib.h:136
int coParallelInit(int numParts, int numPorts)
Definition: coSimClient.c:1021
PortListElem * next
Definition: coSimLib.h:138
~command_object()
Definition: coSimLib.h:47
const char ** d_startup_line
Definition: coSimLib.h:147
int simRequestExec()
check whether simulation requested exec
Definition: coSimLib.h:256
static int openServer(int minPort, int maxPort)
Definition: coSimClient.c:1525
Definition: coSimLib.h:64
std::list< command_object * > * tmp_objects
Definition: coSimLib.h:162
GLuint const GLchar * name
Definition: khronos-glext.h:6722
char * _port
Definition: coSimLib.h:59
uint32_t d_usePort
Definition: coSimLib.h:106
int coParallelPort(const char *portName, int isCellData)
Definition: coSimClient.c:1064
int d_numStartup
Definition: coSimLib.h:150
int32 ** d_vertMap
Definition: coSimLib.h:129
void setVerbose(int level)
set verbose level
Definition: coSimLib.h:238
GLint level
Definition: khronos-glext.h:6344