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