]>
Commit | Line | Data |
---|---|---|
5580185e | 1 | /* |
5580185e | 2 | * $Header$ |
3 | */ | |
4 | ||
939744d7 | 5 | /************************************************************************ |
6 | * | |
7 | * gdb.h | |
8 | * | |
9 | * Includes for the global database facility (gdb) | |
10 | * | |
11 | * Author: Noah Mendelsohn | |
12 | * Copyright: 1986 MIT Project Athena | |
13 | * | |
14 | ************************************************************************/ | |
5580185e | 15 | |
16 | /* | |
17 | * Note: following include may safely be done redundantly, so it doesn't | |
18 | * matter if caller does it too. We need it for fd_set. | |
19 | */ | |
20 | #include <sys/types.h> | |
21 | #include <sys/time.h> | |
22 | ||
23 | #ifndef TRUE | |
24 | #define TRUE 1 | |
25 | #endif | |
26 | ||
27 | #ifndef FALSE | |
28 | #define FALSE 0 | |
29 | #endif | |
30 | ||
31 | #ifndef max | |
32 | #define max(a,b) ((a)>(b)?(a):(b)) | |
33 | #endif | |
34 | ||
35 | #ifndef min | |
36 | #define min(a,b) ((a)<(b)?(a):(b)) | |
37 | #endif | |
38 | ||
39 | #ifndef NFDBITS | |
40 | #define NFDBITS 32 | |
41 | #endif | |
42 | #ifndef howmany | |
43 | #define howmany(x, y) (((x)+((y)-1))/(y)) | |
44 | #endif | |
45 | #ifndef FD_SET | |
46 | #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) | |
47 | #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) | |
48 | #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) | |
49 | #define FD_ZERO(p) bzero(p, sizeof(*(p))) | |
50 | #endif | |
51 | ||
52 | ||
53 | ||
939744d7 | 54 | /*----------------------------------------------------------* |
55 | * | |
56 | * GDB_GIVEUP | |
57 | * | |
58 | * This macro is called with a string argument whenever a | |
59 | * fatal error is encounterd. If you re-define this | |
60 | * macro, you can control the disposition of fatal gdb | |
61 | * errors. | |
62 | * | |
63 | * The gdb library must be recompiled for the change to | |
64 | * take effect. That will have to be fixed sometime. | |
65 | * | |
66 | *----------------------------------------------------------*/ | |
5580185e | 67 | |
68 | #define GDB_GIVEUP(errormsg) g_givup(errormsg); | |
69 | ||
939744d7 | 70 | /*----------------------------------------------------------* |
71 | * | |
72 | * GDB_ROUNDUP | |
73 | * | |
74 | * Round a number up to the next specified boundary. | |
75 | * | |
76 | *----------------------------------------------------------*/ | |
5580185e | 77 | |
78 | #define GDB_ROUNDUP(n,b) ((((n)+(b)-1)/(b))*(b)) | |
79 | ||
80 | extern int gdb_Debug; /* debugging flags are */ | |
81 | /* stored here */ | |
82 | extern FILE *gdb_log; /* file descriptor for */ | |
83 | /* logging gdb output */ | |
84 | ||
85 | ||
86 | /* | |
87 | * connection failure indicator | |
88 | * | |
89 | * This variable is used to communicate between gdb_move_data and | |
90 | * g_con_progress without passing an extra parameter through lots | |
91 | * of procedure calls. When set to FALSE, it indicates that the | |
92 | * connection currently being processed has encountered a fatal error | |
93 | * and should be severed. | |
94 | */ | |
95 | extern int gdb_conok; | |
939744d7 | 96 | /************************************************************************ |
97 | * | |
98 | * USER IDENTIFICATION | |
99 | * | |
100 | * gdb_init puts the user's i.d. and hostname as strings here. | |
101 | * | |
102 | ************************************************************************/ | |
5580185e | 103 | |
104 | extern char *gdb_uname; /* user's string name */ | |
105 | extern char *gdb_host; /* name of local host */ | |
106 | /* goes here */ | |
107 | ||
108 | ||
109 | \f | |
939744d7 | 110 | /************************************************************************ |
111 | * | |
112 | * | |
113 | * TYPE MANAGEMENT | |
114 | * | |
115 | * Declarations used to control the definition and use of 'types' | |
116 | * as supported by the global database system. Most of the | |
117 | * declarations for 'System Defined Types' will not be of concern | |
118 | * to typical users, with the exception of the type names like | |
119 | * INTEGER_T which are defined below. | |
120 | * | |
121 | * In this implementation, user defined types are added | |
122 | * dynamically during execution by calling the appropriate | |
123 | * functions. The define GDB_MAX_TYPES below sets the maximum | |
124 | * total number of types, including both system and user defined, | |
125 | * which the system can support for any one application. When | |
126 | * GDB_MAX_TYPES is changed, the libary must be re-built. Space | |
127 | * for a two dimensional array, with one word for each property | |
128 | * of each possible type, is allocated statically in the library. | |
129 | * | |
130 | ************************************************************************/ | |
5580185e | 131 | |
132 | ||
133 | /* | |
134 | * Maximum number of types we can support, including both system and | |
135 | * user defined. | |
136 | */ | |
137 | ||
138 | #define GDB_MAX_TYPES 50 | |
139 | ||
140 | typedef int FIELD_TYPE; /* data needed to repre- */ | |
141 | /* sent a system or user */ | |
142 | /* defined data type */ | |
143 | /* This is actualy just */ | |
144 | /* a row index in the type */ | |
145 | /* definition table */ | |
146 | ||
939744d7 | 147 | /*---------------------------------------------------------- |
148 | * | |
149 | * System defined types | |
150 | * | |
151 | * WARNING: Any changes to these type definitions must be | |
152 | * carefully matched with the initializations in the | |
153 | * gdb_i_stype routine in gdb_stype.c. Mistakes in these | |
154 | * tables may be VERY difficult to debug. Be careful! | |
155 | * | |
156 | *----------------------------------------------------------*/ | |
5580185e | 157 | |
158 | /* | |
159 | * Primitive types for ingres data | |
160 | */ | |
161 | ||
162 | #define INTEGER_T (0) | |
163 | #define STRING_T (1) | |
164 | #define REAL_T (2) | |
165 | #define DATE_T (3) | |
166 | ||
167 | /* | |
168 | * Structured types | |
169 | */ | |
170 | ||
171 | #define TUPLE_DESCRIPTOR_T (4) | |
172 | #define TUPLE_T (5) | |
173 | #define TUPLE_DATA_T (6) | |
174 | #define RELATION_T (7) | |
175 | ||
176 | /* | |
177 | * Number of system defined types | |
178 | * | |
179 | * This will always be equal to one more than index of last system type | |
180 | */ | |
181 | ||
182 | #define SYSTEM_TYPE_COUNT 8 | |
183 | ||
939744d7 | 184 | /*---------------------------------------------------------- |
185 | * | |
186 | * Type descriptor tables | |
187 | * | |
188 | *----------------------------------------------------------*/ | |
5580185e | 189 | |
190 | /* | |
191 | * gdb_prop_union | |
192 | * | |
193 | * Each entry in the type definition table is a union of this form, | |
194 | * which allows us to store a choice of an integer, a function | |
195 | * pointer, or a pointer to a character string. | |
196 | */ | |
197 | ||
198 | union gdb_prop_union { | |
199 | int i; /* when we want as an */ | |
200 | /* integer */ | |
201 | int (*f)(); /* as a function pointer */ | |
202 | char *cp; /* character pointer */ | |
203 | }; | |
204 | ||
205 | #define TYPE_PROPERTY_COUNT 8 /* number of properties */ | |
206 | /* for each type*/ | |
207 | ||
208 | /* | |
209 | * Uses of the type properties. Each type has a set of properties. | |
210 | * Some are integers, some are functions. The defines below descrive | |
211 | * respectively the 0'th,1'st, 2'nd, etc. properties of EACH type. | |
212 | * | |
213 | * Note: TYPE_PROPERTY_COUNT (above) must be changed when new properties | |
214 | * are added. For system defined types, bindings for the properties | |
215 | * are done in gdb_i_stype in the gdb_stype.c source file. | |
216 | */ | |
217 | ||
218 | #define LENGTH_PROPERTY 0 /* integer */ | |
219 | #define ALIGNMENT_PROPERTY 1 /* integer */ | |
220 | #define NULL_PROPERTY 2 /* function */ | |
221 | #define CODED_LENGTH_PROPERTY 3 /* function */ | |
222 | #define ENCODE_PROPERTY 4 /* function */ | |
223 | #define DECODE_PROPERTY 5 /* function */ | |
224 | #define FORMAT_PROPERTY 6 /* function */ | |
225 | #define NAME_PROPERTY 7 /* char pointer */ | |
226 | ||
227 | /* | |
228 | * gdb_type_def | |
229 | * | |
230 | * Information to describe a single type | |
231 | */ | |
232 | ||
233 | typedef union gdb_prop_union gdb_type_def[TYPE_PROPERTY_COUNT]; | |
234 | ||
235 | ||
236 | /* | |
237 | * g_type_table | |
238 | * | |
239 | * This is the table where the actual definitions for the types are | |
240 | * kept. | |
241 | */ | |
242 | ||
243 | extern gdb_type_def g_type_table[GDB_MAX_TYPES]; | |
244 | extern int gdb_n_types; /* number of entries in */ | |
245 | /* table */ | |
246 | ||
939744d7 | 247 | /*---------------------------------------------------------- |
248 | * | |
249 | * Macros for accessing properties | |
250 | * | |
251 | *----------------------------------------------------------*/ | |
5580185e | 252 | |
253 | #define INT_PROPERTY(type, prop) (g_type_table[type][prop].i) | |
254 | #define STR_PROPERTY(type, prop) (g_type_table[type][prop].cp) | |
255 | #define FCN_PROPERTY(type, prop) (*g_type_table[type][prop].f) | |
256 | ||
257 | \f | |
939744d7 | 258 | /************************************************************************ |
259 | * | |
260 | * STRUCTURED DATA | |
261 | * | |
262 | * Stuff needed to declare and manage TUPLES, TUPLE_DESCRIPTORS | |
263 | * and RELATIONS. | |
264 | * | |
265 | ************************************************************************/ | |
266 | ||
267 | /*---------------------------------------------------------- | |
268 | * | |
269 | * TUPLE_DESCRIPTOR | |
270 | * | |
271 | *----------------------------------------------------------*/ | |
5580185e | 272 | |
273 | #define GDB_DESC_ID 0x54504400 /* "TPD" */ | |
274 | ||
275 | struct tupld_var { /* the variable length */ | |
276 | /* stuff in a tuple */ | |
277 | /* descriptor*/ | |
278 | char *name; /* string name of field */ | |
279 | FIELD_TYPE type; /* type of this field */ | |
280 | int offset; /* byte offset of this field */ | |
281 | /* relative to first byte of */ | |
282 | /* data (not start of whole */ | |
283 | /* tuple) */ | |
284 | int length; /* Length of the actual data */ | |
285 | /* for this field. Note that */ | |
286 | /* alignment requirements of */ | |
287 | /* following field are NOT */ | |
288 | /* included in this length */ | |
289 | }; | |
290 | struct tupl_desc { | |
291 | long id; /* this should say TPD\0 */ | |
292 | int ref_count; /* when this goes to zero, */ | |
293 | /* the descriptor may really */ | |
294 | /* be reclaimed */ | |
295 | int field_count; /* number of fields in */ | |
296 | /* the tuple*/ | |
297 | int data_len; /* length of the data in */ | |
298 | /* the actual tuple */ | |
299 | int str_len; /* length of the strings */ | |
300 | /* stored off the end of */ | |
301 | /* this descriptor*/ | |
302 | struct tupld_var var[1]; /* one of these for each */ | |
303 | /* field, but the C compiler */ | |
304 | /* won't accept the[] decl, */ | |
305 | /* because it's afraid of */ | |
306 | /* uncertain length*/ | |
307 | }; | |
308 | ||
309 | typedef struct tupl_desc *TUPLE_DESCRIPTOR; /* use this to declare a */ | |
310 | /* tuple descriptor anchor */ | |
311 | ||
312 | #define gdb_descriptor_length(num_flds) (sizeof(struct tupl_desc) + ((num_flds)-1) * sizeof(struct tupld_var)) | |
313 | ||
939744d7 | 314 | /*---------------------------------------------------------- |
315 | * | |
316 | * TUPLE | |
317 | * | |
318 | * tuple_dat is allocated by the create_tuple routine. | |
319 | * | |
320 | * TUPLE may be used in user code to declare a handle | |
321 | * on a tuple. | |
322 | * | |
323 | *----------------------------------------------------------*/ | |
5580185e | 324 | |
325 | #define GDB_TUP_ID 0x54555000 | |
326 | ||
327 | typedef struct tuple_dat *TUPLE; /* handle on a tuple */ | |
328 | ||
329 | struct tuple_dat { | |
330 | TUPLE next, prev; /* chain pointers when */ | |
331 | /* tuples are linked, as in */ | |
332 | /* a relation. Convention is*/ | |
333 | /* double linked, circular.*/ | |
334 | long id; /* should say TUP\0 */ | |
335 | TUPLE_DESCRIPTOR desc; /* pointer to the descriptor */ | |
336 | char data[1]; /* data goes here, word */ | |
337 | /* aligned. Should be [] */ | |
338 | /* if compiler would allow */ | |
339 | }; | |
340 | ||
341 | ||
939744d7 | 342 | /*---------------------------------------------------------- |
343 | * | |
344 | * RELATION | |
345 | * | |
346 | * rel_dat is allocated by the create_relation | |
347 | * routine. | |
348 | * | |
349 | * RELATION may be used in user code to declare a handle | |
350 | * on a relation. | |
351 | * | |
352 | *----------------------------------------------------------*/ | |
5580185e | 353 | |
354 | #define GDB_REL_ID 0x52454c00 | |
355 | ||
356 | struct rel_dat { | |
357 | TUPLE first, last; /* chain pointers to tuples */ | |
358 | /* note that first->prev and */ | |
359 | /* last->next are both == */ | |
360 | /* &rel-dat. Maintenance is */ | |
361 | /* simplified by keeping */ | |
362 | /* as the first fields in */ | |
363 | /* both rel_dat and tuple_dat*/ | |
364 | /* a minor non-portability */ | |
365 | long id; /* should contain REL\0 */ | |
366 | TUPLE_DESCRIPTOR desc; /* descriptor for the tuples */ | |
367 | /* in this relation. Should */ | |
368 | /* == that in each tuple */ | |
369 | ||
370 | }; | |
371 | ||
372 | typedef struct rel_dat *RELATION; /* handle on a relation */ | |
373 | \f | |
939744d7 | 374 | /************************************************************************ |
375 | * | |
376 | * transport LAYER DECLARATIONS | |
377 | * | |
378 | * Declares the state maintenance structures for full duplex | |
379 | * connections with asynchronous transmission capability. Most | |
380 | * users need only know that the type CONNECTION is defined, and | |
381 | * that it may be treated as a pointer for most purposes (i.e. it | |
382 | * is compact, and copying it does not actually copy the connection | |
383 | * state.) | |
384 | * | |
385 | ************************************************************************/ | |
5580185e | 386 | |
387 | #define GDB_PROTOCOL_VERSION 0x01 /* version of the gdb */ | |
388 | /* protocols that we're */ | |
389 | /* observing */ | |
390 | #define GDB_STREAM_BUFFER_SIZE 4096 /* amount to read in */ | |
391 | /* one chunk from tcp stream*/ | |
392 | #define GDB_PORT htons(9425) /* temporary until we use */ | |
393 | /* services properly */ | |
394 | #define GDB_BIND_RETRY_COUNT 5 /* number of times to */ | |
395 | /* retry a bind before */ | |
396 | /* giving up. Used when */ | |
397 | /* accepting connections */ | |
398 | #define GDB_BIND_RETRY_INTERVAL 10 /* Number of seconds to wait */ | |
399 | /* between attempts to bind */ | |
400 | /* the listening socket */ | |
401 | #define GDB_MAX_CONNECTIONS 25 /* maximum number of */ | |
402 | /* connections that */ | |
403 | /* any one process can */ | |
404 | /* control simultaneously */ | |
405 | /* | |
406 | * Circumvent bug in ACIS 4.2 socket support | |
407 | */ | |
408 | #ifdef ibm032 | |
409 | #define GDB_MAX_SOCK_WRITE 2047 /* rt can't do socket */ | |
410 | /* writes longer than this */ | |
411 | /* gives errno 40*/ | |
412 | #else | |
413 | #define GDB_MAX_SOCK_WRITE 0x00ffffff | |
414 | #endif | |
415 | ||
939744d7 | 416 | /*---------------------------------------------------------- |
417 | * | |
418 | * Declarations for HALF_CONNECTIONS | |
419 | * | |
420 | * Each full duplex connection has associated with it | |
421 | * two simplex half-connections, each of which | |
422 | * has its own queue of pending operations. The | |
423 | * following describes the state of a half-connection. | |
424 | * | |
425 | *----------------------------------------------------------*/ | |
5580185e | 426 | |
427 | struct half_con_data { | |
428 | /* | |
429 | * these two must be first to match position in OPERATION | |
430 | */ | |
431 | struct oper_data *op_q_first; /* first item in q of pending*/ | |
432 | /* operations for this */ | |
433 | /* half-connection. (chained */ | |
434 | /* circularly to half con, */ | |
435 | /* NOT the con. */ | |
436 | struct oper_data *op_q_last; /* last item in q of pending*/ | |
437 | /* operations for this */ | |
438 | /* half-connection*/ | |
439 | int status; /* values are of type */ | |
440 | /* OPSTATUS. tells whether */ | |
441 | /* transmit/receive is */ | |
442 | /* pending.*/ | |
443 | long flags; /* bit flags */ | |
444 | #define HCON_PROGRESS 0x00000001 /* used by selection */ | |
445 | /* routines to detect */ | |
446 | /* progress */ | |
447 | #define HCON_LISTEN 0x00000002 /* indicates that this is */ | |
448 | /* a special half connection */ | |
449 | /* used only for listenting */ | |
450 | /* to incoming connection */ | |
451 | /* requests */ | |
452 | #define HCON_UNUSED 0x00000004 /* on a one-way connection, */ | |
453 | /* this flag marks an unused */ | |
454 | /* half */ | |
455 | #define HCON_PENDING_LISTEN 0x00000008 /* a queued op on this half */ | |
456 | /* connection is actually */ | |
457 | /* trying to listen */ | |
458 | #define HCON_BUSY 0x00000010 /* we are currently making */ | |
459 | /* progress on this half */ | |
460 | /* connection. Used to */ | |
461 | /* detect re-entrance of */ | |
462 | /* hcon_progress */ | |
463 | int fd; /* main half duplex file */ | |
464 | /* descriptor for this h_conn*/ | |
465 | int oob_fd; /* file descriptor for */ | |
466 | /* out of band signals*/ | |
467 | char *next_byte; /* next byte to send/recv */ | |
468 | int remaining; /* number of bytes remaining */ | |
469 | /* to send/receive */ | |
470 | char *stream_buffer; /* points to a buffer */ | |
471 | /* used to pre-read/write */ | |
472 | /* the stream to avoid */ | |
473 | /* window thrashing */ | |
474 | int stream_buffer_length; /* length of the stream */ | |
475 | /* buffer */ | |
476 | char *stream_buffer_next; /* next byte to read in */ | |
477 | /* stream buffer */ | |
478 | int stream_buffer_remaining; /* number of bytes currently */ | |
479 | /* in use in stream buffer*/ | |
480 | int *accepted_fdp; /* used only for listening */ | |
481 | /* connections. latest */ | |
482 | /* accepted fd is put where*/ | |
483 | /* this points */ | |
484 | int *accepted_len; /* ptr to length of 'from' */ | |
485 | /* data on accept */ | |
486 | ||
487 | }; | |
488 | ||
489 | typedef struct half_con_data *HALF_CONNECTION; | |
490 | ||
491 | ||
939744d7 | 492 | /*---------------------------------------------------------- |
493 | * | |
494 | * Declarations for CONNECTIONS | |
495 | * | |
496 | *----------------------------------------------------------*/ | |
5580185e | 497 | |
498 | #define GDB_CON_ID 0x434f4e00 /*"CON"*/ | |
499 | ||
500 | struct con_data { | |
501 | long id; /* should contain CON\0 */ | |
502 | int status; /* See definitions below. */ | |
503 | /* Do not confuse with */ | |
504 | /* the status sub-fields of */ | |
505 | /* in and out half-cons. */ | |
506 | int version; /* the version of the */ | |
507 | /* protocol being observed */ | |
508 | /* on this connection */ | |
509 | int errno; /* the real errno gets */ | |
510 | /* copied here if it causes */ | |
511 | /* the connection to die */ | |
512 | int (*oob_fcn)(); /* pointer to function to */ | |
513 | /* call when something */ | |
514 | /* arrives on the out of */ | |
515 | /* band channel */ | |
516 | struct half_con_data in, out; /* states of the inbound */ | |
517 | /* and outbound half */ | |
518 | /* sessions.*/ | |
519 | }; | |
520 | ||
521 | typedef struct con_data *CONNECTION; /* the only externally */ | |
522 | /* visible handle on a */ | |
523 | /* connection*/ | |
524 | ||
525 | /* | |
526 | * Definitions of status fields. | |
527 | * | |
528 | * WARNING: If you change any of the following, there are coordinated | |
529 | * changes to be made in gdb_debug.c | |
530 | */ | |
531 | ||
532 | #define CON_STOPPED 1 /* never started, terminated */ | |
533 | #define CON_UP 2 /* ready to use */ | |
534 | #define CON_STARTING 3 /* trying to start */ | |
535 | #define CON_STOPPING 4 /* trying to stop */ | |
536 | ||
537 | /* | |
538 | * The following are used as keywords when distinguishing input from output | |
539 | * half connections. | |
540 | */ | |
541 | #define CON_INPUT 1 /* this is an input half */ | |
542 | /* session*/ | |
543 | #define CON_OUTPUT 2 /* this is an output half */ | |
544 | /* session*/ | |
545 | ||
546 | ||
939744d7 | 547 | /*---------------------------------------------------------- |
548 | * | |
549 | * gdb_cons | |
550 | * | |
551 | * This is the array of connection control data | |
552 | * structures for gdb. Every connection has its | |
553 | * structure stored here, but they are in no | |
554 | * particular order. Because the connection data | |
555 | * itself cannot be moved (due to possible dangling | |
556 | * pointers), there may be some unused connections | |
557 | * in the middle of this array. gdb_mcons is the | |
558 | * 1 based number of the highest connection which is | |
559 | * actually in use at this time. This is a considerable | |
560 | * optimization for the typical case where very few | |
561 | * are in use, and turnover is low. | |
562 | * | |
563 | * These are externs for globals defined in gdb_lib.h | |
564 | * and included by gdb.c. | |
565 | * | |
566 | *----------------------------------------------------------*/ | |
5580185e | 567 | |
568 | extern int gdb_mcons; /* one based number of the */ | |
569 | /* highest connection */ | |
570 | /* descriptor we're using */ | |
571 | /* at the moment */ | |
572 | ||
573 | extern int gdb_mfd; /* number of the highest */ | |
574 | /* file descriptor in use */ | |
575 | /* for a connection */ | |
576 | extern struct con_data gdb_cons[GDB_MAX_CONNECTIONS]; | |
577 | /* actual connection data */ | |
578 | /* is stored here */ | |
579 | ||
580 | extern fd_set gdb_crfds, gdb_cwfds, gdb_cefds; /* connection related file */ | |
581 | /* descriptor maps to be */ | |
582 | /* used in select */ | |
583 | fd_set last_crfds, last_cwfds, last_cefds; /* these file desc. bit */ | |
584 | /* masks are set up */ | |
585 | /* for each select call */ | |
586 | /* to include the user */ | |
587 | /* supplied and the */ | |
588 | /* connection related */ | |
589 | /* fd's */ | |
590 | ||
939744d7 | 591 | /*---------------------------------------------------------- |
592 | * | |
593 | * OPERATIONS | |
594 | * | |
595 | *----------------------------------------------------------*/ | |
5580185e | 596 | |
597 | #define GDB_OP_ID 0x4f505200 | |
598 | ||
599 | struct oper_data { | |
600 | struct oper_data *next, *prev; /* forward and back chain */ | |
601 | long id; /* should contain OPR\0 */ | |
602 | int tag; /* unique identifier for */ | |
603 | /* this operation */ | |
604 | int status; /* current state of this */ | |
605 | /* oaperation*/ | |
606 | int flags; | |
607 | #define OPF_MARKED_COMPLETE 0x00000001 /* operation was already */ | |
608 | /* complete when opsel was */ | |
609 | /* called*/ | |
610 | #define OPF_MARKED_CANCELLED 0x00000002 /* operation was already */ | |
611 | /* cancelled when opsel was */ | |
612 | /* called*/ | |
613 | int result; /* when the operation */ | |
614 | /* completes, this field is */ | |
615 | /* set to reflect its dispos-*/ | |
616 | /* ition. Contents of this */ | |
617 | /* field will depend on the */ | |
618 | /* operation being performed */ | |
619 | HALF_CONNECTION halfcon; /* the half connection on */ | |
620 | /* which this operation is */ | |
621 | /* queued */ | |
622 | /* May be meaningless if not */ | |
623 | /* queued..*/ | |
624 | char *arg; /* pointer to user data */ | |
625 | union fcn { | |
626 | int (*init)(); /* pointer to routine to */ | |
627 | /* call to start this */ | |
628 | ||
629 | /* operation*/ | |
630 | int (*cont)(); /* pointer to function to */ | |
631 | /* be called when this */ | |
632 | /* logical operation */ | |
633 | /* continues*/ | |
634 | } fcn; | |
635 | ||
636 | int (*cancel)(); /* this routine gets called */ | |
637 | /* to handle a cancel request*/ | |
638 | /* this field is normally */ | |
639 | /* set to NULL when the */ | |
640 | /* operation is queued and */ | |
641 | /* updated as required by */ | |
642 | /* the init and cont funcs. */ | |
643 | }; | |
644 | ||
645 | typedef struct oper_data OPERATION_DATA; /* an actual operation */ | |
646 | /* descritor, creator is */ | |
647 | /* responsible for making */ | |
648 | /* sure that memory is not */ | |
649 | /* freed while in use */ | |
650 | typedef OPERATION_DATA *OPERATION; /* a handle on an operation */ | |
651 | /* this is what most */ | |
652 | /* applications will use */ | |
653 | ||
939744d7 | 654 | /*---------------------------------------------------------- |
655 | * | |
656 | * STATES OF AN OPERATION | |
657 | * | |
658 | * These represent the state of an asynchronous, queued | |
659 | * operation. For convenience of the application programmer, | |
660 | * some of these are folded together when queried through the | |
661 | * operation_status routine. In particular, operation status | |
662 | * returns only one of: | |
663 | * | |
664 | * OP_NOT_RUNNING, OP_RUNNING, OP_COMPLETE, or | |
665 | * OP_CANCELLED. | |
666 | * | |
667 | * Any other status is reported as OP_RUNNING. This is | |
668 | * done on the assumption that it makes correct coding | |
669 | * of applications less error-prone, as there are fewer | |
670 | * cases to check, and most of them would not be of | |
671 | * interest anyway. | |
672 | * | |
673 | * Note that OP_CANCELLED may be generated by the system | |
674 | * even when no explicit request for cancellation has been | |
675 | * issued. For example, this may occur when a connection | |
676 | * is severed unexpectedly. | |
677 | * | |
678 | * WARNING: If you change any of the following, be sure | |
679 | * to make the equivalent changes to gdb_debug.c. | |
680 | * | |
681 | * We also define here certain standard values of OP_RESULT, | |
682 | * since some return conventions presume that op_status | |
683 | * and op_result values are orthogonal. | |
684 | * | |
685 | *----------------------------------------------------------*/ | |
5580185e | 686 | |
687 | #define OP_SUCCESS 0 /* this value is actually */ | |
688 | /* used only in result */ | |
689 | /* fields, but it is */ | |
690 | /* sometimes convenient to */ | |
691 | /* have status and result */ | |
692 | /* have orthogonal values */ | |
693 | #define OP_NOT_STARTED 1 /* this operation has been */ | |
694 | /* initialized but is not on */ | |
695 | /* any connection's queue */ | |
696 | #define OP_QUEUED 2 /* this operation is on */ | |
697 | /* some connection's queue */ | |
698 | /* but it has not yet */ | |
699 | /* reached the head of the q */ | |
700 | #define OP_RUNNING 3 /* op is at head of q trying */ | |
701 | /* to progress */ | |
702 | #define OP_COMPLETE 4 /* operation has run to */ | |
703 | /* completion. result field */ | |
704 | /* is now valid */ | |
705 | #define OP_CANCELLING 5 /* we are in the process of */ | |
706 | /* (trying to) cancel this */ | |
707 | /* operation */ | |
708 | #define OP_CANCELLED 6 /* operation was prematurely */ | |
709 | /* terminated. result field */ | |
710 | /* is NOT valid. */ | |
711 | #define OP_MARKED 7 /* used by op_select_all */ | |
712 | #define OP_REQUEUED 8 /* returned by an init or */ | |
713 | /* continuation routine to */ | |
714 | /* indicate that the */ | |
715 | /* operation has requeued */ | |
716 | /* itself */ | |
717 | #define OP_PREEMPTED 9 /* returned by an init or */ | |
718 | /* continuation routine to */ | |
719 | /* indicate that the op has */ | |
720 | /* preempted itself by */ | |
721 | /* queueing a new operation */ | |
722 | /* ahead of itself */ | |
723 | ||
939744d7 | 724 | /*---------------------------------------------------------- |
725 | * | |
726 | * LIST_OF_OPERATIONS | |
727 | * | |
728 | *----------------------------------------------------------*/ | |
5580185e | 729 | |
730 | struct oper_list { | |
731 | int count; /* number of operations */ | |
732 | /* in the list */ | |
733 | OPERATION op[1]; /* really op[n], but */ | |
734 | /* structs must have a */ | |
735 | /* definite length */ | |
736 | }; | |
737 | ||
738 | typedef struct oper_list *LIST_OF_OPERATIONS; /* handle on a list */ | |
739 | ||
740 | #define size_of_list_of_operations(n) \ | |
741 | (sizeof(struct oper_list) + (n-1)*sizeof(OPERATION)) | |
742 | ||
939744d7 | 743 | /*---------------------------------------------------------- |
744 | * | |
745 | * gdb_notime | |
746 | * | |
747 | * Pass this to select when doing a poll. | |
748 | * | |
749 | *----------------------------------------------------------*/ | |
5580185e | 750 | |
751 | extern struct timeval gdb_notime; | |
752 | ||
753 | \f | |
939744d7 | 754 | /************************************************************************ |
755 | * | |
756 | * CHECKING ROUTINES IMPLEMENTED AS MACROS | |
757 | * | |
758 | ************************************************************************/ | |
5580185e | 759 | |
760 | extern char g_errstr[150]; /* build emsgs here */ | |
761 | ||
762 | #define GDB_INIT_CHECK g_chk_init(); /* make sure gdb_init */ | |
763 | /* was called */ | |
764 | ||
765 | #define GDB_CHECK_CON(con, where) if ((con)->id != GDB_CON_ID) \ | |
766 | { (void) sprintf(g_errstr, "Invalid connection descriptor passed to \"%s\"\n", where); \ | |
767 | GDB_GIVEUP(g_errstr) } | |
768 | ||
769 | ||
770 | #define GDB_CHECK_TUP(tup, where) if ((tup)->id != GDB_TUP_ID) \ | |
771 | { (void) sprintf(g_errstr, "Invalid tuple passed to \"%s\"\n", where); \ | |
772 | GDB_GIVEUP(g_errstr) } | |
773 | ||
774 | ||
775 | #define GDB_CHECK_TPD(tpd, where) if ((tpd)->id != GDB_DESC_ID) \ | |
776 | { (void) sprintf(g_errstr, "Invalid tuple descriptor passed to \"%s\"\n", where); \ | |
777 | GDB_GIVEUP(g_errstr) } | |
778 | ||
779 | ||
780 | #define GDB_CHECK_REL(rel, where) if ((rel)->id != GDB_REL_ID) \ | |
781 | { (void) sprintf(g_errstr, "Invalid relation passed to \"%s\"\n", where); \ | |
782 | GDB_GIVEUP(g_errstr) } | |
783 | ||
784 | #define GDB_CHECK_OP(op, where) if ((op)->id != GDB_OP_ID) \ | |
785 | { (void) sprintf(g_errstr, "Invalid operation passed to \"%s\"\n", where); \ | |
786 | GDB_GIVEUP(g_errstr) } | |
787 | ||
788 | #define GDB_CHECK_DB(db, where) if (db->id != GDB_DB_ID) \ | |
789 | { (void) sprintf(g_errstr, "Invalid database handle passed to \"%s\"\n", where); \ | |
790 | GDB_GIVEUP(g_errstr) } | |
791 | ||
792 | ||
793 | ||
794 | \f | |
939744d7 | 795 | /************************************************************************ |
796 | * | |
797 | * TRANSPORT ROUTINES IMPLEMENTED AS MACROS | |
798 | * | |
799 | ************************************************************************/ | |
800 | ||
801 | /*---------------------------------------------------------- | |
802 | * | |
803 | * connection_status | |
804 | * | |
805 | * Returns the status of the indicated connection. | |
806 | * Possible return values are: | |
807 | * | |
808 | * CON_STOPPED never started or terminated | |
809 | * CON_UP currently usable | |
810 | * CON_STARTING transient state on way up | |
811 | * CON_STOPPING transient state on way down | |
812 | * | |
813 | *----------------------------------------------------------*/ | |
5580185e | 814 | |
815 | #define connection_status(con) ((con)->status) | |
816 | ||
939744d7 | 817 | /*---------------------------------------------------------- |
818 | * | |
819 | * connection_errno | |
820 | * | |
821 | * When a connection dies due to an error on a system | |
822 | * call, the corresponding errno is recorded in the | |
823 | * connection descriptor. This macro returns that value. | |
824 | * | |
825 | *----------------------------------------------------------*/ | |
5580185e | 826 | |
827 | #define connection_errno(con) ((con)->errno) | |
828 | ||
829 | ||
830 | \f | |
939744d7 | 831 | /************************************************************************ |
832 | * | |
833 | * SERVER/CLIENT MANAGEMENT | |
834 | * | |
835 | * Definitions used in starting and maintaining communication | |
836 | * between servers and clients (as opposed to peers.) | |
837 | * | |
838 | ************************************************************************/ | |
5580185e | 839 | |
840 | #define GDB_MAX_SERVER_RETRIES 3 /* maximum number of times */ | |
841 | /* clients will accept */ | |
842 | /* forwarding requests from */ | |
843 | /* a given server */ | |
844 | ||
845 | ||
846 | extern TUPLE_DESCRIPTOR gdb_tosrv; /* descriptor for request */ | |
847 | /* tuples sent to the */ | |
848 | /* server during negotiation*/ | |
849 | ||
850 | extern TUPLE_DESCRIPTOR gdb_fmsrv; /* descriptor for request */ | |
851 | /* tuples sent from the */ | |
852 | /* server during negotiation*/ | |
853 | ||
854 | #define GDB_MAX_SERVER_ID_SIZE 255 /* longest name of a server */ | |
855 | /* that we can handle */ | |
856 | #define GDB_MAX_SERVER_PARMS_SIZE 1023 /* longest parm string we */ | |
857 | /* can exchange between */ | |
858 | /* server and client*/ | |
859 | ||
939744d7 | 860 | /*---------------------------------------------------------- |
861 | * | |
862 | * The following are values returned in the disposition | |
863 | * field of the response tuple to indicate what the | |
864 | * server has decided to do about the connection | |
865 | * request. | |
866 | * | |
867 | *----------------------------------------------------------*/ | |
5580185e | 868 | |
869 | #define GDB_ACCEPTED 1 | |
870 | #define GDB_REFUSED 2 | |
871 | #define GDB_FORWARDED 3 | |
872 | ||
939744d7 | 873 | /*---------------------------------------------------------- |
874 | * | |
875 | * Global variables inherited by a child from a server | |
876 | * parent. | |
877 | * | |
878 | *----------------------------------------------------------*/ | |
5580185e | 879 | |
880 | extern TUPLE gdb_client_tuple; /* request tuple sent from */ | |
881 | /* the client */ | |
882 | ||
883 | extern char gdb_sockaddr_of_client[100]; /* this should really be */ | |
884 | /* sockaddr_in, but I don't */ | |
885 | /* want everyone to have */ | |
886 | /* to include all those */ | |
887 | /* big .h files */ | |
888 | extern int gdb_socklen; /* length of above */ | |
889 | ||
890 | ||
891 | \f | |
939744d7 | 892 | /************************************************************************ |
893 | * | |
894 | * DATABASE MANAGEMENT | |
895 | * | |
896 | * This layer of GDB provides access to the services of a relational | |
897 | * database from anywhere in a GDB network. | |
898 | * | |
899 | ************************************************************************/ | |
900 | ||
901 | /*---------------------------------------------------------- | |
902 | * | |
903 | * GDB_DB_SERVICE | |
904 | * | |
905 | * The name of the service, as found in /etc/services, | |
906 | * for GDB database servers. | |
907 | * | |
908 | *----------------------------------------------------------*/ | |
5580185e | 909 | |
910 | #define GDB_DB_SERVICE "#9420" | |
911 | ||
939744d7 | 912 | /*---------------------------------------------------------- |
913 | * | |
914 | * DATABASE | |
915 | * | |
916 | * Describes a client's active connection to a database. | |
917 | * | |
918 | *----------------------------------------------------------*/ | |
5580185e | 919 | |
920 | #define GDB_DB_ID 0x44420000 /* eye catcher */ | |
921 | ||
922 | struct db_struct { | |
923 | long id; /* eye catcher */ | |
924 | CONNECTION connection; /* the GDB connection */ | |
925 | /* used to get at this */ | |
926 | /* database */ | |
927 | int status; /* status of this */ | |
928 | /* database connection */ | |
929 | #define DB_OPEN 1 /* database opened */ | |
930 | /* successfully */ | |
931 | #define DB_CLOSED 2 /* not open */ | |
932 | char *name; /* pointer to string name */ | |
933 | /* of the database, for */ | |
934 | /* debugging */ | |
935 | char *server; /* pointer to the i.d. */ | |
936 | /* of the server, for */ | |
937 | /* debugging */ | |
938 | }; | |
939 | ||
940 | typedef struct db_struct *DATABASE; | |
941 | ||
939744d7 | 942 | /*---------------------------------------------------------- |
943 | * | |
944 | * Return codes from DB operations | |
945 | * | |
946 | *----------------------------------------------------------*/ | |
5580185e | 947 | |
948 | #define DB_NO_SUCH_OP 3 | |
949 | ||
939744d7 | 950 | /*---------------------------------------------------------- |
951 | * | |
952 | * Parameters which limit sizes of things | |
953 | * | |
954 | *----------------------------------------------------------*/ | |
5580185e | 955 | |
956 | #define GDB_MAX_QUERY_SIZE 2048 /* length of the longest */ | |
957 | /* substituted query */ | |
958 | /* string we can make */ | |
959 | #define GDB_MAX_QUERY_FIELDS 100 /* maximum number of fields */ | |
960 | /* we can retrieve in one */ | |
961 | /* query */ | |
962 | #define GDB_SIZE_OF_INGRES_TEXT 2001 /* number of chars in */ | |
963 | /* largest ingres text */ | |
964 | /* field */ | |
965 | #define GDB_MAX_RETRIEVED_TEXT_FIELDS 60 /* maximum number of text */ | |
966 | /* type fields we can */ | |
967 | /* retrieve in a single */ | |
968 | /* query. we hold this */ | |
969 | /* down because stack space */ | |
970 | /* is taken for max size of */ | |
971 | /* each during query. */ | |
972 | ||
939744d7 | 973 | /*---------------------------------------------------------- |
974 | * | |
975 | * Return codes from database operations | |
976 | * | |
977 | *----------------------------------------------------------*/ | |
5580185e | 978 | |
979 | #define DB_PARSE_FAIL (-3) /* couldn't parse */ | |
980 | /* the request string*/ | |
981 | ||
982 | \f | |
939744d7 | 983 | /************************************************************************ |
984 | * | |
985 | * DATABASE OPERATIONS IMPLEMENTED | |
986 | * AS MACROS | |
987 | * | |
988 | ************************************************************************/ | |
989 | ||
990 | /*---------------------------------------------------------- | |
991 | * | |
992 | * DB_STATUS | |
993 | * | |
994 | *----------------------------------------------------------*/ | |
5580185e | 995 | |
996 | #define DB_STATUS(dbhandle) ((dbhandle)->status) | |
997 | ||
998 | ||
999 | ||
1000 | \f | |
939744d7 | 1001 | /************************************************************************ |
1002 | * | |
1003 | * STRING MANAGEMENT | |
1004 | * | |
1005 | * To allow dynamic manipulation of strings in gdb without | |
1006 | * excessive memory re-allocation, we define a string as a | |
1007 | * counted byte space. Though this space will frequently be used | |
1008 | * to store a standard null terminated string, that is not | |
1009 | * required. | |
1010 | * | |
1011 | * Current representation for a string is a pointer followed by | |
1012 | * an integer length. A null pointer indicates a null string, in | |
1013 | * which case the length is arbitrary. Any other pointer is to | |
1014 | * memory which was allocated by db_alloc in which must be free'd | |
1015 | * eventually with db_free. | |
1016 | * | |
1017 | ************************************************************************/ | |
5580185e | 1018 | |
1019 | typedef struct str_dat { | |
1020 | char *ptr; /* pointer to the data */ | |
1021 | int length; /* length of the allocated */ | |
1022 | /* memory (not necessarily */ | |
1023 | /* length of null-term'd */ | |
1024 | /* string stored there) */ | |
1025 | } STRING; | |
1026 | ||
939744d7 | 1027 | /*---------------------------------------------------------- |
1028 | * | |
1029 | * Macros for manipulating strings. These return | |
1030 | * the actual data from the string and the size of | |
1031 | * the data space respectively. To get the length of | |
1032 | * the null terminated string which might be stored | |
1033 | * there, use strlen(STRING_DATA(string)). | |
1034 | * | |
1035 | *----------------------------------------------------------*/ | |
5580185e | 1036 | |
1037 | ||
1038 | #define STRING_DATA(str) ((str).ptr) | |
1039 | #define MAX_STRING_SIZE(str) ((str).length) | |
1040 | ||
1041 | ||
939744d7 | 1042 | /************************************************************************ |
1043 | * | |
1044 | * MEMORY ALLOCATION | |
1045 | * | |
1046 | * db_alloc and db_free are the externally visible names of | |
1047 | * the memory allocation services. These actually call the | |
1048 | * routines pointed to by the vectors gdb_amv and gdb_fmv, which | |
1049 | * default to the supplied routines gdb_am and gdb_fm. Users | |
1050 | * may supply their own memory allocation by storing over the | |
1051 | * vectors. This may be done prior to calling gdb_init to | |
1052 | * insure that all dynamic memory is controlled by the user. | |
1053 | * | |
1054 | ************************************************************************/ | |
5580185e | 1055 | |
1056 | #define db_alloc (*gdb_amv) | |
1057 | #define db_free (*gdb_fmv) | |
1058 | ||
1059 | extern char *gdb_am(); | |
1060 | extern int gdb_fm(); | |
1061 | ||
1062 | extern char *((*gdb_amv)()); | |
1063 | extern int (*gdb_fmv)(); | |
1064 | ||
1065 | \f | |
939744d7 | 1066 | /************************************************************************ |
1067 | * | |
1068 | * STRUCTURED DATA ROUTINES IMPLEMENTED AS MACROS | |
1069 | * | |
1070 | ************************************************************************/ | |
1071 | ||
1072 | /*---------------------------------------------------------- | |
1073 | * | |
1074 | * ADD_TUPLE_TO_RELATION | |
1075 | * | |
1076 | *----------------------------------------------------------*/ | |
5580185e | 1077 | |
1078 | #define ADD_TUPLE_TO_RELATION(relation, tuple) \ | |
1079 | { \ | |
1080 | (tuple)->prev = (relation)->last; \ | |
1081 | (tuple)->next = (TUPLE)(relation); \ | |
1082 | (relation)->last = tuple; \ | |
1083 | (tuple)->prev->next = tuple; \ | |
1084 | } | |
1085 | ||
939744d7 | 1086 | /*---------------------------------------------------------- |
1087 | * | |
1088 | * ADD_TUPLE_AFTER_TUPLE | |
1089 | * | |
1090 | *----------------------------------------------------------*/ | |
5580185e | 1091 | |
1092 | #define ADD_TUPLE_AFTER_TUPLE(relation, tuple, prev_tuple) \ | |
1093 | { \ | |
1094 | (tuple)->prev = (prev_tuple)->next->prev; \ | |
1095 | (tuple)->next = (prev_tuple)->next; \ | |
1096 | (tuple)->next->prev = tuple; \ | |
1097 | (prev_tuple)->next = tuple; \ | |
1098 | } | |
1099 | ||
939744d7 | 1100 | /*---------------------------------------------------------- |
1101 | * | |
1102 | * REMOVE_TUPLE_FROM_RELATION | |
1103 | * | |
1104 | *----------------------------------------------------------*/ | |
5580185e | 1105 | |
1106 | #define REMOVE_TUPLE_FROM_RELATION(relation, tuple) \ | |
1107 | { \ | |
1108 | (tuple)->prev->next = (tuple)->next; \ | |
1109 | (tuple)->next->prev = (tuple)->prev; \ | |
1110 | } | |
1111 | ||
1112 | ||
939744d7 | 1113 | /*---------------------------------------------------------- |
1114 | * | |
1115 | * DESCRIPTOR_FROM_TUPLE | |
1116 | * | |
1117 | *----------------------------------------------------------*/ | |
5580185e | 1118 | |
1119 | #define DESCRIPTOR_FROM_TUPLE(tuple) ((tuple)->desc) | |
1120 | ||
939744d7 | 1121 | /*---------------------------------------------------------- |
1122 | * | |
1123 | * DESCRIPTOR_FROM_RELATION | |
1124 | * | |
1125 | *----------------------------------------------------------*/ | |
5580185e | 1126 | |
1127 | #define DESCRIPTOR_FROM_RELATION(relation) ((relation)->desc) | |
1128 | ||
939744d7 | 1129 | /*---------------------------------------------------------- |
1130 | * | |
1131 | * REFERENCE_TUPLE_DESCRIPTOR | |
1132 | * | |
1133 | * Bumps the reference count for a tuple descriptor. | |
1134 | * Intended only for internal use of GDB. | |
1135 | * | |
1136 | *----------------------------------------------------------*/ | |
5580185e | 1137 | |
1138 | #define REFERENCE_TUPLE_DESCRIPTOR(tpd) (++((tpd)->ref_count)) | |
1139 | ||
939744d7 | 1140 | /*---------------------------------------------------------- |
1141 | * | |
1142 | * UNREFERENCE_TUPLE_DESCRIPTOR | |
1143 | * | |
1144 | * Decrements the reference count for a tuple descriptor. | |
1145 | * Intended only for internal use of GDB. Warning: it | |
1146 | * is the user's responsibility to use delete_tuple_descriptor | |
1147 | * instead of this macro in any situation in which the | |
1148 | * reference count might go to zero. | |
1149 | * | |
1150 | *----------------------------------------------------------*/ | |
5580185e | 1151 | |
1152 | #define UNREFERENCE_TUPLE_DESCRIPTOR(tpd) (--((tpd)->ref_count)) | |
1153 | ||
939744d7 | 1154 | /*---------------------------------------------------------- |
1155 | * | |
1156 | * FIELD_FROM_TUPLE | |
1157 | * | |
1158 | *----------------------------------------------------------*/ | |
5580185e | 1159 | |
1160 | #define FIELD_FROM_TUPLE(tuple, field_index) \ | |
1161 | (((tuple)->data) + (((tuple)->desc)->var[field_index].offset)) | |
1162 | ||
939744d7 | 1163 | /*---------------------------------------------------------- |
1164 | * | |
1165 | * FIELD_OFFSET_IN_TUPLE | |
1166 | * | |
1167 | *----------------------------------------------------------*/ | |
5580185e | 1168 | |
1169 | #define FIELD_OFFSET_IN_TUPLE(tuple_descriptor, field_index) \ | |
1170 | ((tuple_descriptor)->var[field_index].offset) | |
1171 | ||
939744d7 | 1172 | /*---------------------------------------------------------- |
1173 | * | |
1174 | * FIELD_TYPE_IN_TUPLE | |
1175 | * | |
1176 | *----------------------------------------------------------*/ | |
5580185e | 1177 | |
1178 | #define FIELD_TYPE_IN_TUPLE(tuple_descriptor, field_index) \ | |
1179 | ((tuple_descriptor)->var[field_index].type) | |
1180 | ||
939744d7 | 1181 | /*---------------------------------------------------------- |
1182 | * | |
1183 | * FIRST_TUPLE_IN_RELATION | |
1184 | * | |
1185 | *----------------------------------------------------------*/ | |
5580185e | 1186 | |
1187 | #define FIRST_TUPLE_IN_RELATION(relation) \ | |
1188 | (((relation)->first) == (TUPLE)relation ? NULL : (relation)-> first) | |
1189 | ||
939744d7 | 1190 | /*---------------------------------------------------------- |
1191 | * | |
1192 | * NEXT_TUPLE_IN_RELATION | |
1193 | * | |
1194 | *----------------------------------------------------------*/ | |
5580185e | 1195 | |
1196 | #define NEXT_TUPLE_IN_RELATION(relation, prev) \ | |
1197 | (((prev)->next) == (TUPLE)relation ? NULL : prev->next ) | |
1198 | ||
939744d7 | 1199 | /*---------------------------------------------------------- |
1200 | * | |
1201 | * PREV_TUPLE_IN_RELATION | |
1202 | * | |
1203 | *----------------------------------------------------------*/ | |
5580185e | 1204 | |
1205 | #define PREV_TUPLE_IN_RELATION(relation, next) \ | |
1206 | (((next)->prev) == (TUPLE) relation ? NULL : next->prev) | |
1207 | ||
1208 | ||
1209 | ||
1210 | \f | |
939744d7 | 1211 | /************************************************************************ |
1212 | * | |
1213 | * TRANSPORT and OPERATION SERVICES IMPLEMENTED AS MACROS | |
1214 | * | |
1215 | ************************************************************************/ | |
1216 | ||
1217 | /*---------------------------------------------------------- | |
1218 | * | |
1219 | * OPERATION_FROM_DATA | |
1220 | * | |
1221 | * Given OPERATION_DATA, return the corresponding handle | |
1222 | * of type OPERATION. Currently, OPERATION is just | |
1223 | * implemented as a pointer to OPERATION_DATA. | |
1224 | * | |
1225 | *----------------------------------------------------------*/ | |
5580185e | 1226 | |
1227 | #define OPERATION_FROM_DATA(op_data) \ | |
1228 | ((OPERATION)&(op_data)) | |
1229 | ||
939744d7 | 1230 | /*---------------------------------------------------------- |
1231 | * | |
1232 | * OP_TAG | |
1233 | * | |
1234 | * Return the tag for a given operation. | |
1235 | * | |
1236 | *----------------------------------------------------------*/ | |
5580185e | 1237 | |
1238 | #define OP_TAG(operation) ((operation)->tag) | |
1239 | ||
939744d7 | 1240 | /*---------------------------------------------------------- |
1241 | * | |
1242 | * OP_STATUS | |
1243 | * | |
1244 | * Return the status of a given operation. Note that | |
1245 | * status describes an operations progress through | |
1246 | * execution. It has the same values for all operations. | |
1247 | * Result describes the final outcome of an operation. | |
1248 | * It's values depend on the particular operation which | |
1249 | * was attempted. | |
1250 | * | |
1251 | *----------------------------------------------------------*/ | |
5580185e | 1252 | |
1253 | #define OP_STATUS(operation) ((operation)->status) | |
1254 | ||
939744d7 | 1255 | /*---------------------------------------------------------- |
1256 | * | |
1257 | * OP_DONE | |
1258 | * | |
1259 | * True iff the operation is either OP_COMPLETE or | |
1260 | * OP_CANCELLED. | |
1261 | * | |
1262 | *----------------------------------------------------------*/ | |
5580185e | 1263 | |
1264 | #define OP_DONE(op) ((op)->status == OP_COMPLETE || (op)->status == OP_CANCELLED) | |
1265 | ||
939744d7 | 1266 | /*---------------------------------------------------------- |
1267 | * | |
1268 | * OP_RESULT | |
1269 | * | |
1270 | * Return the result of a given operation. Note that | |
1271 | * status describes an operations progress through | |
1272 | * execution. It has the same values for all operations. | |
1273 | * Result describes the final outcome of an operation. | |
1274 | * It's values depend on the particular operation which | |
1275 | * was attempted. The special result value -1 is used | |
1276 | * to indicate an invalid value for result. Generally, | |
1277 | * -1 is returned when result is accidently queried at | |
1278 | * a time when OP_STATUS != OPERATION_COMPLETE. | |
1279 | * | |
1280 | *----------------------------------------------------------*/ | |
5580185e | 1281 | |
1282 | #define OP_RESULT(operation) ((operation)->result) | |
1283 | ||
1284 | \f | |
939744d7 | 1285 | /************************************************************************ |
1286 | * | |
1287 | * Debugging Interfaces | |
1288 | * | |
1289 | ************************************************************************/ | |
1290 | ||
1291 | /*---------------------------------------------------------- | |
1292 | * | |
1293 | * The following operation codes my be passed to | |
1294 | * gdb_debug to set special debugging modes of operation. | |
1295 | * | |
1296 | * Note that most of these are toggles | |
1297 | * | |
1298 | *----------------------------------------------------------*/ | |
5580185e | 1299 | |
1300 | #define GDB_LOG 0x00000001 /* turn on tracing to */ | |
1301 | /* log file */ | |
1302 | #define GDB_NOFORK 0x00000002 /* don't fork forking */ | |
1303 | /* servers */ | |
1304 | ||
1305 | \f | |
939744d7 | 1306 | /************************************************************************ |
1307 | * | |
1308 | * Things which have to be at the end because they require | |
1309 | * the various types to be defined first. | |
1310 | * | |
1311 | ************************************************************************/ | |
5580185e | 1312 | |
1313 | ||
1314 | #ifdef DUMB_7_CHAR_LOADER | |
939744d7 | 1315 | /*---------------------------------------------------------- |
1316 | * | |
1317 | * Long Names for Routines | |
1318 | * | |
1319 | * External names in Unix must generally be unique | |
1320 | * within the first 7 characters or so, at least for | |
1321 | * some versions of ld. To account for this without | |
1322 | * making all our routine names terribly short and | |
1323 | * cryptic, we use the following defines. | |
1324 | * | |
1325 | *----------------------------------------------------------*/ | |
5580185e | 1326 | |
1327 | #define string_alloc gdb_sta | |
1328 | #define string_free gdb_stf | |
1329 | ||
1330 | #define create_tuple_descriptor gdb_ctd | |
1331 | #define delete_tuple_descriptor gdb_dtd | |
1332 | #define field_index gdb_fi | |
1333 | #define create_tuple gdb_ctup | |
1334 | #define delete_tuple gdb_dtup | |
1335 | #define initialize_tuple gdb_itup | |
1336 | #define null_tuple_strings gdb_ntps | |
1337 | ||
1338 | #define create_relation gdb_crel | |
1339 | #define delete_relation gdb_drel | |
1340 | #define tuples_in_relation gdb_trel | |
1341 | ||
1342 | ||
1343 | /* | |
1344 | * Transport layer | |
1345 | */ | |
1346 | #define create_operation gdb_crop | |
1347 | #define delete_operation gdb_dop | |
1348 | #define initialize_operation gdb_inop | |
1349 | #define reset_operation gdb_rsop | |
1350 | #define cancel_operation gdb_cnop | |
1351 | ||
1352 | #define create_list_of_operations gdb_clop | |
1353 | #define delete_list_of_operations gdb_dlop | |
1354 | ||
1355 | #define op_select gdb_opsel | |
1356 | #define op_select_any gdb_opsel | |
1357 | #define op_select_all gdb_aopsel | |
1358 | #define con_select gdb_cnsel | |
1359 | ||
1360 | #define gdb_receive_data gdb_rcdat | |
1361 | #define gdb_send_data gdb_sndat | |
1362 | #define gdb_start_listening gdb_stl | |
1363 | #define start_accepting_client gdb_stac | |
1364 | ||
1365 | ||
1366 | #define gdb_listen gdb_lis | |
1367 | ||
1368 | /* | |
1369 | * Connection management | |
1370 | */ | |
1371 | #define start_peer_connection gdb_spconn | |
1372 | #define sever_connection gdb_svconn | |
1373 | #define start_server_connection gdb_stsrv | |
1374 | #define create_listening_connection gdb_clc | |
1375 | #define start_replying_to_client gdb_strtc | |
1376 | #define create_forking_server gdb_cfs | |
1377 | ||
1378 | ||
1379 | /* | |
1380 | * Asynchronous operations | |
1381 | */ | |
1382 | #define start_sending_object gdb_snobj | |
1383 | #define start_receiving_object gdb_rcobj | |
1384 | #define preempt_and_start_receiving_object gdb_prcobj | |
1385 | ||
1386 | #define queue_operation gdb_qop | |
1387 | ||
1388 | #define requeue_operation g_req_op | |
1389 | ||
1390 | #define complete_operation gdb_cmpo | |
1391 | /* | |
1392 | * Synchronous operations | |
1393 | */ | |
1394 | #define send_object gdb_sobj | |
1395 | #define receive_object gdb_robj | |
1396 | /* | |
1397 | * Database operations | |
1398 | */ | |
1399 | #define access_db gdb_adb | |
1400 | #define start_accessing_db gdb_sadb | |
1401 | #define perform_db_operation gdb_pdbo | |
1402 | #define db_query gdb_dbq | |
1403 | #define start_performing_db_operation gdb_spdb | |
1404 | #define start_db_query gdb_sdbq | |
1405 | #else | |
1406 | #define op_select_any op_select | |
b42dcf6c | 1407 | #endif /* DUMB_7_CHAR_LOADER */ |
5580185e | 1408 | |
1409 | extern char *string_alloc(); | |
1410 | extern int string_free(); | |
1411 | extern TUPLE_DESCRIPTOR create_tuple_descriptor(); | |
1412 | extern int delete_tuple_descriptor(); | |
1413 | extern int field_index(); | |
1414 | extern TUPLE create_tuple(); | |
1415 | extern int delete_tuple(); | |
1416 | extern int initialize_tuple(); | |
1417 | extern int null_tuple_strings(); | |
1418 | extern RELATION create_relation(); | |
1419 | extern int delete_relation(); | |
1420 | extern OPERATION create_operation(); | |
1421 | extern LIST_OF_OPERATIONS create_list_of_operations(); | |
1422 | extern OPERATION g_op_newhead(); | |
1423 | extern CONNECTION start_peer_connection(); | |
1424 | extern CONNECTION sever_connection(); | |
1425 | extern CONNECTION start_server_connection(); | |
1426 | extern CONNECTION create_listening_connection(); | |
1427 | extern CONNECTION create_forking_server(); | |
1428 | extern int start_sending_object(); | |
1429 | extern int start_receiving_object(); | |
1430 | extern int preempt_and_start_receiving_object(); | |
1431 | extern int queue_operation(); | |
1432 | extern int requeue_operation(); | |
1433 | extern int complete_operation(); | |
1434 | extern int send_object(); | |
1435 | extern int receive_object(); | |
1436 | ||
1437 | ||
939744d7 | 1438 | /*---------------------------------------------------------- |
1439 | * | |
1440 | * Other routines requiring extern to avoid forward | |
1441 | * reference to non integer type functions. | |
1442 | * | |
1443 | *----------------------------------------------------------*/ | |
5580185e | 1444 | |
1445 | extern CONNECTION g_make_con(); |