OONF Plugin Lifecycle

From OLSR.org Wiki
Jump to: navigation, search

An OONF Plugin definition contains multiple (optional callbacks) that are triggered during different phases of the application life.

The oonf_subsystem plugin definition contains the following callbacks:

  • init
  • initiate_shutdown
  • cleanup
  • early_cfg_init

The cfg_schema_section configuration definition contains two more callbacks:

  • cb_validate
  • cb_delta_handler

The callbacks will be explained in the order they are called by the applications main code.

early_cfg_init

early_cfg_init is the first callback that will be called. This one is triggered even before any subsystem is initialized and before the configuration is parsed, the plugin should NOT call other plugins at this place.

The callback allows the plugin to modify its configuration definition. The Link Config Plugin uses this callback to automatically create configuration entries for existing OONF Layer2 Plugin values.

The callback can also be used to store the logging handler of the subsystem in a different variable. This is used by the NHDP Plugin to allow access from other source files to this variable. Most plugins can directly access the field of the subsystem definition.

This callback is called in dependency order, which means that plugins can assume that the callback was already called for their dependencies.

init

init is the constructor of the plugin. It is called when the plugin should initialize its static resources that do NOT depend on configuration. At this time all dependencies of the plugin are already initialized, so they can be used in this callback.

This callback is called in dependency order, which means that plugins can assume that the callback was already called for their dependencies.

cb_validate

cb_validate can be used to check the consistency of a whole configuration section. The plugin should NOT act on this configuration, it should just check and output an error if necessary.

This callback is called once per configuration section definition, the plugin should not assume a certain order.

cb_delta_handler

cb_delta_handler announces that all plugins have been initialized and the application is now within the main loop.

It is called once at the beginning of the main loop and once for each runtime configuration change of the user.

The plugin should allocate all resources that depend on the configuration settings here. Because configuration changes can happen at any time the plugin should be prepared to change its configuration based on the old settings instead of just allocating new resources.

This callback is called once per reconfiguration and once at the start of the application, the plugin should not assume a specific order.

initiate_shutdown

initiate_shutdown is a warning to the plugin that the application will end very soon. For a few hundred milliseconds the plugin can still use the functionality of all dependencies.

This callback is used by the OLSRv2 Plugin to tell the operation system to remove all existing routes while it still can use the socket scheduler to parse the results.

This callback is called in reverse dependency order, which means that plugins can assume that the callback will be called later for their dependencies.

cleanup

cleanup is the last callback triggered by the applications main code. It tells the plugin to free all allocated resources.

This callback is called in reverse dependency order, which means that plugins can assume that the callback will be called later for their dependencies.