src/module.h
author Tero Marttila <terom@fixme.fi>
Wed, 01 Apr 2009 00:57:34 +0300
changeset 105 b6b183fbf373
parent 103 454aea1e4f11
child 108 50ff7ac8a725
permissions -rw-r--r--
implement a separate nexus_lua module
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef MODULE_H
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define MODULE_H
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 * @file
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 *
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
     7
 * Dynamically loadable modules for use with nexus.
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
     8
 *
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
     9
 * The modules are loaded using dlopen(), and hence should be standard dynamic libraries. Modules are then "loaded" by
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    10
 * resolving a `struct module_funcs` symbol called "<modname>_funcs", and then using the init func to construct a
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    11
 * "context", which is then further manipulated by various other module functions.
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
#include "nexus.h"
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    14
#include "config.h"
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
#include "error.h"
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
#include <sys/queue.h>
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
    18
#include <stdbool.h>
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
 * Information required to load/identify a module.
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
struct module_info {
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    /** Human-readable name */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
    const char *name;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
    
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
    /** Filesystem path to the .so */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
    const char *path;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
};
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
/**
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    32
 * A table of (function/other) pointers defining a module's behaviour. This is dynamically resolved from the module DSO
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    33
 * using the "<mod_name>_module" symbol.
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    34
 */
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    35
struct module_desc {
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    36
    /**
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    37
     * Initialize the module, returning an opaque context pointer that is stored in the module state, and supplied for
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    38
     * subsequent calls. The supplied nexus arg can be used to access the global state.
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    39
     *
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    40
     * @param nexus a pointer to the nexus struct containing the global state
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    41
     * @param ctx_ptr the context pointer should be returned via this
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    42
     * @param err returned error info
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    43
     */
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    44
    err_t (*init) (struct nexus *nexus, void **ctx_ptr, struct error_info *err);
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    45
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    46
    /**
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    47
     * A module may define a set of available configuration parameters for use by module_conf, by setting this to an
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    48
     * array of config_option's.
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    49
     *
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    50
     * The handler functions will recieve the module's context pointer as their ctx argument.
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    51
     */
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    52
    const struct config_option *config_options;
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    53
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    54
    /**
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    55
     * Unload the module, removing all handlers/callbacks added to the nexus' irc_client. This does not have to act
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    56
     * immediately, and will still have access to all irc_* resources it had earlier, and may perform I/O to unload
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    57
     * cleanly. But the unloading should complete reasonably quickly, after which all event handlers added by the
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    58
     * module to the nexus' ev_base should have been removed, and resources released.
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    59
     *
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    60
     * @param ctx the module's context pointer as returned by init
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    61
     */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    62
    err_t (*unload) (void *ctx);
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    63
};
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    64
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    65
/**
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
 * A loaded module.
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
struct module {
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
    /** The identifying info for the module */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
    struct module_info info;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    72
    /** The dlopen handle */
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    73
    void *handle;
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    74
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    75
    /** The module entry point */
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    76
    struct module_desc *desc;
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    77
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
    /** The module context object */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
    void *ctx;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    81
    /** Reference back to modules struct used to load this module */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    82
    struct modules *modules;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    83
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    84
    /**
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    85
     * Is the module currently being unloaded?
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    86
     */
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    87
    bool unloading;
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
    88
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    89
    /** Our entry in the list of modules */
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
    90
    TAILQ_ENTRY(module) modules_list;
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
};
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
 * A set of loaded modules, and functionality to load more
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
struct modules {
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    97
    /** The nexus in use */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    98
    struct nexus *nexus;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    99
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
    /** List of loaded modules */
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   101
    TAILQ_HEAD(module_ctx_modules, module) list;
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   102
};
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   103
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   104
/**
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   105
 * Possible error codes
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   106
 */
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   107
enum module_error_code {
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   108
    _ERR_MODULE_BEGIN = _ERR_MODULE,
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   109
    
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   110
    ERR_MODULE_OPEN,        ///< dlopen() failed
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   111
    ERR_MODULE_NAME,        ///< invalid module_info.name
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   112
    ERR_MODULE_SYM,         ///< invalid symbol
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   113
    ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   114
    ERR_MODULE_CONF,        ///< value error in configuration data
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
};
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   117
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   118
/**
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   119
 * Maximum length of a module name
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   120
 */
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   121
#define MODULE_NAME_MAX 24
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   122
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   123
/**
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   124
 * Maximum length of module symbol suffix
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   125
 */
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   126
#define MODULE_SUFFIX_MAX 16
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   127
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   128
/**
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   129
 * Maximum length of symbol name name, including terminating NUL
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   130
 */
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   131
#define MODULE_SYMBOL_MAX (MODULE_NAME_MAX + 1 + MODULE_SUFFIX_MAX + 1)
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   132
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   133
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   134
 * Create a new modules state
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   135
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
err_t modules_create (struct modules **modules_ptr, struct nexus *nexus);
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   138
/**
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   139
 * Return a module's name
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   140
 */
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   141
const char* module_name (struct module *module);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   142
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   143
/**
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   144
 * Load a new module
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   145
 *
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   146
 * @param modules the module-loading context
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   147
 * @param module_ptr return the new module via this, if not NULL
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   148
 * @param info the info required to identify and load the module
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   149
 * @param err return error info
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   150
 */
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   151
err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *info, struct error_info *err);
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   152
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   153
/**
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   154
 * Lookup a module by name
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   155
 *
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   156
 * @param modules the modules state
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   157
 * @param name the module name to get
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   158
 * @return the module struct, or NULL if not found
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   159
 */
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   160
struct module* module_get (struct modules *modules, const char *name);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   161
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   162
/**
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   163
 * Look up a module configuration option by name
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   164
 */
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   165
const struct config_option* module_conf_lookup (struct module *module, const char *name, struct error_info *err);
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   166
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   167
/**
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   168
 * Apply a module configuration option using a structured value
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   169
 */
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   170
err_t module_conf (struct module *module, const struct config_option *opt, const struct config_value *value, struct error_info *err);
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   171
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   172
/**
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   173
 * Set a module configuration option using a raw value
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   174
 */
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 87
diff changeset
   175
err_t module_conf_raw (struct module *module, const char *name, char *value, struct error_info *err);
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
/**
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   178
 * Unload a module. This means calling its 'unload' func, which will then go about shutting down the module. This might
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   179
 * not happen right away, though, so the module is not destroyed yet.
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 54
diff changeset
   180
 *
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   181
 * XXX: currently the module is never destroyed, there needs to be a "module unload done" callback...
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   183
err_t module_unload (struct module *module);
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   184
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   185
/**
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   186
 * Destroy a module, releasing as many resources as possible
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   187
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   188
void module_destroy (struct module *module);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   189
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   190
/**
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   191
 * Unload all modules, this just calls module_unload for each module, logging errors as warnings.
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   192
 *
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   193
 * XXX: currently, this does not destroy any modules, or the modules state itself.
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   194
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   195
err_t modules_unload (struct modules *modules);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   196
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   197
/**
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   198
 * Destroy all modules immediately.
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   199
 *
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   200
 * XXX: this doesn't leaves hanging module resources. The program will probably crash in soon
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   201
 */
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   202
void modules_destroy (struct modules *modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   203
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   204
#endif