The ic module is an Erlang implementation of an OMG IDL compiler. Depending on the choice of back-end the code will map to Erlang, C, or Java. The compiler generates client stubs and server skeletons.
Two kinds of files are generated for each scope: Ordinary code files and header files. The latter are used for defining record definitions, while the ordinary files contain the object interface functions.
ic:gen(FileName) -> Result
ic:gen(FileName, [Option]) -> Result
Types:
Result = ok | error | {ok, [Warning]} | {error, [Warning],
[Error]}
Option = [ GeneralOption | CodeOption | WarningOption |
BackendOption]
GeneralOption =
{outdir, String()} | {cfgfile, String()} | {use_preproc, bool()} |
{preproc_cmd, String()} | {preproc_flags, String()}
CodeOption =
{gen_hrl, bool()} | {serv_last_call, exception | exit} |
{{impl, String()}, String()} | {light_ifr, bool()}
this | {this, String()} | {{this, String()}, bool()} |
from | {from, String()} | {{from, String()}, bool()} |
handle_info | {handle_info, String()} | {{handle_info,
String()}, bool()} |
timeout | {timeout, String()} | {{timeout, String()}, bool()} |
{scoped_op_calls, bool()} | {scl, bool()} |
{user_protocol, Prefix} |
{c_timeout, SendTimeout, RecvTimeout} |
{c_report, bool()} |
{precond, {atom(), atom()}} | {{precond, String()} {atom(),
atom()}} |
{postcond, {atom(), atom()}} | {{postcond, String()}
{atom(), atom()}}
WarningOption =
{'Wall', bool()} | {maxerrs, int() | infinity} |
{maxwarns, int() | infinity} | {nowarn, bool()} |
{warn_name_shadow, bool()} | {pedantic, bool()} |
{silent, bool()}
BackendOption = {be, Backend}
Backend = erl_corba | erl_template | erl_plain | erl_genserv |
c_client | c_server | java
DirNAme = string() | atom()
FileName = string() | atom()
The tuple {Option, true}
can be replaced by
Option
for boolean values.
The ic:gen/2
function can be called from the command
line as follows:
erlc "+Option" ... File.idl
Example:
erlc "+{be,c_client}" '+{outdir, "../out"}' File.idl
{outdir, "output/generated"}
.
".ic_config"
.
{cfgfile, "special.cfg"}
.
preproc_cmd++preproc_flags++FileName
{preproc_cmd, "erl"})
.
{preproc_cmd, "gcc -x c++ -E"}
.
{preproc_flags, "-I../include"}
.
false
. To be able to
use this option Orber must be configured to use Light IFR (see
Orber's User's Guide). When this options is used, the size of the
generated files used to register the API in the IFR DB are minimized.
{light_ifr, true}
.
gen_server handle_call
either raise a
CORBA exception or just exit plainly. Default is the exception.
"M1::I1"
.
this
which activates the
parameter for all interfaces in the source file, {this,
IntfName}
which activates the parameter for a specified
interface and {{this, IntfName}, false}
which
deactivates the parameter for a specified
interface.
this)
activates the parameter for
all interfaces.
{this, "M1::I1"}
activates the
parameter for all functions of M1::I1
.
[this, {{this, "M1::I2"}, false}]
activates the parameter for all interfaces except
M1::I2
.
from
and this
options are used the invokers
reference parameter will be passed as the second
parameter. This makes it possible for the implementation to
respond to a request and continue executing
afterwards. Consult the gen_server
and Orber
documentation how this option may be used. from
which activates the
parameter for all interfaces in the source file, {from,
IntfName}
which activates the parameter for a specified
interface and {{from, IntfName}, false}
which
deactivates the parameter for a specified interface.
from)
activates the parameter for
all interfaces.
[{from, "M1::I1"}]
activates the
parameter for all functions of M1::I1
.
[from, {{from, "M1::I2"}, false}]
activates the parameter for all interfaces except
M1::I2
.
handle_info
in the object implementation module on all unexpected
messages. Useful if the object implementation need to trap
exits.
handle_info
will activates module
implementation handle_info
for all interfaces in the
source file.
{{handle_info, "M1::I1"}, true}
will activates module implementation handle_info
for
the specified interface.
[handle_info, {{handle_info,
"M1::I1"}, false}]
will generate the handle_info
call for all interfaces except M1::I1
.
{timeout,"M::I"})
produces server
stub which will has an extra timeout parameter in the initialization
function for that interface.
timeout
produces server
stub which will has an extra timeout parameter in the initialization
function for all interfaces in the source file.
[timeout, {{timeout,"M::I"}, false}]
produces server stub which will has an extra timeout
parameter in the initialization function for all interfaces
except M1::I1
.
All
of the parts generated by ic
have to agree in the use of this option. Default is
false
.
[{be,c_genserv},{scoped_op_calls,true}])
produces
client stubs which sends "scoped" requests to a gen_server
or a c-server.
[{be,c_client},{user_protocol, "my_special"}])
produces
client stubs which use C protocol functions with the prefix
"my_special".
[{be,c_client},{c_timeout, 10000, 20000}])
produces
client stubs which use a 10 seconds send timeout, and a
20 seconds receive timeout.
stderr
(C back-ends only).
timeouts are specified in milliseconds.
[{be,c_client}, c_report])
.
3.3
. Due to better semantic checks on enumerants,
the compiler discovers name clashes between user defined
types and enumerant values in the same name space. By
enabling this option the compiler turns off the extended
semantic check on enumerant values. Default is
false
.
{scl,true}
{precond, {M,
F}}
which activates the call for operations in all
interfaces in the source file, {{precond, IntfName}, {M,
F}}
which activates the call for all operations in a
specific interface and {{precond, OpName}, {M, F}}
which activates the call for a specific operation.
m:f(Module, Function, Args)
.
{precond, {mod, fun}}
adds the call
of m:f for all operations in the idl file.
[{{precond, "M1::I"}, {mod, fun}}]
adds the call of m:f
for all operations in the
interface M1::I1
.
[{{precond, "M1::I::Op"}, {mod,
fun}}]
adds the call of m:f
for the operation
M1::I::Op
.
{postcond, {M,
F}}
which activates the call for operations in all
interfaces in the source file, {{postcond, IntfName}, {M,
F}}
which activates the call for all operations in a
specific interface and {{postcond, OpName}, {M, F}}
which activates the call for a specific operation.
m:f(Module, Function, Args, Result)
.
{postcond, {mod, fun}}
adds the call
of m:f for all operations in the idl file.
[{{postcond, "M1::I"}, {mod, fun}}]
adds the call of m:f
for all operations in the
interface M1::I1
.
[{{postcond, "M1::I::Op"}, {mod,
fun}}]
adds the call of m:f
for the operation
M1::I::Op
.
infinity
. Default number is 10.
infinity
. Default value is
infinity.
Which back-end IC will generate code for is determined by the supplied
{be,atom()}
option. If left out, erl_corba
is used.
Currently, IC support the following back-ends:
c_client
instead.
The IDL compiler allows several preprocessors to be used, the
Erlang
IDL preprocessor
or other standard C
preprocessors.
Options can be used to provide extra flags such as include
directories to the preprocessor. The build in the Erlang IDL
preprocessor is used by default, but any standard C preprocessor
such as gcc
is adequate.
The preprocessor command is formed by appending the prepoc_cmd to the preproc_flags option and then appending the input IDL file name.
The compiler can be configured in two ways:
The configuration file is optional and overrides the compiler
defaults and is in turn overridden by the command line options.
The configuration file shall contain options in the form of
Erlang terms. The configuration file is read using
file:consult
.
An example of a configuration file, note the "." after each line.
{outdir, gen_dir}. {{impl, "M1::M2::object"}, "obj"}.
The compiler will produce output in several files depending on
scope declarations found in the IDL file. At most
three file types will be generated for each scope (including the top scope),
depending on the compiler back-end and the compiled interface.
Generally, the output per interface will be a header file (.hrl
/
.h
) and one or more Erlang/C files (.erl
/.c
).
Please look at the language mapping for each back-end for details.
There will be at least one set of files for an IDL file, for the file level scope. Modules and interfaces also have their own set of generated files.