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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>CORBA_Environment C Structure</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="9"><!-- Empty --></A>
<H2>9 CORBA_Environment C Structure</H2>
<A NAME="corbaenv"><!-- Empty --></A>
<P>This chapter describes the CORBA_Environment C structure.
<A NAME="9.1"><!-- Empty --></A>
<H3>9.1 C Structure</H3>
<P> Here is the complete definition of the CORBA_Environment
C structure, defined in file "ic.h" :
<PRE>
/* 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 outpuy
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;
</PRE>
<P> The structure is divided into three parts:
<P>
<UL>
<LI>
The CORBA Compatibility part, demanded by the standard OMG
IDL mapping v2.0.
<BR>
</LI>
<LI>
The external implementation part used for generated
client/server code.
<BR>
</LI>
<LI>
The internal part useful for those who wish to define their
own functions.
<BR>
</LI>
</UL>
<A NAME="9.2"><!-- Empty --></A>
<H3>9.2 The CORBA Compatibility Part</H3>
<P> Contains only one field <CODE>_major</CODE> defined as a
CORBA_Exception_type. The CORBA_Exception type is an integer
which can be one of:
<P>
<UL>
<LI>
<STRONG>CORBA_NO_EXCEPTION</STRONG>, by default equal to 0, can be
set by the application programmer to another value.
<BR>
</LI>
<LI>
<STRONG>CORBA_SYSTEM_EXCEPTION</STRONG>, by default equal to -1, can
be set by the application programmer to another value.
<BR>
</LI>
</UL>
<P> The current definition of these values are:
<PRE>
#define CORBA_NO_EXCEPTION 0
#define CORBA_SYSTEM_EXCEPTION -1
</PRE>
<A NAME="9.3"><!-- Empty --></A>
<H3>9.3 The External Part</H3>
<P> This part contains the following fields:
<P>
<UL>
<LI>
int <STRONG>_fd</STRONG> - a file descriptor returned from
erl_connect. Used for connection setting.
<BR>
</LI>
<LI>
char* <STRONG>_inbuf</STRONG> - 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.
<BR>
</LI>
<LI>
int <STRONG>_inbufsz</STRONG> - 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
<BR>
</LI>
<LI>
int <STRONG>_outbufsz</STRONG> - start size of output buffer. The
value of this field can change under runtime in case of
input buffer expansion to fit larger messages
<BR>
</LI>
<LI>
char* <STRONG>_outbuf</STRONG> - 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.
<BR>
</LI>
<LI>
int <STRONG>_memchunk</STRONG> - 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 allways set to >= 32, should be at
least 1024 for performance reasons.
<BR>
</LI>
<LI>
char <STRONG>regname[256]</STRONG> - a registered name for a process.
<BR>
</LI>
<LI>
erlang_pid* <STRONG>_to_pid</STRONG> - an Erlang process identifier,
is only used if the registered_name parameter is the empty
string.
<BR>
</LI>
<LI>
erlang_pid* <STRONG>_from_pid</STRONG> - your own process id so the
answer can be returned.
<BR>
</LI>
</UL>
<A NAME="9.4"><!-- Empty --></A>
<H3>9.4 The Internal Part</H3>
<P> This part contains the following fields:
<P>
<UL>
<LI>
int <STRONG>_iin</STRONG> - Index for input buffer. Initially set
to zero. Updated to agree with the length of the received
encoded message.
<BR>
</LI>
<LI>
int <STRONG>_iout</STRONG> - Index for output buffer Initially set
to zero. Updated to agree with the length of the message
encoded to the communication counterpart.
<BR>
</LI>
<LI>
char <STRONG>_operation[256]</STRONG> - Pointer for operation name.
Set to the operation to be called.
<BR>
</LI>
<LI>
int <STRONG>_received</STRONG> - Used to count parameters.
Initially set to zero.
<BR>
</LI>
<LI>
erlang_pid <STRONG>_caller</STRONG> - Used to identify the caller.
Initiated to a value that identifies the caller.
<BR>
</LI>
<LI>
erlang_ref <STRONG>_unique</STRONG> - Used to identify the call.
Set to a default value in the case of generated functions.
<BR>
</LI>
<LI>
CORBA_char* <STRONG>_exc_id</STRONG> - Exception id field.
Initially set to NULL to agree with the initial value of
_major (CORBA_NO_EXCEPTION).
<BR>
</LI>
<LI>
void* <STRONG>_exc_value</STRONG> - Exception value field Initially
set to <STRONG>NULL</STRONG> to agree with the initial value of
_major (CORBA_NO_EXCEPTION).
<BR>
</LI>
</UL>
<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.
<A NAME="9.5"><!-- Empty --></A>
<H3>9.5 Creating and Initiating the CORBA_Environment Structure</H3>
<P> There are two ways to set the CORBA_Environment structure:
<P>
<UL>
<LI>
Manually
<BR>
The following default values must be set to the
CORBA_Environment *<STRONG>ev</STRONG> fields, when buffers for
input/output should have the size <STRONG>inbufsz</STRONG>/
<STRONG>outbufsz</STRONG>:<BR>
<UL>
<LI>
<STRONG>ev->_inbufsz</STRONG> = <STRONG>inbufsz</STRONG>;
<BR>
The value for this field can be between 0 and maximum
size of a signed integer.
<BR>
</LI>
<LI>
<STRONG>ev->_inbuf</STRONG> = malloc(<STRONG>inbufsz</STRONG>);
<BR>
The size of the allocated buffer must be equal to the
value of its corresponding index, _inbufsz.
<BR>
</LI>
<LI>
<STRONG>ev->_outbufsz</STRONG> = <STRONG>outbufsz</STRONG>;
<BR>
The value for this field can be between 0 and maximum
size of a signed integer.
<BR>
</LI>
<LI>
<STRONG>ev->_outbuf</STRONG> = malloc(<STRONG>outbufsz</STRONG>);
<BR>
The size of the allocated buffer must be equal to the
value of its corresponding index, _outbufsz.
<BR>
</LI>
<LI>
<STRONG>ev->_memchunk</STRONG> = <STRONG>__OE_MEMCHUNK__</STRONG>;
<BR>
Please note that __OE_MEMCHUNK__ is equal to
<STRONG>1024</STRONG>, you can set this value to a value bigger
than 32 yourself.
<BR>
</LI>
<LI>
<STRONG>ev->_to_pid</STRONG> = <STRONG>NULL</STRONG>;
<BR>
</LI>
<LI>
<STRONG>ev->_from_pid</STRONG> = <STRONG>NULL</STRONG>;
<BR>
</LI>
</UL>
<BR>
</LI>
<LI>
By using the <STRONG>CORBA_Environment_alloc</STRONG>/2 function.
<BR>
The CORBA_Environment_alloc function is defined as:
<BR>
<PRE>
CORBA_Environment *CORBA_Environment_alloc(int inbufsz,
int outbufsz);
</PRE>
where:<BR>
<UL>
<LI>
<STRONG>inbufsz</STRONG> is the desired size of input buffer<BR>
</LI>
<LI>
<STRONG>outbufsz</STRONG> is the desired size of output
buffer<BR>
</LI>
<LI>
return value is a <STRONG>pointer</STRONG> to an allocated and
initialized <STRONG>CORBA_Environment</STRONG> structure.<BR>
<BR>
</LI>
</UL>
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.<BR>
To free the space allocated by CORBA_Environment_alloc/2:<BR>
<UL>
<LI>
First call CORBA_free for the input and output buffers.
<BR>
</LI>
<LI>
After freeing the buffer space, call CORBA_free for
the CORBA_Environment space.
<BR>
</LI>
</UL>
</LI>
</UL>
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
<TD>
<P> Remember to set the fields <STRONG>_fd</STRONG>, <STRONG>_regname</STRONG>,
<STRONG>*_to_pid</STRONG> and/or <STRONG>*_from_pid</STRONG> to the
appropriate application values. These are not automatically
set by the stubs.
</TD>
</TR>
</TABLE>
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
<TD>
<P>Never assign static buffers to the buffer pointers. Never set
the <STRONG>_memchunk</STRONG> field to a value less than
<STRONG>32</STRONG>. </TD>
</TR>
</TABLE>
<A NAME="9.6"><!-- Empty --></A>
<H3>9.6 Setting System Exceptions</H3>
<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>
<UL>
<LI>
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.
<BR>
</LI>
<LI>
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" :
<BR>
<PRE>
#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"
</PRE>
</LI>
</UL>
<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"
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|