コード例 #1
0
		protected override void GenerateSetMethodCodeCore(CodeContainerBase container, string localValueVarName, ref bool localValueVarUsed, string lenVarName, ref bool lenVarUsed, string retErrVarName)
		{
			VariableDeclaration objIdLenVar = new VariableDeclaration(
				new VariableType(localValueVarName + "_len", LwipDefs.Vt_U8),
				String.Format("{0} / sizeof({1})", lenVarName, LwipDefs.Vt_U32));
			lenVarUsed = true;

			container.Declarations.Add(objIdLenVar);

			base.GenerateSetMethodCodeCore(container, localValueVarName, ref localValueVarUsed, lenVarName, ref lenVarUsed, retErrVarName);

			container.AddCode(String.Format("LWIP_UNUSED_ARG({0});", objIdLenVar.Type.Name));
		}
コード例 #2
0
ファイル: SnmpScalarArrayNode.cs プロジェクト: plocklsh/lwip
		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));
		}
コード例 #3
0
ファイル: SnmpMib.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(MibCFile mibFile)
		{
			base.GenerateCode(mibFile);

			System.Diagnostics.Debug.Assert((this.BaseOid != null) && (this.BaseOid.Length > 0));
			
			// create and add BaseOID declarations
			StringBuilder boidInitialization = new StringBuilder("{");
			foreach (uint t in this.BaseOid)
			{
				boidInitialization.Append(t);
				boidInitialization.Append(",");
			}
			boidInitialization.Length -= 1;
			boidInitialization.Append("}");

			VariableDeclaration boidDecl = new VariableDeclaration(
				new VariableType(this.Name + "_base_oid", LwipDefs.Vt_U32, null, ConstType.Value, String.Empty),
				boidInitialization.ToString(), true);

			mibFile.Declarations.Add(boidDecl);
			mibFile.Declarations.Add(GetExportDeclaration());
		}
コード例 #4
0
        public override void GenerateCode(MibCFile mibFile)
        {
            string getMethodName;
            string testMethodName;
            string setMethodName;

            if (this.useExternalMethods)
            {
                getMethodName  = this.externalGetMethod;
                testMethodName = this.externalTestMethod;
                setMethodName  = this.externalSetMethod;
            }
            else
            {
                getMethodName  = LwipDefs.Null;
                testMethodName = LwipDefs.Null;
                setMethodName  = LwipDefs.Null;

                if ((this.accessMode == SnmpAccessMode.ReadWrite) || (this.accessMode == SnmpAccessMode.ReadOnly))
                {
                    FunctionDeclaration  getMethodDecl = new FunctionDeclaration(this.Name + LwipDefs.FnctSuffix_GetValue, isStatic: true);
                    getMethodDecl.Parameter.Add(new VariableType("instance", LwipDefs.Vt_StNodeInstance, "*"));
                    getMethodDecl.Parameter.Add(new VariableType("value", VariableType.VoidString, "*"));
                    getMethodDecl.ReturnType = new VariableType(null, LwipDefs.Vt_S16);
                    mibFile.Declarations.Add(getMethodDecl);

                    Function getMethod = Function.FromDeclaration(getMethodDecl);
                    getMethodName = getMethod.Name;

                    VariableDeclaration returnValue = new VariableDeclaration((VariableType)getMethod.ReturnType.Clone());
                    returnValue.Type.Name = "value_len";
                    getMethod.Declarations.Add(returnValue);
                    getMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getMethod.Parameter[0].Name);

                    bool valueVarUsed = false;
                    GenerateGetMethodCode(getMethod, getMethod.Parameter[1].Name, ref valueVarUsed, returnValue.Type.Name);
                    if (!valueVarUsed)
                    {
                        getMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getMethod.Parameter[1].Name);
                    }

                    getMethod.AddCodeFormat("return {0};", returnValue.Type.Name);

                    mibFile.Implementation.Add(getMethod);
                }

                if ((this.accessMode == SnmpAccessMode.ReadWrite) || (this.accessMode == SnmpAccessMode.WriteOnly))
                {
                    bool valueVarUsed;
                    bool lenVarUsed;
                    VariableDeclaration returnValue;

                    if (this.restrictions.Count > 0)
                    {
                        FunctionDeclaration testMethodDecl = new FunctionDeclaration(this.Name + LwipDefs.FnctSuffix_SetTest, isStatic: true);
                        testMethodDecl.Parameter.Add(new VariableType("instance", LwipDefs.Vt_StNodeInstance, "*"));
                        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);
                        mibFile.Declarations.Add(testMethodDecl);

                        Function testMethod = Function.FromDeclaration(testMethodDecl);
                        testMethodName = testMethod.Name;

                        returnValue = new VariableDeclaration((VariableType)testMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_WrongValue);
                        returnValue.Type.Name = "err";
                        testMethod.Declarations.Add(returnValue);
                        testMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", testMethod.Parameter[0].Name);

                        valueVarUsed = false;
                        lenVarUsed = false;

                        GenerateTestMethodCode(testMethod, testMethod.Parameter[2].Name, ref valueVarUsed, testMethod.Parameter[1].Name, ref lenVarUsed, returnValue.Type.Name);

                        if (!valueVarUsed)
                        {
                            testMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", testMethod.Parameter[2].Name);
                        }
                        if (!lenVarUsed)
                        {
                            testMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", testMethod.Parameter[1].Name);
                        }

                        testMethod.AddCodeFormat("return {0};", returnValue.Type.Name);

                        mibFile.Implementation.Add(testMethod);

                    }
                    else
                    {
                        testMethodName = LwipDefs.FnctName_SetTest_Ok;
                    }

                    FunctionDeclaration setMethodDecl  = null;
                    setMethodDecl = new FunctionDeclaration(this.Name + LwipDefs.FnctSuffix_SetValue, isStatic: true);
                    setMethodDecl.Parameter.Add(new VariableType("instance", LwipDefs.Vt_StNodeInstance, "*"));
                    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);
                    mibFile.Declarations.Add(setMethodDecl);

                    Function setMethod = Function.FromDeclaration(setMethodDecl);
                    setMethodName = setMethod.Name;

                    returnValue = new VariableDeclaration((VariableType)setMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_Ok);
                    returnValue.Type.Name = "err";
                    setMethod.Declarations.Add(returnValue);
                    setMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", setMethod.Parameter[0].Name);

                    valueVarUsed = false;
                    lenVarUsed = false;

                    GenerateSetMethodCode(setMethod, setMethod.Parameter[2].Name, ref valueVarUsed, setMethod.Parameter[1].Name, ref lenVarUsed, returnValue.Type.Name);

                    if (!valueVarUsed)
                    {
                        setMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", setMethod.Parameter[2].Name);
                    }
                    if (!lenVarUsed)
                    {
                        setMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", setMethod.Parameter[1].Name);
                    }

                    setMethod.AddCodeFormat("return {0};", returnValue.Type.Name);

                    mibFile.Implementation.Add(setMethod);
                }
            }

            // create and add node declaration
            string nodeInitialization;
            if (this.accessMode == SnmpAccessMode.ReadOnly)
            {
                nodeInitialization = String.Format("SNMP_SCALAR_CREATE_NODE_READONLY({0}, {1}, {2})",
                    this.Oid,
                    LwipDefs.GetAsn1DefForSnmpDataType(this.dataType),
                    getMethodName);
            }
            else
            {
                nodeInitialization = String.Format("SNMP_SCALAR_CREATE_NODE({0}, {1}, {2}, {3}, {4}, {5})",
                    this.Oid,
                    LwipDefs.GetLwipDefForSnmpAccessMode(this.accessMode),
                    LwipDefs.GetAsn1DefForSnmpDataType(this.dataType),
                    getMethodName,
                    testMethodName,
                    setMethodName);
            }

            mibFile.Declarations.Add(new VariableDeclaration(
                new VariableType(this.FullNodeName, LwipDefs.Vt_StScalarNode, null, ConstType.Value),
                nodeInitialization, isStatic: true));
        }
