| 1 |
/************************************************************************* |
| 2 |
* Copyright (c) 2011 AT&T Intellectual Property |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* https://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: Details at https://graphviz.org |
| 9 |
*************************************************************************/ |
| 10 |
|
| 11 |
/* |
| 12 |
A gvcontext is a single instance of a GVC_t data structure providing |
| 13 |
for a set of plugins for processing one graph at a time, and a job |
| 14 |
description provividing for a sequence of graph jobs. |
| 15 |
|
| 16 |
Sometime in the future it may become the basis for a thread. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "config.h" |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
|
| 23 |
#include "builddate.h" |
| 24 |
#include <common/render.h> |
| 25 |
#include <common/types.h> |
| 26 |
#include <gvc/gvplugin.h> |
| 27 |
#include <gvc/gvcjob.h> |
| 28 |
#include <gvc/gvcint.h> |
| 29 |
#include <gvc/gvcproc.h> |
| 30 |
#include <gvc/gvc.h> |
| 31 |
#include <util/alloc.h> |
| 32 |
|
| 33 |
/* from common/textspan.c */ |
| 34 |
extern void textfont_dict_close(GVC_t *gvc); |
| 35 |
|
| 36 |
/* from common/globals.c */ |
| 37 |
extern int graphviz_errors; |
| 38 |
|
| 39 |
static char *LibInfo[] = { |
| 40 |
"graphviz", /* Program */ |
| 41 |
PACKAGE_VERSION, /* Version */ |
| 42 |
BUILDDATE /* Build Date */ |
| 43 |
}; |
| 44 |
|
| 45 |
GVC_t *gvNEWcontext(const lt_symlist_t *builtins, int demand_loading) |
| 46 |
{ |
| 47 |
GVC_t *gvc = gv_alloc(sizeof(GVC_t)); |
| 48 |
|
| 49 |
gvc->common.info = LibInfo; |
| 50 |
gvc->common.errorfn = agerrorf; |
| 51 |
gvc->common.builtins = builtins; |
| 52 |
gvc->common.demand_loading = demand_loading; |
| 53 |
|
| 54 |
return gvc; |
| 55 |
} |
| 56 |
|
| 57 |
void gvFinalize(GVC_t * gvc) |
| 58 |
{ |
| 59 |
if (gvc->active_jobs) |
| 60 |
gvrender_end_job(gvc->active_jobs); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
int gvFreeContext(GVC_t * gvc) |
| 65 |
{ |
| 66 |
GVG_t *gvg, *gvg_next; |
| 67 |
gvplugin_package_t *package, *package_next; |
| 68 |
gvplugin_available_t *api, *api_next; |
| 69 |
|
| 70 |
emit_once_reset(); |
| 71 |
gvg_next = gvc->gvgs; |
| 72 |
while ((gvg = gvg_next)) { |
| 73 |
gvg_next = gvg->next; |
| 74 |
free(gvg); |
| 75 |
} |
| 76 |
package_next = gvc->packages; |
| 77 |
while ((package = package_next)) { |
| 78 |
package_next = package->next; |
| 79 |
free(package->path); |
| 80 |
free(package->name); |
| 81 |
free(package); |
| 82 |
} |
| 83 |
gvjobs_delete(gvc); |
| 84 |
free(gvc->config_path); |
| 85 |
free(gvc->input_filenames); |
| 86 |
textfont_dict_close(gvc); |
| 87 |
for (size_t i = 0; i < sizeof(gvc->apis) / sizeof(gvc->apis[0]); ++i) { |
| 88 |
for (api = gvc->apis[i]; api != NULL; api = api_next) { |
| 89 |
api_next = api->next; |
| 90 |
free(api->typestr); |
| 91 |
free(api); |
| 92 |
} |
| 93 |
} |
| 94 |
free(gvc->layerIDs); |
| 95 |
free(gvc); |
| 96 |
return (graphviz_errors + agerrors()); |
| 97 |
} |
| 98 |
|
| 99 |
GVC_t* gvCloneGVC (GVC_t * gvc0) |
| 100 |
{ |
| 101 |
GVC_t *gvc = gv_alloc(sizeof(GVC_t)); |
| 102 |
|
| 103 |
gvc->common = gvc0->common; |
| 104 |
memcpy (&gvc->apis, &gvc0->apis, sizeof(gvc->apis)); |
| 105 |
memcpy (&gvc->api, &gvc0->api, sizeof(gvc->api)); |
| 106 |
gvc->packages = gvc0->packages; |
| 107 |
|
| 108 |
return gvc; |
| 109 |
} |
| 110 |
|
| 111 |
void gvFreeCloneGVC (GVC_t * gvc) |
| 112 |
{ |
| 113 |
gvjobs_delete(gvc); |
| 114 |
free(gvc); |
| 115 |
} |
| 116 |
|