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));
        }
Exemplo n.º 2
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_U16);
                    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));
        }
Exemplo n.º 3
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
        }