1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE chapter SYSTEM "chapter.dtd">
9
<holder>Ericsson AB, All Rights Reserved</holder>
12
The contents of this file are subject to the Erlang Public License,
13
Version 1.1, (the "License"); you may not use this file except in
14
compliance with the License. You should have received a copy of the
15
Erlang Public License along with this software. If not, it can be
16
retrieved online at http://www.erlang.org/.
18
Software distributed under the License is distributed on an "AS IS"
19
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20
the License for the specific language governing rights and limitations
23
The Initial Developer of the Original Code is Ericsson AB.
26
<title>The C Server Back-end</title>
29
<date>2004-01-14</date>
34
<title>Introduction</title>
35
<p>With the option <c>{be, c_server}</c> the IDL Compiler generates
36
C server skeletons according to the IDL to C mapping, on top of
37
the Erlang distribution and gen_server protocols.</p>
38
<p>The developer has to write additional code, that together with
39
the generated C server skeletons, form a hidden Erlang
40
node. That additional code contains implementations of call-back
41
functions that implement the true server functionality, and also
42
code uses <c>erl_interface</c> functions for defining the hidden
43
node and for establishing connections to other Erlang nodes.</p>
47
<title>Generated Stub Files</title>
48
<p>The generated stub files are:</p>
49
<list type="bulleted">
51
<p>For each IDL interface, a C source file, the name of which
52
is <c><![CDATA[<Scoped Interface Name>__s.c]]></c>. Each operation of the
53
IDL interface is mapped to a C function (with scoped name)
57
<p>C source files that contain functions for type conversion,
58
memory allocation, and data encoding/decoding;</p>
61
<p>C header files that contain function prototypes and type
65
<p>All C functions are exported (i.e. not declared static).</p>
69
<title>C Skeleton Functions</title>
70
<p>For each IDL operation a C skeleton function is generated, the
71
prototype of which is <c><![CDATA[int <Scoped Function Name>__exec(<Interface Object> oe_obj, CORBA_Environment *oe_env)]]></c>, where <c><![CDATA[<Interface Object>]]></c>, and
72
<c>CORBA_Environment</c> are of the same type as for the
73
generated C client stubs code.</p>
74
<p>Each <c><![CDATA[<Scoped Function Name>__exec()]]></c> function calls the
75
call-back function</p>
76
<p><c><![CDATA[<Scoped Function Name>_rs* <Scoped Function Name>__cb(<Interface Object> oe_obj, <Parameters>, CORBA_Environment *oe_env)]]></c></p>
77
<p>where the arguments are of the same type as those generated for
79
<p>The return value <c><![CDATA[<Scoped Function Name>_rs* ]]></c> is a pointer
80
to a function with the same signature as the call-back function
81
<c><![CDATA[<Scoped Function Name>_cb]]></c>, and is called after the call-back
82
function has been evaluated (provided that the pointer is not equal
87
<title>The Server Loop</title>
88
<p>The developer has to implement code for establishing connections
89
with other Erlang nodes, code for call-back functions and restore
92
<p>In addition, the developer also has to implement code for a
93
server loop, that receives messages and calls the relevant
94
<c>__exec</c> function. For that purpose the IC library function
95
<c>oe_server_receive()</c> function can be used.</p>
99
<title>Generating, Compiling and Linking</title>
100
<p>To generate the C server skeletons type the following in an
101
appropriate shell:</p>
102
<p><c>erlc -I ICROOT/include "+{be, c_server}" File.idl</c>,</p>
103
<p>where <c>ICROOT</c> is the root of the IC application. The
104
<c>-I ICROOT/include</c> is only needed if <c>File.idl</c>
105
refers to <c>erlang.idl</c>.</p>
106
<p>When compiling a generated C skeleton file, the directories
107
<c>ICROOT/include</c> and <c>EICROOT/include</c>, have to be
108
specified as include directories, where <c>EIROOT</c> is the
109
root directory of the Erl_interface application.</p>
110
<p>When linking object files the <c>EIROOT/lib</c> and
111
<c>ICROOT/priv/lib</c> directories have to be specified. </p>
115
<title>An Example</title>
116
<p>In this example the IDL specification file "random.idl" is used
117
for generating C server skeletons (the file is contained in the IC
118
<c>/examples/c-server</c> directory):</p>
126
oneway void init(in long seed1, in long seed2, in long seed3);
131
<p>Generate the C server skeletons:</p>
133
erlc '+{be, c_server}' random.idl
134
Erlang IDL compiler version X.Y.Z </code>
135
<p>Six files are generated. </p>
136
<p>Compile the C server skeletons:</p>
137
<p>Please read the <c>ReadMe</c> file in the
138
<c>examples/c-server</c> directory.</p>
139
<p>In the same directory you can find all the code for this
140
example. In particular you will find the <c>server.c</c> file
141
that contains all the additional code that must be written to
142
obtain a complete server.</p>
143
<p>In the <c>examples/c-server</c> directory you will also find
144
source code for an Erlang client, which can be used for testing