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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>Using the Plain Erlang Back-end</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="4"><!-- Empty --></A>
<H2>4 Using the Plain Erlang Back-end</H2>
<A NAME="4.1"><!-- Empty --></A>
<H3>4.1 Introduction</H3>
<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.
<A NAME="4.2"><!-- Empty --></A>
<H3>4.2 Compiling the Code</H3>
<P> In the Erlang shell type :
<P> ic:gen(<CODE><filename>, [{be, erl_plain}])</CODE>.<A NAME="4.3"><!-- Empty --></A>
<H3>4.3 Writing the Implementation File</H3>
<P> For each IDL interface <CODE><interface name></CODE> defined in the IDL file:
<P>
<UL>
<LI>
Create the corresponding Erlang file that will hold the
Erlang implementation of the IDL definitions.
</LI>
<LI>
Call the implementation file after the scope of the IDL interface,
followed by the suffix <CODE>_impl</CODE>.
</LI>
<LI>
Export the implementation functions.
</LI>
</UL>
<P> For each function defined in the IDL interface :
<P>
<UL>
<LI>
Implement an Erlang function that uses as arguments in the same
order, as the input ch_c_gen_serv_map.sgmlarguments described in the IDL file, and returns
the value described in the interface.
</LI>
<LI>
When using the function, follow the mapping described in chapter 2.
</LI>
</UL>
<A NAME="4.4"><!-- Empty --></A>
<H3>4.4 An Example</H3>
<P> <A NAME="plain_idl"><!-- Empty --></A>
In this example, a file "random.idl" is generates code for the plain erlang
back-end :
<P>
<UL>
<LI>
Main file : "plain.idl"<BR>
<PRE>
module rmod {
interface random {
double produce();
oneway void init(in long seed1, in long seed2, in long seed3);
};
};
</PRE>
</LI>
</UL>
<P>Compile the file :
<PRE>
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>
</PRE>
<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
<CODE>rmod_random.erl</CODE> is important :.
<A NAME="generated files"><!-- Empty --></A>
<P>
<UL>
<LI>
Erlang file for interface : "rmod_random.erl"<BR>
<PRE>
-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).
</PRE>
</LI>
</UL>
<P> The implementation file should be called <CODE>rmod_random_impl.erl</CODE>
and could look like this:
<PRE>
-module('rmod_random_impl').
-export([produce/0,init/3]).
produce() ->
random:uniform().
init(S1,S2,S3) ->
random:seed(S1,S2,S3).
</PRE>
<P> Compiling the code :
<PRE>
2> make:all().
Recompile: rmod_random
Recompile: oe_random
Recompile: rmod_random_impl
up_to_date
</PRE>
<P>
<P> Running the example :
<PRE>
3> rmod_random:init(1,2,3).
ok
4> rmod_random:produce().
1.97963e-4
5>
</PRE>
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|