-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_manager.h
executable file
·73 lines (56 loc) · 1.9 KB
/
plugin_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _PLUGIN_MANAGER_H_
#define _PLUGIN_MANAGER_H_
#include <unistd.h>
#include <stdlib.h>
#include "list.h"
#include "uthash.h"
#define MAX_PLUGIN_NAME 20
#define MAX_HOOK_NAME 32
#define MODULE_HOOK_STRUCT(NAME) "ptrig_" NAME "_hooks"
#define GENERAL_HOOKS_STRUCT "ptrig_hooks"
#define MAX_HOOK_STRUCT_NAME (MAX_HOOK_NAME + sizeof(MODULE_HOOK_STRUCT()))
struct plugin_manager;
/* Structure that defines a module hook */
struct module_hook {
int (*pre_hook)(void *args, void *data);
int (*post_hook)(void *args, void *data);
};
/* Structure that defines a module hooks list */
struct module_hooks_node {
struct module_hook *m_hook;
struct list_head list;
};
/* Structure that defines a hash table [name]<->[module_hook list]*/
struct module_hooks_table {
char name[MAX_HOOK_NAME];
struct module_hooks_node m_hooks_node;
UT_hash_handle hh;
};
/* Structure that defines a general hook */
struct general_hook {
char name[MAX_PLUGIN_NAME];
int (*init_hook)(void *args);
int (*exit_hook)(void *args);
};
/* Structure that defines a general hooks list */
struct general_hooks_node {
struct general_hook *g_hook;
void *dl_handle;
struct list_head list;
};
/* Initialize the plugin manager structures */
struct plugin_manager *init_plugin_manager(const char *path);
/* Regiser a module that may have plugins */
int register_module(struct plugin_manager *mgr, const char *name);
/* Get all hooks for registered module*/
struct list_head *
get_module_hooks(struct plugin_manager *mgr, const char *name);
/* Get all general hooks from loaded plugins */
struct list_head *get_general_hooks(struct plugin_manager *mgr);
/* Load all plugins. Call after registering all modules */
int load_plugins(struct plugin_manager *mgr);
/* Returns number of plugins loaded */
int get_num_plugins(struct plugin_manager *mgr);
/* Destroy the plugin manager and unload plugins */
int destroy_plugin_manager(struct plugin_manager *mgr);
#endif