54
|
1 |
#ifndef MODULE_H
|
|
2 |
#define MODULE_H
|
|
3 |
|
|
4 |
/**
|
|
5 |
* @file
|
|
6 |
*
|
|
7 |
* Dynamically loadable modules for use with nexus
|
|
8 |
*/
|
|
9 |
#include "nexus.h"
|
|
10 |
#include "error.h"
|
|
11 |
|
|
12 |
#include <sys/queue.h>
|
|
13 |
|
|
14 |
/**
|
|
15 |
* Information required to load/identify a module.
|
|
16 |
*/
|
|
17 |
struct module_info {
|
|
18 |
/** Human-readable name */
|
|
19 |
const char *name;
|
|
20 |
|
|
21 |
/** Filesystem path to the .so */
|
|
22 |
const char *path;
|
|
23 |
};
|
|
24 |
|
|
25 |
/**
|
|
26 |
* A loaded module.
|
|
27 |
*/
|
|
28 |
struct module {
|
|
29 |
/** The identifying info for the module */
|
|
30 |
struct module_info info;
|
|
31 |
|
|
32 |
/** The module context object */
|
|
33 |
void *ctx;
|
|
34 |
|
|
35 |
/** Our entry in the list of modules */
|
|
36 |
TAILQ_ENTRY(module) ctx_modules;
|
|
37 |
};
|
|
38 |
|
|
39 |
/**
|
|
40 |
* A set of loaded modules, and functionality to load more
|
|
41 |
*/
|
|
42 |
struct modules {
|
|
43 |
/** The nexus in use */
|
|
44 |
struct nexus *nexus;
|
|
45 |
|
|
46 |
/** List of loaded modules */
|
|
47 |
TAILQ_HEAD(module_ctx_modules, module) modules;
|
|
48 |
};
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Module initialization function type
|
|
52 |
*/
|
|
53 |
typedef void* (*module_init_func_t) (struct nexus *nexus, struct error_info *err);
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Create a new modules state
|
|
57 |
*/
|
|
58 |
err_t modules_create (struct modules **modules_ptr, struct nexus *nexus);
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Load a new module.
|
|
62 |
*/
|
|
63 |
err_t module_load (struct moduels *modules, struct module **module, const struct module_info *info, struct error_info *err);
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Unload a module
|
|
67 |
*/
|
|
68 |
err_t module_unload (struct module *module);
|
|
69 |
|
|
70 |
#endif
|