COVISE Core
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>
16#include <util/coviseCompat.h>
17#ifndef YAC
18#include <api/coModule.h>
19#include <covise/covise.h>
20#else
21#include <comm/logic/coSocketListener.h>
22#endif
23#include <net/covise_connect.h>
24
29namespace covise
30{
31
33{
34
35public:
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)
39 , _name(name)
40 , _data(data)
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
65#else
66class APIEXPORT coSimLib : public coSimpleModule, public coSocketListener
67#endif
68{
69public:
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
82private:
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
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
173protected:
174#include "coSimLibComm.h"
175
178
181
184
185 // this allows to choose between the different start-ups
187
188 int reAccept();
189
190public:
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
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
#define APIEXPORT
Definition: coExport.h:275
GLint level
Definition: khronos-glext.h:6344
GLuint buffer
Definition: khronos-glext.h:6606
GLuint const GLchar * name
Definition: khronos-glext.h:6722
GLuint GLuint num
Definition: khronos-glext.h:10593
GLenum GLuint GLenum GLsizei length
Definition: khronos-glext.h:6279
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: khronos-glext.h:6354
GLenum type
Definition: khronos-glext.h:6279
int coParallelInit(int numParts, int numPorts)
Definition: coSimClient.c:1031
int recvData(void *buffer, size_t length)
Definition: coSimClient.c:1500
int coParallelPort(const char *portName, int isCellData)
Definition: coSimClient.c:1074
static int openServer(int minPort, int maxPort)
Definition: coSimClient.c:1559
int sendData(const void *buffer, size_t length)
Definition: coSimClient.c:1432
static int openClient(unsigned long ip, int port, float timeout)
Definition: coSimClient.c:1617
static int acceptServer(float wait)
Definition: coSimClient.c:1666
int min(int a, int b)
Definition: cutil_math.h:60
int max(int a, int b)
Definition: cutil_math.h:55
list of all chemical elements
Definition: coConfig.h:27
Definition: coDistributedObject.h:296
parameter to choose values from a list
Definition: coChoiceParam.h:30
Definition: coModule.h:48
Definition: coSimLib.h:33
char * _name
Definition: coSimLib.h:59
char * _data
Definition: coSimLib.h:59
int _type
Definition: coSimLib.h:58
int _actNode
Definition: coSimLib.h:60
int _length
Definition: coSimLib.h:60
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
char * _port
Definition: coSimLib.h:59
~command_object()
Definition: coSimLib.h:47
int _numComp
Definition: coSimLib.h:60
Definition: coSimLib.h:68
int32 ** d_cellMap
Definition: coSimLib.h:128
int d_socket
Definition: coSimLib.h:112
int d_simExec
Definition: coSimLib.h:157
coSimLib(const coSimLib &)
Copy-Constructor: NOT IMPLEMENTED.
int getVerboseLevel()
request verbose level
Definition: coSimLib.h:244
int d_numStartup
Definition: coSimLib.h:150
coChoiceParam * p_StartupSwitch
Definition: coSimLib.h:186
int simRequestExec()
check whether simulation requested exec
Definition: coSimLib.h:256
void setVerbose(int level)
set verbose level
Definition: coSimLib.h:238
coChoiceParam * getStartupChoice()
get the startup choice
Definition: coSimLib.h:250
int d_verbose
Definition: coSimLib.h:115
char * d_name
Definition: coSimLib.h:121
int32 d_actNode
Definition: coSimLib.h:143
char ** d_startup_label
Definition: coSimLib.h:146
coSimLib()
Default constructor: NOT IMPLEMENTED.
bool d_byteswap
Definition: coSimLib.h:118
int32 d_numVert
Definition: coSimLib.h:129
int int32
Definition: coSimLib.h:70
uint32_t d_localIP
Definition: coSimLib.h:106
int d_numNodes
Definition: coSimLib.h:130
std::list< command_object * > * command_objects
Definition: coSimLib.h:161
const char ** d_startup_line
Definition: coSimLib.h:147
std::list< command_object * > * tmp_objects
Definition: coSimLib.h:162
int server_socket
Definition: coSimLib.h:109
int32 d_command
Definition: coSimLib.h:124
coSimLib & operator=(const coSimLib &)
Assignment operator: NOT IMPLEMENTED.
Definition: coSimLib.h:132
const char * name
Definition: coSimLib.h:133
int numParts
Definition: coSimLib.h:135
PortListElem * next
Definition: coSimLib.h:138
int *** map
Definition: coSimLib.h:134
coDistributedObject * openObj
Definition: coSimLib.h:136
Definition: coSimpleModule.h:27