IC and C out-parameter to Erlang

Babbis Xagorarakis <>
Wed May 3 16:42:14 CEST 2000


Hi,

there are many ways to solve this,
please consider the following simple case :

* a global variable case used to save the incoming message by write
function.
    This message has an oversized buffer to hold every message from
erlang.

* each time write is called, the contents of the incoming message are
copied
    to the global message variable by use of set_message().
    Afterwards, the incoming message is deleted by CORBA_free ( You are
    not allowed to modify input, by OMG-spec ). This is done by defining
the
    proper restore function to be called by server loop,
simple_restore().

* each time read is called, the contents of the current global message
are
    accessed by get_message and sent to erlang.

The idl spec should be like this :

module tmsystem {
    typedef sequence<char> message;
    interface telemetry {
        void write(in message telecommand);
        message read_tm();
    };
};


And the code for server callback file could be like this :


#define MAXLENGTH = 10240;

char buf[LEN];
tmsystem_message message;


/* Copy the contents of a message to
   the default message storage */
int set_message(tmsystem_message *in) {
    int i;

    if (in->_length > MAXLENGTH)
      return -1;

    message._length = in._length;

    for(i = 0; i < in->_length; i++)
      message._buffer[i] = in->_buffer[i];

    return 0;
}


/* Access the stored message */
tmsystem_message* get_message() {
    return message;
}


/* A simple restore function */
void simple_restore(tmsystem_telemetry oe_obj, tmsystem_message* in,
CORBA_Environment *oe_env) {
    CORBA_free(in);
}


/* The write callback function */
tmsystem_telemetry_write__rs*
tmsystem_telemetry_write__cb(tmsystem_telemetry oe_obj,
tmsystem_message* in, CORBA_Environment *oe_env) {

    /* Set the global message */
    set_message(in);

    /* Define the restore funtion */
    return (tmsystem_telemetry_write__rs*) (simple_restore);
}


/* The read callback function */
tmsystem_telemetry_read_tm__rs*
tmsystem_telemetry_read_tm__cb(CORBA_Object oe_obj, tmsystem_message**
ret, CORBA_Environment *oe_env){

    /* Access and send the message */
    *ret = get_message();

   /* No restore is needed here */
  return (tmsystem_telemetry_read_tm__rs*) NULL;
}



I hope this will help

BR

Babbis


> I have some difficulties in understanding how to pass an object from
> C-server to Erlang-client.
>
> Currently I have
>
> module tmsystem
>     typedef sequence<char> message;
>     interface telemetry {
>         void write(in message telecommand);
>        message read_tm(in message telecommand);
>    };
> };
>
> I can nicely send an Erlang list (from Erlang) with the
write-procedure
> to a C-server.
>
> But I'm not really understanding how I should implement the
counterpart
> read_tm, which is called from Erlang in order to receive a list as a
result.
> I know that I should somehow provide the allocated object to C_server
to but
> the result in. So now I send large enough (12*1024 list elements!)
> in-parameter and make the result to point to that list-structure.
>
> What is the correct way to this (the allocation for the result) ?



--
Babbis Xagorarakis, Ericsson Network Core Products






More information about the erlang-questions mailing list