Elektra  0.9.4
Deferred Plugin Calls

Calling exported functions is a primary way for coordinating plugins in Elektra. Since some plugins encapsulate other plugins, exported functions from encapsulated plugins become unavailable.

Since encapsulating plugins cannot implement and forward calls for every function exported by encapsulated plugins a generic mechanism for function calls to these encapsulated plugins is needed.

Since some plugins also lazy-load encapsulated plugins the call mechanism is required to be able to defer these calls until the plugins are loaded.

For example when setting I/O bindings with elektraIoSetBinding() the exported function setIoBinding is called for all globally mounted plugins. Since global mounting is implemented using the "list" plugin which uses lazy-loading for its plugins the exported functions from the plugins are unavailable.

Other examples are the "dini" and "multifile" plugins which use multiple plugins to support different file formats. These plugins also "hide" functions exported by encapsulated plugins.

  1. Plugins encapsulating other plugins shall be able to lazy-load them.
  2. Callers shall not be entangled in encapsulating plugin details.
  3. The encapsulation of the plugins shall not be broken.
  4. The mechanism shall be generic.
  1. The called functions do not return a value (e.g. set, open, close, ...). Callbacks can be used as return channel (see "Implications")

Encapsulating plugins export a function called deferredCall with the declaration void elektraDeferredCall (Plugin * plugin, char * name, KeySet * parameters). Encapsulating plugins shall save multiple deferred calls and call the exported functions specified by name passing the parameters KeySet when a plugin is initialized in the same order as received.

Plugins that support deferred calls shall have the following declaration for their functions void somePluginFunction (Plugin * plugin, KeySet * parameters). The calling developer is responsible for ensuring that the called functions have a compatible declaration. Encapsulated plugins that do not export a specified function name are omitted.

The solution allows to change encapsulating plugin implementations without breaking callers.

The called function receive their parameters via a KeySet.

While called functions could return data using the parameters KeySet (or a separate KeySet) there is no defined moment when the data can be collected. Defining such a moment would break the lazy-loading constraint. It is recommended to use callbacks passed as parameters. Callback function declarations are not limited by this decision.

Utility functions that help with managing deferred calls would be nice: