COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
dmgr.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 COVISE_DMGRPROC_H
9 #define COVISE_DMGRPROC_H
10 
11 #include <covise/covise_process.h>
12 #include <shm/covise_shm.h>
13 #include "covise_avl_tree.h"
14 #include <covise/covise_global.h>
15 #include <covise/covise_signal.h>
16 #include <covise/covise.h>
17 #include <signal.h>
18 #ifndef _WIN32
19 #include <sys/time.h>
20 #endif
21 #ifdef _AIX
22 int kill(pid_t pid, int sig);
23 #endif
24 
25 /***********************************************************************\
26  ** **
27  ** Datamanager Process classes Version: 1.5 **
28  ** **
29  ** **
30  ** Description : All classes that work as the processes own data **
31  ** and function base. Each process should make a new **
32  ** object of its appropriate class type to have **
33  ** access to the basic functionality. **
34  ** **
35  ** Classes : DataManagerProcess, ObjectEntry **
36  ** **
37  ** Copyright (C) 1996 by University of Stuttgart **
38  ** Computer Center (RUS) **
39  ** Allmandring 30 **
40  ** 7000 Stuttgart 80 **
41  ** **
42  ** **
43  ** Author : A. Wierse (RUS) **
44  ** **
45  ** History : **
46  ** 19.11.96 Ver 1.0 **
47  ** **
48 \***********************************************************************/
49 
50 #if !defined(__linux__) && !defined(_WIN32)
51 #define COVISE_Signals
52 #endif
53 
54 namespace covise
55 {
56 
57 class DMEntry;
58 
60 {
62  friend class DataManagerProcess;
63  char *name; // name of the object
64  int version; // version of the object
65  int shm_seq_no; // shm_seq_no of the object
66  int offset; // offset of the object
67  int type; // type of the object
68  Connection *owner; // connection to the process that created this object
69  List<AccessEntry> *access; // list of access rights to this object
70  DMEntry *dmgr; // pointer to the DM which sent the object (can be like owner)
71 public:
73  {
74  name = 0L;
75  shm_seq_no = offset = -1;
76  dmgr = 0L;
77  version = 1;
79  };
80  ObjectEntry(char *n);
81  ObjectEntry(char *n, int type, int no, int o, Connection *c, DMEntry *dm = 0L);
82  ObjectEntry(char *n, int no, int o, Connection *c, DMEntry *dm = 0L);
84  {
85  return (strcmp(name, oe.name) == 0 ? 1 : 0);
86  };
88  {
89  return (strcmp(name, oe.name) >= 0 ? 1 : 0);
90  };
92  {
93  return (strcmp(name, oe.name) <= 0 ? 1 : 0);
94  };
96  {
97  return (strcmp(name, oe.name) > 0 ? 1 : 0);
98  };
100  {
101  return (strcmp(name, oe.name) < 0 ? 1 : 0);
102  };
103  void add_access(Connection *c, access_type a, access_type c_a);
104  void set_current_access(Connection *c, access_type c_a);
105  access_type get_access_right(Connection *c);
106  access_type get_access(Connection *c);
107  void remove_access(Connection *c);
108  void set_dmgr(DMEntry *dm)
109  {
110  dmgr = dm;
111  };
112  void pack_and_send_object(Message *msg, DataManagerProcess *dm);
113  void pack_address(Message *msg);
114  void print();
115  ~ObjectEntry();
116 };
117 
119 {
120  friend class DataManagerProcess;
121  friend class ObjectEntry;
122 
123 private:
124  int id;
130  DMEntry(int i, char *h, Connection *c);
131  const char *get_hostname(void);
133  {
134  return conn;
135  };
136  int make_data_conn(char *new_interface);
137  int complete_data_conn(Message *msg);
138  int recv_data_msg(Message *msg) // receive Data Message
139  {
140  return data_conn->recv_msg(msg);
141  };
142  int send_data_msg(const Message *msg) // send Data Message
143  {
144  return data_conn->send_msg(msg);
145  };
146 
147 public:
148  void print(){};
149  int send_msg(Message *msg)
150  {
151  return conn->send_msg(msg);
152  };
153 };
154 
156 {
158  friend class ObjectEntry;
159 
160 private:
161  int id;
166  TMEntry(int i, char *h, Connection *c);
167  int make_data_conn(char *new_interface);
168  int complete_data_conn(Message *msg);
169  int recv_data_msg(Message *msg) // receive Data Message
170  {
171  return data_conn->recv_msg(msg);
172  };
173  int send_data_msg(const Message *msg) // send Data Message
174  {
175  return data_conn->send_msg(msg);
176  };
177 
178 public:
179  void print(){};
180 };
181 
182 class AddressOrderedTree;
183 class SizeOrderedTree;
184 
186 {
191 
192 public:
193  coShmAlloc(int *key, DataManagerProcess *d);
195  {
196  delete shm;
197  };
198  coShmPtr *malloc(shmSizeType size);
199  void get_shmlist(char *ptr)
200  {
201  shm->get_shmlist((int *)ptr);
202  };
203  void free(coShmPtr *adr)
204  {
205  free(adr->shm_seq_no, adr->offset);
206  };
207  void free(int shm_seq_no, shmSizeType offset);
208  void print();
209  void collect_garbage(){};
210  void new_desk(void);
211 };
212 
214 {
215 #ifdef CRAY
216  friend class ApplicationProcess;
217 #endif
219  ServerConnection *transfermanager; // Connection to the transfermanager
220  ServerConnection *tmpconn; // tmpconn for intermediate use
221  coShmAlloc *shm; // pointer to the sharedmemory
224  pid_t *pid_list;
226  bool is_bad_; // connection failed?
227  static int max_t;
228 
229 public:
230  DataManagerProcess(char *name, int id, int *key);
231  // DataManagerProcess(char *n, int arc, char *arv[]);
233  {
234  //int sleep_count = 0,
235  int i;
236  save_object_id();
237  // delete shm; // destructor (deletes shared memory)
238  print_comment(__LINE__, __FILE__, "Anfang von ~DataManagerProcess");
239  /*while(no_of_pids > 0 && sleep_count < 500)
240  {
241 #if defined(__hpux)
242  struct timeval timeout;
243  timeout.tv_sec = 0;
244  timeout.tv_usec = 50;
245 
246  select(0, 0, 0, 0, &timeout);
247 #else
248  select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout);
249 #endif
250  sleep_count++;
251  }*/
252  //cout << "sleep_count: " << sleep_count << endl;
253  for (i = 0; i < no_of_pids; i++)
254  {
255 //cout << "Killing process no. " << pid_list[i] << endl;
256 #ifndef _WIN32
257  kill(pid_list[i], SIGTERM);
258 #else
259  HANDLE hPid = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid_list[i]);
260  TerminateProcess(hPid, SIGTERM);
261  CloseHandle(hPid);
262 #endif
263  }
264  for (i = 0; i < SharedMemory::global_seq_no - 1; i++)
265  {
266  //cout << "Deleting SharedMemory no. " << i << endl;
267  delete SharedMemory::shm_array[i];
268  }
269  };
270 
271  int DTM_new_desk(void);
272  int rmv_rdmgr(char *hostname);
273  void rmv_acc2objs(CO_AVL_Node<ObjectEntry> *root, Connection *conn);
274 
276  {
277  return is_bad_;
278  };
279 
280  // build connection to the controller:
281  void contact_datamanager(int port, Host *host);
282  void contact_controller(int port, Host *host);
283  void init_object_id();
284  void save_object_id();
285  void start_transfermanager(); // start the transfermgr.
286  int get_trfmgr_port();
287  void connect_trfmgr(Host *h, int port);
288  void send_trf_msg(Message *); // send message to the transfermgr.
289  void exch_trf_msg(Message *); // send message to the transfermgr.
290  void prepare_for_contact(int *port); // perform bind and return port to use
291  void wait_for_contact(); // establish prepared connection
292  void wait_for_dm_contact(); // establish prepared connection
293  int make_data_connection(char *name, char *new_interface);
294  int complete_data_connection(Message *msg);
295  Message *wait_for_msg(); // wait for a message
296  Message *wait_for_msg(int, Connection *); // wait for a specific message
297  // wait for specific messages
298  Message *wait_for_msg(int *, int, Connection *);
299  // take action according to msg
300  int handle_msg(Message *msg, bool &localAlloc);
301  void deleteMessageData(Message *msg);
302  void ask_for_object(Message *msg); // answer requests immediately
303  void has_object_changed(Message *msg); // answer requests immediately
304  char *get_all_hosts_for_object(char *); // looks for all hosts that have object
305  // add new object in database
306  int add_object(char *n, int no, int o, Connection *c);
307  // add new object in database
308  int add_object(char *n, int otype, int no, int o, Connection *c);
309  int add_object(ObjectEntry *oe); // add new object in database
310  ObjectEntry *get_object(char *n); // get object from database
311  // get object from database and take care that the
312  // accesses are updated correctly:
313  ObjectEntry *get_object(char *n, Connection *c);
314  ObjectEntry *get_local_object(char *n); // get object only from local database
315  int delete_object(char *n); // delete object from database
316  int destroy_object(char *n, Connection *c); // remove obj from sharedmem.
317  // create transferred object
318  ObjectEntry *create_object_from_msg(Message *msg, DMEntry *dme);
319  // update from transferred object
320  int update_object_from_msg(Message *msg, DMEntry *dme);
321  int forward_new_part(Message *); // sends new part of partitioned object
322  int receive_new_part(Message *); // receives new part of partitioned object
323  // inserts new part of
324  int insert_new_part(ObjectEntry *, ObjectEntry *);
325  // partitioned object in shm representation
326  coShmPtr *shm_alloc(ShmMessage *msg); // allocate memory depending on msg
327  // returns offset into shared memory
328  // allocate memory of size
329  coShmPtr *shm_alloc(int type, shmSizeType msize = 0);
330  // returns offset into shared memory
331  int shm_free(coShmPtr *); // free memory (recursive !!)
332  void send_to_all_connections(Message *);
333  int shm_free(int, int); // free memory (recursive !!)
335  {
336  shm->print();
337  };
339  {
340  return shm->get_pointer();
341  };
342  void signal_handler(int signo, void *);
343  void remove_pid(int pid)
344  {
345  int i;
346  for (i = 0; i < no_of_pids && pid_list[i] != pid; i++)
347  ;
348  if (i < no_of_pids)
349  {
350  pid_list[i] = pid_list[no_of_pids - 1];
351  no_of_pids--;
352  }
353  }
354  void clean_all(int);
355  // nur temporaer eingefuegt, zum testen !! ^
356 };
357 
358 // not yet implemented
360 {
364  ServerConnection *tmpconn; // tmpconn for intermediate use
365  ShmAccess *shm; // pointer to the sharedmemory
366 public:
367  TransferManagerProcess(char *n, int arc, char *arv[]);
368  // ~TransferManagerProcess() {
369  // delete datamanager;
370  // };
371  void contact_transfermanager(int port, Host *host);
372  void contact_datamanager(int port); // build connection to datamanager
373  void contact_controller(int, Host *){};
374  void prepare_for_contact(int *port); // perform bind and return port to use
375  void wait_for_tm_contact(); // establish prepared connection
376  int make_data_connection(char *name, char *new_interface);
377  int complete_data_connection(Message *msg);
378  int handle_msg(Message *msg); // take action according to msg
381  {
382  return shm->get_pointer();
383  };
384  // nur temporaer eingefuegt, zum testen !! ^
385 };
386 
387 class DMGREXPORT DmgrMessage : public ShmMessage // message especially for memory allocation
388 {
389 public: // at the datamanager
391  int process_new_object_list(DataManagerProcess *dmgr);
392  int process_list(DataManagerProcess *dmgr);
393 };
394 
395 #ifdef shm_ptr
396 #undef shm_ptr
397 #endif
398 }
399 #endif
int id
Definition: dmgr.h:161
int operator<=(ObjectEntry &oe)
Definition: dmgr.h:91
DmgrMessage()
Definition: dmgr.h:390
GLsizeiptr size
Definition: khronos-glext.h:6610
int transfermgr
Definition: dmgr.h:129
static class SizeOrderedTree * free_size_list
Definition: dmgr.h:190
Definition: dmgr.h:213
GLintptr offset
Definition: khronos-glext.h:6611
ObjectEntry()
Definition: dmgr.h:72
Definition: covise_list.h:53
Definition: covise_connect.h:115
List< AccessEntry > * access
Definition: dmgr.h:69
Definition: covise_process.h:170
Definition: dmgr.h:185
Definition: covise_msg.h:87
Definition: covise_shm.h:311
int operator>(ObjectEntry &oe)
Definition: dmgr.h:95
bool is_connected()
Definition: dmgr.h:275
int recv_data_msg(Message *msg)
Definition: dmgr.h:138
GLboolean GLboolean GLboolean GLboolean a
Definition: khronos-glext.h:6895
Connection * get_conn(void)
Definition: dmgr.h:132
access_type
Definition: covise_shm.h:81
void set_dmgr(DMEntry *dm)
Definition: dmgr.h:108
Definition: covise_shm.h:379
void remove_pid(int pid)
Definition: dmgr.h:343
int operator==(ObjectEntry &oe)
Definition: dmgr.h:83
int operator<(ObjectEntry &oe)
Definition: dmgr.h:99
Definition: covise_avl_tree.h:46
GLfloat GLfloat GLfloat GLfloat h
Definition: khronos-glext.h:8441
coShmAlloc * shm
Definition: dmgr.h:221
Definition: dmgr.h:359
void print_shared_memory_statistics()
Definition: dmgr.h:334
unsigned int shmSizeType
Definition: covise_shm.h:202
AVLTree< ObjectEntry > * objects
Definition: dmgr.h:222
void handle_shm_msg(Message *)
Definition: dmgr.h:379
Definition: dmgr.h:118
int shm_seq_no
Definition: covise_shm.h:347
Connection * conn
Definition: dmgr.h:163
int id
Definition: dmgr.h:124
int send_data_msg(const Message *msg)
Definition: dmgr.h:142
GLuint const GLchar * name
Definition: khronos-glext.h:6722
const GLubyte * c
Definition: khronos-glext.h:9864
int send_data_msg(const Message *msg)
Definition: dmgr.h:173
Definition: dmgr.h:155
Definition: covise_host.h:18
Definition: dmgr.h:59
void clean_all(int arg)
Definition: dmgr_process.cpp:327
void contact_controller(int, Host *)
Definition: dmgr.h:373
void * get_shared_memory_address()
Definition: dmgr.h:380
List< TMEntry > * transfer_mgrs
Definition: dmgr.h:363
Connection * conn
Definition: dmgr.h:126
Definition: coFileUtil.cpp:32
Connection * owner
Definition: dmgr.h:68
static class SharedMemory ** shm_array
Definition: covise_shm.h:212
static int global_seq_no
Definition: covise_shm.h:214
DataManagerConnection * datamanager
Definition: dmgr.h:361
AVLTree< ObjectEntry > * objects
Definition: dmgr.h:362
void get_shmlist(char *ptr)
Definition: dmgr.h:199
AVLTree< ObjectEntry > * objects
Definition: dmgr.h:128
Definition: covise_connect.h:200
int no_of_pids
Definition: dmgr.h:225
int offset
Definition: dmgr.h:66
Connection * data_conn
Definition: dmgr.h:164
void print()
Definition: dmgr.h:179
Definition: covise_appproc.h:19
int send_msg(Message *msg)
Definition: dmgr.h:149
bool is_bad_
Definition: dmgr.h:226
Connection * data_conn
Definition: dmgr.h:127
int ObjectEntry_compare(ObjectEntry *a, ObjectEntry *b)
Definition: dmgr_process.cpp:304
int operator>=(ObjectEntry &oe)
Definition: dmgr.h:87
DMEntry * dmgr
Definition: dmgr.h:70
Host * host
Definition: dmgr.h:125
char * name
Definition: dmgr.h:63
shmSizeType offset
Definition: covise_shm.h:348
void * get_shared_memory_address()
Definition: dmgr.h:338
pid_t * pid_list
Definition: dmgr.h:224
int version
Definition: dmgr.h:64
Definition: covise_avl_tree.h:43
int shm_seq_no
Definition: dmgr.h:65
int recv_data_msg(Message *msg)
Definition: dmgr.h:169
void pack_and_send_object(Message *msg, DataManagerProcess *dm)
Definition: dmgr_process.cpp:2056
Host * host
Definition: dmgr.h:162
ServerConnection * tmpconn
Definition: dmgr.h:220
List< DMEntry > * data_mgrs
Definition: dmgr.h:223
int type
Definition: dmgr.h:67
Definition: dmgr_mem_avltrees.h:372
static class AddressOrderedTree * used_list
Definition: dmgr.h:188
ServerConnection * tmpconn
Definition: dmgr.h:364
GLdouble n
Definition: khronos-glext.h:8447
~coShmAlloc()
Definition: dmgr.h:194
AVLTree< ObjectEntry > * objects
Definition: dmgr.h:165
static int max_t
Definition: dmgr.h:227
#define DMGREXPORT
Definition: coExport.h:313
static class AddressOrderedTree * free_list
Definition: dmgr.h:189
void collect_garbage()
Definition: dmgr.h:209
void print_comment(int line, const char *filename, const char *fmt,...)
Definition: coLog.cpp:25
ServerConnection * transfermanager
Definition: dmgr.h:219
Definition: covise_connect.h:269
GLenum type
Definition: khronos-glext.h:6279
~DataManagerProcess()
Definition: dmgr.h:232
void print()
Definition: dmgr.h:148
ShmAccess * shm
Definition: dmgr.h:365
void free(coShmPtr *adr)
Definition: dmgr.h:203
class DataManagerProcess * dmgrproc
Definition: dmgr.h:187
Definition: dmgr_mem_avltrees.h:220
Definition: dmgr.h:387
GLuint GLint GLboolean GLint GLenum access
Definition: khronos-glext.h:8584
Definition: message.h:111