libamxrt
0.4.2
Ambiorix Run Time Library
|
Functions | |
amxc_var_t * | amxrt_get_config (void) |
Gets the htable variant containing the configuration options. More... | |
amxo_parser_t * | amxrt_get_parser (void) |
Gets runtime odl parser. More... | |
amxd_dm_t * | amxrt_get_dm (void) |
Gets the runtime data model storage. More... | |
void | amxrt_new (void) |
Create the ambiorix runtime. More... | |
int | amxrt (int argc, char *argv[], amxrt_arg_fn_t fn) |
This function can create full ambiorix application (data model provider or client). More... | |
int | amxrt_init (int argc, char *argv[], amxrt_arg_fn_t fn) |
Initializes the ambiorix runtime. More... | |
int | amxrt_register_or_wait (void) |
Register the data model or wait for required data model objects. More... | |
int | amxrt_run (void) |
Starts the event loop. More... | |
void | amxrt_stop (void) |
Stops the runtime. More... | |
void | amxrt_delete (void) |
Clean-up ambiorix runtime. More... | |
int | amxrt_load_odl_files (int argc, char *argv[], int index) |
Load odls files mentioned on the command line or the default odl file. More... | |
int | amxrt_connect (void) |
Connects to all bus sockets. More... | |
void | amxrt_enable_syssigs (amxc_var_t *syssigs) |
Enables system signals that should be monitored by the eventloop. More... | |
int | amxrt_config_init (int argc, char *argv[], int *index, amxrt_arg_fn_t fn) |
Initializes the default runtime configuration. More... | |
void | amxrt_config_scan_backend_dirs (void) |
Scan backend directories for available backends. More... | |
void | amxrt_config_read_env_var (const char *var_name, const char *config_name, int32_t var_type) |
Helper function to read an environment variable and add it's value to the runtime configuration. More... | |
int | amxrt_dm_save_load_main (int reason, amxd_dm_t *dm, amxo_parser_t *parser) |
The data model auto load and save module. More... | |
The ambiorix runtime library can be used to easily create a stand-alone data model provider application or data model client.
The runtime library provides:
The simplest possible way to use this library is in this example code:
The above example can also be written as follows:
This gives you to possibility to perform other tasks in between.
int amxrt | ( | int | argc, |
char * | argv[], | ||
amxrt_arg_fn_t | fn | ||
) |
This function can create full ambiorix application (data model provider or client).
Typically this function is called from your main. Optionally a command line option handler can be added.
This function will create and start the event loop, and therefor will only return when the event loop has stopped. The event loop can be stopped by calling amxrt_el_stop. Typically this is done from within an event handler.
By default following signals are being monitored and handled:
This function will call the following function (in this order):
Example of usage:
argc | the number of arguments available |
argv | the vector containing the commandline arguments |
fn | (optional) a pointer to a callback function to handle the option or NULL |
Definition at line 334 of file amxrt.c.
int amxrt_config_init | ( | int | argc, |
char * | argv[], | ||
int * | index, | ||
amxrt_arg_fn_t | fn | ||
) |
Initializes the default runtime configuration.
Sets the default values for all default configuration options.
Also uses the command line option parser and if needed adapts the configuration accordingly.
argc | the number of arguments available |
argv | the vector containing the commandline arguments |
index | pointer to an integer, will be set to the first command line argument that is not an option. |
fn | (optional) a pointer to a callback function to handle the option or NULL |
Definition at line 217 of file amxrt_config.c.
void amxrt_config_read_env_var | ( | const char * | var_name, |
const char * | config_name, | ||
int32_t | var_type | ||
) |
Helper function to read an environment variable and add it's value to the runtime configuration.
As envrionment variables values can only be fetched as strings, a type must be provided to which the value must be converted. The value will be stored using this type in the runtime configuration.
var_name | The environment variable name. |
config_name | The runtime configuration option name |
var_type | The variant type, this is the type how the value will be stored |
Definition at line 264 of file amxrt_config.c.
void amxrt_config_scan_backend_dirs | ( | void | ) |
Scan backend directories for available backends.
When auto-detection (configuration option "auto-detect") is enabled, all directories in the configuration option "backend-dir" are scanned for valid shared object files. Each found shared object file is added to the list of possible backends that can be used.
When auto-detection is disabled this function will do nothing.
Definition at line 246 of file amxrt_config.c.
int amxrt_connect | ( | void | ) |
Connects to all bus sockets.
When auto-detect is enabled the ambiorix runtime will check if the well known linux domain bus sockets exists and they will be added to the "uris" config.
Using command line option "-u" extra sockets can be added. It is also possible to define the sockets that needs to be opened in the config section of an odl file.
The supported config options are:
Definition at line 488 of file amxrt.c.
void amxrt_delete | ( | void | ) |
Clean-up ambiorix runtime.
All open sockets will be closed and all loaded backends will be unloaded.
This function is typically called just before the application exits.
Definition at line 378 of file amxrt.c.
int amxrt_dm_save_load_main | ( | int | reason, |
amxd_dm_t * | dm, | ||
amxo_parser_t * | parser | ||
) |
The data model auto load and save module.
The ambiorix runtime library embeds a module that can be used to automatically load and save the data model.
To make use of this module, it's entry point must be registered. Registering of the entry point can be done by calling amxo_parser_add_entry_point.
Example:
This function will be called when the entry points are invoked. See amxrt_register_or_wait and amxrt_stop.
This module needs configuration, see the readme for more information
reason | the reason why the entry point is called. |
dm | the data model pointer |
parser | the odl parser |
Definition at line 457 of file amxrt_save_load.c.
void amxrt_enable_syssigs | ( | amxc_var_t * | syssigs | ) |
Enables system signals that should be monitored by the eventloop.
The default implementation of the event loop will only monitor
If other signals needs to be monitored, a list variant must be created, containing the identifiers of the signals and passed to this function.
syssigs | list variant containing the signal identifiers. |
Definition at line 516 of file amxrt.c.
amxc_var_t* amxrt_get_config | ( | void | ) |
amxd_dm_t* amxrt_get_dm | ( | void | ) |
amxo_parser_t* amxrt_get_parser | ( | void | ) |
Gets runtime odl parser.
To manually read the odl files using the parser use any of the libamxo functions.
Example:
int amxrt_init | ( | int | argc, |
char * | argv[], | ||
amxrt_arg_fn_t | fn | ||
) |
Initializes the ambiorix runtime.
This function will:
The odl file files that are loaded can be passed as command line arguments after the command line options. If no odls are provided at command line the runtime will try to load the default odl file for the application, using the applications name (argv[0]). The default that it will try to load is "/etc/amx/<appname>/<appname>.odl". If no odl files are provided and the default doesn't exist, this function will continue without an error.
The (bus) back-ends loaded can be specified using command line option -B or added in one of the odl files in the config section with config name "backends", which must be a list of backend shared objects that must be loaded. If auto-detection is turned on (this is the default), all shared objects that are valid ambiorix back-ends will be loaded from the back-end directory (by default this is "/usr/bin/mods/amxb"). The default back-end directory can be changed in a odl file config section with config name "backend-dir" or on the command line with "-o backend-dir=<thedir>".
The sockets that the run-time needs to connect to can be specified with commandline option -u or in an odl config section with config name "uris" or "data-uris", both configuration settings must be a list of uris. The difference between uris and data-uris is that when the application has a data model available it will only be registered using the sockets that are mentioned in the "uris".
argc | the number of arguments available |
argv | the vector containing the commandline arguments |
fn | (optional) a pointer to a callback function to handle the option or NULL |
Definition at line 348 of file amxrt.c.
int amxrt_load_odl_files | ( | int | argc, |
char * | argv[], | ||
int | index | ||
) |
Load odls files mentioned on the command line or the default odl file.
By default odl files can be specified after the command line options. This function will load these odl files.
If no odl files are specified at the command line, the default odl file will be loaded. The application name (Argv[0]) will be used to find the default odl file.
The default odl file is "/etc/amx/<appname>/<appname>.odl".
If no odl files are defined at the commandline and the default odl file does't exist, nothing is loaded an no error is thrown.
This function will also scan the default mib dir for the application. If a mib dir is available and contains mib definitions, these are not loaded by default. Mib definitions will be loaded when needed.
argc | the number of arguments available |
argv | the vector containing the commandline arguments |
index | should be set to the first command line that is not an option |
Definition at line 466 of file amxrt.c.
void amxrt_new | ( | void | ) |
Create the ambiorix runtime.
This function must be called before any other amxrt function.
This function creates:
This function is typically called as first in the main.
When done with the ambiorix run time, call amxrt_delete
Definition at line 313 of file amxrt.c.
int amxrt_register_or_wait | ( | void | ) |
Register the data model or wait for required data model objects.
When the application has a data model available, it can be registered using this function. As soon as the data model is registered, the application becomes a data model provider.
If required objects are defined (using odl files with "requires" or using command line option -R), then this function will wait until these objects become available on the used bus systems before registering the data model.
The wait can only be fulfilled when an eventloop is running, as it needs event handling.
When registering of the data model succeeded, the entry-points of the loaded modules/plugins are called with reason AMXO_START (0).
Definition at line 389 of file amxrt.c.
int amxrt_run | ( | void | ) |
Starts the event loop.
This function just calls amxrt_el_start. This function returns when the event loop is stopped or when starting the event loop fails.
Definition at line 425 of file amxrt.c.
void amxrt_stop | ( | void | ) |
Stops the runtime.
Only call this function when the event loop has stopped, never call this method in event handlers. Call amxrt_el_stop instead and call this function after the call that starts the event loop.
This function will teardown the ambiorix runtime:
This function is typically called when the event loop is stopped and the application is going to be closed.
Definition at line 440 of file amxrt.c.