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.
In the Erlang shell type :
ic:gen(
For each IDL interface
For each function defined in the IDL interface :
Main file : "plain.idl"
\011
module rmod {
interface random {
double produce();
oneway void init(in long seed1, in long seed2, in long seed3);
};
};
Compile the file :
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>
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
Erlang file for interface : "rmod_random.erl"
-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).
The implementation file should be called
-module('rmod_random_impl').
-export([produce/0,init/3]).
produce() ->
random:uniform().
init(S1,S2,S3) ->
random:seed(S1,S2,S3).
Compiling the code :
2> make:all().
Recompile: rmod_random
Recompile: oe_random
Recompile: rmod_random_impl
up_to_date
Running the example :
3> rmod_random:init(1,2,3).
ok
4> rmod_random:produce().
1.97963e-4
5>