コード例 #5
0
		protected virtual void GenerateSetMethodCode(Function setMethod, string switchSelector)
		{
			VariableDeclaration returnValue = new VariableDeclaration((VariableType)setMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_Ok);
			returnValue.Type.Name = "err";
			setMethod.Declarations.Add(returnValue);
			Switch sw = new Switch(switchSelector);

			bool valueVarUsed = false;
			bool lenVarUsed = false;
			
			foreach (SnmpScalarNode scalarNode in this.AggregatedScalarNodes)
			{
				if ((scalarNode.AccessMode == SnmpAccessMode.WriteOnly) || (scalarNode.AccessMode == SnmpAccessMode.ReadWrite))
				{
					SwitchCase sc = new SwitchCase(scalarNode.Oid.ToString(CultureInfo.InvariantCulture));
					sc.Declarations.Add(new Comment(scalarNode.Name, singleLine: true));

					scalarNode.GenerateSetMethodCode(sc, setMethod.Parameter[2].Name, ref valueVarUsed, setMethod.Parameter[1].Name, ref lenVarUsed, returnValue.Type.Name);

					sw.Switches.Add(sc);
				}
			}

			SwitchCase scd = SwitchCase.GenerateDefault();
			scd.AddCodeFormat("LWIP_DEBUGF(SNMP_MIB_DEBUG,(\"{0}(): unknown id: %\"S32_F\"\\n\", {1}));", setMethod.Name, switchSelector);
			sw.Switches.Add(scd);

			if (!valueVarUsed)
			{
				setMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", setMethod.Parameter[2].Name);
			}
			if (!lenVarUsed)
			{
				setMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", setMethod.Parameter[1].Name);
			}

			setMethod.AddElement(sw);

			setMethod.AddCodeFormat("return {0};", returnValue.Type.Name);
		}
コード例 #6
0
ファイル: SnmpTableNode.cs プロジェクト: plocklsh/lwip
		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
		}
