COVISE Core
coDistributedObject.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_DISTRIBUTED_OBJECT_H
9#define CO_DISTRIBUTED_OBJECT_H
10
11#include <util/covise_list.h>
12#include <util/coObjID.h>
13#include "coShmPtrArray.h"
14
15/*
16 $Log: $
17 * Revision 1.1 1993/09/25 20:42:21 zrhk0125
18 * Initial revision
19 *
20*/
21
22/***********************************************************************\
23 ** **
24 ** Distributed Object class Version: 1.1 **
25 ** **
26 ** **
27 ** Description : The base class for all objects that are **
28 ** distributed between processes. **
29 ** Basic functionality to use shared storage is **
30 ** provided for its subclasses. **
31 ** **
32 ** Classes : coDistributedObject **
33 ** **
34 ** Copyright (C) 1993 by University of Stuttgart **
35 ** Computer Center (RUS) **
36 ** Allmandring 30 **
37 ** 7000 Stuttgart 80 **
38 ** **
39 ** **
40 ** Author : A. Wierse (RUS) **
41 ** **
42 ** History : **
43 ** 15.04.93 Ver 1.0 **
44 ** 26.05.93 Ver 1.1 PackElement introduced for **
45 ** sending whole Objects between **
46 ** Data Managers **
47 ** **
48\***********************************************************************/
49namespace covise
50{
51class DataHandle;
52class ApplicationProcess;
53
54DOEXPORT void PackElement_print(class PackElement *);
55
57{
58public:
60 shmSizeType offset; // offset to the type header
61 int type;
62 shmSizeType size; // size in bytes
63 int length; // number of elements, if array or any-type
64 char *ptr; // pointer to the data (not the type-header
66 {
67 length = shm_seq_no = offset = type = size = 0;
68 ptr = NULL;
69 }
70 void print()
71 {
73 };
74};
75
77{
78public:
79 int type;
82 {
83 type = t_no;
84 vconstr = vc;
85 };
86 void print(){};
87};
88
89// structure for the _dl functions
91{
93 const void *ptr;
94};
95
98
100{
101 // REMEMBER: upon insertion of new elements adjust getHeaderSize
102 // and getIntHeaderSize, and modify:
103 // DataManagerProcess::create_object_from_msg
104 // coDistributedObject::getObjectInfo(coDoInfo **info_list)
105 // AND correct coDistributedObject::checkObj
106
107private:
115 int version_type; // INTSHM
117 int refcount_type; // INTSHM
119 int name_type; // CHARSH
122 int attr_type; // SHMPTR or NULLPTR
125 // the following only for partitioned Objects!!
127 int part_object_type; // Object type
129 int part_max_number_of_parts; // Max number of parts
131 int part_curr_number_of_parts; // Current number of parts
132 int part_address_list_type; // SHMPTR or NULLPTR
135
136public:
137 static int getHeaderSize()
138 {
139 return getIntHeaderSize() * sizeof(int);
140 }; // size must be adjusted manually!!
141
142 static int getIntHeaderSize()
143 {
145 }; // size must be adjusted manually!!
146
148 {
149 return object_type;
150 };
151
153 {
154 if (number_of_elements_type == INTSHM)
155 return number_of_elements;
156 else
157 {
158 print_error(__LINE__, __FILE__,
159 "numberOFElements not found");
160 return 0;
161 }
162 }
163
165 {
166 if (version_type == INTSHM)
167 return version;
168 else
169 {
170 print_error(__LINE__, __FILE__,
171 "version number not found");
172 return 0;
173 }
174 }
175
177 {
178 return ++version;
179 }
180
182 {
183 if (refcount_type == INTSHM)
184 return refcount;
185 else
186 {
187 print_error(__LINE__, __FILE__,
188 "reference counter not found");
189 return 0;
190 }
191 };
192
194 {
195 return ++refcount;
196 };
198 {
199 return --refcount;
200 };
201 const char *getName() const; // do not delete the resulting pointer
202 coStringShmArray *getAttributes();
204 {
205 return attr_type;
206 };
208 {
209 return 0;
210 };
212 {
213 return (int)((&number_of_elements_type - &object_type) * sizeof(int));
214 };
216 {
217 return (int)((&version_type - &object_type) * sizeof(int));
218 };
220 {
221 return (int)((&refcount_type - &object_type) * sizeof(int));
222 };
223 void get_objectid(int *h, int *t)
224 {
225 *h = objectid_h;
226 *t = objectid_t;
227 };
228 void set_object_type(int ot)
229 {
230 object_type = ot;
231 };
232 void set_objectid(int h, int t)
233 {
234 objectid_type = COVISE_OBJECTID;
235 objectid_h = h;
236 objectid_t = t;
237 };
239 {
240 number_of_elements_type = INTSHM;
241 number_of_elements = noe;
242 };
243 void set_version(int v)
244 {
245 version_type = INTSHM;
246 version = v;
247 };
248 void set_refcount(int rc)
249 {
250 refcount_type = INTSHM;
251 refcount = rc;
252 };
253 void set_name(int sn, shmSizeType o, char *n); // namelength must fit!!
255 {
256 if (sn == 0)
257 attr_type = COVISE_NULLPTR;
258 else
259 attr_type = SHMPTR;
260 attr_shm_seq_no = sn;
261 attr_offset = o;
262 };
263 void print();
264};
265
267{
268public:
269 int type;
270 const char *type_name;
271 const char *description;
272 char *obj_name; //optional, only in the case of DISTROBJ
273 void *ptr;
275 : type(0)
276 , type_name(NULL)
277 , description(NULL)
278 , obj_name(NULL)
279 , ptr(NULL){};
281 {
282 delete obj_name;
283 }
284 void print()
285 {
286 cout << "Type: " << type << ", " << type_name << std::endl;
287 if (description)
288 cout << "Description: " << description << std::endl;
289 if (obj_name)
290 cout << "Object Name: " << obj_name << std::endl;
291 cout << "Pointer: " << ptr << std::endl;
292 }
293};
294
296{
297 friend class ApplicationProcess;
298 friend class coShmArrayPtr;
299 //friend class DO_PartitionedObject;
300 friend void coShmPtrArray::set(int i, const class coDistributedObject *elem);
302
303 static int xfer_arrays;
304
305protected:
309 coStringShmArray *attributes = nullptr;
310 mutable coDoHeader *header = nullptr;
311 char type_name[7];
312 int type_no = 0;
313 char *name = nullptr;
314 int loc_version = -1;
315 bool new_ok;
316 int size = 0;
317 mutable char *attribs = nullptr; // Data space for Attributes
318 int getShmArray() const;
320 {
321 shmarr = arr;
322 return rebuildFromShm();
323 };
324 virtual int rebuildFromShm() = 0;
325 virtual int getObjInfo(int, coDoInfo **) const
326 {
327 print_comment(__LINE__, __FILE__,
328 "getObjInfo called from coDistributedObject");
329 return 0;
330 };
331
333 bool checkObj(int shmSegNo, shmSizeType shmOffs, bool &printed) const;
334 virtual coDistributedObject *cloneObject(const coObjInfo &newinfo) const = 0;
335
336public:
338 void getShmLocation(int &shmSegNo, shmSizeType &offset) const;
339
341 void addAttribute(const char *, const char *);
342
344 void addAttributes(int, const char *const *, const char *const *);
345
347 const char *getAttribute(const char *) const;
348
350 int getNumAttributes() const;
351
353 int getAllAttributes(const char ***name, const char ***content) const;
354
356 void copyAllAttributes(const coDistributedObject *src);
357
359 char *getName() const
360 {
361 return name;
362 }
363
365 const char *getType() const
366 {
367 return type_name;
368 }
369
371 int isType(const char *reqType) const
372 {
373 return (0 == strcmp(reqType, type_name));
374 }
375
377 bool objectOk() const
378 {
379 return new_ok;
380 }
381
383 {
384 size = 0;
385 loc_version = 0;
386 new_ok = true;
387 xfer_arrays = 1;
388 attributes = NULL;
389 attribs = NULL;
390 shmarr = NULL;
391 type_name[0] = '\0';
392 type_no = 0;
393 header = NULL;
394 name = NULL;
395 // printf("---- new coDistributedObject: %x\n", this);
396 };
397
399 {
400 size = 0;
401 loc_version = 0;
402 new_ok = true;
403 xfer_arrays = 1;
404 attributes = NULL;
405 attribs = NULL;
406 shmarr = NULL;
407 header = NULL;
408 type_name[0] = '\0';
409 type_no = 0;
410 const char *n = info.getName();
411 if (n)
412 {
413 name = new char[strlen(n) + 1];
414 strcpy(name, n);
415 }
416 else
417 name = NULL;
418 };
419
420 coDistributedObject(const coObjInfo &info, const char *t)
421 {
422 // printf("---- new coDistributedObject: %x\n", this);
423 size = 0;
424 loc_version = 0;
425 new_ok = true;
426 xfer_arrays = 1;
427 attributes = NULL;
428 attribs = NULL;
429 shmarr = NULL;
430 header = NULL;
431 strncpy(type_name, t, 7);
432 type_name[6] = '\0';
433 type_no = calcType(type_name);
434 const char *n = info.getName();
435 if (n)
436 {
437 name = new char[strlen(n) + 1];
438 strcpy(name, n);
439 }
440 else
441 name = NULL;
442 };
443
444 coDistributedObject(const coObjInfo &info, int shmSeg, shmSizeType offs, char *t)
445 {
446 size = 0;
447 loc_version = 0;
448 new_ok = true;
449 xfer_arrays = 1;
450 attributes = NULL;
451 attribs = NULL;
452 shmarr = new coShmArray(shmSeg, offs);
453 header = (coDoHeader *)shmarr->getPtr();
454 strncpy(type_name, t, 7);
455 type_name[6] = '\0';
456 type_no = calcType(type_name);
457 attribs = NULL;
458 const char *n = info.getName();
459 if (n)
460 {
461 name = new char[strlen(n) + 1];
462 strcpy(name, n);
463 }
464 else
465 name = NULL;
466
467 if (createFromShm(shmarr) == 0)
468 {
469 print_comment(__LINE__, __FILE__, "createFromShm == 0");
470 new_ok = false;
471 }
472 };
473
474 virtual ~coDistributedObject();
475 coDistributedObject *clone(const coObjInfo &newinfo) const;
478 static const coDistributedObject *createFromShm(const coObjInfo &newinfo);
479 static const coDistributedObject *createUnknown(coShmArray *);
480 static const coDistributedObject *createUnknown(int seg, shmSizeType offs);
481 void copyObjInfo(coObjInfo *info) const;
482
483 const coDistributedObject *createUnknown() const;
484
485 int *store_header(int, int, int, int *, data_type *, long *, covise::DataHandle &idata);
486 int restore_header(int **, int, int *, int *, shmSizeType *);
487 void init_header(int *, int *, int, data_type **, long **);
488
489 int update_shared_dl(int count, covise_data_list *dl);
490 int store_shared_dl(int count, covise_data_list *dl);
491 int restore_shared_dl(int count, covise_data_list *dl);
492
493 void setType(const char *, const char *);
494 static int calcType(const char *);
495 static char *calcTypeString(int);
496 int getObjectInfo(coDoInfo **) const;
497 int get_type_no() const
498 {
499 return type_no;
500 }
501 int access(access_type);
502 // access_type set_access(access_type);
503 // access_type set_access_block(access_type);
504 // access_type get_access() { return current_access; };
505 int destroy();
506 char *object_on_hosts() const;
507 // int incRefCount() { return header->incRefCount(); };
508 int incRefCount() const
509 {
510 return refcount = refcount + 1;
511 }
512 // int decRefCount() { return header->decRefCount(); }
513 int decRefCount() const
514 {
515 return refcount = refcount - 1;
516 }
517 int getRefCount() const
518 {
519 return refcount;
520 }
521 void print() const
522 {
523 }
524
525 static int set_vconstr(const char *, coDistributedObject *(*)(coShmArray *));
526
528 // contact CRB, get Obj, call restore_shared.
529 void getObjectFromShm();
530
532 bool checkObject() const;
533};
534}
535#endif
#define DOEXPORT
Definition: coExport.h:331
#define NULL
Definition: covise_list.h:22
GLdouble n
Definition: khronos-glext.h:8447
GLenum src
Definition: khronos-glext.h:7031
GLsizeiptr size
Definition: khronos-glext.h:6610
const GLdouble * v
Definition: khronos-glext.h:6442
GLuint GLuint GLsizei count
Definition: khronos-glext.h:6343
GLdouble GLdouble t
Definition: khronos-glext.h:6449
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
GLenum GLuint GLenum GLsizei length
Definition: khronos-glext.h:6279
const GLint * attribs
Definition: khronos-glext.h:11807
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
static coShmArray * getShmArray(const char *name)
Definition: coDistributedObject.cpp:60
void print_error(int line, const char *filename, const char *fmt,...)
Definition: coLog.cpp:132
const int INTSHM
Definition: covise_shm.h:125
const int SHMPTR
Definition: covise_shm.h:133
const int NUMBER_OF_SHM_SIZE_HEADER_ELEMENTS
Definition: coDistributedObject.h:97
void PackElement_print(PackElement *th)
Definition: coDistributedObject.cpp:1596
long data_type
Definition: message.h:28
access_type
Definition: covise_shm.h:82
unsigned int shmSizeType
Definition: covise_shm.h:202
const int COVISE_NULLPTR
Definition: covise_shm.h:139
const int COVISE_OBJECTID
Definition: covise_shm.h:134
void print_comment(int line, const char *filename, const char *fmt,...)
Definition: coLog.cpp:25
const int NUMBER_OF_INT_HEADER_ELEMENTS
Definition: coDistributedObject.h:96
std::enable_if< I==sizeof...(Tp), void >::type print(Stream &s, const std::tuple< Tp... > &t)
Definition: tokenbuffer_util.h:68
Definition: coObjID.h:231
const char * getName() const
Definition: coObjID.h:308
Definition: covise_list.h:78
Definition: dataHandle.h:18
Definition: covise_appproc.h:20
void * getPtr()
Definition: covise_shm.h:372
Definition: covise_shm.h:482
Definition: covise_shm.h:655
Definition: coDistributedObject.h:57
int length
Definition: coDistributedObject.h:63
int type
Definition: coDistributedObject.h:61
int shm_seq_no
Definition: coDistributedObject.h:59
shmSizeType offset
Definition: coDistributedObject.h:60
char * ptr
Definition: coDistributedObject.h:64
shmSizeType size
Definition: coDistributedObject.h:62
PackElement()
Definition: coDistributedObject.h:65
void print()
Definition: coDistributedObject.h:70
Definition: coDistributedObject.h:77
void print()
Definition: coDistributedObject.h:86
VirtualConstructor(int t_no, coDistributedObject *(*vc)(coShmArray *arr))
Definition: coDistributedObject.h:81
int type
Definition: coDistributedObject.h:79
Definition: coDistributedObject.h:91
data_type type
Definition: coDistributedObject.h:92
const void * ptr
Definition: coDistributedObject.h:93
Definition: coDistributedObject.h:100
int get_version_offset()
Definition: coDistributedObject.h:215
int part_address_list_shm_seq_no
Definition: coDistributedObject.h:133
void set_version(int v)
Definition: coDistributedObject.h:243
int get_number_of_elements()
Definition: coDistributedObject.h:152
int decRefCount()
Definition: coDistributedObject.h:197
static int getHeaderSize()
Definition: coDistributedObject.h:137
int objectid_t
Definition: coDistributedObject.h:112
int attr_type
Definition: coDistributedObject.h:122
int number_of_elements
Definition: coDistributedObject.h:114
shmSizeType attr_offset
Definition: coDistributedObject.h:124
int name_type
Definition: coDistributedObject.h:119
int get_refcount()
Definition: coDistributedObject.h:181
int get_version()
Definition: coDistributedObject.h:164
int attr_shm_seq_no
Definition: coDistributedObject.h:123
int objectid_h
Definition: coDistributedObject.h:111
int name_shm_seq_no
Definition: coDistributedObject.h:120
void set_number_of_elements(int noe)
Definition: coDistributedObject.h:238
int number_of_elements_type
Definition: coDistributedObject.h:113
int part_object_type_type
Definition: coDistributedObject.h:126
int getObjectType()
Definition: coDistributedObject.h:147
void addAttributes(int sn, shmSizeType o)
Definition: coDistributedObject.h:254
int refcount_type
Definition: coDistributedObject.h:117
shmSizeType part_address_list_offset
Definition: coDistributedObject.h:134
void set_refcount(int rc)
Definition: coDistributedObject.h:248
int part_address_list_type
Definition: coDistributedObject.h:132
int objectid_type
Definition: coDistributedObject.h:110
int get_refcount_offset()
Definition: coDistributedObject.h:219
int part_curr_number_of_parts_type
Definition: coDistributedObject.h:130
int incRefCount()
Definition: coDistributedObject.h:193
int part_curr_number_of_parts
Definition: coDistributedObject.h:131
shmSizeType number_of_bytes
Definition: coDistributedObject.h:109
int increase_version()
Definition: coDistributedObject.h:176
int version
Definition: coDistributedObject.h:116
int version_type
Definition: coDistributedObject.h:115
int part_max_number_of_parts
Definition: coDistributedObject.h:129
static int getIntHeaderSize()
Definition: coDistributedObject.h:142
void get_objectid(int *h, int *t)
Definition: coDistributedObject.h:223
int part_max_number_of_parts_type
Definition: coDistributedObject.h:128
int get_number_of_elements_offset()
Definition: coDistributedObject.h:211
int refcount
Definition: coDistributedObject.h:118
void set_object_type(int ot)
Definition: coDistributedObject.h:228
int object_type
Definition: coDistributedObject.h:108
int getObjectType_offset()
Definition: coDistributedObject.h:207
int part_object_type
Definition: coDistributedObject.h:127
void set_objectid(int h, int t)
Definition: coDistributedObject.h:232
shmSizeType name_offset
Definition: coDistributedObject.h:121
int get_attr_type()
Definition: coDistributedObject.h:203
Definition: coDistributedObject.h:267
~coDoInfo()
Definition: coDistributedObject.h:280
void * ptr
Definition: coDistributedObject.h:273
int type
Definition: coDistributedObject.h:269
void print()
Definition: coDistributedObject.h:284
coDoInfo()
Definition: coDistributedObject.h:274
const char * description
Definition: coDistributedObject.h:271
char * obj_name
Definition: coDistributedObject.h:272
const char * type_name
Definition: coDistributedObject.h:270
Definition: coDistributedObject.h:296
coIntShm version
Definition: coDistributedObject.h:306
coShmArray * shmarr
Definition: coDistributedObject.h:308
char * getName() const
get the object's name
Definition: coDistributedObject.h:359
static int xfer_arrays
Definition: coDistributedObject.h:303
int get_type_no() const
Definition: coDistributedObject.h:497
coDistributedObject()
Definition: coDistributedObject.h:382
static List< VirtualConstructor > * vconstr_list
Definition: coDistributedObject.h:301
coDistributedObject(const coObjInfo &info, int shmSeg, shmSizeType offs, char *t)
Definition: coDistributedObject.h:444
int getRefCount() const
Definition: coDistributedObject.h:517
void print() const
Definition: coDistributedObject.h:521
coDistributedObject(const coObjInfo &info)
Definition: coDistributedObject.h:398
virtual int getObjInfo(int, coDoInfo **) const
Definition: coDistributedObject.h:325
const char * getType() const
get the object's type
Definition: coDistributedObject.h:365
bool objectOk() const
check whether object was created or received ok
Definition: coDistributedObject.h:377
coDistributedObject(const coObjInfo &info, const char *t)
Definition: coDistributedObject.h:420
virtual int rebuildFromShm()=0
int isType(const char *reqType) const
check whether this is a certain type
Definition: coDistributedObject.h:371
int createFromShm(coShmArray *arr)
Definition: coDistributedObject.h:319
virtual coDistributedObject * cloneObject(const coObjInfo &newinfo) const =0
int incRefCount() const
Definition: coDistributedObject.h:508
coIntShm refcount
Definition: coDistributedObject.h:307
int decRefCount() const
Definition: coDistributedObject.h:513
bool new_ok
Definition: coDistributedObject.h:315
void set(int i, const coDistributedObject *elem)
Definition: coShmPtrArray.cpp:107