-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin_loader.c
More file actions
87 lines (63 loc) · 2.18 KB
/
plugin_loader.c
File metadata and controls
87 lines (63 loc) · 2.18 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
/*
Copyright (C) 2010, 2011 Christian Klauer
This file is part of OpenRTDynamics, the Real-Time Dynamics Framework
OpenRTDynamics is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenRTDynamics is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with OpenRTDynamics. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include "libdyn.h"
#include "plugin_loader.h"
#ifdef __ORTD_PLUGINS_ENABLED
void *ortd_load_plugin(struct dynlib_simulation_t *sim, char *name)
{
void *lib_handle;
int (*init_fn)(struct dynlib_simulation_t *sim);
int x;
char *error;
lib_handle = dlopen(name, RTLD_LAZY);
if (!lib_handle)
{
#ifdef DEBUG
fprintf(stderr, "%s\n", dlerror());
#endif
return NULL;
}
// printf("lib loaded\n");
init_fn = dlsym(lib_handle, "ortd_plugin_init");
if ((error = dlerror()) != NULL)
{
// could not open shared lib
//#ifdef DEBUG
fprintf(stderr, "Could not find entry point ortd_plugin_init: %s\n", error);
fprintf(stderr, "Make sure you have a C-function called like this.\n");
fprintf(stderr, "Maybe you forgot to put this function into extern \"C\" { .... }.\n");
//#endif
dlclose(lib_handle);
return NULL;
}
// printf("got init fn\n");
// call init function
int ret = (*init_fn)(sim);
if (ret != 0) {
fprintf(stderr, "libdyn: Init of plugin %s faild with return value %d\n", name, ret);
// exit(1);
dlclose(lib_handle);
return NULL;
}
// printf("called init fn\n");
fprintf(stderr, "libdyn: Initialisation of plugin %s finished\n", name);
return lib_handle;
// dlclose(lib_handle);
}
#endif