dmi_module_register

Synopsis

#include <opendmi/module.h>

bool dmi_module_register(dmi_module_t *module);

Description

The dmi_module_register function makes an extension module of a program available along with the built-in ones, so that a program brings structure types of its own. A registered module is found by dmi_module_find, listed by dmi_module_next after the built-in ones, in the order of registration, and enabled the same way as they are: with dmi_add_extension, or for the platforms it lists as a context is opened, see dmi_module_find for the members of a module.

A module is registered once, and stays registered for as long as the program runs: there is no way to unregister it. The module is not copied, so it must stay valid for as long as the program runs. The library links the registered modules through their next member, which it sets, so a module is not constant.

Registration is not thread-safe, and belongs to the start of the program, before the contexts which use the module are created.

Parameters

module

Module to register, which must have a code.

Return value

Returns true if the module has been registered, and false if module is nullptr or has no code, or if an available module, either a built-in or a registered one, has the same code, in which case nothing is registered.

Errors

DMI_ERROR_ARGUMENT_NULL

Raised if module is nullptr, in which case it is not reported, since there is no context to hold it.

DMI_ERROR_ARGUMENT_INVALID

Raised if the code of module is nullptr, and not reported either.

A module whose code is taken is refused silently.

Example

static dmi_module_t example_module = {
    .code     = "example",
    .name     = "Example extensions",
    .entities = (const dmi_entity_spec_t *[]){
        &example_spec,
        nullptr
    }
};

if (!dmi_module_register(&example_module))
    return 1;