COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
dmgr_packer.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 EC_PACKER_H
9 #define EC_PACKER_H
10 
11 #include "dmgr.h"
12 #include <covise/covise.h>
13 
14 #ifdef shm_ptr
15 #undef shm_ptr
16 #endif
17 
18 namespace covise
19 {
20 
21 const int SIZEOF_IEEE_CHAR = 1;
22 const int SIZEOF_IEEE_SHORT = 2;
23 const int SIZEOF_IEEE_INT = 4;
24 const int SIZEOF_IEEE_LONG = 4;
25 const int SIZEOF_IEEE_FLOAT = 4;
26 const int SIZEOF_IEEE_DOUBLE = 8;
27 
28 const int IOVEC_MIN_SIZE = 10000;
29 #ifdef CRAY
30 const int OBJECT_BUFFER_SIZE = 25000 * SIZEOF_ALIGNMENT;
31 const int IOVEC_MAX_LENGTH = 1;
32 #else
34 const int IOVEC_MAX_LENGTH = 16;
35 #endif
36 
37 // the following computes the size of a type entry for a data object
38 // usually: TYPE + Data (for char, short, int, etc.) or
39 // TYPE + SHM_SEQ_NO + OFFSET (for shmptr, arrays, etc.)
40 // size is in integers
41 
42 #ifndef MAX
43 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
44 #endif
45 const int MAX_INT_PER_DATA = MAX((sizeof(double) / sizeof(int)), 2);
46 const int SIZE_PER_TYPE_ENTRY = sizeof(int) + MAX_INT_PER_DATA * sizeof(int);
47 
49 {
50 private:
51  char *buffer; // Buffer for write
52  int buffer_size; // Buffer size
53  int *intbuffer; // integer pointer to write buffer
54  int intbuffer_ptr; // current field for integer write buffer
55  int intbuffer_size; // integer size of write buffer
56  int convert; // conversion necessary?
57  Message *msg; // message that will be sent
58  Connection *conn; // connection through which the message will be sent
59  DataManagerProcess *datamgr; // to allow shm_alloc
60 public:
61  //initialize for receive
63  {
64  datamgr = dm;
65  msg = m;
66  conn = msg->conn;
67  convert = conn->convert_to;
68  buffer = msg->data;
69  msg->data = 0L;
70  intbuffer = (int *)buffer;
71  buffer_size = msg->length;
72  intbuffer_size = msg->length / sizeof(int);
73  intbuffer_ptr = 0;
74  };
75  PackBuffer(Message *m) // initialize for send
76  {
77  datamgr = 0L;
78  msg = m;
79  conn = msg->conn;
80  convert = conn->convert_to;
81  buffer = new char[OBJECT_BUFFER_SIZE];
82  intbuffer = (int *)buffer;
83  buffer_size = OBJECT_BUFFER_SIZE;
84  intbuffer_size = OBJECT_BUFFER_SIZE / sizeof(int);
85  intbuffer_ptr = 0;
86  };
88  {
89  delete[] buffer;
90  // delete msg;
91  };
92  void send();
93  void receive();
94  char *get_ptr_for_n_bytes(int &n); // returns pointer to buffer and
95  // sets n to length of available space (always aligned to SIZEOF_ALIGNMENT)
96  void write_int(int i);
97  void read_int(int &i);
98  void put_back_int();
99  char *get_current_pointer_for_n_bytes(int &n);
100  void skip_n_bytes(int n); // returns pointer to buffer and
101 };
102 
104 {
105  PackBuffer *buffer; // Buffer to fill for sending/to empty for receiving
106  int *shm_obj_ptr; // pointer to the current working position in the object
107  int convert; // conversion flag
108  int number_of_data_elements; // number of elements to process (does not
109  // include header)
111  DataManagerProcess *datamgr; // to allow shm_alloc
112 #ifndef CRAY
113  static int iovcovise_arr[IOVEC_MAX_LENGTH];
114 #endif
115  int get_buffer_ptr(int);
116  int write_object();
117  int write_header();
118  int write_type();
119  int write_object_id();
120  int write_char();
121  int write_short();
122  int write_int();
123  int write_long();
124  int write_float();
125  int write_double();
126  int write_char_array();
127  int write_short_array();
128  int write_int_array();
129  int write_long_array();
130  int write_float_array();
131  int write_double_array();
132  int write_shm_string_array();
133  int write_shm_pointer_array();
134  int write_null_pointer();
135  //int write_shm_pointer(int transfer_array = 1);
136  //int write_shm_pointer_direct(int transfer_array = 1);
137  int write_shm_pointer();
138  int write_shm_pointer_direct();
139  int write_number_of_elements();
140  coShmPtr *read_object(char **);
141  coShmPtr *read_header(char **);
142  int read_type();
143  int read_object_id();
144  int read_char();
145  int read_short();
146  int read_int();
147  int read_long();
148  int read_float();
149  int read_double();
150  int read_char_array();
151  int read_short_array();
152  int read_int_array();
153  int read_long_array();
154  int read_float_array();
155  int read_double_array();
156  int read_shm_string_array();
157  int read_shm_pointer_array();
158  int read_null_pointer();
159  int read_shm_pointer();
160  int read_number_of_elements();
161 
162 public:
163  Packer(Message *m, int s, int o);
165  Packer();
167  {
168  delete buffer;
169  };
170  int pack()
171  {
172  return write_object();
173  };
174  coShmPtr *unpack(char **tmp_name)
175  {
176  return read_object(tmp_name);
177  };
178  void flush();
179 };
180 }
181 #endif
int intbuffer_size
Definition: dmgr_packer.h:55
Connection * conn
Definition: dmgr_packer.h:58
const int SIZEOF_IEEE_INT
Definition: dmgr_packer.h:23
Definition: covise_connect.h:115
const int SIZE_PER_TYPE_ENTRY
Definition: dmgr_packer.h:46
#define MAX(a, b)
Definition: dmgr_packer.h:43
const int OBJECT_BUFFER_SIZE
Definition: dmgr_packer.h:33
const int SIZEOF_IEEE_CHAR
Definition: dmgr_packer.h:21
int pack()
Definition: dmgr_packer.h:170
const int IOVEC_MIN_SIZE
Definition: dmgr_packer.h:28
int convert
Definition: dmgr_packer.h:107
const int SIZEOF_ALIGNMENT
Definition: covise_shm.h:79
const int SIZEOF_IEEE_DOUBLE
Definition: dmgr_packer.h:26
GLdouble n
Definition: khronos-glext.h:8447
#define DMGREXPORT
Definition: coExport.h:301
coShmPtr * shm_ptr
Definition: dmgr_packer.h:110
coShmPtr * unpack(char **tmp_name)
Definition: dmgr_packer.h:174
Definition: dmgr_packer.h:48
const int SIZEOF_IEEE_SHORT
Definition: dmgr_packer.h:22
GLdouble s
Definition: khronos-glext.h:6441
int * intbuffer
Definition: dmgr_packer.h:53
const int SIZEOF_IEEE_FLOAT
Definition: dmgr_packer.h:25
Definition: message.h:111
int intbuffer_ptr
Definition: dmgr_packer.h:54
PackBuffer(DataManagerProcess *dm, Message *m)
Definition: dmgr_packer.h:62
~PackBuffer()
Definition: dmgr_packer.h:87
DataManagerProcess * datamgr
Definition: dmgr_packer.h:111
const int MAX_INT_PER_DATA
Definition: dmgr_packer.h:45
~Packer()
Definition: dmgr_packer.h:166
int buffer_size
Definition: dmgr_packer.h:52
char * buffer
Definition: dmgr_packer.h:51
Definition: covise_shm.h:379
GLuint buffer
Definition: khronos-glext.h:6606
PackBuffer * buffer
Definition: dmgr_packer.h:105
Definition: dmgr_packer.h:103
const int SIZEOF_IEEE_LONG
Definition: dmgr_packer.h:24
const GLfloat * m
Definition: khronos-glext.h:12117
const int IOVEC_MAX_LENGTH
Definition: dmgr_packer.h:34
DataManagerProcess * datamgr
Definition: dmgr_packer.h:59
PackBuffer(Message *m)
Definition: dmgr_packer.h:75
int convert
Definition: dmgr_packer.h:56
Message * msg
Definition: dmgr_packer.h:57
Definition: dmgr.h:213
int number_of_data_elements
Definition: dmgr_packer.h:108
int * shm_obj_ptr
Definition: dmgr_packer.h:106