📄 gen-any.c
字号:
fprintf (src," * cause pre-mature destruction of the ANY tables.\n"); fprintf (src," * The ANY tables will be destroyed by the runtime library.\n"); fprintf (src," */\n");#if 0 fprintf (src," ~InitAny%s() { AsnAny::AsnAnyDestroyHashTbls(); }\n",modName);#endif fprintf (src,"};\n\n"); fprintf (src,"static InitAny%s anyInitalizer;\n", modName); /* print constructor method that build hash tbl to src file*/ fprintf (src,"InitAny%s::InitAny%s()\n", modName, modName); fprintf (src,"{\n");/* REN -- 5/11/2001 -- Changed method in which anyRefs get written. Originalcode looped through the module's basic types and local type refs and wrote theanys that referred to them. Corrected method loops through the valueRefs andwrites all of the SNMP Object Types.Removed the following loops: first print value for OID's * do any lib types first * i = 0; for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++) { arl = LIBTYPE_GET_ANY_REFS (j); if (arl != NULL) { FOR_EACH_LIST_ELMT (ar, arl) { installedSomeHashes = TRUE; if (ar->id->choiceId == OIDORINT_OID) { fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++); PrintCxxOidValue (src, r, ar->id->a.oid); fprintf (src,";\n"); } else if (ar->id->choiceId == OIDORINT_INTID) { fprintf (src," %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++); PrintCxxIntValue (src, r, ar->id->a.intId); fprintf (src,";\n"); } } } } FOR_EACH_LIST_ELMT (td, m->typeDefs) { if (td->anyRefs != NULL) { cxxtdi = td->cxxTypeDefInfo; FOR_EACH_LIST_ELMT (ar, td->anyRefs) { installedSomeHashes = TRUE; if (ar->id->choiceId == OIDORINT_OID) { fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++); PrintCxxOidValue (src, r, ar->id->a.oid); fprintf (src,";\n"); } else if (ar->id->choiceId == OIDORINT_INTID) { fprintf (src," %s int%d", r->typeConvTbl[BASICTYPE_INTEGER].className, i++); PrintCxxIntValue (src, r, ar->id->a.intId); fprintf (src,";\n"); } } } } * now print hash init calls * i = 0; for (j = BASICTYPE_BOOLEAN; j < BASICTYPE_MACRODEF; j++) { arl = LIBTYPE_GET_ANY_REFS (j); if (arl != NULL) { FOR_EACH_LIST_ELMT (ar, arl) { if (ar->id->choiceId == OIDORINT_OID) fprintf (src," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className); else fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, r->typeConvTbl[j].className); } } } FOR_EACH_LIST_ELMT (td, m->typeDefs) { if (td->anyRefs != NULL) { FOR_EACH_LIST_ELMT (ar, td->anyRefs) { cxxtdi = td->cxxTypeDefInfo; if (ar->id->choiceId == OIDORINT_OID) fprintf (src," AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, ar->anyIdName, cxxtdi->className); else fprintf (src," AsnAny::InstallAnyByInt (int%d, %s, new %s);\n", i++, ar->anyIdName, cxxtdi->className); } } }REN -- 5/11/2001 -- added the following: */ /* first print value for OID's */ i = 0; FOR_EACH_LIST_ELMT (vd, m->valueDefs) { if (vd->value != NULL) { t = vd->value->type; if ((GetBuiltinType(t) == BASICTYPE_MACROTYPE) && (t->basicType->a.macroType->choiceId == MACROTYPE_SNMPOBJECTTYPE)) { bv = vd->value->basicValue; if (bv != NULL) { installedSomeHashes = TRUE; if (bv->choiceId == BASICVALUE_OID) { fprintf (src," %s oid%d", r->typeConvTbl[BASICTYPE_OID].className, i++); PrintCxxOidValue (src, r, bv->a.oid, 1); fprintf (src,";\n"); } } } } } fprintf (src,"\n\n"); /* now print hash init calls */ i = 0; FOR_EACH_LIST_ELMT (vd, m->valueDefs) { if (vd->value != NULL) { t = vd->value->type; if ((GetBuiltinType(t) == BASICTYPE_MACROTYPE) && (t->basicType->a.macroType->choiceId == MACROTYPE_SNMPOBJECTTYPE)) { bv = vd->value->basicValue; if (bv != NULL) { strcpy (anyId, vd->definedName); Dash2Underscore (anyId, strlen (anyId)); strcat (anyId, "_ANY_ID"); installedSomeHashes = TRUE; t = t->basicType->a.macroType->a.snmpObjectType->syntax; /* If the syntax of this any is a basic type, get the class name from the rules table. */ typeId = t->basicType->choiceId; if (((typeId >= BASICTYPE_BOOLEAN) && (typeId <= BASICTYPE_SETOF)) || ((typeId >= BASICTYPE_NUMERIC_STR) && (typeId <= BASICTYPE_T61_STR))) { typeName = r->typeConvTbl[typeId].className; } /* Else if the syntax of this any is either a locally defined type or an imported type, get the class name from the this type's ref info. */ else { td = GetTypeDef(t); if (td != NULL) { cxxtdi = td->cxxTypeDefInfo; typeName = cxxtdi->className; } else typeName = NULL; } if (typeName == NULL) fprintf(src, "*** ERROR *** Unknown ANY\n\n"); else { if (bv->choiceId == BASICVALUE_OID) { fprintf (src, " AsnAny::InstallAnyByOid (oid%d, %s, new %s);\n", i++, anyId, typeName); } else if (bv->choiceId == BASICVALUE_INTEGER) { fprintf (src, " AsnAny::InstallAnyByInt (%d, %s, new %s);\n", bv->a.integer, anyId, typeName); } } } } } }/* REN -- end */ if (!installedSomeHashes) { fprintf (src," /* Since no INTEGER/OID to ANY type relations were defined\n"); fprintf (src," * (usually done via MACROs) you must manually do the code\n"); fprintf (src," * to fill the hash tbl.\n"); fprintf (src," * if the ids are INTEGER use the following:\n"); fprintf (src," * AsnAny::InstallAnyByInt (3, ??_ANY_ID, new <className>);\n"); fprintf (src," * if the ids are OBJECT IDENTIFIERs use the following:\n"); fprintf (src," * AsnAny::InstallAnyByOid (OidValue, ??_ANY_ID, new <className>);\n"); fprintf (src," * put the ??_ANY_IDs in the AnyId enum.\n\n"); fprintf (src," * For example if you have some thing like\n"); fprintf (src," * T1 ::= SEQUENCE { id INTEGER, ANY DEFINED BY id }\n"); fprintf (src," * and the id 1 maps to the type BOOLEAN use the following:\n"); fprintf (src," * AsnAny::InstallAnyByInt (1, SOMEBOOL_ANY_ID, new AsnBool);\n"); fprintf (src," */\n ???????\n"); /* generate compile error */ } fprintf (src,"} /* InitAny::InitAny */\n\n\n");/* RWC;4/23/01;#endif *//* RWC;4/23/01; r;m;mods;hdr;src; */ /*AVOIDS warning.*/} /* PrintAnyHashInitRoutine *//* REN -- 5/11/2001 -- GetTypeDef() function added to return the type def infofor the given type. */static TypeDef*GetTypeDef PARAMS ((t), Type *t){ if (t == NULL) return NULL; switch (t->basicType->choiceId) { case BASICTYPE_LOCALTYPEREF: case BASICTYPE_IMPORTTYPEREF: return t->basicType->a.localTypeRef->link; break; default: return NULL; } /*fprintf (errFileG, "GetTypeDef: ERROR - cannot get type def for unlinked local/import type refs\n"); return NULL;*/} /* GetTypeDef *//* REN -- end */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -