home *** CD-ROM | disk | FTP | other *** search
- .Na "dbsetbusy"
- .Aa
- .Fu
- Call a user-supplied function when \*L is reading from \*S.
- .Ih "function, calling when \*L is reading from \*S"
- .Sy
- .Sf "void dbsetbusy(dbproc, busyfunc)"
- .Sp "DBPROCESS" "*dbproc"
- .mc |
- .Sp "void" "(*(*busyfunc)())()"
- .Co
- .mc
- .Bl
- This routine associates a user-supplied function with the
- specified \f2dbproc\f1.
- The user-supplied function will automatically be called whenever
- \*L is reading or waiting to read output from \*S.
- For example, an application may want to print a message
- whenever \*S is accessed.
- .I "dbsetbusy()"
- will cause the user-supplied function
- .I "busyfunc()"
- to be called in this case.
- .Bl
- Similarly,
- .I "dbsetidle()"
- may also be used to associate a user-supplied function, \f2idlefunc()\f1, with a
- .I "dbproc."
- \f2idlefunc()\f1 will automatically be
- called whenever \*L has finished reading
- output from \*S.
- .Bl
- The server sends result data to the application in packets of 512 bytes.
- (The final packet in a set of results may be less than 512 bytes.)
- \*L calls \f2busyfunc()\f1 at the beginning of
- each packet and \f2idlefunc()\f1 at
- the end of each packet.
- If the output from the server spans multiple packets,
- \f2busyfunc()\f1 and \f2idlefunc()\f1 will be called
- multiple times.
- .mc |
- .Bl
- Here's an example of
- installing and defining \f2busyfunc()\f1 and \f2idlefunc()\f1:
- .SD
- .in +3n
- .ta +4n +4n +4n +4n +4n +4n
- .ne 3
- int (*busyfunc())(); /* busyfunc is a function which returns
- * a pointer to a function which returns
- * an integer.
- */
- void idlefunc();
-
- int counterfunc();
- ...
-
- main()
- {
- DBPROCESS *dbproc;
- ...
-
- dbproc = dbopen(login, NULL);
-
- /* Now that we have a DBPROCESS, install the busy-function
- * and the idle-function.
- */
- dbsetbusy(dbproc, busyfunc);
- dbsetidle(dbproc, idlefunc);
-
- dbcmd(dbproc, "select * from sysdatabases");
- dbcmd(dbproc, " select * from sysobjects");
- dbsqlexec(dbproc);
-
- /* DB-Library calls busyfunc() for the first time during
- * dbsqlexec(). Depending on the size of the results,
- * it may call busyfunc() again during processing of
- * the results. */
-
- while (dbresults(dbproc) != NO_MORE_RESULTS)
- dbprrow(dbproc);
-
- /* DB-Library calls idlefunc() each time a packet of results
- * has been received. Depending on the size of the results,
- * it may call idlefunc() multiple times during processing of
- the results. */
- ...
- }
-
- int (*busyfunc(dbproc))()
- DBPROCESS *dbproc;
- {
- printf("Waiting for data...\en");
-
- /* busyfunc returns a pointer to a routine which returns an integer. */
- return(counterfunc);
- }
-
- void idlefunc(procptr, dbproc)
- int (*procptr)(); /* idlefunc's first parameter is a pointer
- * to a routine which returns an integer.
- * This is the same pointer that busyfunc
- * returns.
- */
- DBPROCESS *dbproc;
- {
- int count;
-
- printf("Data is ready.\en");
- count = (*procptr)();
-
- printf
- ("Counterfunc has been called %d %s.\en",
- count, (count == 1 ? "time" : "times"));
-
- }
-
- int counterfunc()
- {
- static int counter = 0;
-
- return(++counter);
- }
- .in -3n
- .ED
- .mc
- .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.
- .mc |
- .Pi busyfunc
- The user-supplied function that \*L will call whenever
- it accesses \*S.
- \*L calls \f2busyfunc()\f1 with a single parameter\(ema pointer to the
- DBPROCESS from the \f2dbsetbusy()\f1 call.
- .sp
- \f2busyfunc()\f1 returns a pointer to a function that returns an integer.
- .in -.375i
- .Re
- .mc
- .br
- None.
- .Sa
- dbsetidle
-