4 * Operations to generate JAX AgentX class files.
6 * Copyright (c) 2000 Frank Strauss, Technical University of Braunschweig.
8 * See the file "COPYING" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * @(#) $Id: dump-jax.c 1455 2002-10-30 09:17:37Z schoenw $
32 static char *package = NULL;
42 { SMI_BASETYPE_OCTETSTRING, "Opaque", "byte[]", "OPAQUE" },
43 { SMI_BASETYPE_UNSIGNED32, "TimeTicks", "long", "TIMETICKS" },
44 { SMI_BASETYPE_UNSIGNED32, "Counter", "long", "COUNTER32" },
45 { SMI_BASETYPE_UNSIGNED32, "Counter32", "long", "COUNTER32" },
46 { SMI_BASETYPE_OCTETSTRING, "IpAddress", "byte[]", "IPADDRESS" },
47 { SMI_BASETYPE_INTEGER32, NULL, "int", "INTEGER" },
48 { SMI_BASETYPE_OCTETSTRING, NULL, "byte[]", "OCTETSTRING" },
49 { SMI_BASETYPE_OBJECTIDENTIFIER, NULL, "AgentXOID", "OBJECTIDENTIFIER" },
50 { SMI_BASETYPE_UNSIGNED32, NULL, "long", "GAUGE32" },
51 { SMI_BASETYPE_INTEGER64, NULL, "long", "INTEGER" },
52 { SMI_BASETYPE_UNSIGNED64, NULL, "long", "COUNTER64" },
53 { SMI_BASETYPE_ENUM, NULL, "int", "INTEGER" },
54 { SMI_BASETYPE_BITS, NULL, "byte[]", "OCTETSTRING" },
55 { SMI_BASETYPE_UNKNOWN, NULL, NULL, NULL }
60 static char* translate1Upper(char *m)
62 static char *sarray[5];
69 if (spos == 5) spos = 0;
72 for (i = 0; s[i]; i++) {
73 if (s[i] == '-') s[i] = '_';
75 if (islower((int) s[0])) {
84 static FILE * createFile(char *name, char *suffix)
89 fullname = xmalloc(strlen(name) + (suffix ? strlen(suffix) : 0) + 2);
90 strcpy(fullname, name);
92 strcat(fullname, suffix);
94 if (!access(fullname, R_OK)) {
95 fprintf(stderr, "smidump: %s already exists\n", fullname);
99 f = fopen(fullname, "w");
101 fprintf(stderr, "smidump: cannot open %s for writing: ", fullname);
112 static char *getJavaType(SmiType *smiType)
117 for(i=0; convertType[i].basetype != SMI_BASETYPE_UNKNOWN; i++) {
118 if (smiType->basetype == convertType[i].basetype)
119 return convertType[i].javatype;
128 static char *getAgentXType(SmiType *smiType)
132 SmiModule *smiModule;
136 parentType = smiGetParentType(smiType);
138 smiModule = smiGetTypeModule(parentType);
139 if (smiModule && strlen(smiModule->name)) {
140 smiType = parentType;
144 for(i=0; convertType[i].basetype != SMI_BASETYPE_UNKNOWN; i++) {
145 if (smiType->basetype == convertType[i].basetype) {
146 if (!convertType[i].smitype) {
147 return convertType[i].agentxtype;
149 if ((smiType->name) &&
150 (!strcmp(convertType[i].smitype, smiType->name))) {
151 return convertType[i].agentxtype;
162 static int isGroup(SmiNode *smiNode)
166 if (smiNode->nodekind == SMI_NODEKIND_ROW) {
170 for(childNode = smiGetFirstChildNode(smiNode);
172 childNode = smiGetNextChildNode(childNode)) {
173 if (childNode->nodekind == SMI_NODEKIND_SCALAR) {
183 static int isAccessible(SmiNode *groupNode)
188 for (smiNode = smiGetFirstChildNode(groupNode);
190 smiNode = smiGetNextChildNode(smiNode)) {
191 if ((smiNode->nodekind == SMI_NODEKIND_SCALAR
192 || smiNode->nodekind == SMI_NODEKIND_COLUMN)
193 && (smiNode->access == SMI_ACCESS_READ_ONLY
194 || smiNode->access == SMI_ACCESS_READ_WRITE)) {
204 static unsigned int getMaxSize(SmiType *smiType)
208 unsigned int max = 0, size;
210 switch (smiType->basetype) {
211 case SMI_BASETYPE_OCTETSTRING:
214 case SMI_BASETYPE_OBJECTIDENTIFIER:
221 for(smiRange = smiGetFirstRange(smiType);
222 smiRange ; smiRange = smiGetNextRange(smiRange)) {
223 if (smiRange->maxValue.value.unsigned32 > max) {
224 max = smiRange->maxValue.value.unsigned32;
227 if (max > 0 && max < size) {
231 parentType = smiGetParentType(smiType);
233 unsigned int psize = getMaxSize(parentType);
244 static void dumpTable(SmiNode *smiNode)
247 SmiNode *parentNode, *columnNode;
251 parentNode = smiGetParentNode(smiNode);
253 f = createFile(translate1Upper(parentNode->name), ".java");
260 " * This Java file has been generated by smidump "
261 SMI_VERSION_STRING "." " Do not edit!\n"
262 " * It is intended to be used within a Java AgentX sub-agent"
270 " This class represents a Java AgentX (JAX) implementation of\n"
271 " the table %s defined in %s.\n"
274 " @author smidump " SMI_VERSION_STRING "\n"
275 " @see AgentXTable\n"
276 " */\n\n", parentNode->name, smiGetNodeModule(smiNode)->name);
280 "package %s;\n\n", package);
284 "import java.util.Vector;\n"
286 "import jax.AgentXOID;\n"
287 "import jax.AgentXVarBind;\n"
288 "import jax.AgentXResponsePDU;\n"
289 "import jax.AgentXSetPhase;\n"
290 "import jax.AgentXTable;\n"
291 "import jax.AgentXEntry;\n"
294 fprintf(f, "public class %s extends AgentXTable\n{\n\n",
295 translate1Upper(parentNode->name));
299 " private final static long[] OID = {");
300 for (i = 0; i < smiNode->oidlen; i++) {
301 fprintf(f, "%s%d", i ? ", " : "", smiNode->oid[i]);
303 fprintf(f, "};\n\n");
307 " public %s()\n", translate1Upper(parentNode->name));
310 " oid = new AgentXOID(OID);\n"
312 " // register implemented columns\n");
313 for (columnNode = smiGetFirstChildNode(smiNode);
315 columnNode = smiGetNextChildNode(columnNode)) {
316 if (columnNode->access >= SMI_ACCESS_READ_ONLY) {
318 " columns.addElement(new Long(%d));\n",
319 columnNode->oid[columnNode->oidlen-1]);
326 " public %s(boolean shared)\n",
327 translate1Upper(parentNode->name));
332 " oid = new AgentXOID(OID);\n"
334 " // register implemented columns\n");
335 for (columnNode = smiGetFirstChildNode(smiNode);
337 columnNode = smiGetNextChildNode(columnNode)) {
338 if (columnNode->access >= SMI_ACCESS_READ_ONLY) {
340 " columns.addElement(new Long(%d));\n",
341 columnNode->oid[columnNode->oidlen-1]);
348 " public AgentXVarBind getVarBind(AgentXEntry entry,"
352 " AgentXOID oid = new AgentXOID(getOID(), column, entry.getInstance());\n"
354 " switch ((int)column) {\n");
356 for (columnNode = smiGetFirstChildNode(smiNode);
358 columnNode = smiGetNextChildNode(columnNode)) {
359 if (columnNode->access >= SMI_ACCESS_NOTIFY) {
362 columnNode->oid[columnNode->oidlen-1],
367 " %s value = ((%s)entry).get_%s();\n",
368 getJavaType(smiGetNodeType(columnNode)),
369 translate1Upper(smiNode->name),
372 " return new AgentXVarBind(oid, "
373 "AgentXVarBind.%s, value);\n",
374 getAgentXType(smiGetNodeType(columnNode)));
388 " public int setEntry(AgentXSetPhase phase,\n"
389 " AgentXEntry entry,\n"
391 " AgentXVarBind vb)\n");
395 " switch ((int)column) {\n");
397 for (columnNode = smiGetFirstChildNode(smiNode);
399 columnNode = smiGetNextChildNode(columnNode)) {
400 if (columnNode->access >= SMI_ACCESS_READ_WRITE) {
403 columnNode->oid[columnNode->oidlen-1],
408 " if (vb.getType() != AgentXVarBind.%s)\n"
409 " return AgentXResponsePDU.WRONG_TYPE;\n",
410 getAgentXType(smiGetNodeType(columnNode)));
411 vb_type = getJavaType(smiGetNodeType(columnNode));
412 vb_type = strcmp("byte[]", vb_type) ? vb_type : "bytes";
415 " return ((%s)entry).set_%s(phase, vb.%sValue());\n",
416 translate1Upper(smiNode->name),
428 " return AgentXResponsePDU.NOT_WRITABLE;\n"
434 if (fflush(f) || ferror(f)) {
435 perror("smidump: write error");
444 static void dumpEntry(SmiNode *smiNode)
447 SmiNode *columnNode, *indexNode;
455 f = createFile(translate1Upper(smiNode->name), ".java");
462 " * This Java file has been generated by smidump "
463 SMI_VERSION_STRING "." " Do not edit!\n"
464 " * It is intended to be used within a Java AgentX sub-agent"
472 " This class represents a Java AgentX (JAX) implementation of\n"
473 " the table row %s defined in %s.\n"
476 " @author smidump " SMI_VERSION_STRING "\n"
477 " @see AgentXTable, AgentXEntry\n"
478 " */\n\n", smiNode->name, smiGetNodeModule(smiNode)->name);
482 "package %s;\n\n", package);
486 "import jax.AgentXOID;\n"
487 "import jax.AgentXSetPhase;\n"
488 "import jax.AgentXResponsePDU;\n"
489 "import jax.AgentXEntry;\n"
492 fprintf(f, "public class %s extends AgentXEntry\n{\n\n",
493 translate1Upper(smiNode->name));
495 for (columnNode = smiGetFirstChildNode(smiNode);
497 columnNode = smiGetNextChildNode(columnNode)) {
499 smiType = smiGetNodeType(columnNode);
500 if (!smiType) continue;
501 p = getJavaType(smiType);
502 if (!strcmp(p, "long")) {
504 } else if (!strcmp(p, "int")) {
506 } else if (!strcmp(p, "byte[]")) {
507 smiRange = smiGetFirstRange(smiType);
508 if ((smiRange && (!smiGetNextRange(smiRange)) &&
509 (!memcmp(&smiRange->minValue, &smiRange->maxValue,
510 sizeof(SmiValue))))) {
511 sprintf(init, "new byte[%ld]",
512 smiRange->maxValue.value.integer32);
514 sprintf(init, "new byte[0]");
516 } else if (!strcmp(p, "AgentXOID")) {
517 strcpy(init, "new AgentXOID()");
519 strcpy(init, "null");
522 " protected %s %s = %s;\n",
523 getJavaType(smiGetNodeType(columnNode)),
527 if (columnNode->access == SMI_ACCESS_READ_WRITE) {
529 " protected %s undo_%s = %s;\n",
530 getJavaType(smiGetNodeType(columnNode)),
535 for (element = smiGetFirstElement(smiNode), cnt = 0;
537 element = smiGetNextElement(element)) {
538 indexNode = smiGetElementNode(element);
539 for (columnNode = smiGetFirstChildNode(smiNode);
541 columnNode = smiGetNextChildNode(columnNode)) {
542 if (!strcmp(columnNode->name, indexNode->name))
547 fprintf(f, " // foreign indices\n");
550 fprintf(f, " protected %s %s;\n",
551 getJavaType(smiGetNodeType(indexNode)),
558 " public %s(", translate1Upper(smiNode->name));
559 for (element = smiGetFirstElement(smiNode), cnt = 0;
561 element = smiGetNextElement(element)) {
563 fprintf(f, ",\n%*s", 4 + 7 + 1 + strlen(smiNode->name), " ");
566 indexNode = smiGetElementNode(element);
568 getJavaType(smiGetNodeType(indexNode)),
573 for (element = smiGetFirstElement(smiNode);
575 element = smiGetNextElement(element)) {
576 indexNode = smiGetElementNode(element);
577 fprintf(f, " this.%s = %s;\n",
578 indexNode->name, indexNode->name);
581 for (element = smiGetFirstElement(smiNode);
583 element = smiGetNextElement(element)) {
584 indexNode = smiGetElementNode(element);
586 p = getJavaType(smiGetNodeType(indexNode));
587 if (!strcmp(p, "long")) {
588 fprintf(f, " instance.append(%s);\n",
590 } else if (!strcmp(p, "int")) {
591 fprintf(f, " instance.append(%s);\n",
593 } else if (!strcmp(p, "byte[]")) {
594 smiType = smiGetNodeType(indexNode);
595 smiRange = smiGetFirstRange(smiType);
596 if ((smiRange && (!smiGetNextRange(smiRange)) &&
597 (!memcmp(&smiRange->minValue, &smiRange->maxValue,
598 sizeof(SmiValue)))) ||
599 (smiNode->implied && (!smiGetNextElement(element)))) {
600 fprintf(f, " instance.appendImplied(%s);\n",
603 fprintf(f, " instance.append(%s);\n",
606 } else if (!strcmp(p, "AgentXOID")) {
607 if (smiNode->implied && (!smiGetNextElement(element))) {
608 fprintf(f, " instance.appendImplied(%s);\n",
611 fprintf(f, " instance.append(%s);\n",
615 fprintf(f, " // [smidump: type of %s not supported]\n",
624 for (element = smiGetFirstElement(smiNode);
626 element = smiGetNextElement(element)) {
627 indexNode = smiGetElementNode(element);
630 " public %s get_%s()\n"
635 getJavaType(smiGetNodeType(indexNode)),
636 indexNode->name, indexNode->name);
639 for (columnNode = smiGetFirstChildNode(smiNode);
641 columnNode = smiGetNextChildNode(columnNode)) {
642 smiType = smiGetNodeType(columnNode);
643 if (columnNode->access >= SMI_ACCESS_NOTIFY) {
644 for (element = smiGetFirstElement(smiNode);
646 element = smiGetNextElement(element)) {
647 indexNode = smiGetElementNode(element);
648 if (indexNode == columnNode) break;
652 " public %s get_%s()\n"
657 getJavaType(smiType),
658 columnNode->name, columnNode->name);
661 if (columnNode->access == SMI_ACCESS_READ_WRITE) {
663 " public int set_%s(AgentXSetPhase phase, %s value)\n"
666 getJavaType(smiGetNodeType(columnNode)));
668 " switch (phase.getPhase()) {\n"
669 " case AgentXSetPhase.TEST_SET:\n"
671 " case AgentXSetPhase.COMMIT:\n"
675 if (!strcmp("byte[]", getJavaType(smiGetNodeType(columnNode)))) {
677 " %s = new byte[value.length];\n"
678 " for(int i = 0; i < value.length; i++)\n"
679 " %s[i] = value[i];\n",
690 " case AgentXSetPhase.UNDO:\n"
696 " case AgentXSetPhase.CLEANUP:\n");
697 if (!strcmp("byte[]",getJavaType(smiGetNodeType(columnNode)))) {
699 " undo_%s = null;\n",
705 " return AgentXResponsePDU.PROCESSING_ERROR;\n"
707 " return AgentXResponsePDU.NO_ERROR;\n"
715 if (fflush(f) || ferror(f)) {
716 perror("smidump: write error");
723 static void dumpEntryImpl(SmiNode *smiNode)
726 SmiNode *columnNode, *indexNode;
731 f = createFile(translate1Upper(smiNode->name), "Impl.java");
738 " * This Java file has been generated by smidump "
739 SMI_VERSION_STRING ". It\n"
740 " * is intended to be edited by the application programmer and\n"
741 " * to be used within a Java AgentX sub-agent environment.\n"
747 " This class extends the Java AgentX (JAX) implementation of\n"
748 " the table row %s defined in %s.\n"
749 " */\n\n", smiNode->name, smiGetNodeModule(smiNode)->name);
753 "package %s;\n\n", package);
757 "import jax.AgentXOID;\n"
758 "import jax.AgentXSetPhase;\n"
759 "import jax.AgentXResponsePDU;\n"
760 "import jax.AgentXEntry;\n"
763 fprintf(f, "public class %sImpl extends %s\n{\n\n",
764 translate1Upper(smiNode->name),
765 translate1Upper(smiNode->name));
769 " public %sImpl(", translate1Upper(smiNode->name));
770 for (element = smiGetFirstElement(smiNode), cnt = 0;
772 element = smiGetNextElement(element)) {
774 fprintf(f, ",\n%*s", 4 + 7 + 1 + strlen(smiNode->name), " ");
777 indexNode = smiGetElementNode(element);
779 getJavaType(smiGetNodeType(indexNode)),
785 for (element = smiGetFirstElement(smiNode), cnt = 0;
787 element = smiGetNextElement(element)) {
789 fprintf(f, ",\n%*s", 2 + strlen(smiNode->name), " ");
792 indexNode = smiGetElementNode(element);
793 fprintf(f, "%s", indexNode->name);
801 for (columnNode = smiGetFirstChildNode(smiNode);
803 columnNode = smiGetNextChildNode(columnNode)) {
804 smiType = smiGetNodeType(columnNode);
805 if (!smiType) continue;
806 if (columnNode->access >= SMI_ACCESS_NOTIFY) {
808 " public %s get_%s()\n"
813 getJavaType(smiType),
814 columnNode->name, columnNode->name);
816 if (columnNode->access == SMI_ACCESS_READ_WRITE) {
818 " public int set_%s(AgentXSetPhase phase, %s value)\n"
821 getJavaType(smiGetNodeType(columnNode)));
823 " switch (phase.getPhase()) {\n"
824 " case AgentXSetPhase.TEST_SET:\n"
826 " case AgentXSetPhase.COMMIT:\n"
830 if (!strcmp("byte[]", getJavaType(smiGetNodeType(columnNode)))) {
832 " %s = new byte[value.length];\n"
833 " for(int i = 0; i < value.length; i++)\n"
834 " %s[i] = value[i];\n",
845 " case AgentXSetPhase.UNDO:\n"
851 " case AgentXSetPhase.CLEANUP:\n");
852 if (!strcmp("byte[]",getJavaType(smiGetNodeType(columnNode)))) {
854 " undo_%s = null;\n",
860 " return AgentXResponsePDU.PROCESSING_ERROR;\n"
862 " return AgentXResponsePDU.NO_ERROR;\n"
870 if (fflush(f) || ferror(f)) {
871 perror("smidump: write error");
880 static SmiNode *dumpScalars(SmiNode *smiNode)
884 SmiNode *parentNode, *currNode;
891 parentNode = smiGetParentNode(smiNode);
893 f = createFile(translate1Upper(parentNode->name), ".java");
900 " * This Java file has been generated by smidump "
901 SMI_VERSION_STRING "." " Do not edit!\n"
902 " * It is intended to be used within a Java AgentX sub-agent"
909 " This class represents a Java AgentX (JAX) implementation of\n"
910 " the scalar group %s defined in %s.\n"
913 " @author smidump " SMI_VERSION_STRING "\n"
914 " @see AgentXGroup, AgentXScalars\n"
915 " */\n\n", parentNode->name, smiGetNodeModule(smiNode)->name);
919 "package %s;\n\n", package);
923 "import java.util.Vector;\n"
924 "import java.util.Enumeration;\n"
925 "import jax.AgentXOID;\n"
926 "import jax.AgentXVarBind;\n"
927 "import jax.AgentXSetPhase;\n"
928 "import jax.AgentXResponsePDU;\n"
929 "import jax.AgentXScalars;\n"
932 fprintf(f, "public class %s extends AgentXScalars\n{\n\n",
933 translate1Upper(parentNode->name));
936 " private final static long[] %sOID = {",
937 translate1Upper(parentNode->name));
938 for (i = 0; i < parentNode->oidlen; i++) {
939 fprintf(f, "%s%d", i ? ", " : "", parentNode->oid[i]);
941 fprintf(f, "};\n\n");
943 /* ------- variable definitions */
945 for (currNode = smiNode;
946 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
947 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
949 " protected AgentXOID %sOID;\n"
950 " protected final static long[] %sName = {",
951 translate1Upper(currNode->name),
952 translate1Upper(currNode->name)
954 for (i = 0; i < currNode->oidlen; i++) {
955 fprintf(f, "%s%d", i ? ", " : "", currNode->oid[i]);
957 fprintf(f, ", 0};\n");
959 smiType = smiGetNodeType(currNode);
960 p = getJavaType(smiType);
961 if (!strcmp(p, "long")) {
963 } else if (!strcmp(p, "int")) {
965 } else if (!strcmp(p, "byte[]")) {
966 smiRange = smiGetFirstRange(smiType);
967 if ((smiRange && (!smiGetNextRange(smiRange)) &&
968 (!memcmp(&smiRange->minValue, &smiRange->maxValue,
969 sizeof(SmiValue))))) {
970 sprintf(init, "new byte[%ld]",
971 smiRange->maxValue.value.integer32);
973 sprintf(init, "new byte[0]");
975 } else if (!strcmp(p, "AgentXOID")) {
976 strcpy(init, "new AgentXOID()");
978 strcpy(init, "null");
981 " protected %s %s = %s;\n",
982 getJavaType(smiGetNodeType(currNode)),
986 if (currNode->access == SMI_ACCESS_READ_WRITE) {
988 " protected %s undo_%s = %s;\n",
989 getJavaType(smiGetNodeType(currNode)),
994 /* ------- constructor */
997 " oid = new AgentXOID(%sOID);\n"
998 " data = new Vector();\n",
999 translate1Upper(parentNode->name),
1000 translate1Upper(parentNode->name));
1002 for (currNode = smiNode;
1003 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
1004 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
1006 " %sOID = new AgentXOID(%sName);\n"
1007 " data.addElement(%sOID);\n",
1008 translate1Upper(currNode->name),
1009 translate1Upper(currNode->name),
1010 translate1Upper(currNode->name));
1012 fprintf(f," }\n\n");
1013 /* ------- get & set methods */
1014 for (currNode = smiNode;
1015 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
1016 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
1017 smiType = smiGetNodeType(currNode);
1018 if (currNode->access >= SMI_ACCESS_NOTIFY) {
1020 " public %s get_%s()\n"
1025 getJavaType(smiType),
1026 currNode->name, currNode->name);
1028 if (currNode->access == SMI_ACCESS_READ_WRITE) {
1030 " public int set_%s(AgentXSetPhase phase, %s value)\n"
1033 getJavaType(smiGetNodeType(currNode)));
1035 " switch (phase.getPhase()) {\n"
1036 " case AgentXSetPhase.TEST_SET:\n"
1038 " case AgentXSetPhase.COMMIT:\n"
1042 if (!strcmp("byte[]", getJavaType(smiGetNodeType(currNode)))) {
1044 " %s = new byte[value.length];\n"
1045 " for(int i = 0; i < value.length; i++)\n"
1046 " %s[i] = value[i];\n",
1057 " case AgentXSetPhase.UNDO:\n"
1063 " case AgentXSetPhase.CLEANUP:\n");
1064 if (!strcmp("byte[]",getJavaType(smiGetNodeType(currNode)))) {
1066 " undo_%s = null;\n",
1072 " return AgentXResponsePDU.PROCESSING_ERROR;\n"
1074 " return AgentXResponsePDU.NO_ERROR;\n"
1078 /* ------ handle get get-next and set requests */
1080 " public AgentXVarBind getScalar(AgentXOID pos,"
1083 " if ((pos == null) || (pos.compareTo(oid) != 0))\n"
1084 " return new AgentXVarBind(oid,"
1085 " AgentXVarBind.NOSUCHOBJECT);\n"
1088 for (currNode = smiNode;
1089 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
1090 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
1092 " if (pos == %sOID)\n"
1093 " return new AgentXVarBind(oid,"
1094 " AgentXVarBind.%s, \n"
1096 translate1Upper(currNode->name),
1097 getAgentXType(smiGetNodeType(currNode)),
1103 " return new AgentXVarBind(oid,"
1104 " AgentXVarBind.NOSUCHOBJECT);\n }\n\n");
1107 " public int setScalar(AgentXSetPhase phase,"
1109 " AgentXVarBind inVb)\n {\n"
1110 " if ((pos == null) || (pos.compareTo(inVb.getOID()) != 0))\n"
1111 " return AgentXResponsePDU.INCONSISTENT_NAME;\n"
1115 for (currNode = smiNode;
1116 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
1117 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
1118 vb_type = getJavaType(smiGetNodeType(currNode));
1119 vb_type = strcmp("byte[]", vb_type) ? vb_type : "bytes";
1120 if (currNode->access == SMI_ACCESS_READ_WRITE)
1122 " if (pos == %sOID)\n"
1124 "set_%s(phase, inVb.%sValue());\n",
1125 translate1Upper(currNode->name),
1132 " return AgentXResponsePDU.NOT_WRITABLE;\n"
1135 " public AgentXVarBind getNextScalar(AgentXOID pos,"
1136 " AgentXOID oid)\n {\n"
1137 " if ((pos == null) || (pos.compareTo(oid) <= 0))\n"
1138 " return new AgentXVarBind(oid,"
1139 " AgentXVarBind.ENDOFMIBVIEW);\n"
1142 for (currNode = smiNode;
1143 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
1144 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
1146 " if (pos == %sOID)\n"
1147 " return new AgentXVarBind(pos,"
1148 " AgentXVarBind.%s, \n"
1150 translate1Upper(currNode->name),
1151 getAgentXType(smiGetNodeType(currNode)),
1157 " return new AgentXVarBind(pos,"
1158 " AgentXVarBind.ENDOFMIBVIEW);\n }\n\n");
1162 if (fflush(f) || ferror(f)) {
1163 perror("smidump: write error");
1168 /* skip all already processed nodes */
1170 smiNode && (smiNode->nodekind == SMI_NODEKIND_SCALAR);
1171 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
1176 static void dumpNotifications(SmiNode *smiNode)
1181 SmiElement *element;
1182 SmiNode *elementNode;
1185 snt = smiGetNodeType(smiNode);
1187 f = createFile(translate1Upper(smiNode->name), ".java");
1194 " * This Java file has been generated by smidump "
1195 SMI_VERSION_STRING "." " Do not edit!\n"
1196 " * It is intended to be used within a Java AgentX sub-agent"
1204 "package %s;\n\n", package);
1208 "import jax.AgentXOID;\n"
1209 "import jax.AgentXVarBind;\n"
1210 "import jax.AgentXNotification;\n"
1211 "import java.util.Vector;\n"
1214 fprintf(f, "public class %s extends AgentXNotification\n{\n\n",
1215 translate1Upper(smiNode->name));
1218 " private final static long[] %s_OID = {",
1220 for (i = 0; i < smiNode->oidlen; i++) {
1221 fprintf(f, "%s%d", i ? ", " : "", smiNode->oid[i]);
1225 " private static AgentXVarBind snmpTrapOID_VarBind =\n"
1226 " new AgentXVarBind(snmpTrapOID_OID,\n"
1227 " AgentXVarBind.OBJECTIDENTIFIER,\n"
1228 " new AgentXOID(%s_OID));\n\n",
1231 for (element = smiGetFirstElement(smiNode), cnt = 1;
1233 element = smiGetNextElement(element), cnt++) {
1234 elementNode = smiGetElementNode(element);
1235 fprintf(f, " private final static long[] OID%d = {", cnt);
1236 for (i = 0; i < elementNode->oidlen; i++) {
1237 fprintf(f, "%s%d", i ? ", " : "", elementNode->oid[i]);
1241 " private final AgentXOID %s_OID = "
1242 "new AgentXOID(OID%d",
1243 elementNode->name, cnt);
1246 if (elementNode->nodekind != SMI_NODEKIND_COLUMN ||
1247 (smiGetNodeModule(elementNode) != smiGetNodeModule(smiNode))) {
1249 " private static AgentXVarBind varBind_%s = new AgentXVarBind(\n"
1250 " %sOID, AgentXVarBind.%s\n);\n",
1253 getAgentXType(smiGetNodeType(elementNode)));
1259 translate1Upper(smiNode->name));
1260 for (element = smiGetFirstElement(smiNode), cnt = 0;
1262 element = smiGetNextElement(element)) {
1263 elementNode = smiGetElementNode(element);
1264 if (smiGetNodeModule(elementNode) == smiGetNodeModule(smiNode)) {
1265 if (cnt) fprintf(f,", ");
1267 fprintf(f, "%s %s_%d",
1268 translate1Upper(smiGetParentNode(elementNode)->name),
1269 smiGetParentNode(elementNode)->name, cnt);
1274 " AgentXVarBind varBind;\n"
1276 " // add the snmpTrapOID object\n"
1277 " varBindList.addElement(snmpTrapOID_VarBind);\n");
1278 for (element = smiGetFirstElement(smiNode), cnt = 1;
1280 element = smiGetNextElement(element), cnt++) {
1281 elementNode = smiGetElementNode(element);
1283 if (smiGetNodeModule(elementNode) == smiGetNodeModule(smiNode)) {
1286 "\n // add the %s %s object of %s_%d\n",
1288 elementNode->nodekind == SMI_NODEKIND_COLUMN ?
1289 "columnar" : "scalar",
1290 smiGetParentNode(elementNode)->name, cnt);
1292 if (elementNode->nodekind == SMI_NODEKIND_COLUMN) {
1295 " oid.appendImplied(%s_%d.getInstance());\n",
1297 smiGetParentNode(elementNode)->name, cnt);
1299 " varBind = new AgentXVarBind(oid,\n"
1300 " AgentXVarBind.%s,\n"
1301 " %s_%d.get_%s());\n",
1302 getAgentXType(smiGetNodeType(elementNode)),
1303 smiGetParentNode(elementNode)->name, cnt,
1306 " varBindList.addElement(varBind);\n");
1312 " oid.append(0);\n");
1314 " varBind = new AgentXVarBind(oid,\n"
1315 " AgentXVarBind.%s,\n"
1316 " %s_%d.get_%s());\n",
1317 getAgentXType(smiGetNodeType(elementNode)),
1318 smiGetParentNode(elementNode)->name, cnt,
1321 " varBindList.addElement(varBind);\n");
1326 " // the notification's object %s "
1327 "is not contained in this module.\n",
1336 " public Vector getVarBindList() {\n"
1337 " return varBindList;\n }\n\n");
1342 if (fflush(f) || ferror(f)) {
1343 perror("smidump: write error");
1350 static void dumpScalarImpl(SmiNode *smiNode)
1353 SmiNode *parentNode, *currNode;
1356 parentNode = smiGetParentNode(smiNode);
1358 f = createFile(translate1Upper(parentNode->name), "Impl.java");
1365 " * This Java file has been generated by smidump "
1366 SMI_VERSION_STRING ". It\n"
1367 " * is intended to be edited by the application programmer and\n"
1368 " * to be used within a Java AgentX sub-agent environment.\n"
1374 " This class extends the Java AgentX (JAX) implementation of\n"
1375 " the scalar group %s defined in %s.\n"
1376 " */\n\n", parentNode->name, smiGetNodeModule(smiNode)->name);
1380 "package %s;\n\n", package);
1384 "import java.util.Vector;\n"
1385 "import java.util.Enumeration;\n"
1386 "import jax.AgentXOID;\n"
1387 "import jax.AgentXSetPhase;\n"
1388 "import jax.AgentXResponsePDU;\n"
1391 fprintf(f, "public class %sImpl extends %s\n{\n\n",
1392 translate1Upper(parentNode->name),
1393 translate1Upper(parentNode->name));
1395 for (currNode = smiNode;
1396 currNode && (currNode->nodekind == SMI_NODEKIND_SCALAR) ;
1397 currNode = smiGetNextNode(currNode,SMI_NODEKIND_ANY)) {
1398 smiType = smiGetNodeType(currNode);
1399 if (currNode->access >= SMI_ACCESS_NOTIFY) {
1401 " public %s get_%s()\n"
1406 getJavaType(smiType),
1407 currNode->name, currNode->name);
1409 if (currNode->access == SMI_ACCESS_READ_WRITE) {
1411 " public int set_%s(AgentXSetPhase phase, %s value)\n"
1414 getJavaType(smiGetNodeType(currNode)));
1416 " switch (phase.getPhase()) {\n"
1417 " case AgentXSetPhase.TEST_SET:\n"
1419 " case AgentXSetPhase.COMMIT:\n"
1423 if (!strcmp("byte[]", getJavaType(smiGetNodeType(currNode)))) {
1425 " %s = new byte[value.length];\n"
1426 " for(int i = 0; i < value.length; i++)\n"
1427 " %s[i] = value[i];\n",
1437 " case AgentXSetPhase.UNDO:\n"
1443 " case AgentXSetPhase.CLEANUP:\n");
1444 if (!strcmp("byte[]",getJavaType(smiGetNodeType(currNode)))) {
1446 " undo_%s = null;\n",
1450 " undo_%s = -1; // TODO: better check!\n",
1456 " return AgentXResponsePDU.PROCESSING_ERROR;\n"
1458 " return AgentXResponsePDU.NO_ERROR;\n"
1466 if (fflush(f) || ferror(f)) {
1467 perror("smidump: write error");
1475 static void dumpJax(int modc, SmiModule **modv, int flags, char *output)
1480 for (i = 0; i < modc; i++) {
1482 for(smiNode = smiGetFirstNode(modv[i], SMI_NODEKIND_ROW);
1484 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ROW)) {
1485 if (isGroup(smiNode) && isAccessible(smiNode)) {
1488 dumpEntryImpl(smiNode);
1492 for(smiNode = smiGetFirstNode(modv[i], SMI_NODEKIND_SCALAR);
1494 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_SCALAR)) {
1495 dumpScalarImpl(smiNode);
1496 smiNode = dumpScalars(smiNode);
1499 for(smiNode = smiGetFirstNode(modv[i], SMI_NODEKIND_NOTIFICATION);
1501 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_NOTIFICATION)) {
1502 dumpNotifications(smiNode);
1511 static SmidumpDriverOption opt[] = {
1512 { "package", OPT_STRING, &package, 0,
1513 "make classes part of a given package"},
1514 { 0, OPT_END, 0, 0 }
1517 static SmidumpDriver driver = {
1521 SMIDUMP_DRIVER_CANT_UNITE | SMIDUMP_DRIVER_CANT_OUTPUT,
1522 "Java AgentX sub-agent classes in separate files",
1527 smidumpRegisterDriver(&driver);