src/spbot/module.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 May 2009 23:57:48 +0300
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 134 src/module.h@978041c1c04d
child 218 5229a5d098b2
permissions -rw-r--r--
nexus.c compiles
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.
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    12
 *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    13
 * Modules are also reference counted, mainly for implementing module_unload(). When a module is first loaded, it has
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    14
 * a reference count of one - the entry in struct modules. Later, modules can be referenced using module_get(), and
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    15
 * returned with module_put() once done. The module should never be destroyed during its lifetime, until a
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    16
 * module_unload() occurs. At this point, the module is removed from the modules_list, and the one reference is
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    17
 * 'passed on' to the module itself. Once it has finished unloading, it can call module_unloaded() on the reference it was
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    18
 * given by module_desc::unload, which may then result in a deferred module_destroy().
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    19
 *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    20
 * Module destroying itself is an interesting issue, since modules effectively need to be able to destroy themselves
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    21
 * (as they must be able to perform cleanup, and then notify completion from inside an event loop callback). This means
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    22
 * that they cannot directly execute a module_destroy() on themselves - if we call dlclose() with dlopen-mapped code
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    23
 * pages on the stack, a segfault ensues. Hence, they must call module_unloaded() on themselves, which then executes a
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    24
 * deferred module_destroy() if there are no references left. Otherwise, the module should be safe from external code,
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    25
 * as module_put() should never cause a module to be destroyed before module_unloaded() is executed, due to the primary
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    26
 * reference.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    27
 *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    28
 * Ugh, it's compliated, I need to write a clearer explenation once it's implemented :)
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
 */
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    30
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    31
struct module;
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    32
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
#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
    34
#include "config.h"
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    35
#include <lib/error.h>
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
#include <sys/queue.h>
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
    38
#include <stdbool.h>
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    40
enum module_error_code {
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    41
    ERR_MODULE_NONE, 
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    42
    ERR_MODULE_NAME,        ///< invalid module_info.name
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    43
    ERR_MODULE_DUP,         ///< module already opened
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    44
    ERR_MODULE_PATH,        ///< resolving the path failed
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    45
    ERR_MODULE_OPEN,        ///< dlopen() failed
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    46
    ERR_MODULE_SYM,         ///< invalid symbol
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    47
    ERR_MODULE_INIT_FUNC,   ///< invalid module_init_func_t
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    48
    ERR_MODULE_CONF,        ///< value error in configuration data
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    49
    ERR_MODULE_STATE,       ///< module in wrong state for operation
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    50
};
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    51
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    52
const struct error_list module_errors;
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    53
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
 * Information required to load/identify a module.
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
struct module_info {
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
    /** Human-readable name */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
    const char *name;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
    
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
    /** Filesystem path to the .so */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
    const char *path;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
};
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
/**
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
    66
 * 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
    67
 * 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
    68
 */
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
    69
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
    70
    /**
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    71
     * 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
    72
     * 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
    73
     *
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    74
     * Implementing this is mandatory.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    75
     *
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    76
     * @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
    77
     * @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
    78
     * @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
    79
     */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
    80
    err_t (*init) (struct nexus *nexus, void **ctx_ptr, error_t *err);
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    81
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    82
    /**
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
    83
     * 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
    84
     * 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
    85
     *
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
    86
     * The handler functions will recieve the module's context pointer as their ctx argument.
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    87
     *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    88
     * Implementing this is optional, but recommended.
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    89
     */
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    90
    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
    91
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
    92
    /**
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    93
     * 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
    94
     * 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
    95
     * 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
    96
     * 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
    97
     *
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    98
     * The module given as an argument is the module itself - which has been removed from the modules_list - the
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
    99
     * primary reference is passed on to the module. Once the module has finished unloading, it may call module_put(),
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   100
     * which may then call module_destroy(), if no other references were left.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   101
     *
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   102
     * If the unload operation fails (returns an error code), then the module is considered as unloaded (as if
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   103
     * module_unloaded() was called - don't call this if you return an error).
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   104
     *
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents: 111
diff changeset
   105
     * Implementing this is optional, if all of this can be implemented in destroy.
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   106
     *
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   107
     * @param ctx the module's context pointer as returned by init
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   108
     * @param module the hanging module reference, that must be passed to module_unloaded()
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   109
     * @return error code
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   110
     */
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   111
    err_t (*unload) (void *ctx, struct module *module);
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   112
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   113
    /**
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   114
     * Destroy the module now. No later chances, the module's code will be unloaded directly after this, which means
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   115
     * that attempts to execute the module's code (even on the stack...) after this will segfault.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   116
     *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   117
     * The module code /should/ garuntee that this is never called from *inside* the module code - calls to
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   118
     * module_destroy() will be deferred via the event loop if needed.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   119
     *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   120
     * Implementing this is optional.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   121
     */
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   122
    void (*destroy) (void *ctx);
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   123
};
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   124
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   125
/**
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
 * A loaded module.
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
struct module {
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   129
    /** The identifying info for the module */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   130
    struct module_info info;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   131
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   132
    /** Possible dynamically allocated path */
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   133
    char *path_buf;
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   134
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
   135
    /** 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
   136
    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
   137
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
   138
    /** 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
   139
    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
   140
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   141
    /** The module context object */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   142
    void *ctx;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   143
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   144
    /** 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
   145
    struct modules *modules;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   146
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   147
    /** Reference count for destroy() */
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   148
    size_t refcount;
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   149
    
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   150
    /** Is the module currently being unloaded? */
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
   151
    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
   152
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   153
    /** 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
   154
    TAILQ_ENTRY(module) modules_list;
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   155
};
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   156
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   158
 * A set of loaded modules, and functionality to load more
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   159
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   160
struct modules {
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   161
    /** The nexus in use */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   162
    struct nexus *nexus;
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   163
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   164
    /** Module search path */
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   165
    const char *path;
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   166
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
    /** 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
   168
    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
   169
};
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
   170
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
   171
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
   172
/**
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
   173
 * 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
   174
 */
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
   175
#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
   176
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
   177
/**
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
   178
 * 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
   179
 */
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
#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
   181
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
   182
/**
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
   183
 * 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
   184
 */
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
   185
#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
   186
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
/**
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
 * Create a new modules state
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   189
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   190
err_t modules_create (struct modules **modules_ptr, struct nexus *nexus);
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   191
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   192
/**
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   193
 * Set a search path for finding modules by name. The given string won't be copied.
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   194
 *
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   195
 * A module called "<name>" will be searched for at "<path>/mod_<name>.so"
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   196
 *
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   197
 * If path is NULL, this doesn't change anything. This returns the old path, which may be NULL.
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   198
 *
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   199
 * @param modules the modules state
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   200
 * @param path the new search path, or NULL to just get the old one
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   201
 * @return the old search path
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   202
 */
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   203
const char* modules_path (struct modules *modules, const char *path);
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   204
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   205
/**
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   206
 * Get a reference to the module, which must be returned using module_put
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   207
 *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   208
 * @param modules the modules state
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   209
 * @param name the module name to get
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   210
 * @return the module struct, or NULL if not found
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   211
 */
134
978041c1c04d update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   212
struct module* modules_get (struct modules *modules, const char *name);
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   213
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   214
/**
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   215
 * Unload all modules, this just calls module_unload for each module, logging errors as warnings.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   216
 */
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   217
err_t modules_unload (struct modules *modules);
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   218
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   219
/**
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   220
 * Destroy all modules immediately.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   221
 */
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   222
void modules_destroy (struct modules *modules);
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   223
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   224
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   225
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   226
/*******************************************/
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   227
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   228
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   229
/**
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   230
 * 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
   231
 */
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   232
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
   233
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   234
/**
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   235
 * Load a new module, as named by info.
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   236
 *
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   237
 * If info->path is not given, the module will be searched for using the path set by modules_path().
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   238
 *
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   239
 * If module_ptr is given, a reference (that must be module_put'd) is returned, that must be returned using 
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   240
 * module_put().
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   241
 *
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   242
 * @param modules the module-loading context
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   243
 * @param module_ptr retuturned new module struct, as a new reference, if not NULL.
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
   244
 * @param info the info required to identify and load the module
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   245
 * @param err returned error info
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   246
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   247
err_t module_load (struct modules *modules, struct module **module_ptr, const struct module_info *info, error_t *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
   248
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
   249
/**
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   250
 * Return a module retrieved using module_get
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   251
 */
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   252
void module_put (struct module *module);
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   253
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   254
/**
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
   255
 * 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
   256
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   257
const struct config_option* module_conf_lookup (struct module *module, const char *name, error_t *err);
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
   258
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
   259
/**
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
   260
 * 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
   261
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   262
err_t module_conf (struct module *module, const struct config_option *opt, const struct config_value *value, error_t *err);
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
   263
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
   264
/**
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
   265
 * 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
   266
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   267
err_t module_conf_raw (struct module *module, const char *name, char *value, error_t *err);
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   268
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   269
/**
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   270
 * Unload a module. This removes the module from the modules_list, marks it as unloading, and then calls the module's
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   271
 * \p unload function, passing it the primary reference. The module's unload code will then go about shutting down the
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   272
 * module, and once that is done, it may module_put() the primary reference, which may then lead to module_destroy().
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   273
 *
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   274
 * This returns ERR_MODULE_STATE if the module is already being unloaded, or other errors from the module's own unload
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   275
 * functionality.
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   276
 */
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   277
err_t module_unload (struct module *module);
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   278
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   279
/**
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   280
 * Used by a module itself to indicate that an module_desc::unload() operation has completed. This will execute a
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   281
 * deferred module_destroy() if there are no more references left on the module.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   282
 *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   283
 * Note: this is not intended to be called from outside the given module itself...
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   284
 */
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   285
void module_unloaded (struct module *module);
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   286
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   287
/**
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   288
 * Destroy a module, releasing as many resources as possible, but not stopping for errors.
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   289
 *
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   290
 * This does not enforce the correct refcount - 'tis the caller's responsibility. Prints out a warning if
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 108
diff changeset
   291
 * refcount > 0.
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   292
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   293
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
   294
54
9f74e924b01a initial modules code
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
#endif