Add finalize function as exported function to external renderer and use it in the main app after rendering

This commit is contained in:
2019-11-16 22:44:41 +01:00
parent c7ceef7d66
commit cf2947d2d5
5 changed files with 36 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
{
int (*so_render_func)(struct gds_cell *, GList *, const char *, double) = NULL;
int (*so_init_func)(const char *, const char *) = NULL;
int (*so_finalize_func)(void) = NULL;
void *so_handle = NULL;
char *error_msg;
int forking_req;
@@ -93,7 +94,7 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
so_render_func = (int (*)(struct gds_cell *, GList *, const char *, double))
dlsym(so_handle, xstr(EXTERNAL_LIBRARY_RENDER_FUNCTION));
error_msg = dlerror();
if (error_msg != NULL) {
if (error_msg) {
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
goto ret_close_so_handle;
}
@@ -101,11 +102,19 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
/* Load the init function */
so_init_func = (int (*)(const char *, const char *))dlsym(so_handle, xstr(EXTERNAL_LIBRARY_INIT_FUNCTION));
error_msg = dlerror();
if (error_msg != NULL) {
if (error_msg) {
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
goto ret_close_so_handle;
}
/* Load the finalize function */
so_finalize_func = (int (*)(void))dlsym(so_handle, xstr(EXTERNAL_LIBRARY_FINALIZE_FUNCTION));
error_msg = dlerror();
if (error_msg) {
fprintf(stderr, "Finalize function not found in library:\n%s\n", error_msg);
goto ret_close_so_handle;
}
/* Check if forking is requested */
if (dlsym(so_handle, xstr(EXTERNAL_LIBRARY_FORK_REQUEST)))
forking_req = 1;
@@ -127,6 +136,9 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
if (!ret)
ret = so_render_func(toplevel_cell, layer_info_list, output_file, scale);
/* Finalize the external renderer */
ret |= so_finalize_func();
/* If we are in a separate process, terminate here */
if (forking_req)
exit(ret);