libamxrt  0.4.2
Ambiorix Run Time Library
Runtime

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...
 

Detailed Description

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:

#include <amxrt/amxrt.h>
int main(in argc, char* argv[]) {
int retval = 0;
retval = amxrt(argc, argv, NULL);
return retval;
}
int amxrt(int argc, char *argv[], amxrt_arg_fn_t fn)
This function can create full ambiorix application (data model provider or client).
Definition: amxrt.c:334
void amxrt_delete(void)
Clean-up ambiorix runtime.
Definition: amxrt.c:378
void amxrt_new(void)
Create the ambiorix runtime.
Definition: amxrt.c:313
int main(void)
Definition: test_main.c:62

The above example can also be written as follows:

#include <amxrt/amxrt.h>
int main(in argc, char* argv[]) {
int retval = 0;
retval = amxrt_init(argc, argv, fn);
when_failed(retval, leave);
when_failed(retval, leave);
retval = amxrt_run();
leave:
return retval;
}
int amxrt_init(int argc, char *argv[], amxrt_arg_fn_t fn)
Initializes the ambiorix runtime.
Definition: amxrt.c:348
int amxrt_run(void)
Starts the event loop.
Definition: amxrt.c:425
void amxrt_stop(void)
Stops the runtime.
Definition: amxrt.c:440
int amxrt_register_or_wait(void)
Register the data model or wait for required data model objects.
Definition: amxrt.c:389

This gives you to possibility to perform other tasks in between.

Function Documentation

◆ amxrt()

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:

  • SIGINT - when triggered the eventloop is stopped
  • SIGTERM - when triggered the eventloop is stopped
  • SIGALRM - used for ambiorix timers (amxp_timer_t)
Note
When using this function an odl file must be loaded (can be an empty one or an odl file that only contains configuration). If no odl file was loaded this function will return with an error.

This function will call the following function (in this order):

Example of usage:

#include <stdio.h>
#include <amxrt/amxrt.h>
static int amxrt_handle_cmd_line_arg(amxc_var_t* config,
int arg_id,
UNUSED const char* value) {
int rv = -1;
const char* name = GET_CHAR(amxrt_get_config(), "name");
switch(arg_id) {
case 'V': {
printf("%s %d.%d.%d\n", name, 1, 2, 3);
}
break;
default:
rv = -2;
break;
}
return rv;
}
int main(int argc, char* argv[]) {
int retval = 0;
amxrt_cmd_line_add_option(0, 'V', "version", no_argument, "Print version", NULL);
retval = amxrt(argc, argv, amxrt_handle_cmd_line_arg);
return retval;
}
int amxrt_cmd_line_add_option(int id, char short_option, const char *long_option, int has_args, const char *doc, const char *arg_doc)
Adds a command line option definition.
Definition: amxrt_args.c:206
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
Definition: amxrt.c:301
config
Definition: test.odl:54
Parameters
argcthe number of arguments available
argvthe vector containing the commandline arguments
fn(optional) a pointer to a callback function to handle the option or NULL
Returns
Non zero indicates an error, 0 will indicate that the event loop has stopped without any error.

Definition at line 334 of file amxrt.c.

334  {
335  int retval = 0;
336 
337  retval = amxrt_init(argc, argv, fn);
338  when_failed(retval, leave);
339  retval = amxrt_register_or_wait();
340  when_failed(retval, leave);
341  retval = amxrt_run();
342 
343 leave:
344  amxrt_stop();
345  return retval;
346 }

◆ amxrt_config_init()

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.

Parameters
argcthe number of arguments available
argvthe vector containing the commandline arguments
indexpointer 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
Returns
returns 0 if no error occured.

Definition at line 217 of file amxrt_config.c.

