Skip to content

Inter-module Communications

The SDK has functionality to allow different modules to communicate via exported functions. To achieve that, one module has to export functions, while another has to import the functions from the exporter.

Note

Modules can both export functions, as well as import functions from another module.

Exporting Functions

For a module to export functions, it must define them in the file module_defs.m4d (at the root of the module directory, e.g: <SDK root>/custom/module/<module name>/module_defs.m4d).

The format to export a function is as follows:

define_external_function(
    `output_data',
    `bool',
    `char *data')

Note

  • The opening and closing quotes are different.
  • There must be a newline after the closing parenthesis.
  • The name of the function is the first parameter.
  • The return value of the function is the second parameter.
  • Any parameters passed to the function come third and later.

At compile time, the SDK takes the definitions from module_defs.m4d and creates the function prototypes in a file named <module name>_module_defs.h. For the case above, the exporting module will need to have the following code:

#include "<module name>_module_defs.h"

bool output_data(char *data)
{
  TLOG(TLOG_SEVERITY_LEVEL__INFORMATIONAL, "Sent: %s", data);
  return true;
}

Importing Functions

For the module that will be importing functions to call, it must first include the file generated by the SDK named &lt;module name&gt;_module_libs.h. Then, it must populate a pointer named g_&lt;module name&gt;ExternalFunctionEntry_pointer using the ltrx_module_functions_lookup() API. It can then call the functions directly.

If in the example above, the exporting module is named output_tlog, then the importing module will need the following:

#include "output_tlog_module_libs.h"

const struct output_tlog_external_functions *g_output_tlogExternalFunctionEntry_pointer;

g_output_tlogExternalFunctionEntry_pointer = ltrx_module_functions_lookup("output_tlog");

if (g_output_tlogExternalFunctionEntry_pointer == 0)
{
  TLOG(TLOG_SEVERITY_LEVEL__INFORMATIONAL, "Error loading module");
}

Data can be sent by using the following:

output_data(buf);