User's Guide
Reference Manual
Release Notes
PDF
Top

ic
User's Guide
Version 4.2.30

Expand All
Contract All

Chapters

- Using the IC Compiler
  - Top of chapter
  - Introduction
  - Compilation of IDL Files
- OMG IDL
  - Top of chapter
  - OMG IDL - Overview
- IC Protocol
  - Top of chapter
  - Introduction
  - Language mappings and IDL operations
  - IC Protocol
  - Gen_server Protocol
  - Erlang Distribution Protocol
- Using the Plain Erlang Back-end
  - Top of chapter
  - Introduction
  - Compiling the Code
  - Writing the Implementation File
  - An Example
- Using the Erlang Generic Server Back-end
  - Top of chapter
  - Introduction
  - Compiling the Code
  - Writing the Implementation File
  - An Example
- IDL to C mapping
  - Top of chapter
  - Introduction
  - C Mapping Characteristics
  - Basic OMG IDL Types
  - Constructed OMG IDL Types
  - OMG IDL Constants
  - OMG IDL Operations
  - Exceptions
  - Access to Attributes
  - Summary of Argument/Result Passing for the C-client
  - Supported Memory Allocation Functions
  - Special Memory Deallocation Functions
  - Exception Access Functions
  - Special Types
  - A Mapping Example
- The C Client Back-end
  - Top of chapter
  - Introduction
  - Generated Stub Files
  - C Interface Functions
  - Generating, Compiling and Linking
  - An Example
- The C Server Back-end
  - Top of chapter
  - Introduction
  - Generated Stub Files
  - C Skeleton Functions
  - The Server Loop
  - Generating, Compiling and Linking
  - An Example
- CORBA_Environment C Structure
  - Top of chapter
  - C Structure
  - The CORBA Compatibility Part
  - The External Part
  - The Internal Part
  - Creating and Initiating the CORBA_Environment Structure
  - Setting System Exceptions
- IDL to Java language Mapping
  - Top of chapter
  - Introduction
  - Specialties in the Mapping
  - Basic OMG IDL Types
  - Constructed OMG IDL Types
  - Mapping for Constants
  - Invocations of Operations
  - Exceptions
  - Access to Attributes
  - Summary of Argument/Result Passing for Java
  - Communication Toolbox
  - The Package com.ericsson.otp.ic
  - The Term Class
  - Stub File Types
  - Client Stub Initialization, Methods Exported
  - Server Skeleton Initialization, Server Stub Implementation, Methods Exported
  - A Mapping Example
  - Running the Compiled Code

# 4 Using the Plain Erlang Back-end

### 4.1 Introduction

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.

### 4.2 Compiling the Code

In the Erlang shell type :

ic:gen(<filename>, [{be, erl_plain}]).

### 4.3 Writing the Implementation File

For each IDL interface <interface name> defined in the IDL file:

- Create the corresponding Erlang file that will hold the Erlang implementation of the IDL definitions.
- Call the implementation file after the scope of the IDL interface, followed by the suffix _impl.
- Export the implementation functions.

For each function defined in the IDL interface :

- 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.
- When using the function, follow the mapping described in chapter 2.

### 4.4 An Example

In this example, a file "random.idl" is generates code for the plain Erlang back-end :

- Main file : "plain.idl"

      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 rmod_random.erl is important :.

- 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 rmod_random_impl.erl and could look like this:

          -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>