[Ericsson Utvecklings AB]

6 Using the C Server Back-end

6.1 Introduction

The mapping of OMG IDL to the C programming language when C Server switch is the back-end of choice is identical to the one use in C IDL mappning. The only difference is on the generated code, and that the idl functions are translated to C function calls for the C Server.

6.2 What Is the C-server Good For?

The C-server uses the same communication protocol as for the Erlang genservers, it is actually a C-genserver. So the C-server can be used for :

6.3 What Kind of Code is Produced?

The code produced is a collection of :

All functions found in the code are exported. The user is free to define his own switches if there is a need for this.

6.4 What Does This Code Do when Used ?

The main functionality of a C server switch is to :

6.5 What Is the Interface of the Functions Produced?

The C source defines the following functions :

The interface for the server switch is :

int < Scoped Interface Name >__switch(< Interface Object > oe_obj, CORBA_Environment *oe_env );

Where :

The interface for the generic message decoder is :

int < Scoped Interface Name >__call_info((< Interface Object > oe_obj, CORBA_Environment *oe_env );

Where :

The interface for the specific call function definition is :

int < Scoped Function Name >__exec(< Interface Object > oe_obj, CORBA_Environment *oe_env );

Where :

The interface for the specific parameter decoder function is :

int < Scoped Function Name >__dec( < Interface Object > oe_obj, < Parameters > CORBA_Environment *oe_env );

Where :

The interface for the specific callback function is :

< Scoped Function Name >__rs* < Scoped Function Name >__cb( < Interface Object > oe_obj, < Parameters > CORBA_Environment *oe_env );

Where :

Callback functions are implementation dependent and in order to make things work, the following rule must be followed when passing arguments to callback functions :

The interface for the specific message encoder function is :

int < Scoped Function Name >__enc( < Interface Object > oe_obj, < Parameters > CORBA_Environment *oe_env );

Where :

The encoder function is generated only for usual call IDL-functions (not oneways)

The interface for the specific restore function is :

void < Scoped Function Name >__rs( < Interface Object > oe_obj, < Parameters > CORBA_Environment *oe_env );

Where :

The restore function type definition is recorded on the interface header file. It is unique for each IDL defined interface function

6.6 Functions Used for Internal Purposes

Depending on the data defined and used in the IDL code, C-source files may be generated that hold functions used internally. This is the case when other types than the elementary IDL types are used by the IDL file definitions. All these files must be compiled and linked to the other code.

6.7 Which Header Files to Include ?

The only header files that must be included are the interface files, the files named < Scoped Interface Name >__s.h

6.8 Which Directories/Libraries/Options must Be Included under C-compiling?

Under compilation you will have to include :

Under linking you will have to link with :

6.9 Compiling the Code

In the Erlang shell type :

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

6.10 Implementing the Callback Functions

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

For each function defined in the IDL interface :

6.11 An Example

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

Compile the file :

      Erlang (BEAM) emulator version 4.9
      
      Eshell V4.9  (abort with ^G)
      1> ic:gen(random,[{be, c_server}]).
      Erlang IDL compiler version 3.2
      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 :.

The implementation file must be a C file, in this example we use a file called callbacks.c. This file must be implemented in a similar way :


#include <stdlib.h>
#include "rmod_random__s.h"


rmod_random_produce__rs* rmod_random_produce__cb(rmod_random 
                                                 oe_obj, double *rs, 
                                                 CORBA_Environment *oe_env)
{
  *rs = (double) rand();

  return (rmod_random_produce__rs*) NULL;
}
 

rmod_random_init__rs* rmod_random_init__cb(rmod_random oe_obj, 
                                           long* seed1, long* seed2, 
                                           long* seed3, 
                                           CORBA_Environment *oe_env)
{
  srand(*seed1 * *seed2 * *seed3);
  
  return (rmod_random_init__rs*) NULL;
}

    

Compiling the Code :

Note!

Due to changes inErl_Interface, to allow buffer expansion, a new receiving function ei_receive_encoded/5 is created, while changes have been implemnted in CORBA_Environment initialization. You must consider and adapt these. The example in the ic-3.2/examples/c-server directory demonstrates the changes.

Running the example :


Copyright © 1991-2002 Ericsson Utvecklings AB