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