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