コード例 #7
0
ファイル: SnmpTableNode.cs プロジェクト: plocklsh/lwip
		protected virtual void GenerateGetNextInstanceMethodCode(Function getNextInstanceMethod)
		{
			getNextInstanceMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getNextInstanceMethod.Parameter[0].Name);
			getNextInstanceMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getNextInstanceMethod.Parameter[1].Name);
			getNextInstanceMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getNextInstanceMethod.Parameter[2].Name);

			VariableDeclaration returnValue = new VariableDeclaration((VariableType)getNextInstanceMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_NoSuchInstance);
			returnValue.Type.Name = "err";
			getNextInstanceMethod.Declarations.Add(returnValue);

			StringBuilder indexColumns = new StringBuilder();
			foreach (SnmpScalarNode indexNode in this.indexNodes)
			{
				indexColumns.AppendFormat(
					" {0} ({1}, OID length = {2})\n",
					indexNode.Name,
					indexNode.DataType,
					(indexNode.OidRepresentationLen >= 0) ? indexNode.OidRepresentationLen.ToString() : "variable");
			}
			if (indexColumns.Length > 0)
			{
				indexColumns.Length--;

				getNextInstanceMethod.Declarations.Insert(0, new Comment(String.Format(
					"The instance OID of this table consists of following (index) column(s):\n{0}",
					indexColumns)));
			}

			string augmentsHint = "";
			if (!String.IsNullOrWhiteSpace(this.augmentedTableRow))
			{
				augmentsHint = String.Format(
					"This table augments table '{0}'! Index columns therefore belong to table '{0}'!\n" + 
					"You may simply call the '*{1}' method of this table.\n\n",
					(this.augmentedTableRow.ToLowerInvariant().EndsWith("entry")) ? this.augmentedTableRow.Substring(0, this.augmentedTableRow.Length-5) : this.augmentedTableRow,
					LwipDefs.FnctSuffix_GetNextInstance);
			}

			getNextInstanceMethod.AddElement(new Comment(String.Format(
				"TODO: analyze '{0}->id'/'{0}->len' and return the subsequent row instance\n" +
				"Be aware that '{0}->id'/'{0}->len' must not point to a valid instance or have correct instance length.\n" +
				"If '{0}->len' is 0, return the first instance. If '{0}->len' is longer than expected, cut superfluous OID parts.\n" +
				"If a valid next instance is found, store it in '{0}->id'/'{0}->len' and set '{1} = {2};'\n\n" + 
				"snmp_oid_* methods may be used for easier processing of oid\n\n" + 
				"{3}" + 
				"In order to avoid decoding OID a second time in subsequent get_value/set_test/set_value methods,\n" +
				"you may store an arbitrary value (like a pointer to target value object) in '{4}->reference'/'{4}->reference_len'.\n" +
				"But be aware that not always a subsequent method is called -> Do NOT allocate memory here and try to release it in subsequent methods!\n\n" +
				"You also may replace function pointers in '{4}' param for get/test/set methods which contain the default values from table definition,\n" +
				"in order to provide special methods, for the currently processed cell. Changed pointers are only valid for current request.",
				getNextInstanceMethod.Parameter[1].Name,
				returnValue.Type.Name,
				LwipDefs.Def_ErrorCode_Ok,
				augmentsHint,
				getNextInstanceMethod.Parameter[2].Name
				)));

			getNextInstanceMethod.AddElement(new Comment(String.Format(
				"For easier processing and getting the next instance, you may use the 'snmp_next_oid_*' enumerator.\n" +
				"Simply pass all known instance OID's to it and it returns the next valid one:\n\n" +
				"{0} state;\n" +
				"{1} result_buf;\n" +
				"snmp_next_oid_init(&state, {2}->id, {2}->len, result_buf, LWIP_SNMP_OBJ_ID_LEN);\n" + 
				"while ({{not all instances passed}}) {{\n" + 
				"  {1} test_oid;\n" + 
				"  {{fill test_oid to create instance oid for next instance}}\n" + 
				"  snmp_next_oid_check(&state, test_oid->id, test_oid->len, {{target_data_ptr}});\n" + 
				"}}\n" + 
				"if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {{\n" + 
				"  snmp_oid_assign(row_oid, result_buf->oid, result_buf->len);\n" +
				"  {3}->reference.ptr = state.reference; //==target_data_ptr, for usage in subsequent get/test/set\n" + 
				"  {4} = {5};\n" + 
				"}}"
				,
				LwipDefs.Vt_StNextOidState,
				LwipDefs.Vt_StObjectId,
				getNextInstanceMethod.Parameter[1].Name,
				getNextInstanceMethod.Parameter[2].Name,
				returnValue.Type.Name,
				LwipDefs.Def_ErrorCode_Ok
				)));

			getNextInstanceMethod.AddCodeFormat("return {0};", returnValue.Type.Name);
		}
