isc_que_events() の完全な例
提供:InterBase
次の部分プログラムでは、イベント発生を非同期で待機する isc_que_events() の呼出しを表しています。 ループ内では、他の処理を行っており、イベント フラグ(指定されたイベント関数によって設定される)をチェックして、イベントが投稿されたかどうかを判断しています。 イベントが投稿されていたら、プログラムはイベント フラグをリセットし、 isc_event_counts() を呼び出して、isc_que_events() への前回の呼出し以降、どのイベントが投稿されたかを判別し、その後 isc_que_events() を呼び出して、他の非同期待機を起動します。
#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);
}