public VariableDeclaration(VariableType type, string initialValue = null, bool isStatic = false) : base() { this.Type = type; this.InitialValue = initialValue; this.IsStatic = isStatic; }
protected override void GenerateSetMethodCodeCore(CodeContainerBase container, string localValueVarName, ref bool localValueVarUsed, string lenVarName, ref bool lenVarUsed, string retErrVarName) { VariableType truthVar = new VariableType("bool_value", LwipDefs.Vt_U8); container.Declarations.Add(new VariableDeclaration(truthVar)); container.AddCodeFormat("snmp_decode_truthvalue({0}, &{1});", localValueVarName, truthVar.Name); localValueVarUsed = true; container.AddElement(new Comment(String.Format("TODO: store new value contained in '{0}' here", truthVar.Name), singleLine: true)); }
private void GenerateAggregatedCode(MibCFile mibFile, bool generateDeclarations, bool generateImplementations) { VariableType instanceType = new VariableType("instance", LwipDefs.Vt_StNodeInstance, "*"); base.GenerateAggregatedCode( mibFile, instanceType, String.Format("{0}->node->oid", instanceType.Name), generateDeclarations, generateImplementations); }
public override void GenerateCode(MibCFile mibFile) { VariableType instanceType = new VariableType("node", LwipDefs.Vt_StScalarArrayNodeDef, "*", ConstType.Value); GenerateAggregatedCode( mibFile, instanceType, instanceType.Name + "->oid"); // create and add node definitions StringBuilder nodeDefs = new StringBuilder(); foreach (SnmpScalarNode scalarNode in this.scalarNodes) { nodeDefs.AppendFormat(" {{{0}, {1}, {2}}}, /* {3} */ \n", scalarNode.Oid, LwipDefs.GetAsn1DefForSnmpDataType(scalarNode.DataType), LwipDefs.GetLwipDefForSnmpAccessMode(scalarNode.AccessMode), scalarNode.Name); } if (nodeDefs.Length > 0) nodeDefs.Length--; VariableDeclaration nodeDefsDecl = new VariableDeclaration( new VariableType(this.FullNodeName + "_nodes", LwipDefs.Vt_StScalarArrayNodeDef, null, ConstType.Value, String.Empty), "{\n" + nodeDefs + "\n}" , isStatic: true); mibFile.Declarations.Add(nodeDefsDecl); // create and add node declaration string nodeInitialization = String.Format("SNMP_SCALAR_CREATE_ARRAY_NODE({0}, {1}, {2}, {3}, {4})", this.Oid, nodeDefsDecl.Type.Name, (this.GetMethodRequired) ? this.GetMethodName : LwipDefs.Null, (this.TestMethodRequired) ? this.TestMethodName : LwipDefs.Null, (this.SetMethodRequired) ? this.SetMethodName : LwipDefs.Null ); mibFile.Declarations.Add(new VariableDeclaration( new VariableType(this.FullNodeName, LwipDefs.Vt_StScalarArrayNode, null, ConstType.Value), nodeInitialization, isStatic: true)); }
protected void GenerateAggregatedCode(MibCFile mibFile, VariableType instanceType, string switchSelector, bool generateDeclarations = true, bool generateImplementations = true) { if (this.getMethodRequired) { FunctionDeclaration getMethodDecl = new FunctionDeclaration(this.GetMethodName, isStatic: true); getMethodDecl.Parameter.Add(instanceType); getMethodDecl.Parameter.Add(new VariableType("value", VariableType.VoidString, "*")); getMethodDecl.ReturnType = new VariableType(null, LwipDefs.Vt_U16); if (generateDeclarations) { mibFile.Declarations.Add(getMethodDecl); } if (generateImplementations) { Function getMethod = Function.FromDeclaration(getMethodDecl); GenerateGetMethodCode(getMethod, switchSelector); mibFile.Implementation.Add(getMethod); } } if (this.testMethodRequired) { FunctionDeclaration testMethodDecl = new FunctionDeclaration(this.TestMethodName, isStatic: true); testMethodDecl.Parameter.Add(instanceType); testMethodDecl.Parameter.Add(new VariableType("len", LwipDefs.Vt_U16)); testMethodDecl.Parameter.Add(new VariableType("value", VariableType.VoidString, "*")); testMethodDecl.ReturnType = new VariableType(null, LwipDefs.Vt_Snmp_err); if (generateDeclarations) { mibFile.Declarations.Add(testMethodDecl); } if (generateImplementations) { Function testMethod = Function.FromDeclaration(testMethodDecl); GenerateTestMethodCode(testMethod, switchSelector); mibFile.Implementation.Add(testMethod); } } if (this.setMethodRequired) { FunctionDeclaration setMethodDecl = new FunctionDeclaration(this.SetMethodName, isStatic: true); setMethodDecl.Parameter.Add(instanceType); setMethodDecl.Parameter.Add(new VariableType("len", LwipDefs.Vt_U16)); setMethodDecl.Parameter.Add(new VariableType("value", VariableType.VoidString, "*")); setMethodDecl.ReturnType = new VariableType(null, LwipDefs.Vt_Snmp_err); if (generateDeclarations) { mibFile.Declarations.Add(setMethodDecl); } if (generateImplementations) { Function setMethod = Function.FromDeclaration(setMethodDecl); GenerateSetMethodCode(setMethod, switchSelector); mibFile.Implementation.Add(setMethod); } } }
public override void GenerateCode(MibCFile mibFile) { FunctionDeclaration getInstanceMethodDecl = new FunctionDeclaration(this.FullNodeName + LwipDefs.FnctSuffix_GetInstance, isStatic: true); getInstanceMethodDecl.Parameter.Add(new VariableType("column", LwipDefs.Vt_U32, "*", ConstType.Value)); getInstanceMethodDecl.Parameter.Add(new VariableType("row_oid", LwipDefs.Vt_U32, "*", ConstType.Value)); getInstanceMethodDecl.Parameter.Add(new VariableType("row_oid_len", LwipDefs.Vt_U8, "")); getInstanceMethodDecl.Parameter.Add(new VariableType("cell_instance", LwipDefs.Vt_StNodeInstance, "*")); getInstanceMethodDecl.ReturnType = new VariableType(null, LwipDefs.Vt_Snmp_err); mibFile.Declarations.Add(getInstanceMethodDecl); Function getInstanceMethod = Function.FromDeclaration(getInstanceMethodDecl); GenerateGetInstanceMethodCode(getInstanceMethod); mibFile.Implementation.Add(getInstanceMethod); FunctionDeclaration getNextInstanceMethodDecl = new FunctionDeclaration(this.FullNodeName + LwipDefs.FnctSuffix_GetNextInstance, isStatic: true); getNextInstanceMethodDecl.Parameter.Add(new VariableType("column", LwipDefs.Vt_U32, "*", ConstType.Value)); getNextInstanceMethodDecl.Parameter.Add(new VariableType("row_oid", LwipDefs.Vt_StObjectId, "*")); getNextInstanceMethodDecl.Parameter.Add(new VariableType("cell_instance", LwipDefs.Vt_StNodeInstance, "*")); getNextInstanceMethodDecl.ReturnType = new VariableType(null, LwipDefs.Vt_Snmp_err); mibFile.Declarations.Add(getNextInstanceMethodDecl); Function getNextInstanceMethod = Function.FromDeclaration(getNextInstanceMethodDecl); GenerateGetNextInstanceMethodCode(getNextInstanceMethod); mibFile.Implementation.Add(getNextInstanceMethod); VariableType instanceType = new VariableType("cell_instance", LwipDefs.Vt_StNodeInstance, "*"); GenerateAggregatedCode( mibFile, instanceType, String.Format("SNMP_TABLE_GET_COLUMN_FROM_OID({0}->instance_oid.id)", instanceType.Name)); #region create and add column/table definitions StringBuilder colDefs = new StringBuilder(); foreach (SnmpScalarNode colNode in this.cellNodes) { colDefs.AppendFormat(" {{{0}, {1}, {2}}}, /* {3} */ \n", colNode.Oid, LwipDefs.GetAsn1DefForSnmpDataType(colNode.DataType), LwipDefs.GetLwipDefForSnmpAccessMode(colNode.AccessMode), colNode.Name); } if (colDefs.Length > 0) { colDefs.Length--; } VariableDeclaration colDefsDecl = new VariableDeclaration( new VariableType(this.FullNodeName + "_columns", LwipDefs.Vt_StTableColumnDef, null, ConstType.Value, String.Empty), "{\n" + colDefs + "\n}", isStatic: true); mibFile.Declarations.Add(colDefsDecl); string nodeInitialization = String.Format("SNMP_TABLE_CREATE({0}, {1}, {2}, {3}, {4}, {5}, {6})", this.Oid, colDefsDecl.Type.Name, getInstanceMethodDecl.Name, getNextInstanceMethodDecl.Name, (this.GetMethodRequired) ? this.GetMethodName : LwipDefs.Null, (this.TestMethodRequired) ? this.TestMethodName : LwipDefs.Null, (this.SetMethodRequired) ? this.SetMethodName : LwipDefs.Null ); mibFile.Declarations.Add(new VariableDeclaration( new VariableType(this.FullNodeName, LwipDefs.Vt_StTableNode, null, ConstType.Value), nodeInitialization, isStatic: true)); #endregion }