13
15
rcc_library_handle rccLibraryOpen(char *filename)
16
return (rcc_library_handle)dlopen(filename, RTLD_NOW);
18
if (filename) return (rcc_library_handle)dlopen(filename, RTLD_NOW);
19
#endif /* RCC_PLUGINS */
19
#endif /* RCC_PLUGINS */
22
24
void rccLibraryClose(rcc_library_handle handle)
25
puts("HHHHHHHHHHHHHHHHHHHH");
27
if (handle) dlclose(handle);
27
28
#endif /* RCC_PLUGINS */
30
31
void* rccLibraryFind(rcc_library_handle handle, const char *symbol)
33
return dlsym(handle, symbol);
34
if ((handle)||(symbol)) return dlsym(handle, symbol);
36
35
#endif /* RCC_PLUGINS */
41
static rcc_plugin_handle_s rcc_engine_handles[RCC_MAX_PLUGINS];
46
for (i=0;i<RCC_MAX_PLUGINS;i++)
47
rcc_engine_handles[i].sn = NULL;
52
void rccPluginFree() {
55
for (i=0;i<RCC_MAX_PLUGINS;i++)
56
if (rcc_engine_handles[i].sn) {
57
rccLibraryClose(rcc_engine_handles[i].handle);
58
free(rcc_engine_handles[i].sn);
59
rcc_engine_handles[i].sn = NULL;
64
rcc_plugin_handle rccPluginGetHandleByName(rcc_plugin_type type, const char *name) {
67
rcc_plugin_handle handles;
69
if (!name) return NULL;
72
case RCC_PLUGIN_TYPE_ENGINE:
73
handles = rcc_engine_handles;
79
for (i=0;i<RCC_MAX_PLUGINS;i++)
80
if ((handles[i].sn)&&(!strcasecmp(handles[i].sn, name))) return handles+i;
85
rcc_plugin_handle rccPluginGetFreeHandle(rcc_plugin_type type) {
88
rcc_plugin_handle handles;
91
case RCC_PLUGIN_TYPE_ENGINE:
92
handles = rcc_engine_handles;
98
for (i=0;i<RCC_MAX_PLUGINS;i++)
99
if (!handles[i].sn) return handles+i;
104
rcc_plugin_handle rccPluginLoad(rcc_plugin_type type, const char *name) {
110
rcc_plugin_handle plugin;
112
if (!name) return NULL;
114
plugin = rccPluginGetHandleByName(type, name);
115
if (plugin) return plugin;
117
plugin = rccPluginGetFreeHandle(type);
118
if (!plugin) return plugin;
121
case RCC_PLUGIN_TYPE_ENGINE:
122
pluginfn = (char*)malloc((32 + strlen(rcc_home_dir) + strlen(name))*sizeof(char));
123
if (!pluginfn) return NULL;
125
sprintf(pluginfn, "%s/.rcc/engines/lib%s.so", rcc_home_dir, name);
126
res = dlopen(pluginfn, RTLD_NOW);
128
sprintf(pluginfn, LIBRCC_DATA_DIR "/engines/lib%s.so", name);
129
res = dlopen(pluginfn, RTLD_NOW);
134
infofunc = rccLibraryFind(res, "rccGetInfo");
136
plugin->sn = strdup(name);
138
plugin->handle = (rcc_library_handle)res;
139
plugin->info_function = infofunc;
141
} else rccLibraryClose(res);
142
} else rccLibraryClose(res);
151
rcc_engine *rccPluginEngineGetInfo(const char *name, const char *language) {
153
rcc_plugin_handle handle;
154
rcc_plugin_engine_info_function infofunc;
156
handle = rccPluginLoad(RCC_PLUGIN_TYPE_ENGINE, name);
157
if (!handle) return NULL;
159
infofunc = (rcc_plugin_engine_info_function)(handle->info_function);
160
if (!infofunc) return NULL;
162
return infofunc(language);