1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
<year>1998</year><year>2016</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</legalnotice>
<title>CORBA_Environment C Structure</title>
<prepared></prepared>
<docno></docno>
<date>2003-12-15</date>
<rev>PC1</rev>
<file>ch_c_corba_env.xml</file>
</header>
<marker id="corbaenv"></marker>
<p>This chapter describes the CORBA_Environment C structure.</p>
<section>
<title>C Structure</title>
<p>Here is the complete definition of the CORBA_Environment
C structure, defined in file "ic.h" : </p>
<code type="none">
/* Environment definition */
typedef struct {
/*----- CORBA compatibility part ------------------------*/
/* Exception tag, initially set to CORBA_NO_EXCEPTION ---*/
CORBA_exception_type _major;
/*----- External Implementation part - initiated by the user ---*/
/* File descriptor */
int _fd;
/* Size of input buffer */
int _inbufsz;
/* Pointer to always dynamically allocated buffer for input */
char *_inbuf;
/* Size of output buffer */
int _outbufsz;
/* Pointer to always dynamically allocated buffer for output */
char *_outbuf;
/* Size of memory chunks in bytes, used for increasing the output
buffer, set to >= 32, should be around >= 1024 for performance
reasons */
int _memchunk;
/* Pointer for registered name */
char _regname[256];
/* Process identity for caller */
erlang_pid *_to_pid;
/* Process identity for callee */
erlang_pid *_from_pid;
/*- Internal Implementation part - used by the server/client ---*/
/* Index for input buffer */
int _iin;
/* Index for output buffer */
int _iout;
/* Pointer for operation name */
char _operation[256];
/* Used to count parameters */
int _received;
/* Used to identify the caller */
erlang_pid _caller;
/* Used to identify the call */
erlang_ref _unique;
/* Exception id field */
CORBA_char *_exc_id;
/* Exception value field */
void *_exc_value;
} CORBA_Environment;
</code>
<p>The structure is divided into three parts:</p>
<list type="bulleted">
<item>
<p>The CORBA Compatibility part, demanded by the standard OMG
IDL mapping v2.0.</p>
</item>
<item>
<p>The external implementation part used for generated
client/server code.</p>
</item>
<item>
<p>The internal part useful for those who wish to define their
own functions.</p>
</item>
</list>
</section>
<section>
<title>The CORBA Compatibility Part</title>
<p>Contains only one field <c>_major</c> defined as a
CORBA_Exception_type. The CORBA_Exception type is an integer
which can be one of:</p>
<list type="bulleted">
<item>
<p><em>CORBA_NO_EXCEPTION</em>, by default equal to 0, can be
set by the application programmer to another value.</p>
</item>
<item>
<p><em>CORBA_SYSTEM_EXCEPTION</em>, by default equal to -1, can
be set by the application programmer to another value.</p>
</item>
</list>
<p>The current definition of these values are:</p>
<code type="none">
#define CORBA_NO_EXCEPTION 0
#define CORBA_SYSTEM_EXCEPTION -1
</code>
</section>
<section>
<title>The External Part</title>
<p>This part contains the following fields:</p>
<list type="bulleted">
<item>
<p>int <em>_fd</em> - a file descriptor returned from
erl_connect. Used for connection setting.</p>
</item>
<item>
<p>char* <em>_inbuf</em> - pointer to a buffer used for
input. Buffer size checks are done under runtime that
prevent buffer overflows. This is done by expanding the
buffer to fit the input message. In order to allow buffer
reallocation, the output buffer must always be dynamically
allocated. The pointer value can change under runtime in
case of buffer reallocation.</p>
</item>
<item>
<p>int <em>_inbufsz</em> - start size of input buffer. Used
for setting the input buffer size under initialization of
the Erl_Interface function ei_receive_encoded/5. The value
of this field can change under runtime in case of input
buffer expansion to fit larger messages</p>
</item>
<item>
<p>int <em>_outbufsz</em> - start size of output buffer. The
value of this field can change under runtime in case of
input buffer expansion to fit larger messages</p>
</item>
<item>
<p>char* <em>_outbuf</em> - pointer to a buffer used for
output. Buffer size checks prevent buffer overflows under
runtime, by expanding the buffer to fit the output message
in cases of lack of space in buffer. In order to allow
buffer reallocation, the output buffer must always be
dynamically allocated. The pointer value can change under
runtime in case of buffer reallocation.</p>
</item>
<item>
<p>int <em>_memchunk</em> - expansion unit size for the output
buffer. This is the size of memory chunks in bytes used for
increasing the output in case of buffer expansion. The value
of this field must be always set to >= 32, should be at
least 1024 for performance reasons.</p>
</item>
<item>
<p>char <em>regname[256]</em> - a registered name for a process. </p>
</item>
<item>
<p>erlang_pid* <em>_to_pid</em> - an Erlang process identifier,
is only used if the registered_name parameter is the empty
string.</p>
</item>
<item>
<p>erlang_pid* <em>_from_pid</em> - your own process id so the
answer can be returned.</p>
</item>
</list>
</section>
<section>
<title>The Internal Part</title>
<p>This part contains the following fields:</p>
<list type="bulleted">
<item>
<p>int <em>_iin</em> - Index for input buffer. Initially set
to zero. Updated to agree with the length of the received
encoded message.</p>
</item>
<item>
<p>int <em>_iout</em> - Index for output buffer Initially set
to zero. Updated to agree with the length of the message
encoded to the communication counterpart.</p>
</item>
<item>
<p>char <em>_operation[256]</em> - Pointer for operation name.
Set to the operation to be called.</p>
</item>
<item>
<p>int <em>_received</em> - Used to count parameters.
Initially set to zero.</p>
</item>
<item>
<p>erlang_pid <em>_caller</em> - Used to identify the caller.
Initiated to a value that identifies the caller.</p>
</item>
<item>
<p>erlang_ref <em>_unique</em> - Used to identify the call.
Set to a default value in the case of generated functions.</p>
</item>
<item>
<p>CORBA_char* <em>_exc_id</em> - Exception id field.
Initially set to NULL to agree with the initial value of
_major (CORBA_NO_EXCEPTION).</p>
</item>
<item>
<p>void* <em>_exc_value</em> - Exception value field Initially
set to <em>NULL</em> to agree with the initial value of
_major (CORBA_NO_EXCEPTION).</p>
</item>
</list>
<p>The advanced user who defines his own functions has to
update/support these values in a way similar to how they are
updated in the generated code.</p>
</section>
<section>
<title>Creating and Initiating the CORBA_Environment Structure</title>
<p>There are two ways to set the CORBA_Environment structure:</p>
<list type="bulleted">
<item>
<p>Manually</p>
<p>The following default values must be set to the
CORBA_Environment *<em>ev</em> fields, when buffers for
input/output should have the size <em>inbufsz</em>/
<em>outbufsz</em>:</p>
<list type="bulleted">
<item>
<p><em>ev->_inbufsz</em> = <em>inbufsz</em>;</p>
<p>The value for this field can be between 0 and maximum
size of a signed integer.</p>
</item>
<item>
<p><em>ev->_inbuf</em> = malloc(<em>inbufsz</em>);</p>
<p>The size of the allocated buffer must be equal to the
value of its corresponding index, _inbufsz.</p>
</item>
<item>
<p><em>ev->_outbufsz</em> = <em>outbufsz</em>;</p>
<p>The value for this field can be between 0 and maximum
size of a signed integer.</p>
</item>
<item>
<p><em>ev->_outbuf</em> = malloc(<em>outbufsz</em>);</p>
<p>The size of the allocated buffer must be equal to the
value of its corresponding index, _outbufsz.</p>
</item>
<item>
<p><em>ev->_memchunk</em> = <em>__OE_MEMCHUNK__</em>;</p>
<p>Please note that __OE_MEMCHUNK__ is equal to
<em>1024</em>, you can set this value to a value bigger
than 32 yourself.</p>
</item>
<item>
<p><em>ev->_to_pid</em> = <em>NULL</em>;</p>
</item>
<item>
<p><em>ev->_from_pid</em> = <em>NULL</em>;</p>
</item>
</list>
<p></p>
</item>
<item>
<p>By using the <em>CORBA_Environment_alloc</em>/2 function. </p>
<p>The CORBA_Environment_alloc function is defined as:</p>
<code type="none">
CORBA_Environment *CORBA_Environment_alloc(int inbufsz,
int outbufsz);
</code>
<p>where:</p>
<list type="bulleted">
<item>
<p><em>inbufsz</em> is the desired size of input buffer</p>
</item>
<item>
<p><em>outbufsz</em> is the desired size of output
buffer</p>
</item>
<item>
<p>return value is a <em>pointer</em> to an allocated and
initialized <em>CORBA_Environment</em> structure.</p>
<p></p>
</item>
</list>
<p>This function will set all needed default values and
allocate buffers equal to the values passed, but will not
allocate space for the _to_pid and _from_pid fields.</p>
<p>To free the space allocated by CORBA_Environment_alloc/2:</p>
<list type="bulleted">
<item>
<p>First call CORBA_free for the input and output buffers.</p>
</item>
<item>
<p>After freeing the buffer space, call CORBA_free for
the CORBA_Environment space.</p>
</item>
</list>
</item>
</list>
<note>
<p>Remember to set the fields <em>_fd</em>, <em>_regname</em>,
<em>*_to_pid</em> and/or <em>*_from_pid</em> to the
appropriate application values. These are not automatically
set by the stubs.</p>
</note>
<warning>
<p>Never assign static buffers to the buffer pointers. Never set
the <em>_memchunk</em> field to a value less than
<em>32</em>.</p>
</warning>
</section>
<section>
<title>Setting System Exceptions</title>
<p>If the user wishes to set own system exceptions at critical
positions on the code, it is strongly recommended to use one of
the current values:</p>
<list type="bulleted">
<item>
<p>CORBA_NO_EXCEPTION upon success. The value of the _exc_id
field should be then set to NULL. The value of the
_exc_value field should be then set to NULL.</p>
</item>
<item>
<p>CORBA_SYSTEM_EXCEPTION upon system failure. The value of
the _exc_id field should be then set to one of the values
defined in "ic.h" :</p>
<code type="none">
#define UNKNOWN "UNKNOWN"
#define BAD_PARAM "BAD_PARAM"
#define NO_MEMORY "NO_MEMORY"
#define IMPL_LIMIT "IMP_LIMIT"
#define COMM_FAILURE "COMM_FAILURE"
#define INV_OBJREF "INV_OBJREF"
#define NO_PERMISSION "NO_PERMISSION"
#define INTERNAL "INTERNAL"
#define MARSHAL "MARSHAL"
#define INITIALIZE "INITIALIZE"
#define NO_IMPLEMENT "NO_IMPLEMENT"
#define BAD_TYPECODE "BAD_TYPECODE"
#define BAD_OPERATION "BAD_OPERATION"
#define NO_RESOURCES "NO_RESOURCES"
#define NO_RESPONSE "NO_RESPONSE"
#define PERSIST_STORE "PERSIST_STORE"
#define BAD_INV_ORDER "BAD_INV_ORDER"
#define TRANSIENT "TRANSIENT"
#define FREE_MEM "FREE_MEM"
#define INV_IDENT "INV_IDENT"
#define INV_FLAG "INV_FLAG"
#define INTF_REPOS "INTF_REPOS"
#define BAD_CONTEXT "BAD_CONTEXT"
#define OBJ_ADAPTER "OBJ_ADAPTER"
#define DATA_CONVERSION "DATA_CONVERSION"
#define OBJ_NOT_EXIST "OBJECT_NOT_EXIST"
</code>
</item>
</list>
<p>The value of the _exc_value field should be then set to a string
that explains the problem in an informative way. The user
should use the functions CORBA_exc_set/4 and
CORBA_exception_free/1 to free the exception.
The user has to use CORBA_exception_id/1 and
CORBA_exception_value/1 to access exception information.
Prototypes for these functions are declared in "ic.h"</p>
</section>
</chapter>
|