コード例 #8
0
ファイル: SnmpTableNode.cs プロジェクト: plocklsh/lwip
		protected virtual void GenerateGetInstanceMethodCode(Function getInstanceMethod)
		{
			VariableDeclaration returnValue = new VariableDeclaration((VariableType)getInstanceMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_NoSuchInstance);
			returnValue.Type.Name = "err";
			getInstanceMethod.Declarations.Add(returnValue);

			int instanceOidLength = 0;
			StringBuilder indexColumns = new StringBuilder();
			foreach (SnmpScalarNode indexNode in this.indexNodes)
			{
				if (instanceOidLength >= 0)
				{
					if (indexNode.OidRepresentationLen >= 0)
					{
						instanceOidLength += indexNode.OidRepresentationLen;
					}
					else
					{
						// at least one index column has a variable length -> we cannot perform a static check
						instanceOidLength = -1;
					}
				}

				indexColumns.AppendFormat(
					" {0} ({1}, OID length = {2})\n",
					indexNode.Name,
					indexNode.DataType,
					(indexNode.OidRepresentationLen >= 0) ? indexNode.OidRepresentationLen.ToString() : "variable");
			}
			if (indexColumns.Length > 0)
			{
				indexColumns.Length--;

				getInstanceMethod.Declarations.Insert(0, new Comment(String.Format(
					"The instance OID of this table consists of following (index) column(s):\n{0}",
					indexColumns)));
			}

			string augmentsHint = "";
			if (!String.IsNullOrWhiteSpace(this.augmentedTableRow))
			{
				augmentsHint = String.Format(
					"This table augments table '{0}'! Index columns therefore belong to table '{0}'!\n" + 
					"You may simply call the '*{1}' method of this table.\n\n",
					(this.augmentedTableRow.ToLowerInvariant().EndsWith("entry")) ? this.augmentedTableRow.Substring(0, this.augmentedTableRow.Length-5) : this.augmentedTableRow,
					LwipDefs.FnctSuffix_GetInstance);
			}

			CodeContainerBase ccb = getInstanceMethod;
			if (instanceOidLength > 0)
			{
				IfThenElse ite = new IfThenElse(String.Format("{0} == {1}", getInstanceMethod.Parameter[2].Name, instanceOidLength));
				getInstanceMethod.AddElement(ite);
				ccb = ite;
			}

			ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[0].Name);
			ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[1].Name);
			if (instanceOidLength <= 0)
			{
				ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[2].Name);
			}
			ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[3].Name);

			ccb.AddElement(new Comment(String.Format(
				"TODO: check if '{0}'/'{1}' params contain a valid instance oid for a row\n" +
				"If so, set '{2} = {3};'\n\n" + 
				"snmp_oid_* methods may be used for easier processing of oid\n\n" + 
				"{4}" + 
				"In order to avoid decoding OID a second time in subsequent get_value/set_test/set_value methods,\n" +
				"you may store an arbitrary value (like a pointer to target value object) in '{5}->reference'/'{5}->reference_len'.\n" +
				"But be aware that not always a subsequent method is called -> Do NOT allocate memory here and try to release it in subsequent methods!\n\n" +
				"You also may replace function pointers in '{5}' param for get/test/set methods which contain the default values from table definition,\n" +
				"in order to provide special methods, for the currently processed cell. Changed pointers are only valid for current request.",
				getInstanceMethod.Parameter[1].Name,
				getInstanceMethod.Parameter[2].Name,
				returnValue.Type.Name,
				LwipDefs.Def_ErrorCode_Ok,
				augmentsHint,
				getInstanceMethod.Parameter[3].Name
				)));

			getInstanceMethod.AddCodeFormat("return {0};", returnValue.Type.Name);
		}
コード例 #9
0
ファイル: SnmpTreeNode.cs プロジェクト: plocklsh/lwip
		public override void GenerateCode(MibCFile mibFile)
		{
			string nodeInitialization;

			if (LwipOpts.GenerateSingleAccessMethodsForTreeNodeScalars && (this.childScalarNodes.Count > 1))
			{
				GenerateAggregatedCode(mibFile, false, true);
			}

			// create and add node declaration
			if (this.childNodes.Count > 0)
			{
				StringBuilder subnodeArrayInitialization = new StringBuilder();

				for (int i=0; i<this.childNodes.Count; i++)
				{
					subnodeArrayInitialization.Append("  &");
					subnodeArrayInitialization.Append(this.childNodes[i].FullNodeName);
					subnodeArrayInitialization.Append(".node");
					if (!(this.childNodes[i] is SnmpTreeNode))
					{
						subnodeArrayInitialization.Append(".node");
					}

					if (i < (this.childNodes.Count - 1))
					{
						subnodeArrayInitialization.Append(",\n");
					}
				}

				VariableDeclaration subnodeArray = new VariableDeclaration(
					new VariableType(this.Name + "_subnodes", LwipDefs.Vt_StNode, "*", ConstType.Value, String.Empty),
					"{\n" + subnodeArrayInitialization + "\n}",
					isStatic: true);

				mibFile.Declarations.Add(subnodeArray);

				nodeInitialization = String.Format("SNMP_CREATE_TREE_NODE({0}, {1})", this.Oid, subnodeArray.Type.Name);
			}
			else
			{
				nodeInitialization = String.Format("SNMP_CREATE_EMPTY_TREE_NODE({0})", this.Oid);
			}

			mibFile.Declarations.Add(new VariableDeclaration(
				new VariableType(this.FullNodeName, LwipDefs.Vt_StTreeNode, null, ConstType.Value),
				nodeInitialization,
				isStatic: true));
		}