MCO_RET mco_uda_async_event_wait( /*IN*/ mco_db_h db,
/*IN*/ unsigned short struct_no,
/*IN*/ unsigned short event_no );
| |
---|
db | 数据库句柄 |
struct_no | 结构/类编号(必须介于 0 和 - 1 之间)mco_dict_struct_count() |
event_no | 事件编号 |
此函数会阻止线程,直到应用程序触发指定的事件,或者应用程序通过调用 function 或 显式释放事件处理程序。mco_uda_async_event_release()``mco_uda_async_event_release_all()
| |
---|
MCO_S_OK | 已成功释放事件处理程序 |
MCO_E_INVALID_HANDLE | 数据库句柄无效 |
MCO_S_EVENT_RELEASED | 该事件由应用程序发布 |
/* 应用程序代码片段 */
typedef struct ThrParam_
{
sample_task_t task;
mco_db_h db;
unsigned short struct_no;
unsigned short event_no;
int event_count;
int finished;
} ThrParam;
void async_event_handler( sample_task_t * descriptor )
{
ThrParam* thr_p = (ThrParam*) descriptor->param;
mco_dict_struct_info_t struct_info;
mco_dict_field_info_t field_info;
mco_dict_event_info_t event_info;
mco_db_h db = thr_p->db;
char *event_type;
MCO_RET rc;
thr_p->finished = 0;
thr_p->event_count = 0;
mco_dict_struct(metadict, 0, thr_p->struct_no, &struct_info);
mco_dict_event(metadict, 0, thr_p->struct_no, thr_p->event_no, &event_info);
if (event_info.type == MCO_EVENT_UPDATE) {
mco_dict_field(metadict, 0, thr_p->struct_no, event_info.field_no, &field_info);
}
switch (event_info.type) {
case MCO_EVENT_UPDATE : event_type = "UPDATE"; break;
case MCO_EVENT_NEW : event_type = "NEW"; break;
case MCO_EVENT_DELETE : event_type = "DELETE"; break;
case MCO_EVENT_DELETE_ALL : event_type = "DELETE_ALL"; break;
case MCO_EVENT_CHECKPOINT : event_type = "CHECKPOINT"; break;
case MCO_EVENT_CLASS_UPDATE : event_type = "CLASSUPDATE"; break;
}
for (;;)
{
rc = mco_uda_async_event_wait(db, thr_p->struct_no, thr_p->event_no);
printf("Async. event : class %s, event_no=%d, type=%s ", struct_info.name, thr_p->event_no, event_type);
if (event_info.type == MCO_EVENT_UPDATE) {
printf("field=%s ", field_info.name);
}
if (rc != MCO_S_OK) {
printf(" exiting. Num. of events=%d\n", thr_p->event_count);
thr_p->finished = 1;
return ;
}
++thr_p->event_count;
printf("\n");
}
}
void start_async_handlers(mco_db_h db)
{
unsigned short struct_count, s, e;
mco_dict_struct_info_t struct_info;
unsigned short thr_num = 0;
mco_dict_struct_count(metadict, 0, &struct_count);
for (s = 0; s < struct_count; ++s) {
mco_dict_struct(metadict, 0, s, &struct_info);
for (e = 0; e < struct_info.event_count; ++e) {
all_thr_param[thr_num].db = db;
all_thr_param[thr_num].struct_no = s;
all_thr_param[thr_num].event_no = e;
sample_start_connected_task(&all_thr_param[thr_num].task, async_event_handler, db_name, &all_thr_param[thr_num]);
++thr_num;
sample_sleep(100);
}
}
}
int main(int argc, char* argv[])
{
MCO_RET rc;
mco_db_h db;
...
start_async_handlers(db);
...
}