34#include <glib/gi18n.h>
66 const
char *output_file,
double scale, const
char *so_path, const
char *params)
68 int (*so_render_func)(
struct gds_cell *, GList *,
const char *, double) = NULL;
69 int (*so_init_func)(
const char *,
const char *) = NULL;
70 void *so_handle = NULL;
78 fprintf(stderr, _(
"Path to shared object not set!\n"));
83 if (!output_file || !toplevel_cell || !layer_info_list)
87 so_handle = dlopen(so_path, RTLD_LAZY);
89 fprintf(stderr, _(
"Could not load external library '%s'\nDetailed error is:\n%s\n"), so_path, dlerror());
94 so_render_func = (int (*)(
struct gds_cell *, GList *,
const char *, double))
96 error_msg = dlerror();
97 if (error_msg != NULL) {
98 fprintf(stderr, _(
"Rendering function not found in library:\n%s\n"), error_msg);
99 goto ret_close_so_handle;
104 error_msg = dlerror();
105 if (error_msg != NULL) {
106 fprintf(stderr, _(
"Init function not found in library:\n%s\n"), error_msg);
107 goto ret_close_so_handle;
120 g_message(_(
"Calling external renderer."));
129 ret = so_render_func(toplevel_cell, layer_info_list, output_file, scale);
138 waitpid(fork_pid, &forked_status, 0);
139 ret = WEXITSTATUS(forked_status);
142 g_message(_(
"External renderer finished."));
153 ExternalRenderer *ext_renderer = GDS_RENDER_EXTERNAL_RENDERER(renderer);
154 LayerSettings *settings;
155 GList *layer_infos = NULL;
156 const char *output_file;
167 ext_renderer->cli_param_string);
169 g_object_unref(settings);
176 ExternalRenderer *self;
178 self = GDS_RENDER_EXTERNAL_RENDERER(obj);
180 switch (property_id) {
182 g_value_set_string(value, self->shared_object_path);
185 g_value_set_string(value, self->cli_param_string);
188 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
195 ExternalRenderer *self;
197 self = GDS_RENDER_EXTERNAL_RENDERER(obj);
199 switch (property_id) {
201 if (self->shared_object_path)
202 g_free(self->shared_object_path);
203 self->shared_object_path = g_value_dup_string(value);
206 if (self->cli_param_string)
207 g_free(self->cli_param_string);
208 self->cli_param_string = g_value_dup_string(value);
211 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
218 ExternalRenderer *self;
220 self = GDS_RENDER_EXTERNAL_RENDERER(self_obj);
222 if (self->shared_object_path) {
223 g_free(self->shared_object_path);
224 self->shared_object_path = NULL;
227 G_OBJECT_CLASS(external_renderer_parent_class)->dispose(self_obj);
234 GdsOutputRendererClass *inherited_parent_class;
235 GObjectClass *oclass;
237 inherited_parent_class = GDS_RENDER_OUTPUT_RENDERER_CLASS(klass);
238 oclass = G_OBJECT_CLASS(klass);
250 g_param_spec_string(N_(
"shared-object-path"),
251 N_(
"Shared object file path"),
252 N_(
"Path to the shared object to search rendering function in."),
256 g_param_spec_string(N_(
"param-string"),
257 N_(
"Shared object renderer parameter string"),
258 N_(
"Command line arguments passed to the external shared object renderer"),
266 self->shared_object_path = NULL;
267 self->cli_param_string = NULL;
278 N_(
"param-string"), param_string, NULL);
Render according to command line parameters.
static void external_renderer_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
#define GDS_RENDER_TYPE_EXTERNAL_RENDERER
#define EXTERNAL_LIBRARY_FORK_REQUEST
Global integer specified by an external renderer to signal, that the init and render functions shall ...
static void external_renderer_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
static GParamSpec * external_renderer_properties[N_PROPERTIES]
static void external_renderer_init(ExternalRenderer *self)
static int external_renderer_render_cell(struct gds_cell *toplevel_cell, GList *layer_info_list, const char *output_file, double scale, const char *so_path, const char *params)
Execute render function in shared object to render the supplied cell.
static void external_renderer_class_init(ExternalRendererClass *klass)
static int external_renderer_render_output(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale)
ExternalRenderer * external_renderer_new()
Create new ExternalRenderer object.
ExternalRenderer * external_renderer_new_with_so_and_param(const char *so_path, const char *param_string)
Create new ExternalRenderer object with specified shared object path.
#define FORCE_FORK
if != 0, then forking is forced regardless of the shared object's settings
static void external_renderer_dispose(GObject *self_obj)
@ N_PROPERTIES
Shared object renderer parameter string from CLI.
@ PROP_SO_PATH
Shared object path property.
const char * gds_output_renderer_get_output_file(GdsOutputRenderer *renderer)
Convenience function for getting the "output-file" property.
LayerSettings * gds_output_renderer_get_and_ref_layer_settings(GdsOutputRenderer *renderer)
Get layer settings.
#define GDS_RENDER_TYPE_OUTPUT_RENDERER
int EXPORTED_FUNC_DECL() EXTERNAL_LIBRARY_RENDER_FUNCTION(struct gds_cell *toplevel, GList *layer_info_list, const char *output_file_name, double scale)
int EXPORTED_FUNC_DECL() EXTERNAL_LIBRARY_INIT_FUNCTION(const char *params, const char *version)
const char * _app_version_string
This string holds the Git Based Version Number of the app.
GList * layer_settings_get_layer_info_list(LayerSettings *settings)
Get a GList with layer_info structs.
char * shared_object_path
A Cell inside a gds_library.