# &develguide;

## Available Functions

### `erl_load_api(erl_api)`

Function to be called directly from other modules to load the API. On success return 0, on error 1.

Meaning of the parameters is as follows:

- erl_api_t* erl_api - API bindings structure.

### `rpc(reply, module, function, args)`

This function supports calling Erlang functions on remote nodes. On success function returns 0.

Meaning of parameters is as follows:

- ei_x_buff* reply - dynamic ei buffer where RPC reply returns.

- str *module - string containing module name.

- str *function - string containing function name.

- ei_x_buff *args - dynamic ei buffer with encoded arguments.

### `reg_send(server, msg)`

This function sends an Erlang term to a registered process. On success return 0.

Meaning of parameters is as follows:

- str *server - string containing registered name of the intended recipient process on remote node.

- ei_x_buff *msg - dynamic ei buffer with encoded erlang term. The msg must be encoded with version byte.

### `send(pid, msg)`

This function sends an Erlang term to a process. On success return 0.

Meaning of parameters is as follows:

- erlang_pid *pid - pid of the intended recipient process on remote node.

- ei_x_buff *msg - dynamic ei buffer with encoded erlang term. The msg must be encoded with version byte.

### `reply(msg)`

Function to send reply on processed message.

Meaning of parameters is as follows:

- ei_x_buff *msg - dynamic ei buffer with encoded erlang term.

### `xavp2xbuff(xbuff, xavp)`

Function encodes XAVP variable into ei dynamic buffer. How to create XAVP variable see source code.

Meaning of parameters is as follows:

- ei_x_buff *xbuff - dynamic ei buffer where XAVP variable will be encoded.

- sr_xavp_t *xavp - XAVP variable to be encoded.

### `xbuff2xavp(xavp, xbuff)`

Function decodes ei dynamic buffer into XAVP variable.

Meaning of parameters is as follows:

- sr_xavp_t **xavp - XAVP variable where ei buffer will be decoded.

- ei_x_buff *xbuff - dynamic ei buffer.

### Example of using API

    /* note: new without version byte */
    ei_x_new(&ei_req);

    /* ei_x_buff <- XAVP */
    if (erl_api.xavp2xbuff(&ei_req,xreq)) {
    	LM_ERR("failed to encode\n");
    	ei_x_free(&ei_req);
    	return -1;
    }

    memset((void*)&ei_rep,0,sizeof(ei_x_buff));

    erl_api.rpc(&ei_rep,&module,&function,&ei_req);
    ...

    /* must be XAVP */
    xrepl->val.type = SR_XTYPE_XAVP;

    /* XAVP <- ei_x_buff */
    if (erl_api.xbuff2xavp(&xrepl->val.v.xavp,&ei_rep)){
    	LM_ERR("failed to decode\n");
    	ei_x_free(&ei_req);
    	ei_x_free(&ei_rep);
    	return -1;
    }