⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfd-access-unsorted-external-defines.m2i

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 M2I
📖 第 1 页 / 共 3 页
字号:
    /*     * 1) individually     */@   foreach $node index@@      include m2c_setup_node.m2i@        /*         * TODO:         * set rowreq_ctx_ref->rowreq_ctx->tbl_idx->$node@      if $m2c_node_needlength == 1@         *     and rowreq_ctx_ref->tbl_idx->${node}_len@      end@         */@   end@ #foreach    /*     * OR     */        /*         * 2) by calling ${context}_indexes_set()         * ${context}_indexes_set(rowreq_ctx_ref->tbl_idx,@   foreach $node index@@      include m2c_setup_node.m2i@@        if $m2c_node_needlength == 1@    *       ${node}_ptr, ${node}_len@        else@    *       $node@        end@@   end@ # foreach index    *      );    */@   end@ # example@end@ #ifconf    return MFD_SUCCESS;} /* ${context}_loop_get_first *//** * get the next data index * * Summary * ------- *  This function returns the next data item in the data set. The same *  caveat applies here as did above. The indexes are the important parts *  during loop processing. * *  Note that this function does not correspond to a SNMP GET-NEXT pdu, and *  you should return data items in whatever order they are already in. *  (In fact, if your data is already ordered in the same order as the *  SNMP indexes, you shouldn't be using the unsorted-access code). * * More Details * ------------ * rowreq_ctx_ref->rowreq_ctx will have been set in ${context}_loop_get_first. * * If there is currently no data available, return MFD_END_OF_DATA. * Otherwise, you should set the indexes in rowreq_ctx_ref->rowreq_ctx->tbl_idx. * * You should set the index (or indexes) in rowreq_ctx_ref->rowreq_ctx->tbl_idx to the * appropriate value for this row. * * @param $mfd_aue_param_cmt * @param loop_ctx_ref  Pointer to your loop reference. * @param rowreq_ctx_ref  Pointer to a context reference. * * @retval MFD_SUCCESS     : success. * @retval MFD_END_OF_DATA : no more data available * @retval MFD_ERROR       : error. */int${context}_loop_get_next( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,                        ${context}_ref_rowreq_ctx *rowreq_ctx_ref){    DEBUGMSGTL(("verbose:${context}:${context}_loop_get_next","called\n"));    netsnmp_assert(loop_ctx_ref && loop_ctx_ref->loop_ctx);    netsnmp_assert(rowreq_ctx_ref);    /*     * we just need the index for now. Reuse the one in the loop context's     * temporary row request context. (rowreq_ctx_ref->rowreq_ctx->tbl_idx)     */    rowreq_ctx_ref->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;   @   if $m2c_include_examples == 1@$example_start    /*     * get a line (skip blank lines)     */    do {        if (!fgets(loop_ctx_ref->loop_ctx->line, sizeof(loop_ctx_ref->loop_ctx->line),                   loop_ctx_ref->loop_ctx->filep)) {            /* we're done */            fclose(loop_ctx_ref->loop_ctx->filep);            loop_ctx_ref->loop_ctx->filep = NULL;        }    } while (loop_ctx_ref->loop_ctx->filep && (loop_ctx_ref->loop_ctx->line[0] == '\n'));    /*     * check for end of data     */    if(NULL == loop_ctx_ref->loop_ctx->filep)        return MFD_END_OF_DATA;    /*     * TODO:     * set local vars for index from loop_ctx_ref->loop_ctx     *  this can be done in one of two ways:     */        /*     * 1) individually     */@   foreach $node index@@      include m2c_setup_node.m2i@        /*         * TODO:         * set rowreq_ctx_ref->rowreq_ctx->tbl_idx->$node@      if $m2c_node_needlength == 1@         *     and rowreq_ctx_ref->tbl_idx->${node}_len@      end@         */@   end@ #foreach    /*     * OR     */        /*         * 2) by calling ${context}_indexes_set()         * ${context}_indexes_set(rowreq_ctx_ref->tbl_idx,@   foreach $node index@@      include m2c_setup_node.m2i@@        if $m2c_node_needlength == 1@    *       ${node}_ptr, ${node}_len@        else@    *       $node@        end@@   end@ # foreach index    *      );    */$example_end@    end@ # example    return MFD_SUCCESS;} /* ${context}_loop_get_next *//** * duplicate the current loop reference * * Summary *  ------- *  During loop iteration, the iterator keeps track of the row that *  is the current best match. This function is called when the *  current row is a better match than any previous row. * *  You should save any information you need to be able to locate this row *  again from the current loop context to a new loop context. * *  At the end of the loop, when the best match has been found, the saved *  loop context will be used to get the data for the row by calling *  ${context}_loop_get_data().@if $m2c_data_transient != 0@ # persistent * *  Since your data is transient, you need to make a copy of it before *  the iterator moves on to the next row.@end@ *@if $m2c_data_transient != 0@ # persistent * More Details * ------------@   if $m2c_data_transient == 1@ # short term *  Since your data is semi-TRANSIENT data, you could just keep a pointer *  to the data in the loop reference. The data should then be copied in *  ${context}_loop_get_data().@   else@ # $m2c_data_transient == 2@ # copy immediately *  One idea would be to copy it space allocated in the loop reference *  structure. Another would be to simply have a pointer in the loop *  reference structure, and allocate memory here. *@   end@@end@ * @param $mfd_aue_param_cmt * @param loop_ctx_ref  Reference to current loop context. * @param save_loop_ctx_ref Reference to a loop context for saving the current *                  position. If reuse is not set or *                  save_loop_ctx_ref->loop_ctx is NULL, allocate *                  a new one. If reuse is set, you may reuse  the existing *                  loop_ctx. * @param reuse     Indicates if an existing save_loop_ctx_ref->loop_ctx *                  may be reused. * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR   : error. */int${context}_loop_save_position($mfd_aue_param_decl,                       ${context}_ref_loop_ctx *loop_ctx_ref,                       ${context}_ref_loop_ctx *save_loop_ctx_ref,                       int reuse){    DEBUGMSGTL(("verbose:${context}:${context}_loop_save_position","called\n"));    netsnmp_assert(loop_ctx_ref && save_loop_ctx_ref);    /*     * TODO:     * 1) allocate new loop context, unless you can reuse a previous pointer.     * 2) save information for the position of loop_ctx_ref in save_loop_ctx_ref.     */    if((0 == reuse) || (NULL == save_loop_ctx_ref->loop_ctx))        save_loop_ctx_ref->loop_ctx = SNMP_MALLOC_TYPEDEF(${context}_loop_context);    if(NULL == save_loop_ctx_ref->loop_ctx) {        snmp_log(LOG_ERR, "could not allocate memory\n");        return MFD_ERROR;    }    /*     * if you can reuse a previously saved contex, just swap     * it out with the loop iterator     */    if(reuse && save_loop_ctx_ref->loop_ctx->rowreq_ctx) {        ${context}_rowreq_ctx * tmp_rowreq_ctx = save_loop_ctx_ref->loop_ctx->rowreq_ctx;        save_loop_ctx_ref->loop_ctx->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;        loop_ctx_ref->loop_ctx->rowreq_ctx = tmp_rowreq_ctx;    }    else {        /*         * take the current pointer         */        save_loop_ctx_ref->loop_ctx->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;                /*         * allocate a new context to replace the one you just took.         */@   eval $m2c_tmp = ""@@   if ($m2c_data_allocate == 1) || ($m2c_data_init == 1)@@      eval $m2c_tmp = "NULL"@@      if ($m2c_data_allocate == 1) && ($m2c_data_init == 1)@@         eval $m2c_tmp = "$m2c_tmp, NULL"@@      @end@@   end@        loop_ctx_ref->loop_ctx->rowreq_ctx = ${context}_allocate_rowreq_ctx($m2c_tmp);        if(NULL == loop_ctx_ref->loop_ctx->rowreq_ctx) {            SNMP_FREE(loop_ctx_ref->loop_ctx);            return MFD_ERROR;        }    } @if $m2c_data_transient == 0@ # persistent    /** non-TRANSIENT data: no need to copy */@elsif $m2c_data_transient == 1@ # short term    /** semi-TRANSIENT data: will copy data when index found */    /** only need to copy pertinent data from loop context */@elsif $m2c_data_transient == 2@ # copy immediately    /*     * TRANSIENT data: copy all the data.     */@end@@if $m2c_include_examples == 1@$example_start@  if $m2c_data_transient == 1@ # short term    /** save line to do that */    memcpy(save_loop_ctx_ref->loop_ctx->line, loop_ctx_ref->loop_ctx->line,           sizeof(loop_ctx_ref->loop_ctx->line));@  elsif $m2c_data_transient == 2@ # copy immediately@    foreach $node nonindex@@      include m2c_setup_node.m2i@    /*     * TODO:     * set rowreq_ctx_ref->${m2c_data_item}$node     *     from the loop context     */@    end@@  end@$example_end@end@ # example        return MFD_SUCCESS;} /* ${context}_loop_save_position */@if $m2c_data_transient != 0@ # semi-transient/** * set ${context}_data from a data context * * Summary * ------- *  At the end of the loop, when the best match has been found, the saved *  loop context will be used to get the data for the row by calling *  ${context}_loop_get_data(). * *  You should return a fully populated row request context in *  rowreq_ctx_ref->rowreq_ctx. * * More Details * ------------ * @param $mfd_aue_param_cmt * @param loop_ctx_ref pointer to your loop reference. * @param rowreq_ctx_ref pointer to a context reference. */int${context}_loop_get_data( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref,                           ${context}_ref_rowreq_ctx *rowreq_ctx_ref){    DEBUGMSGTL(("verbose:${context}:${context}_loop_get_data","called\n"));    netsnmp_assert((NULL != loop_ctx_ref) && (NULL != loop_ctx_ref->loop_ctx));    netsnmp_assert(NULL != rowreq_ctx_ref);    netsnmp_assert(NULL != rowreq_ctx_ref->rowreq_ctx);    /*     * take temporary row request context from loop context     */    rowreq_ctx_ref->rowreq_ctx = loop_ctx_ref->loop_ctx->rowreq_ctx;    loop_ctx_ref->loop_ctx->rowreq_ctx = NULL;        /*     * copy data to the data context (rowreq_ctx_ref->${m2c_data_item})@   if $m2c_include_examples == 1@     * in loop_save_position, we saved line to do that@   end@     */@   foreach $node nonindex@@      include m2c_setup_node.m2i@    /*     * $m2c_node_summary     */@   eval $m2c_ctx_lh = "rowreq_ctx_ref->$m2c_ctx_rh"@@   eval $m2c_ctx_lhs = "rowreq_ctx_ref->$m2c_ctx_rhs"@@   eval $m2c_ctx_rh = "loop_ctx_ref->loop_ctx->$node"@@   eval $m2c_ctx_rhs = "loop_ctx_ref->loop_ctx->${node}_len"@@   include generic-value-map.m2i@    @   end@   return MFD_SUCCESS;} /* ${context}_loop_get_data */@end@ // if $m2c_data_transient != 0/** * clean up a loop reference * * Summary * ------- *  This function will be called once the loop iteration has completed *  to release any memory or resources allocated for the loop context. * * More Details * ------------ * @param $mfd_aue_param_cmt * @param loop_ctx_ref  Pointer to your loop reference. * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR   : error. */int${context}_loop_cleanup_context( $mfd_aue_param_decl, ${context}_ref_loop_ctx *loop_ctx_ref){    DEBUGMSGTL(("verbose:${context}:${context}_loop_cleanup_context","called\n"));        netsnmp_assert(loop_ctx_ref);        if(!loop_ctx_ref->loop_ctx)        return MFD_ERROR;    /*     * release the row request context, if it wasn't taken     */    if(loop_ctx_ref->loop_ctx->rowreq_ctx)        ${context}_release_rowreq_ctx(loop_ctx_ref->loop_ctx->rowreq_ctx);    /*     * TODO:     * release resources     */@if $m2c_include_examples == 1@$example_start    /*     * close file     */    if(loop_ctx_ref->loop_ctx->filep)        fclose(loop_ctx_ref->loop_ctx->filep);$example_end    @end@    /*     * free loop context     */    free(loop_ctx_ref->loop_ctx);        return MFD_SUCCESS;} /* ${context}_loop_cleanup_context */@end@ // m2c_processing_type eq 'c'##########################################################################//######################################################################//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@if $m2c_processing_type eq 'r'@

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -