Example #1
0
        public virtual void GenerateTestMethodCode(CodeContainerBase container, string valueVarName, ref bool valueVarUsed, string lenVarName, ref bool lenVarUsed, string retErrVarName)
        {
            if (this.Restrictions.Count > 0)
            {
                bool localVarUsed;
                if (GenerateValueDeclaration(container, LocalValueName, valueVarName))
                {
                    valueVarUsed = true;
                    localVarUsed = false;
                }
                else
                {
                    localVarUsed = true;                      // do not generate UNUSED_ARG code
                }

                if (!String.IsNullOrWhiteSpace(this.FixedValueLength))
                {
                    // check for fixed value
                    container.AddCodeFormat("LWIP_ASSERT(\"Invalid length for datatype\", ({0} == {1}));", lenVarName, this.FixedValueLength);
                    lenVarUsed = true;
                }

                GenerateTestMethodCodeCore(container, LocalValueName, ref localVarUsed, lenVarName, ref lenVarUsed, retErrVarName);

                if (!localVarUsed)
                {
                    container.AddCode(String.Format("LWIP_UNUSED_ARG({0});", LocalValueName));
                }
            }
            else
            {
                container.AddCodeFormat("{0} == {1};", retErrVarName, LwipDefs.Def_ErrorCode_Ok);
            }
        }
Example #2
0
 protected virtual void GenerateGetMethodCodeCore(CodeContainerBase container, string localValueVarName, ref bool localValueVarUsed, string retLenVarName)
 {
     container.AddElement(new Comment(String.Format("TODO: put requested value to '*{0}' here", localValueVarName), singleLine: true));
     container.AddCodeFormat("{0} = {1};",
                             retLenVarName,
                             (!String.IsNullOrWhiteSpace(this.FixedValueLength)) ? this.FixedValueLength : "0");
 }
        protected override void GenerateGetMethodCodeCore(CodeContainerBase container, string localValueVarName, ref bool localValueVarUsed, string retLenVarName)
        {
            container.AddCodeFormat("snmp_encode_truthvalue({0}, /* TODO: put requested bool value here */ 0);", localValueVarName);
            localValueVarUsed = true;

            container.AddCode(String.Format("{0} = {1};",
                                            retLenVarName,
                                            (!String.IsNullOrWhiteSpace(this.FixedValueLength)) ? this.FixedValueLength : "0"));
        }
        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));
        }
Example #5
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);
        }