A Complete isc_que_events() Example

From InterBase

Go Up to Continuous Processing with isc_que_events()


The following program fragment illustrates calling isc_que_events() to wait asynchronously for event occurrences. Within a loop, it performs other processing, and checks the event flag (presumably set by the specified event function) to determine when an event has been posted. If one has, the program resets the event flag, calls isc_event_counts() to determine which events have been posted since the last call to isc_que_events(), and calls isc_que_events() to initiate another asynchronous wait.

#include <ibase.h>
#define number_of_stocks 3;
#define MAX_LOOP 10
char *event_names[] = {"DEC", "HP", "SUN"};
char *event_buffer, *result_buffer;
ISC_STATUS status_vector[20];
short length;
ISC_LONG event_id;
int i, counter;
int event_flag = 0;
length = (short)isc_event_block(&event_buffer, &result_buffer,
number_of_stocks, "DEC", "HP", "SUN");
isc_que_events(status_vector,
&database_handle, /* Set in previous isc_attach_database(). */
&event_id,
length, /* Returned from isc_event_block(). */
event_buffer,
(isc_callback)event_function,
result_buffer);
if (status_vector[0] == 1 && status_vector[1]) {
isc_print_status(status_vector); /* Display error message. */
return(1);
};
counter = 0;
while (counter < MAX_LOOP) {
counter++;
if (!event_flag) {
/* Do whatever other processing you want. */
;
}
else {
event_flag = 0;
isc_event_counts(status_vector, length, event_buffer, result_buffer);
if (status_vector[0] == 1 && status_vector[1]) {
isc_print_status(status_vector); /*Display error message.*/
return(1);
};
for (i=0; i<number_of_stocks; i++)
if (status_vector[i]) {
/* The event has been posted. Do whatever is appropriate,
 * such as initiating a buy or sell order. Note: event_names[i]
 * tells the name of the event corresponding to status_vector[i]. */
}
isc_que_events( status_vector, &database_handle, &event_id, length,
event_buffer, (isc_callback)event_function, result_buffer);
if (status_vector[0] == 1 && status_vector[1]) {
isc_print_status(status_vector); /*Display error message.*/
return(1);
}
} /* End of else. */
} /* End of while. */
/* Let InterBase know you no longer want to wait asynchronously. */
isc_cancel_events(status_vector, &database_handle, &event_id);
if (status_vector[0] == 1 && status_vector[1]) {
isc_print_status(status_vector); /* Display error message. */
return(1);
}

Advance To: