# mco_uda_unregister_event_handler

> Unregister an event handler.

### Prototype

        MCO_RET mco_uda_unregister_event_handler(	/*IN*/ mco_trans_h t,
                                /*IN*/ unsigned short struct_no,
                                /*IN*/ unsigned short event_no,
                                /*IN*/ mco_uda_event_handler  handler );

### Arguments

t | The transaction handle
struct_no | The structure/class number (must be between 0 and `mco_dict_struct_count()` - 1)
event_no | The event number
handler | The name of an `mco_uda_event_handler` function implementation
t | The transaction handle

### Description

> Unregister an event handler for a specific event previously registered with `mco_uda_register_event_handler()`.

### Return Codes

MCO_S_OK | Handler unregistered successfully
MCO_ERR_UDA | Fatal error unregistering handler

### Example

        Application snippet:

        MCO_RET sync_event_handler(mco_trans_h t, mco_uda_object_handle_p obj, const mco_dict_event_info_t *event_info, void *param)
        {
            mco_dict_struct_info_t struct_info;
            mco_dict_field_info_t field_info;
            mco_uda_value_t val;
            autoid_t obj_autoid;

            mco_dict_struct(metadict, 0, obj->struct_no, &struct_info);
            mco_dict_field_name(metadict, 0, obj->struct_no, "autoid", &field_info);
            val.type = MCO_DD_AUTOID;
            mco_uda_get(obj, field_info.field_no, 0, &val);
            obj_autoid = val.v.u8;

            if (event_info->type == MCO_EVENT_UPDATE || event_info->type == MCO_EVENT_CLASS_UPDATE)
            {
                mco_dict_field(metadict, 0, obj->struct_no, event_info->field_no, &field_info);
                printf("Sync. event for obj %" INT8_FORMAT "d: class %s, event_no=%d, type=UPDATE, when=%s, field=%s, value=",
                obj_autoid, struct_info.name, event_info->event_no, ((int)param == MCO_AFTER_UPDATE) ? "AFTER" : "BEFORE", field_info.name);

                print_obj_field(obj, &field_info);
            } else {
                printf("Sync. event for obj %" INT8_FORMAT "d: class %s, event_no=%d, type=", obj_autoid, struct_info.name, event_info->event_no);
                switch (event_info->type) {
                    case MCO_EVENT_NEW        : printf("NEW"); break;
                    case MCO_EVENT_DELETE     : printf("DELETE"); break;
                    case MCO_EVENT_DELETE_ALL : printf("DELETE_ALL"); break;
                    case MCO_EVENT_CHECKPOINT : printf("CHECKPOINT"); break;
                    default                   : printf("UNKNOWN"); dbg_exit(1);
                }
            }
            printf("\n");
            return MCO_S_OK;
        }

        void unregister_sync_events(mco_trans_h t)
        {
            unsigned short struct_count, s, e;
            mco_dict_struct_info_t struct_info;
            mco_dict_event_info_t event_info;

            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) {
                    mco_dict_event(metadict, 0, s, e, &event_info);
                    if (event_info.type == MCO_EVENT_UPDATE) {
                        mco_uda_unregister_event_handler(t, s, e, &sync_event_handler);
                    }
                    mco_uda_unregister_event_handler(t, s, e, &sync_event_handler);

                }
            }
        }

        int main(int argc, char* argv[])
        {
            MCO_RET rc;
            mco_db_h db;
            mco_trans_h t;
            ...

            mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
            unregister_sync_events(t);
            mco_trans_commit(t);
            ...
        }

### Files

Header file:
mcouda.h
Source file:
mcouda.c
Library:
libmcouda.a