# Database Calculator Callback Handlers

The Database Calculator functions `mco_calc_cinfo_browse()` and `mco_calc_iinfo_browse()` require callback functions to process the information relative to a specific class or index. They have the following prototypes:

        typedef void (*mco_calc_cinfo_h)(mco_calc_t * calc, mco_cc_t * cls,
                           mco_cc_info_t * info, void * ctx);

        typedef void (*mco_calc_iinfo_h)(mco_calc_t * calc, mco_index_stat_t * istat,
                           void * ctx);

Note that the index istat parameter is of type `mco_index_stat_t` defined in file `mco.h` and the context parameter ctx is to allow possible additional application-specific data to be passed into the handler function.

An example of these handler functions are the following:

        static void class_print(mco_calc_t *calc, mco_cc_t *cls,
                        mco_cc_info_t *info, void *unused)
        {
            printf(" -> %s%s:\n", (info->is_pers ? "[PERSISTENT] " : ""), cls->cc_name);
            ...
        }

        static void index_print(mco_calc_t *calc, mco_cc_t *cls,
                        mco_index_stat_t *istat, void *unused)
        {
            int tmp, psize = 0;
            char *str = NULL, c;

            if ((istat->type & MCO_IDXST_TYPE_MASK) == MCO_IDXST_TYPE_MEM) {
                str = "Inmem";
                psize = calc->pg_size;
            }
            else if ((istat->type & MCO_IDXST_TYPE_MASK) == MCO_IDXST_TYPE_DISK) {
                str = "Disk";
                psize = _disk_page_size;
            }

            printf(" -> %s [%s ", istat->plabel, str);
            ...
        }

Related Topics