-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdll.c
More file actions
executable file
·95 lines (79 loc) · 2.23 KB
/
dll.c
File metadata and controls
executable file
·95 lines (79 loc) · 2.23 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <libtaomee/log.h>
#include "dll.h"
async_serv_if_t dll;
#define DLFUNC_NO_ERROR(h, v, name) \
do { \
v = dlsym(h, name); \
dlerror(); \
} while (0)
#define DLFUNC(h, v, name) \
do { \
v = dlsym (h, name); \
if ((error = dlerror ()) != NULL) { \
ERROR_LOG("dlsym error, %s", error); \
dlclose(h); \
h = NULL; \
goto out; \
} \
} while (0)
int register_data_plugin(const char* file_name)
{
char* error;
int ret_code = 0;
if (file_name == NULL)
return 0;
dll.data_handle = dlopen(file_name, RTLD_NOW | RTLD_GLOBAL);
if ((error = dlerror()) != NULL) {
ERROR_LOG("dlopen error, %s", error);
ret_code = 0;
}
BOOT_LOG(ret_code, "dlopen %s", file_name);
}
int register_plugin(const char* file_name, int flag)
{
char* error;
int ret_code = -1;
dll.handle = dlopen(file_name, RTLD_NOW);
if ((error = dlerror()) != NULL) {
ERROR_LOG("dlopen error, %s", error);
goto out;
}
DLFUNC_NO_ERROR(dll.handle, dll.init_service, "init_service");
DLFUNC_NO_ERROR(dll.handle, dll.fini_service, "fini_service");
DLFUNC_NO_ERROR(dll.handle, dll.proc_events, "proc_events");
DLFUNC_NO_ERROR(dll.handle, dll.proc_mcast_pkg, "proc_mcast_pkg");
DLFUNC_NO_ERROR(dll.handle, dll.proc_udp_pkg, "proc_udp_pkg");
DLFUNC(dll.handle, dll.get_pkg_len, "get_pkg_len");
DLFUNC(dll.handle, dll.proc_pkg_from_client, "proc_pkg_from_client");
DLFUNC(dll.handle, dll.proc_pkg_from_serv, "proc_pkg_from_serv");
DLFUNC(dll.handle, dll.on_client_conn_closed, "on_client_conn_closed");
DLFUNC(dll.handle, dll.on_fd_closed, "on_fd_closed");
DLFUNC_NO_ERROR(dll.handle, dll.before_reload, "before_reload");
DLFUNC_NO_ERROR(dll.handle, dll.reload_global_data, "reload_global_data");
DLFUNC_NO_ERROR(dll.handle, dll.sync_service_info, "sync_service_info");
ret_code = 0;
out:
if (!flag) {
BOOT_LOG(ret_code, "dlopen %s", file_name);
} else {
DEBUG_LOG("RELOAD %s\t[%s]", file_name, (ret_code ? "FAIL" : "OK"));
return ret_code;
}
}
void unregister_data_plugin()
{
if (dll.data_handle != NULL){
dlclose(dll.data_handle);
dll.data_handle = NULL;
}
}
void unregister_plugin()
{
if (dll.handle != NULL){
dlclose(dll.handle);
dll.handle = NULL;
}
}