home *** CD-ROM | disk | FTP | other *** search
- .Na "dbsetinterrupt"
- .Aa
- .Fu
- Call user-supplied functions to handle interrupts while waiting
- on a read from \*S.
- .Ih "function, calling to handle interrupts"
- .Ih "interrupt handling"
- .Sy
- .Sf "void dbsetinterrupt(dbproc, chkintr, hndlintr)"
- .Sp "DBPROCESS" "*dbproc"
- .Sp "int" "(*chkintr)()"
- .Sp "int" "(*hndlintr)()"
- .Co
- .Bl
- \*L does non-blocking reads from \*S. While waiting for a
- read from \*S, it will call the
- .I "chkintr()"
- function to see if an interrupt is pending. If there is an interrupt,
- .I "hndlintr()"
- will be called.
- .I "dbsetinterrupt()"
- is provided so that the programmer can substitute alternative interrupt handling for
- the time that the host program is waiting on reads from \*S.
- .Bl
- .I "hndlintr()"
- must return one of the interrupt returns defined in the header file
- \f2sybfront.h\f1: INT_EXIT, INT_CONTINUE, or INT_CANCEL.
- .I "chkintr()"
- must return TRUE or FALSE.
- .Bl
- You can use
- .I "dbcancel()"
- to cancel the current command batch.
- If you have set your own interrupt handler using
- .I "dbsetinterrupt(),"
- however,
- you cannot call
- .I "dbcancel()"
- in your interrupt handler, because this will cause output from \*S to
- \*L to become out of sync.
- If you want to cancel the current command batch from your interrupt handler,
- the interrupt handler should set a flag that you can check before
- the next call to
- .I "dbresults()"
- or
- .I "dbnextrow()."
- .Bl
- \f3Note for Macintosh programmers:\f1 Because \f2dbsetinterrupt()\f1 only makes sense in
- conjunction with \f2signal()\f1,
- it is valid only in MPW Tools.
- .Bl
- Here are example \f2chkintr()\f1 and \f2hndlintr()\f1 routines:
- .SD
- .in +3n
- .ta +4n +4n +4n +4n +4n +4n
- .ne 3
- int chkintr(dbproc)
- DBPROCESS *dbproc;
- {
- /* This routine assumes that the application sets the
- * global variable "OS_interrupt_happened" upon catching
- * an interrupt via some operating system facility.
- */
- if (OS_interrupt_happened)
- {
- /* Clear the interrupt flag, for future use. */
- OS_interrupt_happened = FALSE;
-
- return(TRUE);
- }
- else
- return(FALSE);
- }
-
- int hndlintr(dbproc)
- DBPROCESS *dbproc;
- {
- char response[10];
-
- printf("\enAn interrupt has occurred. Do you want to:\en\en");
- printf("\et1) Abort the program\en");
- printf("\et2) Cancel the current query\en");
- printf("\et3) Continue processing the current query's results\en\en");
- printf("Press 1, 2, or 3, followed by the return key: ");
- gets(response);
-
- switch(response[0])
- {
- case '1':
- return(INT_EXIT);
- break;
- case '2':
- return(INT_CANCEL);
- break;
- case '3':
- return(INT_CONTINUE);
- break;
- default:
- printf("Reponse not understood. Aborting program.\en");
- return(INT_EXIT);
- break;
- }
- }
- .in -3n
- .ED
- .Bz
- .Pa
- .Pi dbproc
- A pointer to the DBPROCESS structure that provides the connection
- for a particular front-end/\*S process. It contains all the
- information that \*L uses to manage communications and data between the
- front end and \*S.
- .Pi chkintr
- A pointer to the user function that \*L will call to check
- whether an interrupt is pending. \*L calls it periodically while waiting
- on a read from \*S.
- \*L calls \f2chkintr()\f1 with a single parameter\(ema pointer to the
- DBPROCESS from the \f2dbsetinterrupt()\f1 call.
- .sp 0.5v
- \f2chkintr()\f1 must return TRUE or FALSE.
- .Pi hndlintr
- A pointer to the user function that \*L will call if an interrupt is
- returned.
- \*L calls \f2hndlintr()\f1 with a single parameter\(ema pointer to the
- DBPROCESS from the \f2dbsetinterrupt()\f1 call.
- .sp 0.5v
- \f2hndlintr()\f1 must return one of the following three values:
- .sp
- .in +17n
- .ta +17n
- .ti -17n
- INT_EXIT Abort the program.
- (Note to UNIX programmers: \*L will not leave a core file.)
- .sp 0.5v
- .ti -17n
- INT_CANCEL Cancel the current command batch.
- .sp 0.5v
- .ti -17n
- INT_CONTINUE Continue to wait for the \*S response.
- .sp
- .in -17n
- .in -.375i
- .Re
- .br
- None.
- .Sa
- dbcancel,
- dbsetbusy,
- dbsetidle
-