Example #1
0
		public static Function FromDeclaration(FunctionDeclaration decl)
		{
			Function result = new Function(decl.Name, decl.IsStatic);
			result.ReturnType = decl.ReturnType.Clone() as VariableType;

			foreach (VariableType param in decl.Parameter)
			{
				result.parameter.Add(param.Clone() as VariableType);
			}

			return result;
		}
        public static Function FromDeclaration(FunctionDeclaration decl)
        {
            Function result = new Function(decl.Name, decl.IsStatic);

            result.ReturnType = decl.ReturnType.Clone() as VariableType;

            foreach (VariableType param in decl.Parameter)
            {
                result.parameter.Add(param.Clone() as VariableType);
            }

            return(result);
        }
Example #3
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));
        }
		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);
				}
			}
		}
Example #5
0
		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
		}