217  {
218  int retval = 0;
219  char* base_name = NULL;
220  amxo_parser_t* parser = amxrt_get_parser();
221 
223 
225 
226  base_name = strdup(basename(argv[0]));
227  when_null_status(base_name, exit, retval = -1);
228  for(int i = strlen(base_name) - 1; i > 0; i--) {
229  if(base_name[i] == '.') {
230  base_name[i] = 0;
231  }
232  }
233  amxc_var_add_key(cstring_t, &parser->config, AMXRT_COPT_NAME, base_name);
234 
235  *index = amxrt_cmd_line_parse(argc, argv, fn);
236  if(*index < 0) {
237  retval = *index;
238  *index = argc;
239  }
240 
241 exit:
242  free(base_name);
243  return retval;
244 }
#define AMXRT_COPT_NAME
Definition: amxrt.h:85
static void amxrt_config_read_env_vars(void)
Definition: amxrt_config.c:67
static void amxrt_config_set_default_dirs(amxo_parser_t *parser)
Definition: amxrt_config.c:103
int amxrt_cmd_line_parse(int argc, char *argv[], amxrt_arg_fn_t fn)
Starts parsing the command line options.
Definition: amxrt_args.c:236
amxo_parser_t * amxrt_get_parser(void)
Gets runtime odl parser.
Definition: amxrt.c:305

◆ amxrt_config_read_env_var()

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.

Parameters
var_nameThe environment variable name.
config_nameThe runtime configuration option name
var_typeThe variant type, this is the type how the value will be stored

Definition at line 264 of file amxrt_config.c.

266  {
267  const char* env = getenv(var_name);
268  amxc_var_t* config = amxrt_get_config();
269  amxc_var_t* coption = GET_ARG(config, config_name);
270  amxc_var_t var_env;
271 
272  amxc_var_init(&var_env);
273 
274  if(env == NULL) {
275  goto exit;
276  }
277 
278  amxc_var_set(cstring_t, &var_env, env);
279 
280  if(coption == NULL) {
281  coption = amxc_var_add_new_key(config, config_name);
282  amxc_var_set_type(coption, var_type);
283  }
284 
285  switch(var_type) {
286  case AMXC_VAR_ID_LIST: {
287  amxc_string_t* str_env = amxc_var_take(amxc_string_t, &var_env);
288  amxc_llist_t parts;
289  amxc_llist_init(&parts);
290  amxc_string_split_to_llist(str_env, &parts, ';');
291  amxc_llist_for_each(it, (&parts)) {
292  amxc_string_t* part = amxc_string_from_llist_it(it);
293  amxc_var_add(cstring_t, coption, amxc_string_get(part, 0));
294  amxc_string_delete(&part);
295  }
296  amxc_llist_clean(&parts, amxc_string_list_it_free);
297  amxc_string_delete(&str_env);
298  }
299  break;
300  default: {
301  amxc_var_convert(coption, &var_env, var_type);
302  }
303  break;
304  }
305 
306 exit:
307  amxc_var_clean(&var_env);
308  return;
309 }

◆ amxrt_config_scan_backend_dirs()

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.

246  {
247  amxo_parser_t* parser = amxrt_get_parser();
248 
249  if(amxc_var_constcast(bool, GET_ARG(&parser->config, AMXRT_COPT_AUTO_DETECT))) {
250  amxc_var_t* backends = GET_ARG(&parser->config, AMXRT_COPT_BACKENDS);
251  amxc_var_t* dirs = GET_ARG(&parser->config, AMXRT_COPT_BACKENDS_DIR);
252  if(amxc_var_type_of(dirs) == AMXC_VAR_ID_LIST) {
253  amxc_var_for_each(dir, dirs) {
254  const char* path = GET_CHAR(dir, NULL);
255  amxp_dir_scan(path, "d_name matches '.*\\.so'", false, amxrt_config_add_backend, backends);
256  }
257  } else {
258  const char* path = GET_CHAR(&parser->config, AMXRT_COPT_BACKENDS_DIR);
259  amxp_dir_scan(path, "d_name matches '.*\\.so'", false, amxrt_config_add_backend, backends);
260  }
261  }
262 }
#define AMXRT_COPT_BACKENDS
Definition: amxrt.h:75
#define AMXRT_COPT_AUTO_DETECT
Definition: amxrt.h:76
#define AMXRT_COPT_BACKENDS_DIR
Definition: amxrt.h:93
static int amxrt_config_add_backend(const char *name, void *priv)
Definition: amxrt_config.c:122

◆ amxrt_connect()

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:

  • "uris" - used to connect on and register the data model of the application
  • "data-uris" - used to connect on, but the data model is not registered on these sockets. " "listen" - creates a listening socket, other applications can connect on these.
Returns
Non zero indicates an error

Definition at line 488 of file amxrt.c.

488  {
489  int retval = 0;
490 
491  retval = amxrt_connection_load_backends(&rt.parser.config);
492  when_failed(retval, leave);
493 
495 
496  // Daemonize before opening sockets
497  // Some bus systems requires this.
498  // Daemonizing (going to background) changes process id, sometimes the process id
499  // is used in the initial handshake
500  if(amxc_var_constcast(bool, GET_ARG(&rt.parser.config, AMXRT_COPT_DAEMON))) {
501  retval = daemon(1, 0);
502  when_failed(retval, leave);
503  }
504 
506  when_failed(retval, leave);
508  when_failed(retval, leave);
510  when_failed(retval, leave);
511 
512 leave:
513  return retval;
514 }
static amxrt_t rt
Definition: amxrt.c:74
static int amxrt_apply_process_settings(amxo_parser_t *parser)
Definition: amxrt.c:209
#define AMXRT_COPT_DAEMON
Definition: amxrt.h:82
PRIVATE int amxrt_connection_connect_all(amxo_parser_t *parser)
PRIVATE int amxrt_connection_load_backends(amxc_var_t *config)
PRIVATE void amxrt_connection_detect_sockets(amxc_var_t *config)
PRIVATE int amxrt_connection_listen_all(amxo_parser_t *parser)
amxo_parser_t parser
Definition: amxrt_priv.h:101

◆ amxrt_delete()

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.

378  {
379  amxd_dm_clean(&rt.dm);
380  amxo_resolver_import_close_all();
381  amxb_be_remove_all();
382 
384  amxc_var_clean(&rt.forced_options);
385 
386  amxo_parser_clean(&rt.parser);
387 }
void amxrt_cmd_line_options_reset(void)
Removes all default options.
Definition: amxrt_args.c:200
amxd_dm_t dm
Definition: amxrt_priv.h:100
amxc_var_t forced_options
Definition: amxrt_priv.h:103

◆ amxrt_dm_save_load_main()

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.

Note
This function should not be called directly.

Example:

amxo_parser_t* parser = amxrt_get_parser();
amxo_parser_add_entry_point(parser, amxrt_dm_save_load_main);
int amxrt_dm_save_load_main(int reason, amxd_dm_t *dm, amxo_parser_t *parser)
The data model auto load and save module.

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

Parameters
reasonthe reason why the entry point is called.
dmthe data model pointer
parserthe odl parser
Returns
returns 0 if no error occured.

Definition at line 457 of file amxrt_save_load.c.

457  {
458  int retval = 0;
459 
460  when_false(amxrt_is_odl_storage_enabled(parser), exit);
461 
462  switch(reason) {
463  case 0: // START
464  retval = amxrt_odl_save_load_init(dm, parser);
465  break;
466  case 1: // STOP
467  amxrt_odl_save_load_cleanup(dm, parser);
468  break;
469  }
470 
471 exit:
472  return retval;
473 }
static int amxrt_odl_save_load_init(amxd_dm_t *dm, amxo_parser_t *parser)
static bool amxrt_is_odl_storage_enabled(amxo_parser_t *parser)
static void amxrt_odl_save_load_cleanup(amxd_dm_t *dm, amxo_parser_t *parser)

◆ amxrt_enable_syssigs()

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

  • SIGINT - when triggered the eventloop is stopped
  • SIGTERM - when triggered the eventloop is stopped
  • SIGALRM - used for ambiorix timers (amxp_timer_t)

If other signals needs to be monitored, a list variant must be created, containing the identifiers of the signals and passed to this function.

Parameters
syssigslist variant containing the signal identifiers.

Definition at line 516 of file amxrt.c.

516  {
517  if(amxc_var_type_of(syssigs) == AMXC_VAR_ID_LIST) {
518  amxc_var_for_each(var, syssigs) {
519  uint32_t sigid = amxc_var_dyncast(uint32_t, var);
520  if((sigid != 0) &&
521  ( sigid != SIGALRM) &&
522  ( sigid != SIGTERM) &&
523  ( sigid != SIGINT)) {
524  amxp_syssig_enable(sigid, true);
525  }
526  }
527  } else {
528  uint32_t sigid = amxc_var_dyncast(uint32_t, syssigs);
529  if((sigid != 0) &&
530  ( sigid != SIGALRM) &&
531  ( sigid != SIGTERM) &&
532  ( sigid != SIGINT)) {
533  amxp_syssig_enable(sigid, true);
534  }
535  }
536 }

◆ amxrt_get_config()

amxc_var_t* amxrt_get_config ( void  )

Gets the htable variant containing the configuration options.

Returns
The htable variant containing the configuration options.

Definition at line 301 of file amxrt.c.

301  {
302  return &rt.parser.config;
303 }

◆ amxrt_get_dm()

amxd_dm_t* amxrt_get_dm ( void  )

Gets the runtime data model storage.

Returns
The amxd_dm_t pointer where the data model is stored.

Definition at line 309 of file amxrt.c.

309  {
310  return &rt.dm;
311 }

◆ amxrt_get_parser()

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:

amxo_parser_t* odl_parser = amxrt_get_parser();
amxd_dm_t* dm = amxrt_get_dm();
amxd_object_t* root = amxd_dm_get_root(dm);
amxo_parser_parse_file(parser, "/tmp/my_definition.odl", root);
amxd_dm_t * amxrt_get_dm(void)
Gets the runtime data model storage.
Definition: amxrt.c:309
Returns
The runtime odl parser.

Definition at line 305 of file amxrt.c.

305  {
306  return &rt.parser;
307 }

◆ amxrt_init()

int amxrt_init ( int  argc,
char *  argv[],
amxrt_arg_fn_t  fn 
)

Initializes the ambiorix runtime.

This function will:

  1. parse the command line options
  2. set the default ambiorix config options
  3. load the odl files (if any)
  4. add the automatic load and save modules entrypoint amxo_parser_add_entry_point
  5. load the ambiorix back-ends
  6. connects to all sockets
  7. enable all system signals that needs to be monitored
  8. create an event loop

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".

Parameters
argcthe number of arguments available
argvthe vector containing the commandline arguments
fn(optional) a pointer to a callback function to handle the option or NULL
Returns
Non zero indicates an error

Definition at line 348 of file amxrt.c.

348  {
349  int retval = 0;
350  int index = 0;
351  amxc_var_t* syssigs = NULL;
352  amxo_parser_t* parser = amxrt_get_parser();
353 
354  amxc_var_set_type(&rt.forced_options, AMXC_VAR_ID_HTABLE);
355  retval = amxrt_config_init(argc, argv, &index, fn);
356  when_failed_status(retval, leave, retval = 10);
357  retval = amxrt_load_odl_files(argc, argv, index);
358  when_failed_status(retval, leave, retval = 11);
360 
361  amxo_parser_add_entry_point(parser, amxrt_dm_save_load_main);
362 
363  retval = amxrt_connect();
364  when_failed_status(retval, leave, retval = 12);
365 
366  syssigs = GET_ARG(&rt.parser.config, "system-signals");
367  if(syssigs != NULL) {
368  amxrt_enable_syssigs(syssigs);
369  }
370 
371  retval = amxrt_el_create();
372  when_failed_status(retval, leave, retval = -13);
373 
374 leave:
375  return retval;
376 }
int amxrt_el_create(void)
Creates and initializes all needed event loop components.
void amxrt_config_scan_backend_dirs(void)
Scan backend directories for available backends.
Definition: amxrt_config.c:246
int amxrt_connect(void)
Connects to all bus sockets.
Definition: amxrt.c:488
int amxrt_load_odl_files(int argc, char *argv[], int index)
Load odls files mentioned on the command line or the default odl file.
Definition: amxrt.c:466
void amxrt_enable_syssigs(amxc_var_t *syssigs)
Enables system signals that should be monitored by the eventloop.
Definition: amxrt.c:516
int amxrt_config_init(int argc, char *argv[], int *index, amxrt_arg_fn_t fn)
Initializes the default runtime configuration.
Definition: amxrt_config.c:217

◆ amxrt_load_odl_files()

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.

Parameters
argcthe number of arguments available
argvthe vector containing the commandline arguments
indexshould be set to the first command line that is not an option
Returns
Non zero indicates an error

Definition at line 466 of file amxrt.c.

466  {
467  int retval = 0;
468  amxd_object_t* root = NULL;
469  bool dm_eventing_enabled = false;
470 
471  dm_eventing_enabled = GET_BOOL(&rt.parser.config, AMXRT_COPT_EVENT);
472  amxp_sigmngr_enable(&rt.dm.sigmngr, dm_eventing_enabled);
473  root = amxd_dm_get_root(&rt.dm);
474  retval = amxrt_parse_odl_string(&rt.parser, root);
475  when_failed(retval, leave);
476  retval = amxrt_parse_odl_files(&rt.parser, argc, argv, index, root);
477  when_failed(retval, leave);
478  retval = amxrt_parse_odl_extensions(&rt.parser, root);
479  when_failed(retval, leave);
480 
481  amxo_parser_scan_mib_dirs(&rt.parser, NULL);
482  amxp_sigmngr_enable(&rt.dm.sigmngr, true);
483 
484 leave:
485  return retval;
486 }
static int amxrt_parse_odl_extensions(amxo_parser_t *parser, amxd_object_t *root)
Definition: amxrt.c:98
static int amxrt_parse_odl_string(amxo_parser_t *parser, amxd_object_t *root)
Definition: amxrt.c:82
static int amxrt_parse_odl_files(amxo_parser_t *parser, int argc, char *argv[], int index, amxd_object_t *root)
Definition: amxrt.c:142
#define AMXRT_COPT_EVENT
Definition: amxrt.h:90

◆ amxrt_new()

void amxrt_new ( void  )

Create the ambiorix runtime.

This function must be called before any other amxrt function.

This function creates:

  • an odl parser, can be fetched using amxrt_get_parser
  • a data model, can be fetched using amxrt_get_datamodel
  • an empty config, can be fetched using amxrt_get_config

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.

313  {
314  amxd_dm_init(&rt.dm);
315  amxo_parser_init(&rt.parser);
316  amxc_llist_init(&rt.event_sources);
317  amxc_llist_init(&rt.cmd_line_args);
318  rt.usage_doc = "[OPTIONS] <odl files>";
319 
320  // command line options given with -F are stored here and can not be overwritten
321  // by odl config section options
322  amxc_var_init(&rt.forced_options);
323  amxc_var_set_type(&rt.forced_options, AMXC_VAR_ID_HTABLE);
324 
326 
327  amxp_sigmngr_add_signal(NULL, "config:changed");
328  amxp_sigmngr_add_signal(NULL, "wait:done");
329  amxp_sigmngr_add_signal(NULL, "wait:cancel");
330 
332 }
PRIVATE void amxrt_cmd_line_add_default_options(void)
Definition: amxrt_args.c:178
PRIVATE void amxrt_config_add_options(amxo_parser_t *parser)
Definition: amxrt_config.c:183
amxc_llist_t cmd_line_args
Definition: amxrt_priv.h:102
amxc_llist_t event_sources
Definition: amxrt_priv.h:104
const char * usage_doc
Definition: amxrt_priv.h:105

◆ amxrt_register_or_wait()

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).

Returns
Non zero indicates an error

Definition at line 389 of file amxrt.c.

389  {
390  int retval = 0;
391  amxc_var_t* req = NULL;
392  const amxc_llist_t* lreq = NULL;
393 
394  req = GET_ARG(&rt.parser.config, AMXRT_COPT_REQUIRES);
395  lreq = amxc_var_constcast(amxc_llist_t, req);
396 
397  if((lreq == NULL) || amxc_llist_is_empty(lreq)) {
398  retval = amxrt_register(&rt.parser, &rt.dm);
399  when_failed_status(retval, leave, retval = -14);
401  } else {
402  if(GET_BOOL(&rt.parser.config, AMXRT_COPT_SUSPEND)) {
403  amxp_sigmngr_suspend(&rt.dm.sigmngr);
404  }
405  amxp_slot_connect(NULL, "wait:done", NULL, amxrt_wait_done, NULL);
406  amxc_var_for_each(path, req) {
407  const char* txt_path = GET_CHAR(path, NULL);
408  if(amxd_dm_findf(&rt.dm, "%s", txt_path) == NULL) {
409  amxrt_print_message("RunTime - Waiting for required object '%s'", txt_path);
410  retval = amxb_wait_for_object(txt_path);
411  if(retval != AMXB_STATUS_OK) {
412  amxrt_print_error("RunTime - Waiting failed for object '%s'", txt_path);
413  break;
414  }
415  }
416  }
417  }
418 
419  when_failed_status(retval, leave, retval = -14);
420 
421 leave:
422  return retval;
423 }
static int amxrt_register(amxo_parser_t *parser, amxd_dm_t *dm)
Definition: amxrt.c:238
static void amxrt_handle_events(amxd_dm_t *dm, amxo_parser_t *parser)
Definition: amxrt.c:264
static void amxrt_wait_done(UNUSED const char *const s, UNUSED const amxc_var_t *const d, UNUSED void *const p)
Definition: amxrt.c:274
#define AMXRT_COPT_SUSPEND
Definition: amxrt.h:101
#define AMXRT_COPT_REQUIRES
Definition: amxrt.h:99
PRIVATE void amxrt_print_message(const char *fmt,...)
PRIVATE void amxrt_print_error(const char *fmt,...)

◆ amxrt_run()

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.

Returns
0 when the event loop stopped, any other value indicates that starting the event loop failed.

Definition at line 425 of file amxrt.c.

425  {
426  int retval = 0;
427 
428  if(GET_BOOL(&rt.parser.config, AMXRT_COPT_DUMP_CONFIG)) {
430  }
431  if(GET_BOOL(&rt.parser.config, AMXRT_COPT_DUMP_CAPS)) {
432  amxrt_caps_dump();
433  }
434 
435  amxrt_el_start();
436 
437  return retval;
438 }
#define AMXRT_COPT_DUMP_CONFIG
Definition: amxrt.h:91
#define AMXRT_COPT_DUMP_CAPS
Definition: amxrt.h:92
PRIVATE void amxrt_print_configuration(void)
int amxrt_el_start(void)
Starts the event loop.
void amxrt_caps_dump(void)
Dumps the capabilities of the process.
Definition: amxrt_cap.c:180

◆ amxrt_stop()

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:

  1. destroys the event loop
  2. call the entry points of loaded modules/plugins in reverse order with reason AMXO_STOP
  3. resets the backend configurations
  4. removes the pid file.
  5. closes the syslog (if it was opened)

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.

440  {
441  amxo_parser_t* parser = amxrt_get_parser();
442  amxd_dm_t* dm = amxrt_get_dm();
443  char* name = amxc_var_dyncast(cstring_t, GET_ARG(&parser->config, AMXRT_COPT_NAME));
444  amxc_var_t* req = GET_ARG(&parser->config, AMXRT_COPT_REQUIRES);
445 
447 
448  amxo_parser_stop_synchronize(parser);
449 
450  if((req == NULL) || amxc_llist_is_empty(amxc_var_constcast(amxc_llist_t, req))) {
451  amxo_parser_rinvoke_entry_points(parser, dm, AMXO_STOP);
452  }
453 
454  amxb_set_config(NULL);
455 
456  amxrt_remove_pid_file(name);
457 
458  if(GET_BOOL(&parser->config, AMXRT_COPT_LOG) &&
459  ( GET_CHAR(&parser->config, AMXRT_COPT_NAME) != NULL)) {
460  closelog();
461  }
462 
463  free(name);
464 }
static void amxrt_remove_pid_file(const char *name)
Definition: amxrt.c:192
#define AMXRT_COPT_LOG
Definition: amxrt.h:98
int amxrt_el_destroy(void)
Cleans-up the event loop components.