COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 \***********************************************************************/
49 namespace covise
50 {
51 
52 class ApplicationProcess;
53 
54 DOEXPORT void PackElement_print(class PackElement *);
55 
57 {
58 public:
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  {
72  PackElement_print(this);
73  };
74 };
75 
77 {
78 public:
79  int type;
80  coDistributedObject *(*vconstr)(coShmArray *arr);
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 
107 private:
113  int number_of_elements_type; // INTSHM
115  int version_type; // INTSHM
116  int version;
117  int refcount_type; // INTSHM
118  int refcount;
119  int name_type; // CHARSH
122  int attr_type; // SHMPTR or NULLPTR
125  // the following only for partitioned Objects!!
126  int part_object_type_type; // INTSHM
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 
136 public:
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!!
254  void addAttributes(int sn, shmSizeType o)
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 {
268 public:
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 << endl;
287  if (description)
288  cout << "Description: " << description << endl;
289  if (obj_name)
290  cout << "Object Name: " << obj_name << endl;
291  cout << "Pointer: " << ptr << 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 
305 protected:
308  mutable coShmArray *shmarr;
310  mutable coDoHeader *header;
311  char type_name[7];
312  int type_no;
313  char *name;
315  bool new_ok;
316  int size;
317  mutable char *attribs; // 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 
336 public:
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 *, int **);
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
const char * getType() const
get the object&#39;s type
Definition: coDistributedObject.h:365
GLfloat GLfloat GLfloat GLfloat h
Definition: khronos-glext.h:8441
coDoHeader * header
Definition: coDistributedObject.h:310
void print()
Definition: coDistributedObject.h:70
coIntShm refcount
Definition: coDistributedObject.h:307
int getRefCount() const
Definition: coDistributedObject.h:517
int number_of_elements
Definition: coDistributedObject.h:114
char * attribs
Definition: coDistributedObject.h:317
access_type
Definition: covise_shm.h:81
int incRefCount() const
Definition: coDistributedObject.h:508
int part_max_number_of_parts_type
Definition: coDistributedObject.h:128
int shm_seq_no
Definition: coDistributedObject.h:59
const char * getName() const
Definition: coObjID.h:308
GLuint const GLchar * name
Definition: khronos-glext.h:6722
int decRefCount() const
Definition: coDistributedObject.h:513
const char * description
Definition: coDistributedObject.h:271
const int COVISE_NULLPTR
Definition: covise_shm.h:139
const int COVISE_OBJECTID
Definition: covise_shm.h:134
int incRefCount()
Definition: coDistributedObject.h:193
int attr_shm_seq_no
Definition: coDistributedObject.h:123
Definition: covise_shm.h:481
GLdouble n
Definition: khronos-glext.h:8447
shmSizeType offset
Definition: coDistributedObject.h:60
int part_curr_number_of_parts_type
Definition: coDistributedObject.h:130
const int NUMBER_OF_INT_HEADER_ELEMENTS
Definition: coDistributedObject.h:96
void set_object_type(int ot)
Definition: coDistributedObject.h:228
void set_version(int v)
Definition: coDistributedObject.h:243
coStringShmArray * attributes
Definition: coDistributedObject.h:309
void print_error(int line, const char *filename, const char *fmt,...)
Definition: coLog.cpp:132
int get_number_of_elements()
Definition: coDistributedObject.h:152
int attr_type
Definition: coDistributedObject.h:122
int part_curr_number_of_parts
Definition: coDistributedObject.h:131
#define NULL
Definition: covise_list.h:22
char * getName() const
get the object&#39;s name
Definition: coDistributedObject.h:359
void set_refcount(int rc)
Definition: coDistributedObject.h:248
void set_objectid(int h, int t)
Definition: coDistributedObject.h:232
int getObjectType()
Definition: coDistributedObject.h:147
int get_version_offset()
Definition: coDistributedObject.h:215
void print()
Definition: coDistributedObject.h:86
GLuint GLuint GLsizei count
Definition: khronos-glext.h:6343
int part_object_type
Definition: coDistributedObject.h:127
const int NUMBER_OF_SHM_SIZE_HEADER_ELEMENTS
Definition: coDistributedObject.h:97
Definition: coObjID.h:230
GLsizeiptr size
Definition: khronos-glext.h:6610
shmSizeType part_address_list_offset
Definition: coDistributedObject.h:134
~coDoInfo()
Definition: coDistributedObject.h:280
long data_type
Definition: message.h:74
const char * type_name
Definition: coDistributedObject.h:270
void print()
Definition: coDistributedObject.h:284
int getObjectType_offset()
Definition: coDistributedObject.h:207
int type
Definition: coDistributedObject.h:269
bool new_ok
Definition: coDistributedObject.h:315
int name_shm_seq_no
Definition: coDistributedObject.h:120
int type
Definition: coDistributedObject.h:61
const int INTSHM
Definition: covise_shm.h:125
coShmArray * shmarr
Definition: coDistributedObject.h:308
int get_type_no() const
Definition: coDistributedObject.h:497
Definition: coDistributedObject.h:266
VirtualConstructor(int t_no, coDistributedObject *(*vc)(coShmArray *arr))
Definition: coDistributedObject.h:81
int object_type
Definition: coDistributedObject.h:108
virtual int getObjInfo(int, coDoInfo **) const
Definition: coDistributedObject.h:325
Definition: coDistributedObject.h:90
const GLdouble * v
Definition: khronos-glext.h:6442
GLuint GLint GLboolean GLint GLenum access
Definition: khronos-glext.h:8584
Definition: covise_appproc.h:19
Definition: coDistributedObject.h:76
static int xfer_arrays
Definition: coDistributedObject.h:303
const void * ptr
Definition: coDistributedObject.h:93
shmSizeType number_of_bytes
Definition: coDistributedObject.h:109
coIntShm version
Definition: coDistributedObject.h:306
Definition: covise_list.h:53
int increase_version()
Definition: coDistributedObject.h:176
int type
Definition: coDistributedObject.h:79
int part_address_list_shm_seq_no
Definition: coDistributedObject.h:133
int get_number_of_elements_offset()
Definition: coDistributedObject.h:211
int objectid_h
Definition: coDistributedObject.h:111
int version_type
Definition: coDistributedObject.h:115
coDistributedObject(const coObjInfo &info, int shmSeg, shmSizeType offs, char *t)
Definition: coDistributedObject.h:444
#define DOEXPORT
Definition: coExport.h:307
int type_no
Definition: coDistributedObject.h:312
int part_object_type_type
Definition: coDistributedObject.h:126
int loc_version
Definition: coDistributedObject.h:314
GLenum type
Definition: khronos-glext.h:6279
static int getHeaderSize()
Definition: coDistributedObject.h:137
int size
Definition: coDistributedObject.h:316
void print_comment(int line, const char *filename, const char *fmt,...)
Definition: coLog.cpp:25
char * obj_name
Definition: coDistributedObject.h:272
int isType(const char *reqType) const
check whether this is a certain type
Definition: coDistributedObject.h:371
shmSizeType size
Definition: coDistributedObject.h:62
void PackElement_print(PackElement *th)
Definition: coDistributedObject.cpp:1645
int number_of_elements_type
Definition: coDistributedObject.h:113
int decRefCount()
Definition: coDistributedObject.h:197
int part_max_number_of_parts
Definition: coDistributedObject.h:129
char * name
Definition: coDistributedObject.h:313
int objectid_type
Definition: coDistributedObject.h:110
bool objectOk() const
check whether object was created or received ok
Definition: coDistributedObject.h:377
void print() const
Definition: coDistributedObject.h:521
coDistributedObject(const coObjInfo &info, const char *t)
Definition: coDistributedObject.h:420
int get_refcount_offset()
Definition: coDistributedObject.h:219
int length
Definition: coDistributedObject.h:63
int part_address_list_type
Definition: coDistributedObject.h:132
coDoInfo()
Definition: coDistributedObject.h:274
coDistributedObject()
Definition: coDistributedObject.h:382
Definition: covise_shm.h:654
PackElement()
Definition: coDistributedObject.h:65
void addAttributes(int sn, shmSizeType o)
Definition: coDistributedObject.h:254
Definition: coDistributedObject.h:295
int name_type
Definition: coDistributedObject.h:119
GLintptr offset
Definition: khronos-glext.h:6611
Definition: coDistributedObject.h:99
coDistributedObject(const coObjInfo &info)
Definition: coDistributedObject.h:398
static coShmArray * getShmArray(const char *name)
Definition: coDistributedObject.cpp:60
shmSizeType name_offset
Definition: coDistributedObject.h:121
char * ptr
Definition: coDistributedObject.h:64
int get_refcount()
Definition: coDistributedObject.h:181
int createFromShm(coShmArray *arr)
Definition: coDistributedObject.h:319
shmSizeType attr_offset
Definition: coDistributedObject.h:124
data_type type
Definition: coDistributedObject.h:92
GLdouble GLdouble t
Definition: khronos-glext.h:6449
GLenum src
Definition: khronos-glext.h:7031
Definition: coDistributedObject.h:56
void set(int i, const coDistributedObject *elem)
Definition: coShmPtrArray.cpp:107
int get_version()
Definition: coDistributedObject.h:164
int version
Definition: coDistributedObject.h:116
int objectid_t
Definition: coDistributedObject.h:112
static List< VirtualConstructor > * vconstr_list
Definition: coDistributedObject.h:301
int refcount_type
Definition: coDistributedObject.h:117
const int SHMPTR
Definition: covise_shm.h:133
int refcount
Definition: coDistributedObject.h:118
GLenum GLuint GLenum GLsizei length
Definition: khronos-glext.h:6279
void set_number_of_elements(int noe)
Definition: coDistributedObject.h:238
void get_objectid(int *h, int *t)
Definition: coDistributedObject.h:223
void * ptr
Definition: coDistributedObject.h:273
const GLint * attribs
Definition: khronos-glext.h:11807
static int getIntHeaderSize()
Definition: coDistributedObject.h:142
unsigned int shmSizeType
Definition: covise_shm.h:202
int get_attr_type()
Definition: coDistributedObject.h:203