Modules

API for working with plugins.

mod_init() walks mod_search_path, loads every shared file, checks if it is
compliant with 'modapi' and runs mod_config() from it.

mod_fini() calls mod_unconfig() for each loaded module and unmaps them


Module states

                      +----------> CONFIG_ERROR
                         |
UNITIALIZED ---> UNCONFIGURED ---> READY ---> REQUEST_ERROR
                                    ^                |
                                    +----------------+

NOTES
Modules are not signed, so do not play with permissions to module path

Constants

MOD_TSLOAD, MOD_MONITOR


Module types

#define MOD_TSLOAD  1
#define MOD_MONITOR 2

MOD_ERROR, MOD_OK


Return values for mod_config() and mod_unconfig() functions

#define MOD_OK  0
#define MOD_ERROR   -1

Functions

mod_search, mod_error

public

LIBEXPORT module_t* mod_search(const char* name)
LIBEXPORT int mod_error(module_t* mod, char* fmtstr, ...)

mod_load_symbol

public

LIBEXPORT void* mod_load_symbol(module_t* mod, const char* name)

mod_get_first

public

LIBEXPORT module_t* mod_get_first()

plat_mod_open, plat_mod_load_symbol, plat_mod_close, plat_mod_error_msg

publicplat

LIBEXPORT PLATAPI int plat_mod_open(plat_mod_library_t* lib, const char* path)
LIBEXPORT PLATAPI int plat_mod_close(plat_mod_library_t* lib)
LIBEXPORT PLATAPI void* plat_mod_load_symbol(plat_mod_library_t* lib, const char* name)
LIBEXPORT PLATAPI char* plat_mod_error_msg(void)

mod_init, mod_fini

public

LIBEXPORT int mod_init(void)
LIBEXPORT void mod_fini(void)

DECLARE_MOD_NAME, DECLARE_MOD_TYPE, DECLARE_MODAPI_VERSION


Module head declarations

#define DECLARE_MODAPI_VERSION(version)
#define DECLARE_MOD_TYPE(type)
#define DECLARE_MOD_NAME(name)

mod_config_func


Prototype for mod_config() and mod_unconfig() functions

typedef int (* mod_config_func)(struct module* mod);

Types

typedef enum mod_status

typedef enum mod_status {
    MOD_UNITIALIZED,
    MOD_UNCONFIGURED,
    MOD_READY,
    MOD_CONFIG_ERROR,
    MOD_REQUEST_ERROR
} mod_status_t;

typedef struct module


Module main structure

MEMBERS

typedef struct module {
    char mod_path[MODPATHLEN];
    plat_mod_library_t mod_library;

    char* mod_name;

    mod_status_t mod_status;
    AUTOSTRING char* mod_status_msg;

    mod_config_func mod_config;
    mod_config_func mod_unconfig;

    void* mod_private;

    struct module* mod_next;
} module_t;