mib2c.conf
来自「eCos操作系统源码」· CONF 代码 · 共 470 行 · 第 1/2 页
CONF
470 行
code: /* minimal include directives */code: #include \"mibincl.h\"code: #include \"mibgroup/util_funcs.h\"code: #include \"mibgroup/mibII/$outputName.h\"code: code: /* code: * ${outputName}_variables_oid:code: * this is the top level oid that we want to register under. Thiscode: * is essentially a prefix, with the suffix appearing in thecode: * variable below.code: */code: code: oid ${outputName}_variables_oid[] = { $commaoid };code: code: /* code: * variable$varlen ${outputName}_variables:code: * this variable defines function callbacks and type return information code: * for the $outputName mib section code: */code: code: struct variable$varlen ${outputName}_variables[] = {code: /* magic number , variable type , ro/rw , callback fn , L, oidsuffix */code: $variables{'variable-structure-info'}{'processed'}code: };code: /* (L = length of the oidsuffix) */code: code: /*code: * init_$outputName():code: * Initialization routine. This is called when the agent starts up.code: * At a minimum, registration of your variables should take place here.code: */code: void init_$outputName(void) {code: code: /* register ourselves with the agent to handle our mib tree */code: REGISTER_MIB(\"$outputName\", ${outputName}_variables, variable$varlen,\code: ${outputName}_variables_oid);code: code: /* place any other initialization junk you need here */code: }code: code: /*code: * var_$outputName():code: * This function is called every time the agent gets a request forcode: * a scalar variable that might be found within your mib sectioncode: * registered above. It is up to you to do the right thing andcode: * return the correct value.code: * You should also correct the value of \"var_len\" if necessary.code: *code: * Please see the documentation for more information about writingcode: * module extensions, and check out the examples in the examplescode: * and mibII directories.code: */code: unsigned char *code: var_$outputName(struct variable *vp, code: oid *name, code: size_t *length, code: int exact, code: size_t *var_len, code: WriteMethod **write_method)code: {code: code: $variables{'code-varInits'}{'code'}code: code: if (header_generic(vp,name,length,exact,var_len,write_method)code: == MATCH_FAILED )code: return NULL;code: code: /* code: * this is where we do the value assignments for the mib results.code: */code: switch(vp->magic) {\n\ncode: $variables{$outputName}{'code-case-statements'}{'processed'}code: default:code: ERROR_MSG(\"\");code: }code: return NULL;code: }code:code: $variables{'code-var_table'}{'processed'}code:code: $variables{'code-write-func'}{'processed'}############################################################################# var_ function for tables, which is handled specially and used above## Note: $vtable is set to the table name in the processtable loop.############################################################################## header file defs first#type: code-var_table-declprocesstable: code-var_table-declcode: FindVarMethod var_$vtable;## Code code per table#type: code-var_tableprocesstable: code-var_tablecode: /*code: * var_$vtable():code: * Handle this table separately from the scalar value case.code: * The workings of this are basically the same as for var_$outputName above.code: */code: unsigned char *code: var_$vtable(struct variable *vp,code: oid *name,code: size_t *length,code: int exact,code: size_t *var_len,code: WriteMethod **write_method)code: {code: code: $variables{'code-varInits'}{'code'}code: code: /* code: * This assumes that the table is a \'simple\' table.code: * See the implementation documentation for the meaning of this.code: * You will need to provide the correct value for the TABLE_SIZE parametercode: *code: * If this table does not meet the requirements for a simple table,code: * you will need to provide the replacement code yourself.code: * Mib2c is not smart enough to write this for you.code: * Again, see the implementation documentation for what is required.code: */code: if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)code: == MATCH_FAILED )code: return NULL;code: code: /* code: * this is where we do the value assignments for the mib results.code: */code: switch(vp->magic) {\n\ncode: $variables{$vtable}{'code-case-statements'}{'processed'}code: default:code: ERROR_MSG(\"\");code: }code: return NULL;code: }############################################################################# case statement sections############################################################################type: code-case-statementsprocess: code-case-statementsskipif: $mib->{'access'} =~ /NoAccess/code: case $NAME:code: " . (($mib->{'access'} =~ /ReadWrite|WriteOnly|Create/) ? "*write_method = write_$mib->{label};" : "") . "code: $variables{$mib->{'type'}}{'case'}code: ############################################################################# storage structure information############################################################################type: variable-structure-infoprocess: variable-structure-infoskipif: $mib->{'access'} =~ /NoAccess/code: " . sprintf("#define %-20s $count", $NAME) . "code: " . sprintf(" { %-20s, %-14s, %-6.6s, %s, %d, { %s } },", $NAME, $variables{$mib->{'type'}}{'asnType'}, $accessToUCD{$mib->{'access'}}, "var_$vroutine", $depth-1, $subid) . "############################################################################# write function defitition, also appended to the end of the .c file.############################################################################## Header info: declair write functions for set processing#process: code-write-func-decltype: code-write-func-declskipif: $mib->{'access'} !~ /Write|Create/code: WriteMethod write_$name;## C code#type: code-write-funcprocess: code-write-funcskipif: $mib->{'access'} !~ /Write|Create/code: intcode: write_$name(int action,code: u_char *var_val,code: u_char var_val_type,code: size_t var_val_len,code: u_char *statP,code: oid *name,code: size_t name_len)code: {code: $variables{$mib->{'type'}}{writeInit}code: int size;code: code: switch ( action ) {code: case RESERVE1:code: if (var_val_type != $variables{$mib->{'type'}}{asnType}){code: fprintf(stderr, \"write to $name not $variables{$mib->{'type'}}{asnType}\\n\");code: return SNMP_ERR_WRONGTYPE;code: }code: if (var_val_len > sizeof($variables{$mib->{'type'}}{variable})){code: fprintf(stderr,\"write to $name: bad length\\n\");code: return SNMP_ERR_WRONGLENGTH;code: }code: break;code: code: case RESERVE2:code: size = var_val_len;code: $variables{$mib->{'type'}}{variable} = ($variables{$mib->{'type'}}{cast}) var_val;code: code: break;code: code: case FREE:code: /* Release any resources that have been allocated */code: break;code: code: case ACTION:code: /* The variable has been stored in $variables{$mib->{'type'}}{variable} forcode: you to use, and you have just been asked to do something withcode: it. Note that anything done here must be reversable in the UNDO case */code: break;code: code: case UNDO:code: /* Back out any changes made in the ACTION case */code: break;code: code: case COMMIT:code: /* Things are working well, so it's now safe to make the changecode: permanently. Make sure that anything done here can't fail! */code: break;code: }code: return SNMP_ERR_NOERROR;code: }code:code:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?