Exemple #1
0
		protected override void GenerateTestMethodCodeCore(CodeContainerBase container, string localValueVarName, ref bool localValueVarUsed, string lenVarName, ref bool lenVarUsed, string retErrVarName)
		{
			System.Diagnostics.Trace.Assert(this.Restrictions.Count > 0);

			StringBuilder ifCond = new StringBuilder();
			foreach (IRestriction restriction in this.Restrictions)
			{
				ifCond.Append(restriction.GetCheckCodeValid("*" + localValueVarName));
				ifCond.Append(" || ");

				localValueVarUsed = true;
			}

			ifCond.Length -= 4;

			IfThenElse ite = new IfThenElse(ifCond.ToString());
			ite.AddCode(String.Format("{0} = {1};", retErrVarName, LwipDefs.Def_ErrorCode_Ok));
			container.AddElement(ite);
		}
Exemple #2
0
		public override void GenerateTestMethodCode(CodeContainerBase container, string valueVarName, ref bool valueVarUsed, string lenVarName, ref bool lenVarUsed, string retErrVarName)
		{
			if (this.Restrictions.Count > 0)
			{
				const string bitVarName = "bits";

				container.Declarations.Add(new VariableDeclaration(new VariableType(bitVarName, LwipDefs.Vt_U32)));

				IfThenElse ite = new IfThenElse(String.Format(
					"snmp_decode_bits(({0} *){1}, {2}, &{3}) == ERR_OK",
					LwipDefs.Vt_U8,
					valueVarName,
					lenVarName,
					bitVarName));

				valueVarUsed = true;
				lenVarUsed = true;

				StringBuilder innerIfCond = new StringBuilder();
				foreach (IRestriction restriction in this.Restrictions)
				{
					innerIfCond.Append(restriction.GetCheckCodeValid(bitVarName));
					innerIfCond.Append(" || ");
				}

				innerIfCond.Length -= 4;

				IfThenElse innerIte = new IfThenElse(innerIfCond.ToString());
				innerIte.AddCode(String.Format("{0} = {1};", retErrVarName, LwipDefs.Def_ErrorCode_Ok));
				ite.AddElement(innerIte);
				container.AddElement(ite);
			}
			else
			{
				base.GenerateTestMethodCode(container, valueVarName, ref valueVarUsed, lenVarName, ref lenVarUsed, retErrVarName);
			}
		}
Exemple #3
0
		public override void GenerateSetMethodCode(CodeContainerBase container, string valueVarName, ref bool valueVarUsed, string lenVarName, ref bool lenVarUsed, string retErrVarName)
		{
			const string bitVarName = "bits";

			container.Declarations.Add(new VariableDeclaration(new VariableType(bitVarName, LwipDefs.Vt_U32)));

			IfThenElse ite = new IfThenElse(String.Format(
				"snmp_decode_bits(({0} *){1}, {2}, &{3}) == ERR_OK",
				LwipDefs.Vt_U8,
				valueVarName,
				lenVarName,
				bitVarName));

			valueVarUsed = true;
			lenVarUsed = true;

			ite.AddElement(new Comment(String.Format("TODO: store new value contained in '{0}' here", bitVarName), singleLine: true));

			container.AddElement(ite);
		}
Exemple #4
0
		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);
		}