Debian Codegraph @

wdoc/graphAcedbInterface.html

raw
1 <HTML>
2
3 <HEAD>
4 <TITLE> ACEDB source code documentation: the acedb/graph interface </TITLE>
5
6 <LINK rel=stylesheet type="text/css"
7 href="./wdoc.css"
8 title="Style sheet for wdoc developer documents">
9
10 </HEAD>
11
12 <BODY>
13
14 <H1> Programmers' guide to the acedb - graph interface </H1>
15
16 <H2>Overview</H2>
17 This document describes the changes made to the graph package
18 (i.e. code in the 'w2' source directory) as part of a restructuring
19 of acedb code to introduce independent packages or libraries of code.
20 In the case of graph this meant removing acedb-specific
21 code (e.g. lexNNN functions etc) from the package so that an independent
22 graph library could be compiled. This has been achieved by allowing the
23 registering of callback functions with the graph package that allow the
24 acedb specific routines to be called from the graph code without introducing
25 link-time dependencies. The rest of this document describes how graph was
26 restructured to do this.
27
28
29 <H2>Then and now.</H2>
30 <H4>How things used to be....</H4>
31 Until now the graph package was included in an application by compiling in the
32 graph source code. If the application was an acedb application the macro ACEDB
33 was defined for the compilation to make sure that acedb specific code in the
34 graph source code was included. This meant no single graph library could be
35 built which could be used by both acedb and non-acedb applications, it also
36 meant that the source code was 'polymorhpic' in a number of ways: some
37 functions had different signatures according to whether ACEDB was defined, some
38 routines had different logic flows, some data structures had different members
39 and so on.
40
41 <H4>How things are now....</H4>
42 For many reasons it was seen as important to remove this 'polymorphism'
43 and produce a single coherent graph package/library which could be used by acedb
44 and non-acedb applications. This single graph package is built into a single
45 library which can be used by all applications. All acedb specific code has
46 been moved to a single module separate from the graph package which contains
47 all the routines and function calls required by acedb to interface
48 to the standard graph library.
49
50 <H2>How the restructuring was done</H2>
51 The new graph library has no acedb-specific code in it, it provides the
52 'bare bones' graphical routines with no acedb database element. acedb
53 applications are then allowed to alter the behaviour of the graph
54 package to allow calling of database routines to set specific types
55 of windows/boxes etc.
56 <P>
57 The underlying mechanism allowing removal of the ACEDB defined sections of
58 code is the definition of a number of function pointers in the graph library
59 which can be used by an acedb application to register its acedb-specific
60 routines. The graph code initialises these pointers to NULL and so can later
61 test them to see if an acedb function has been registered and call it if
62 it has.
63 <P>
64 The following fictious example shows the replacement of some ACEDB defined code
65 with such a function call, the original code:
66 <PRE>
67
68 for (i = 0 ; i < limit ; i++)
69 {
70 some_code ;
71 <font color=red>
72 #ifdef ACEDB
73 lexNNNN(i, key, something) ;
74 #endif
75 </font>
76 some_more_code
77 }
78
79 </PRE>
80 is replaced with:
81 <PRE>
82
83 for (i = 0 ; i < limit ; i++)
84 {
85 some_code ;
86 <font color=red>
87 if (getACEDBLexFunction() != NULL) (getACEDBLexFunction())(i, key, something) ;
88 </font>
89 some_more_code ;
90 }
91
92 </PRE>
93 Hence some 'hard-coded' acedb specific code has been replaced with a dynamic
94 function call thus removing the dependency of the graph code on the acedb code.
95
96 <P>
97 <B>NOTE that, because this was a fairly large change, all alterations to the code
98 have been marked with C comments with the following format:</B>
99 <PRE>
100 /* ACEDB-GRAPH INTERFACE: ....description of change made.... */
101 </PRE>
102 Hence the source tree can easily be searched to find all the changes made.
103
104
105 <H2>Design decisions</H2>
106 In an ideal world a generalised callback interface could have been introduced into the
107 graph package which would support programs other than acedb. In practice there is not
108 really any justification for this, the only
109 requirement for this interface is that it supports existing acedb functions.
110 <P>
111 A new module was introduced into the graph package called graphAcedbInterface.c which
112 contains all of the function pointers and code required to support the graph interface
113 for acedb code. The exported functions of this interface are declared in a new header,
114 graphAcedbInterface.h, the internal non-static functions are declared in graphs internal
115 header, graph_.h.
116 <P>
117 All of the acedb specific code from graph was collected together in one module, acedbgraph.c,
118 and placed in the w4 directory which contains the main module initialisation code for
119 acedb applications. A function was provided in this module that can be called from an acedb
120 application to intialise graph and the graph-acedb interface. This avoids the need for extensive
121 recoding of existing graphical acedb applications. This function which provides the acedb-graph
122 interface is declared in the header acedbgraph.h.
123 <P>
124 This crude diagram summarises this new interface:
125 <PRE>
126 ACEDB * GRAPH
127 *
128 *
129 (acedbgraph.h) * (graph_.h)
130 | * |
131 V * V
132 acedb_app.c ---> acedbgraph.c --------*--> graphAcedbInterface.c <--- rest of
133 | A * graph
134 | | * package
135 | (graphAcedbInterface.h) * A
136 | * |
137 | * |
138 | * |
139 | (graph.h) * |
140 | | * |
141 | V * |
142 ----------------------------------*---------------------------------
143 *
144 *
145 *
146
147
148 </PRE>
149
150 <P>
151 The major design decisions were:
152 <OL>
153 <LI>to use a function callback mechanism to replace the ACEDB defines allowing
154 the new code to execute the acedb specific code in the same way as it
155 was executed when included by #define.
156 <LI>to provide an acedb specific set of functions in a single graph package
157 module (graphAcedbInterface.c) to allow the registering of data and the
158 callback functions.
159 <LI>to collect all the acedb specific code from the graph package into
160 a single module (acedbgraph.c) outside of the graph package.
161 </OL>
162
163
164 <H2>Future changes</H2>
165 There should now be no need to include acedb specific code in the graph package
166 with #defines. All new code should follow this model of function callback interface.
167 Ideally, new acedb requirements for the graph package should be dealt with by
168 introducing more generalised 'callback' functions into the graph package rather than
169 by expanding this interface. The intention is to limit this interface to its current
170 size, it is simply an expedient bit of coding to produce a stand-alone graph package
171 and more importantly stand-alone graph library.
172
173 <H2>Source/Interface/Functions</H2>
174
175 <H3>Source files:</H3>
176 Reflecting the division of function into <I>'acedb'</I> or <I>'graph'</I> code, the
177 source files are divided into two sets:
178
179 <H4>Graph package:</H3>
180 <DL>
181 <DT>graph.h
182 <DD>does not contain <B>any</B> of this interface
183 <DT>graphAcedbInterface.h
184 <DD>declares all public functions of the interface
185 <DT>graph_.h
186 <DD>declares all non-static private functions used internally in graph to support the
187 interface.
188 <DT>graphAcedbInterface.c
189 <DD>contains all graph package code to support the interface
190 </DL>
191
192 <H4>Acedb code:</H3>
193 <DL>
194 <DT>acedbgraph.h
195 <DD>declares all public functions for acedb to initialise its interface to the graph
196 graph package.
197 <DT>acedbgraph.c
198 <DD>contains all functions of the interface
199 </DL>
200
201 Note that non-acedb applications can simply include graph.h while acedb applications
202 include just graphAcedbInterface.h (which include graph.h).
203
204
205 <H3>Interface:</H3>
206 The public interface comprises the following elements:
207 <UL>
208 <LI>in acedbgraph.c:
209 <DL>
210 <DT>acedbAppGraphInit
211 <DD>this function is called once from an acedb application soon after it
212 starts up, it initialises both the graph package and the graph/acedb
213 interface. For most acedb applications this is the only function call required
214 to intialise the interface.
215 <DT>acedbGraphInit
216 <DD>this function initialises the graph/acedb interface and would normally be called
217 by acedbAppGraphInit, applications that required more control can initialise the
218 graph package and the graph/acedb interface separately using graphInit and this
219 call.
220 </DL>
221 See acedbGraph.h for the complete prototypes.
222 <LI>in graphAcedbInterface.c:
223 <DL>
224 <DT>setGraphAcedb<B>NNNN</B>
225 <DD>this set of functions can be called to initialise the function pointers and
226 any data required by the graph interface code. There is approximately one
227 setGraphAcedbNNNN routine for each component of the graph package that contained
228 acedb specific code (e.g. graphps.c has one, graphprint.c has one etc.).
229 </DL>
230 See graphAcedbInterface.h for a complete list and full prototypes.
231 </UL>
232
233 The private interface used only within the graph package comprises:
234 <UL>
235 <LI>in graphAcedbInterface.c:
236 <DL>
237 <DT>getGraphAcedb<B>NNNN</B>
238 <DD>this set of functions can be called to find out if a function has been
239 registered by acedb and then to get the pointer to that function
240 if one has. Since all function pointers for each graph package component
241 are registered with a single setGraphAcedbNNNN, there are many more
242 getGraphAcedbNNNN functions than setGraphAcedbNNNN routines, one for each
243 function registered.
244 </DL>
245 See the acedb/graph interface section of graph_.h for a complete list and full prototypes.
246 </UL>
247
248
249 <H3>Global variables</H3>
250
251 none
252
253
254 </BODY>
255 </HTML>
256
257