aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/doc/src/ch_erl_plain.xml
blob: 36de46f6246b0bbaba5ef16d834c53f67502e47f (plain) (blame)
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
<?xml version="1.0" encoding="latin1" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>1998</year><year>2009</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>Using the Plain Erlang Back-end</title>
    <prepared></prepared>
    <docno></docno>
    <date>98-05-06</date>
    <rev>B</rev>
    <file>ch_erl_plain.xml</file>
  </header>

  <section>
    <title>Introduction</title>
    <p>The mapping of OMG IDL to the Erlang programming language when
      Plain Erlang 
      is the back-end of choice is similar to the one used in pure Erlang IDL
      mapping. The only difference is on the generated code and the extended
      use of pragmas for code generation: IDL functions are translated
      to Erlang
      module function calls.</p>
  </section>

  <section>
    <title>Compiling the Code</title>
    <p>In the Erlang shell type :</p>
    <p>ic:gen(<c><![CDATA[<filename>, [{be, erl_plain}])]]></c>.</p>
  </section>

  <section>
    <title>Writing the Implementation File</title>
    <p>For each IDL interface <c><![CDATA[<interface name>]]></c> defined in the IDL file:</p>
    <list type="bulleted">
      <item>Create the corresponding Erlang file that will hold the
       Erlang implementation of the IDL definitions.  </item>
      <item>Call the implementation file after the scope of the IDL interface, 
       followed by the suffix <c>_impl</c>.</item>
      <item>Export the implementation functions.</item>
    </list>
    <p>For each function defined in the IDL interface :</p>
    <list type="bulleted">
      <item>Implement an Erlang function that uses as arguments in the same
       order, as the input arguments described in the IDL file, and returns 
       the value described in the interface.</item>
      <item>When using the function, follow the mapping described in chapter 2.</item>
    </list>
  </section>

  <section>
    <title>An Example</title>
    <p>      <marker id="plain_idl"></marker>

      In this example, a file "random.idl" is generates code for the plain Erlang
      back-end :</p>
    <list type="bulleted">
      <item>
        <p>Main file : "plain.idl"</p>
        <code type="none">
\011   
module rmod {
 
  interface random {
 
    double produce();
 
    oneway void init(in long seed1, in long seed2, in long seed3);
 
  };
 
};
        </code>
      </item>
    </list>
    <p>Compile the file :</p>
    <code type="none">
      Erlang (BEAM) emulator version 4.9
      
      Eshell V4.9  (abort with ^G)
      1> ic:gen(random,[{be, erl_plain}]).
      Erlang IDL compiler version 2.5.1
      ok
      2> 
    </code>
    <p></p>
    <p>When the file "random.idl" is compiled it produces five files: two for 
      the top scope, two for the interface scope, and one for the module
      scope. The header files for top scope and interface
      are empty and not shown here. In this case only the file for the interface 
      <c>rmod_random.erl</c> is important :. 
            <marker id="generated files"></marker>
</p>
    <list type="bulleted">
      <item>
        <p>Erlang file for interface : "rmod_random.erl"</p>
        <code type="none">

-module(rmod_random).
 
 
 
%% Interface functions
-export([produce/0, init/3]).
 
%%------------------------------------------------------------
%% Operation: produce
%% 
%%   Returns: RetVal
%%
produce() ->
    rmod_random_impl:produce().
 
%%------------------------------------------------------------
%% Operation: init
%% 
%%   Returns: RetVal
%%
init(Seed1, Seed2, Seed3) ->
    rmod_random_impl:init(Seed1, Seed2, Seed3).
        </code>
      </item>
    </list>
    <p>The implementation file should be called <c>rmod_random_impl.erl</c> 
      and could look like this:</p>
    <code type="none">
      -module('rmod_random_impl').
      
      -export([produce/0,init/3]).
      
      
      produce()  ->
        random:uniform().
       
      
      init(S1,S2,S3)  ->
        random:seed(S1,S2,S3).
    </code>
    <p>Compiling the code : </p>
    <code type="none">
2> make:all().
Recompile: rmod_random
Recompile: oe_random
Recompile: rmod_random_impl
up_to_date
    </code>
    <p></p>
    <p>Running the example : </p>
    <code type="none">
3>  rmod_random:init(1,2,3).
ok
4>  rmod_random:produce().  
1.97963e-4
5> 
    </code>
  </section>
</chapter>