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>Using the Plain Erlang Back-end</title>
34
<title>Introduction</title>
35
<p>The mapping of OMG IDL to the Erlang programming language when
37
is the back-end of choice is similar to the one used in pure Erlang IDL
38
mapping. The only difference is on the generated code and the extended
39
use of pragmas for code generation: IDL functions are translated
41
module function calls.</p>
45
<title>Compiling the Code</title>
46
<p>In the Erlang shell type :</p>
47
<p>ic:gen(<c><![CDATA[<filename>, [{be, erl_plain}])]]></c>.</p>
51
<title>Writing the Implementation File</title>
52
<p>For each IDL interface <c><![CDATA[<interface name>]]></c> defined in the IDL file:</p>
53
<list type="bulleted">
54
<item>Create the corresponding Erlang file that will hold the
55
Erlang implementation of the IDL definitions. </item>
56
<item>Call the implementation file after the scope of the IDL interface,
57
followed by the suffix <c>_impl</c>.</item>
58
<item>Export the implementation functions.</item>
60
<p>For each function defined in the IDL interface :</p>
61
<list type="bulleted">
62
<item>Implement an Erlang function that uses as arguments in the same
63
order, as the input arguments described in the IDL file, and returns
64
the value described in the interface.</item>
65
<item>When using the function, follow the mapping described in chapter 2.</item>
70
<title>An Example</title>
71
<p> <marker id="plain_idl"></marker>
73
In this example, a file "random.idl" is generates code for the plain Erlang
75
<list type="bulleted">
77
<p>Main file : "plain.idl"</p>
86
oneway void init(in long seed1, in long seed2, in long seed3);
94
<p>Compile the file :</p>
96
Erlang (BEAM) emulator version 4.9
98
Eshell V4.9 (abort with ^G)
99
1> ic:gen(random,[{be, erl_plain}]).
100
Erlang IDL compiler version 2.5.1
105
<p>When the file "random.idl" is compiled it produces five files: two for
106
the top scope, two for the interface scope, and one for the module
107
scope. The header files for top scope and interface
108
are empty and not shown here. In this case only the file for the interface
109
<c>rmod_random.erl</c> is important :.
110
<marker id="generated files"></marker>
112
<list type="bulleted">
114
<p>Erlang file for interface : "rmod_random.erl"</p>
117
-module(rmod_random).
121
%% Interface functions
122
-export([produce/0, init/3]).
124
%%------------------------------------------------------------
125
%% Operation: produce
130
rmod_random_impl:produce().
132
%%------------------------------------------------------------
137
init(Seed1, Seed2, Seed3) ->
138
rmod_random_impl:init(Seed1, Seed2, Seed3).
142
<p>The implementation file should be called <c>rmod_random_impl.erl</c>
143
and could look like this:</p>
145
-module('rmod_random_impl').
147
-export([produce/0,init/3]).
155
random:seed(S1,S2,S3).
157
<p>Compiling the code : </p>
160
Recompile: rmod_random
162
Recompile: rmod_random_impl
166
<p>Running the example : </p>
168
3> rmod_random:init(1,2,3).
170
4> rmod_random:produce().