Compare commits
3 Commits
v1.2-1
...
cf2947d2d5
Author | SHA1 | Date | |
---|---|---|---|
cf2947d2d5 | |||
c7ceef7d66 | |||
ebce4a2669 |
@@ -40,7 +40,7 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|||||||
add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/translations/output\")
|
add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"${CMAKE_CURRENT_BINARY_DIR}/translations/output\")
|
||||||
message("${BoldMagenta}${CMAKE_CURRENT_BINARY_DIR}/translations/output used as data dir${ColorReset}")
|
message("${BoldMagenta}${CMAKE_CURRENT_BINARY_DIR}/translations/output used as data dir${ColorReset}")
|
||||||
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
message("Global locale directory used. Make sure files in /usr/share/locale are available")
|
message("${BoldCyan}Global locale directory used. Make sure files in /usr/share/locale are available${ColorReset}")
|
||||||
add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"/usr/share\")
|
add_definitions(-DGETTEXT_PACKAGE=\"gds-render\" -DLOCALEDATADIR=\"/usr/share\")
|
||||||
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
|
||||||
|
@@ -22,5 +22,6 @@
|
|||||||
* @ref EXTERNAL_LIBRARY_RENDER_FUNCTION | int EXTERNAL_LIBRARY_RENDER_FUNCTION(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale) | Render cell to output file
|
* @ref EXTERNAL_LIBRARY_RENDER_FUNCTION | int EXTERNAL_LIBRARY_RENDER_FUNCTION(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale) | Render cell to output file
|
||||||
* @ref EXTERNAL_LIBRARY_INIT_FUNCTION | int EXTERNAL_LIBRARY_INIT_FUNCTION(const char *option_string, const char *version_string) | Init function. Executed before rendering. This is given the command line parameters specified for the external renderer and the version string of the currently running gds-render program.
|
* @ref EXTERNAL_LIBRARY_INIT_FUNCTION | int EXTERNAL_LIBRARY_INIT_FUNCTION(const char *option_string, const char *version_string) | Init function. Executed before rendering. This is given the command line parameters specified for the external renderer and the version string of the currently running gds-render program.
|
||||||
* @ref EXTERNAL_LIBRARY_FORK_REQUEST | int EXTERNAL_LIBRARY_FORK_REQUEST; | The pure presence of this integer results in the execution inside a subprocess of hte whole shared object's code
|
* @ref EXTERNAL_LIBRARY_FORK_REQUEST | int EXTERNAL_LIBRARY_FORK_REQUEST; | The pure presence of this integer results in the execution inside a subprocess of hte whole shared object's code
|
||||||
|
* @ref EXTERNAL_LIBRARY_FINALIZE_FUNCTION | int EXTERNAL_LIBRARY_FINALIZE_FUNCTION(void) | Called after rendering
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@@ -32,6 +32,15 @@
|
|||||||
*/
|
*/
|
||||||
#define EXTERNAL_LIBRARY_INIT_FUNCTION exported_init
|
#define EXTERNAL_LIBRARY_INIT_FUNCTION exported_init
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Function name expected to be found in external library for finalizing.
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* int EXTERNAL_LIBRARY_FINALIZE_FUNCTION(void);
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
#define EXTERNAL_LIBRARY_FINALIZE_FUNCTION exported_finalize
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Global integer specified by an external renderer to signal, that the init and render functions shall be executed in a subprocess
|
* @brief Global integer specified by an external renderer to signal, that the init and render functions shall be executed in a subprocess
|
||||||
*
|
*
|
||||||
|
@@ -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_render_func)(struct gds_cell *, GList *, const char *, double) = NULL;
|
||||||
int (*so_init_func)(const char *, const char *) = NULL;
|
int (*so_init_func)(const char *, const char *) = NULL;
|
||||||
|
int (*so_finalize_func)(void) = NULL;
|
||||||
void *so_handle = NULL;
|
void *so_handle = NULL;
|
||||||
char *error_msg;
|
char *error_msg;
|
||||||
int forking_req;
|
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))
|
so_render_func = (int (*)(struct gds_cell *, GList *, const char *, double))
|
||||||
dlsym(so_handle, xstr(EXTERNAL_LIBRARY_RENDER_FUNCTION));
|
dlsym(so_handle, xstr(EXTERNAL_LIBRARY_RENDER_FUNCTION));
|
||||||
error_msg = dlerror();
|
error_msg = dlerror();
|
||||||
if (error_msg != NULL) {
|
if (error_msg) {
|
||||||
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
||||||
goto ret_close_so_handle;
|
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 */
|
/* Load the init function */
|
||||||
so_init_func = (int (*)(const char *, const char *))dlsym(so_handle, xstr(EXTERNAL_LIBRARY_INIT_FUNCTION));
|
so_init_func = (int (*)(const char *, const char *))dlsym(so_handle, xstr(EXTERNAL_LIBRARY_INIT_FUNCTION));
|
||||||
error_msg = dlerror();
|
error_msg = dlerror();
|
||||||
if (error_msg != NULL) {
|
if (error_msg) {
|
||||||
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
fprintf(stderr, "Rendering function not found in library:\n%s\n", error_msg);
|
||||||
goto ret_close_so_handle;
|
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 */
|
/* Check if forking is requested */
|
||||||
if (dlsym(so_handle, xstr(EXTERNAL_LIBRARY_FORK_REQUEST)))
|
if (dlsym(so_handle, xstr(EXTERNAL_LIBRARY_FORK_REQUEST)))
|
||||||
forking_req = 1;
|
forking_req = 1;
|
||||||
@@ -127,6 +136,9 @@ static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *
|
|||||||
if (!ret)
|
if (!ret)
|
||||||
ret = so_render_func(toplevel_cell, layer_info_list, output_file, scale);
|
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 we are in a separate process, terminate here */
|
||||||
if (forking_req)
|
if (forking_req)
|
||||||
exit(ret);
|
exit(ret);
|
||||||
|
@@ -1,2 +1,4 @@
|
|||||||
add_subdirectory(plugin-example)
|
add_subdirectory(plugin-example)
|
||||||
add_custom_target(plugins DEPENDS pluginexample)
|
add_subdirectory(python-renderer)
|
||||||
|
|
||||||
|
add_custom_target(plugins DEPENDS pluginexample pythonrenderer)
|
||||||
|
@@ -1,12 +1,11 @@
|
|||||||
project(pluginexample)
|
project(pluginexample)
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_search_module(PYTHON REQUIRED python3)
|
|
||||||
|
|
||||||
aux_source_directory(src SOURCES)
|
aux_source_directory(src SOURCES)
|
||||||
|
|
||||||
include_directories(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
link_libraries(${PYTHON_LDFLAGS} version)
|
link_libraries(version)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL ${SOURCES})
|
add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL ${SOURCES})
|
||||||
add_dependencies(${PROJECT_NAME} version)
|
add_dependencies(${PROJECT_NAME} version)
|
||||||
|
@@ -17,3 +17,8 @@ int FUNC_DECL(EXTERNAL_LIBRARY_INIT_FUNCTION)(const char *params, const char *ve
|
|||||||
printf("Init with params: %s\ngds-render version: %s\n", params, version);
|
printf("Init with params: %s\ngds-render version: %s\n", params, version);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FUNC_DECL(EXTERNAL_LIBRARY_FINALIZE_FUNCTION)(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
13
plugins/python-renderer/CMakeLists.txt
Normal file
13
plugins/python-renderer/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
project(pythonrenderer)
|
||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_search_module(PYTHON REQUIRED python3)
|
||||||
|
|
||||||
|
aux_source_directory(src SOURCES)
|
||||||
|
|
||||||
|
include_directories(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
link_libraries(${PYTHON_LDFLAGS} version)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} SHARED EXCLUDE_FROM_ALL ${SOURCES})
|
||||||
|
add_dependencies(${PROJECT_NAME} version)
|
||||||
|
|
26
plugins/python-renderer/src/plugin-main.c
Normal file
26
plugins/python-renderer/src/plugin-main.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <glib.h>
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <gds-render/gds-utils/gds-types.h>
|
||||||
|
#include <gds-render/output-renderers/external-renderer-interfaces.h>
|
||||||
|
|
||||||
|
int FUNC_DECL(EXTERNAL_LIBRARY_RENDER_FUNCTION)(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale)
|
||||||
|
{
|
||||||
|
if (!toplevel)
|
||||||
|
return -1000;
|
||||||
|
|
||||||
|
printf("Rendering %s\n", toplevel->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FUNC_DECL(EXTERNAL_LIBRARY_INIT_FUNCTION)(const char *params, const char *version)
|
||||||
|
{
|
||||||
|
PyObject *p_module_name;
|
||||||
|
|
||||||
|
printf("Init with params: %s\ngds-render version: %s\n", params, version);
|
||||||
|
|
||||||
|
Py_Initialize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user