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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
|
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">
<chapter>
<header>
<copyright>
<year>1998</year><year>2013</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
The contents of this file are subject to the Erlang Public License,
Version 1.1, (the "License"); you may not use this file except in
compliance with the License. You should have received a copy of the
Erlang Public License along with this software. If not, it can be
retrieved online at http://www.erlang.org/.
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
</legalnotice>
<title>IDL to C mapping</title>
<prepared></prepared>
<docno></docno>
<date>2002-08-06</date>
<rev>PB1</rev>
<file>ch_c_mapping.xml</file>
</header>
<section>
<title>Introduction</title>
<p>The IC C mapping (used by the C client and C server back-ends) follows
the <em>OMG C Language Mapping Specification</em>. </p>
<p>The C mapping supports the following:</p>
<list type="bulleted">
<item>
<p>All OMG IDL basic types except <c>long double</c> and <c>any</c>.</p>
</item>
<item>
<p>All OMG IDL constructed types.</p>
</item>
<item>
<p>OMG IDL constants.</p>
</item>
<item>
<p>Operations with passing of parameters and receiving of
results. <c>inout</c> parameters are not supported.</p>
</item>
</list>
<p>The following is not supported:
</p>
<list type="bulleted">
<item>
<p>Access to attributes.</p>
</item>
<item>
<p>User defined exceptions.</p>
<p></p>
</item>
<item>
<p>User defined objects.</p>
<p></p>
</item>
</list>
</section>
<section>
<title>C Mapping Characteristics</title>
<section>
<title>Reserved Names</title>
<p>The IDL compiler reserves all identifiers starting with
<c>OE_</c> and <c>oe_</c> for internal use.</p>
</section>
<section>
<title>Scoped Names</title>
<p>The C programmer must always use the global name for a type,
constant or operation. The C global name corresponding to an
OMG IDL global name is derived by converting occurrences of
"::" to underscore, and eliminating the leading "::". So, for
example, an operation <c>op1</c> defined in interface
<c>I1</c> which is defined in module <c>M1</c> would be
written as <c>M1::I1::op1</c> in IDL and as <c>M1_I1_op1</c>
in C.</p>
<warning>
<p>If underscores are used in IDL names it can lead to
ambiguities due to the name mapping described above,
therefore it is advisable to avoid underscores in
identifiers.</p>
</warning>
</section>
<section>
<title>Generated Files</title>
<p>Two files will be generated for each scope. One set of files
will be generated for each module and each interface scope.
An extra set is generated for those definitions at top
level scope. One of the files is a header file(<c>.h</c>), and the
other file is a C source code file (<c>.c</c>). In addition to these
files a number of C source files will be generated for type encodings,
they are named according to the following template:
<c><![CDATA[oe_code_<type>.c]]></c>.</p>
<p>For example:</p>
<code type="none"><![CDATA[
// IDL, in the file "spec.idl"
module m1 {
typedef sequence<long> lseq;
interface i1 {
...
};
...
};
]]></code>
<p>XXX This is C client specific.
Will produce the files <c>oe_spec.h</c> and
<c>oe_spec.c</c> for the top scope level. Then the files
<c>m1.h</c> and <c>m1.c</c> for the module <c>m1</c> and
files <c>m1_i1.h</c> and <c>m1_i1.c</c> for the interface
<c>i1</c>. The typedef will produce <c>oe_code_m1_lseq.c</c>.</p>
<p>The header file contains type definitions for all
<c>struct</c> types and sequences and constants in the IDL file. The
c file contains all operation stubs if the the scope is an interface.</p>
<p>In addition to the scope-related files a C source file will
be generated for encoding operations of all <c>struct</c> and
sequence types.</p>
</section>
</section>
<section>
<title>Basic OMG IDL Types</title>
<p>The mapping of basic types is as follows.</p>
<table>
<row>
<cell align="left" valign="middle"><em>OMG IDL type</em></cell>
<cell align="left" valign="middle"><em>C type</em></cell>
<cell align="left" valign="middle"><em>Mapped to C type</em></cell>
</row>
<row>
<cell align="left" valign="middle">float</cell>
<cell align="left" valign="middle">CORBA_float</cell>
<cell align="left" valign="middle">float</cell>
</row>
<row>
<cell align="left" valign="middle">double</cell>
<cell align="left" valign="middle">CORBA_double</cell>
<cell align="left" valign="middle">double</cell>
</row>
<row>
<cell align="left" valign="middle">short</cell>
<cell align="left" valign="middle">CORBA_short</cell>
<cell align="left" valign="middle">short</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned short</cell>
<cell align="left" valign="middle">CORBA_unsigned_short</cell>
<cell align="left" valign="middle">unsigned short</cell>
</row>
<row>
<cell align="left" valign="middle">long</cell>
<cell align="left" valign="middle">CORBA_long</cell>
<cell align="left" valign="middle">long</cell>
</row>
<row>
<cell align="left" valign="middle">long long</cell>
<cell align="left" valign="middle">CORBA_long_long</cell>
<cell align="left" valign="middle">long</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned long</cell>
<cell align="left" valign="middle">CORBA_unsigned_long</cell>
<cell align="left" valign="middle">unsigned long</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned long long</cell>
<cell align="left" valign="middle">CORBA_unsigned_long_long</cell>
<cell align="left" valign="middle">unsigned long</cell>
</row>
<row>
<cell align="left" valign="middle">char</cell>
<cell align="left" valign="middle">CORBA_char</cell>
<cell align="left" valign="middle">char</cell>
</row>
<row>
<cell align="left" valign="middle">wchar</cell>
<cell align="left" valign="middle">CORBA_wchar</cell>
<cell align="left" valign="middle">unsigned long</cell>
</row>
<row>
<cell align="left" valign="middle">boolean</cell>
<cell align="left" valign="middle">CORBA_boolean</cell>
<cell align="left" valign="middle">unsigned char</cell>
</row>
<row>
<cell align="left" valign="middle">octet</cell>
<cell align="left" valign="middle">CORBA_octet</cell>
<cell align="left" valign="middle">char</cell>
</row>
<row>
<cell align="left" valign="middle">any</cell>
<cell align="left" valign="middle">Not supported</cell>
<cell align="left" valign="middle"></cell>
</row>
<row>
<cell align="left" valign="middle">long double</cell>
<cell align="left" valign="middle">Not supported</cell>
<cell align="left" valign="middle"></cell>
</row>
<row>
<cell align="left" valign="middle">Object</cell>
<cell align="left" valign="middle">Not supported</cell>
<cell align="left" valign="middle"></cell>
</row>
<row>
<cell align="left" valign="middle">void</cell>
<cell align="left" valign="middle">void</cell>
<cell align="left" valign="middle">void</cell>
</row>
<tcaption>OMG IDL Basic Types</tcaption>
</table>
<p>XXX Note that several mappings are not according to OMG C Language
mapping.</p>
</section>
<section>
<title>Constructed OMG IDL Types</title>
<p>Constructed types have mappings as shown in the following table.</p>
<table>
<row>
<cell align="left" valign="middle">OMG IDL type</cell>
<cell align="left" valign="middle">Mapped to C type</cell>
</row>
<row>
<cell align="left" valign="middle">string</cell>
<cell align="left" valign="middle">CORBA_char*</cell>
</row>
<row>
<cell align="left" valign="middle">wstring</cell>
<cell align="left" valign="middle">CORBA_wchar*</cell>
</row>
<row>
<cell align="left" valign="middle">struct</cell>
<cell align="left" valign="middle">struct</cell>
</row>
<row>
<cell align="left" valign="middle">union</cell>
<cell align="left" valign="middle">union</cell>
</row>
<row>
<cell align="left" valign="middle">enum</cell>
<cell align="left" valign="middle">enum</cell>
</row>
<row>
<cell align="left" valign="middle">sequence</cell>
<cell align="left" valign="middle">struct (see below)</cell>
</row>
<row>
<cell align="left" valign="middle">array</cell>
<cell align="left" valign="middle">array</cell>
</row>
<tcaption>OMG IDL Constructed Types</tcaption>
</table>
<p>An OMG IDL sequence (an array of variable length), </p>
<code type="none"><![CDATA[
// IDL
typedef sequence <IDL_TYPE> NAME;
]]></code>
<p>is mapped to a C struct as follows:</p>
<code type="none">
/* C */
typedef struct {
CORBA_unsigned_long _maximum;
CORBA_unsigned_long _length;
C_TYPE* _buffer;
} C_NAME;
</code>
<p>where <c>C_TYPE</c> is the mapping of <c>IDL_TYPE</c>, and where
<c>C_NAME</c> is the scoped name of <c>NAME</c>.</p>
</section>
<section>
<title>OMG IDL Constants</title>
<p>An IDL constant is mapped to a C constant through a C
<c>#define</c> macro, where the name of the macro is scoped.
Example:</p>
<code type="none">
// IDL
module M1 {
const long c1 = 99;
};
</code>
<p>results in the following:</p>
<code type="none">
/* C */
#define M1_c1 99
</code>
</section>
<section>
<title>OMG IDL Operations</title>
<p>An OMG IDL operation is mapped to C function. Each C operation
function has two mandatory parameters: a first parameter of
<em>interface object</em> type, and a last parameter of
<em>environment</em> type.</p>
<p></p>
<p>In a C operation function the the <c>in</c> and <c>out</c>
parameters are located between the first and last parameters
described above, and they appear in the same order as in the IDL
operation declaration.</p>
<p>Notice that <c>inout</c> parameters are not supported. </p>
<p></p>
<p>The return value of an OMG IDL operation is mapped to a
corresponding return value of the C operation function.</p>
<p>Mandatory C operation function parameters:</p>
<list type="bulleted">
<item><c>CORBA_Object oe_obj</c> - the first parameter of a C
operation function. This parameter is required by the <em>OMG C Language Mapping Specification</em>, but in the current
implementation there is no particular use for it.</item>
<item>
<p><c>CORBA_Environment* oe_env</c> - the last parameter of a C
operation function. The parameter is defined in the C header
file <c>ic.h</c> and has the following public fields:</p>
<list type="bulleted">
<item>
<p><c>CORBA_Exception_type _major</c> - indicates if an
operation invocation was successful which will be one of
the following:</p>
<list type="bulleted">
<item>CORBA_NO_EXCEPTION</item>
<item>CORBA_SYSTEM_EXCEPTION</item>
</list>
</item>
<item>int <em>_fd</em> - a file descriptor returned from
<em>erl_connect</em> function.</item>
<item>int <em>_inbufsz</em> - size of input buffer.</item>
<item>char* <em>_inbuf</em> - pointer to a buffer used for
input.</item>
<item>int <em>_outbufsz</em> - size of output buffer.</item>
<item>char* <em>_outbuf</em> - pointer to a buffer used for
output.</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>char <em>regname[256]</em> - a registered name for a
process.</item>
<item>erlang_pid* <em>_to_pid</em> - an Erlang process
identifier, is only used if the registered_name parameter
is the empty string.</item>
<item>erlang_pid* <em>_from_pid</em> - your own process id so
the answer can be returned</item>
</list>
<p>Beside the public fields, other private fields
are internally used but are not mentioned here. </p>
</item>
</list>
<p>Example:</p>
<code type="none">
// IDL
interface i1 {
long op1(in long a);
long op2(in string s, out long count);
};
</code>
<p>Is mapped to the following C functions</p>
<code type="none">
/* C */
CORBA_long i1_op1(i1 oe_obj, CORBA_long a, CORBA_Environment* oe_env)
{
...
}
CORBA_long i1_op2(i1 oe_obj, CORBA_char* s, CORBA_long *count,
CORBA_Environment* oe_env)
{
...
}
</code>
<marker id="op_impl"></marker>
<section>
<title>Operation Implementation</title>
<p>There is no standard CORBA mapping for the C-server side,
as it is implementation-dependent but built in a similar way.
The current server side mapping is different from the client
side mapping in several ways:</p>
<list type="bulleted">
<item>Argument mappings</item>
<item>Result values</item>
<item>Structure</item>
<item>Usage</item>
<item>Exception handling</item>
</list>
</section>
</section>
<section>
<title>Exceptions</title>
<p>Although exception mapping is not implemented, the stubs will
generate CORBA system exceptions in case of operation failure.
Thus, the only exceptions propagated by the system are built in
system exceptions.</p>
</section>
<section>
<title>Access to Attributes</title>
<p>Not Supported</p>
</section>
<section>
<title>Summary of Argument/Result Passing for the C-client</title>
<p>The user-defined parameters can only be <c>in</c> or <c>out</c>
parameters, as
<c>inout</c> parameters are not supported.</p>
<p>This table summarize the types a client passes as arguments to
a stub, and receives as a result.</p>
<table>
<row>
<cell align="left" valign="middle">OMG IDL type</cell>
<cell align="left" valign="middle">In</cell>
<cell align="left" valign="middle">Out</cell>
<cell align="left" valign="middle">Return</cell>
</row>
<row>
<cell align="left" valign="middle">short</cell>
<cell align="left" valign="middle">CORBA_short</cell>
<cell align="left" valign="middle">CORBA_short*</cell>
<cell align="left" valign="middle">CORBA_short</cell>
</row>
<row>
<cell align="left" valign="middle">long</cell>
<cell align="left" valign="middle">CORBA_long</cell>
<cell align="left" valign="middle">CORBA_long*</cell>
<cell align="left" valign="middle">CORBA_long</cell>
</row>
<row>
<cell align="left" valign="middle">long long</cell>
<cell align="left" valign="middle">CORBA_long_long</cell>
<cell align="left" valign="middle">CORBA_long_long*</cell>
<cell align="left" valign="middle">CORBA_long_long</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned short</cell>
<cell align="left" valign="middle">CORBA_unsigned_short</cell>
<cell align="left" valign="middle">CORBA_unsigned_short*</cell>
<cell align="left" valign="middle">CORBA_unsigned_short</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned long</cell>
<cell align="left" valign="middle">CORBA_unsigned_long</cell>
<cell align="left" valign="middle">CORBA_unsigned_long*</cell>
<cell align="left" valign="middle">CORBA_unsigned_long</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned long long</cell>
<cell align="left" valign="middle">CORBA_unsigned_long_long</cell>
<cell align="left" valign="middle">CORBA_unsigned_long_long*</cell>
<cell align="left" valign="middle">CORBA_unsigned_long_long</cell>
</row>
<row>
<cell align="left" valign="middle">float</cell>
<cell align="left" valign="middle">CORBA_float</cell>
<cell align="left" valign="middle">CORBA_float*</cell>
<cell align="left" valign="middle">CORBA_float</cell>
</row>
<row>
<cell align="left" valign="middle">double</cell>
<cell align="left" valign="middle">CORBA_double</cell>
<cell align="left" valign="middle">CORBA_double*</cell>
<cell align="left" valign="middle">CORBA_double</cell>
</row>
<row>
<cell align="left" valign="middle">boolean</cell>
<cell align="left" valign="middle">CORBA_boolean</cell>
<cell align="left" valign="middle">CORBA_boolean*</cell>
<cell align="left" valign="middle">CORBA_boolean</cell>
</row>
<row>
<cell align="left" valign="middle">char</cell>
<cell align="left" valign="middle">CORBA_char</cell>
<cell align="left" valign="middle">CORBA_char*</cell>
<cell align="left" valign="middle">CORBA_char</cell>
</row>
<row>
<cell align="left" valign="middle">wchar</cell>
<cell align="left" valign="middle">CORBA_wchar</cell>
<cell align="left" valign="middle">CORBA_wchar*</cell>
<cell align="left" valign="middle">CORBA_wchar</cell>
</row>
<row>
<cell align="left" valign="middle">octet</cell>
<cell align="left" valign="middle">CORBA_octet</cell>
<cell align="left" valign="middle">CORBA_octet*</cell>
<cell align="left" valign="middle">CORBA_octet</cell>
</row>
<row>
<cell align="left" valign="middle">enum</cell>
<cell align="left" valign="middle">CORBA_enum</cell>
<cell align="left" valign="middle">CORBA_enum*</cell>
<cell align="left" valign="middle">CORBA_enum</cell>
</row>
<row>
<cell align="left" valign="middle">struct, fixed</cell>
<cell align="left" valign="middle">struct*</cell>
<cell align="left" valign="middle">struct*</cell>
<cell align="left" valign="middle">struct</cell>
</row>
<row>
<cell align="left" valign="middle">struct, variable</cell>
<cell align="left" valign="middle">struct*</cell>
<cell align="left" valign="middle">struct**</cell>
<cell align="left" valign="middle">struct*</cell>
</row>
<row>
<cell align="left" valign="middle">union, fixed</cell>
<cell align="left" valign="middle">union*</cell>
<cell align="left" valign="middle">union*</cell>
<cell align="left" valign="middle">union</cell>
</row>
<row>
<cell align="left" valign="middle">union, variable</cell>
<cell align="left" valign="middle">union*</cell>
<cell align="left" valign="middle">union**</cell>
<cell align="left" valign="middle">union*</cell>
</row>
<row>
<cell align="left" valign="middle">string</cell>
<cell align="left" valign="middle">CORBA_char*</cell>
<cell align="left" valign="middle">CORBA_char**</cell>
<cell align="left" valign="middle">CORBA_char*</cell>
</row>
<row>
<cell align="left" valign="middle">wstring</cell>
<cell align="left" valign="middle">CORBA_wchar*</cell>
<cell align="left" valign="middle">CORBA_wchar**</cell>
<cell align="left" valign="middle">CORBA_wchar*</cell>
</row>
<row>
<cell align="left" valign="middle">sequence</cell>
<cell align="left" valign="middle">sequence*</cell>
<cell align="left" valign="middle">sequence**</cell>
<cell align="left" valign="middle">sequence*</cell>
</row>
<row>
<cell align="left" valign="middle">array, fixed</cell>
<cell align="left" valign="middle">array</cell>
<cell align="left" valign="middle">array</cell>
<cell align="left" valign="middle">array_slice*</cell>
</row>
<row>
<cell align="left" valign="middle">array, variable</cell>
<cell align="left" valign="middle">array</cell>
<cell align="left" valign="middle">array_slice**</cell>
<cell align="left" valign="middle">array_slice*</cell>
</row>
<tcaption>Basic Argument and Result passing</tcaption>
</table>
<p>A client is responsible for providing storage of all arguments passed
as <em>in</em> arguments.</p>
<table>
<row>
<cell align="left" valign="middle">OMG IDL type</cell>
<cell align="left" valign="middle">Out</cell>
<cell align="left" valign="middle">Return</cell>
</row>
<row>
<cell align="left" valign="middle">short</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">long</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">long long</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned short</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned long</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">unsigned long long</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">float</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">double</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">boolean</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">char</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">wchar</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">octet</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">enum</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">struct, fixed</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">1</cell>
</row>
<row>
<cell align="left" valign="middle">struct, variable</cell>
<cell align="left" valign="middle">2</cell>
<cell align="left" valign="middle">2</cell>
</row>
<row>
<cell align="left" valign="middle">string</cell>
<cell align="left" valign="middle">2</cell>
<cell align="left" valign="middle">2</cell>
</row>
<row>
<cell align="left" valign="middle">wstring</cell>
<cell align="left" valign="middle">2</cell>
<cell align="left" valign="middle">2</cell>
</row>
<row>
<cell align="left" valign="middle">sequence</cell>
<cell align="left" valign="middle">2</cell>
<cell align="left" valign="middle">2</cell>
</row>
<row>
<cell align="left" valign="middle">array, fixed</cell>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">3</cell>
</row>
<row>
<cell align="left" valign="middle">array, variable</cell>
<cell align="left" valign="middle">3</cell>
<cell align="left" valign="middle">3</cell>
</row>
<tcaption>Client argument storage responsibility</tcaption>
</table>
<table>
<row>
<cell align="left" valign="middle">Case</cell>
<cell align="left" valign="middle">Description</cell>
</row>
<row>
<cell align="left" valign="middle">1</cell>
<cell align="left" valign="middle">Caller allocates all necessary storage, except that which may be encapsulated and managed within the parameter itself.</cell>
</row>
<row>
<cell align="left" valign="middle">2</cell>
<cell align="left" valign="middle">The caller allocates a pointer and passes it by reference to the callee. The callee sets the pointer to point to a valid instance of the parameter's type. The caller is responsible for releasing the returned storage. Following completion of a request, the caller is not allowed to modify any values in the returned storage. To do so the caller must first copy the returned instance into a new instance, then modify the new instance. </cell>
</row>
<row>
<cell align="left" valign="middle">3</cell>
<cell align="left" valign="middle">The caller allocates a pointer to an array slice which has all the same dimensions of the original array except the first, and passes it by reference to the callee. The callee sets the pointer to point to a valid instance of the array. The caller is responsible for releasing the returned storage. Following completion of a request, the caller is not allowed to modify any values in the returned storage. To do so the caller must first copy the returned instance into a new instance, then modify the new instance. </cell>
</row>
<tcaption>Argument passing cases</tcaption>
</table>
<p>The returned storage in case 2 and 3 is allocated as one block of memory
so it is possible to deallocate it with one call of CORBA_free.</p>
</section>
<section>
<title>Supported Memory Allocation Functions</title>
<list type="bulleted">
<item>
<p><em>CORBA_Environment</em> can be allocated from the user by calling
<em>CORBA_Environment_alloc()</em>.</p>
<p>The interface for this function is </p>
<p><c>CORBA_Environment *CORBA_Environment_alloc(int inbufsz, int outbufsz);</c></p>
<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>
</item>
<item>
<p>Strings can be allocated from the user by calling <em>CORBA_string_alloc()</em>.</p>
<p>The interface for this function is </p>
<p><c>CORBA_char *CORBA_string_alloc(CORBA_unsigned_long len);</c></p>
<p>where :</p>
<list type="bulleted">
<item>
<p><em>len</em> is the length of the string to be allocated.</p>
</item>
</list>
</item>
</list>
<p>Thus far, no other type allocation function is supported.</p>
</section>
<section>
<title>Special Memory Deallocation Functions</title>
<list type="bulleted">
<item>
<p><c>void CORBA_free(void *storage)</c></p>
<p>This function will free storage allocated by the stub.</p>
</item>
<item>
<p><c>void CORBA_exception_free(CORBA_environment *ev)</c></p>
<p>This function will free storage allocated under exception propagation. </p>
</item>
</list>
</section>
<section>
<title>Exception Access Functions</title>
<list type="bulleted">
<item>
<p><c>CORBA_char *CORBA_exception_id(CORBA_Environment *ev)</c></p>
<p>This function will return raised exception identity.</p>
</item>
<item>
<p><c>void *CORBA_exception_value(CORBA_Environment *ev)</c></p>
<p>This function will return the value of a raised exception. </p>
</item>
</list>
</section>
<section>
<title>Special Types</title>
<list type="bulleted">
<item>
<p>The erlang binary type has some special features.</p>
<p></p>
<p>While the <c>erlang::binary</c> idl type has the same C-definition as
a generated sequence of octets :</p>
<code type="none"><![CDATA[
module erlang
{
....
// an erlang binary
typedef sequence<octet> binary;
};
]]></code>
<p>it provides a way on sending trasparent data between C and Erlang.</p>
<p>The C-definition (ic.h) for an erlang binary is :</p>
<code type="none">
typedef struct {
CORBA_unsigned_long _maximum;
CORBA_unsigned_long _length;
CORBA_octet* _buffer;
} erlang_binary; /* ERLANG BINARY */
</code>
<p>The differences (between <c>erlang::binary</c> and <c><![CDATA[sequence< octet >]]></c>) are :</p>
<list type="bulleted">
<item>
<p>on the erlang side the user is sending/receiving typical
built in erlang binaries, using <c>term_to_binary() / binary_to_term()</c>
to create / extract binary structures.</p>
</item>
<item>
<p>no encoding/decoding functions are generated</p>
</item>
<item>
<p>the underlying protocol is more efficient than usual sequences of
octets</p>
</item>
</list>
<p>The erlang binary IDL type is defined in <c>erlang.idl</c>, while its
C definition is located in the <c>ic.h</c> header file, both in the
<c><![CDATA[IC-< vsn >/include]]></c> directory.
The user will have to include the file <c>erlang.idl</c> in order to use the
<c>erlang::binary</c> type.</p>
</item>
</list>
</section>
<section>
<title>A Mapping Example</title>
<p> <marker id="stack_idl"></marker>
This is a small example of a simple stack. There are two
operations on the stack, push and pop. The example shows all
generated files as well as conceptual usage of the stack.</p>
<code type="none">
// The source IDL file: stack.idl
struct s {
long l;
string s;
};
interface stack {
void push(in s val);
s pop();
};
</code>
<p>When this file is compiled it produces four files, two for the
top scope and two for the stack interface scope. The important parts
of the generated C code for the stack API is shown below. <marker id="stack_serv"></marker>
</p>
<p>stack.c</p>
<code type="none">
void push(stack oe_obj, s val, CORBA_Environment* oe_env) {
...
}
s* pop(stack oe_obj, CORBA_Environment* oe_env) {
...
}
</code>
<p>oe_stack.h</p>
<code type="none">
#ifndef OE_STACK_H
#define OE_STACK_H
/*------------------------------------------------------------
* Struct definition: s
*/
typedef struct {
long l;
char *s;
} s;
#endif
</code>
<p>stack.h just contains an include statement of <c>oe_stack.h</c>.</p>
<p>oe_code_s.c</p>
<code type="none">
int oe_sizecalc_s(CORBA_Environment
*oe_env, int* oe_size_count_index, int* oe_size) {
...
}
int oe_encode_s(CORBA_Environment *oe_env, s* oe_rec) {
...
}
int oe_decode_s(CORBA_Environment *oe_env, char *oe_first,
int* oe_outindex, s *oe_out) {
...
}
</code>
<p>The only files that are really important are the <c>.h</c>
files and the stack.c file.</p>
</section>
</chapter>
|