34 using System.Collections.Generic;
42 private readonly List<SnmpScalarNode> cellNodes =
new List<SnmpScalarNode>();
43 private readonly List<SnmpScalarNode> indexNodes =
new List<SnmpScalarNode>();
44 private string augmentedTableRow = null;
54 get {
return cellNodes; }
59 get {
return indexNodes; }
64 get {
return this.augmentedTableRow; }
65 set { this.augmentedTableRow = value; }
72 string result = this.
Name.ToLowerInvariant();
73 if (!result.Contains(
"table"))
84 get {
return this.cellNodes; }
93 getInstanceMethodDecl.
Parameter.Add(
new VariableType(
"cell_instance", LwipDefs.Vt_StNodeInstance,
"*"));
105 getNextInstanceMethodDecl.
Parameter.Add(
new VariableType(
"cell_instance", LwipDefs.Vt_StNodeInstance,
"*"));
118 String.Format(
"SNMP_TABLE_GET_COLUMN_FROM_OID({0}->instance_oid.id)", instanceType.
Name));
121 #region create and add column/table definitions 123 StringBuilder colDefs =
new StringBuilder();
126 colDefs.AppendFormat(
" {{{0}, {1}, {2}}}, /* {3} */ \n",
128 LwipDefs.GetAsn1DefForSnmpDataType(colNode.
DataType),
129 LwipDefs.GetLwipDefForSnmpAccessMode(colNode.
AccessMode),
132 if (colDefs.Length > 0)
139 "{\n" + colDefs +
"\n}",
142 mibFile.Declarations.Add(colDefsDecl);
144 string nodeInitialization = String.Format(
"SNMP_TABLE_CREATE({0}, {1}, {2}, {3}, {4}, {5}, {6})",
147 getInstanceMethodDecl.Name, getNextInstanceMethodDecl.Name,
148 (
this.GetMethodRequired) ?
this.GetMethodName : LwipDefs.Null,
149 (
this.TestMethodRequired) ?
this.TestMethodName : LwipDefs.Null,
150 (
this.SetMethodRequired) ?
this.SetMethodName : LwipDefs.Null
167 int instanceOidLength = 0;
168 StringBuilder indexColumns =
new StringBuilder();
171 if (instanceOidLength >= 0)
180 instanceOidLength = -1;
184 indexColumns.AppendFormat(
185 " {0} ({1}, OID length = {2})\n",
190 if (indexColumns.Length > 0)
192 indexColumns.Length--;
194 getInstanceMethod.Declarations.Insert(0,
new Comment(String.Format(
195 "The instance OID of this table consists of following (index) column(s):\n{0}",
199 string augmentsHint =
"";
200 if (!String.IsNullOrWhiteSpace(
this.augmentedTableRow))
202 augmentsHint = String.Format(
203 "This table augments table '{0}'! Index columns therefore belong to table '{0}'!\n" +
204 "You may simply call the '*{1}' method of this table.\n\n",
205 (this.augmentedTableRow.ToLowerInvariant().EndsWith(
"entry")) ? this.augmentedTableRow.Substring(0,
this.augmentedTableRow.Length-5) : this.augmentedTableRow,
206 LwipDefs.FnctSuffix_GetInstance);
210 if (instanceOidLength > 0)
212 IfThenElse ite =
new IfThenElse(String.Format(
"{0} == {1}", getInstanceMethod.Parameter[2].Name, instanceOidLength));
217 ccb.
AddCodeFormat(
"LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[0].Name);
218 ccb.
AddCodeFormat(
"LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[1].Name);
219 if (instanceOidLength <= 0)
221 ccb.
AddCodeFormat(
"LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[2].Name);
223 ccb.
AddCodeFormat(
"LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[3].Name);
226 "TODO: check if '{0}'/'{1}' params contain a valid instance oid for a row\n" +
227 "If so, set '{2} = {3};'\n\n" +
228 "snmp_oid_* methods may be used for easier processing of oid\n\n" +
230 "In order to avoid decoding OID a second time in subsequent get_value/set_test/set_value methods,\n" +
231 "you may store an arbitrary value (like a pointer to target value object) in '{5}->reference'/'{5}->reference_len'.\n" +
232 "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" +
233 "You also may replace function pointers in '{5}' param for get/test/set methods which contain the default values from table definition,\n" +
234 "in order to provide special methods, for the currently processed cell. Changed pointers are only valid for current request.",
235 getInstanceMethod.Parameter[1].Name,
236 getInstanceMethod.Parameter[2].Name,
237 returnValue.Type.Name,
238 LwipDefs.Def_ErrorCode_Ok,
240 getInstanceMethod.Parameter[3].Name
243 getInstanceMethod.AddCodeFormat(
"return {0};", returnValue.Type.Name);
256 StringBuilder indexColumns =
new StringBuilder();
259 indexColumns.AppendFormat(
260 " {0} ({1}, OID length = {2})\n",
265 if (indexColumns.Length > 0)
267 indexColumns.Length--;
269 getNextInstanceMethod.Declarations.Insert(0,
new Comment(String.Format(
270 "The instance OID of this table consists of following (index) column(s):\n{0}",
274 string augmentsHint =
"";
275 if (!String.IsNullOrWhiteSpace(
this.augmentedTableRow))
277 augmentsHint = String.Format(
278 "This table augments table '{0}'! Index columns therefore belong to table '{0}'!\n" +
279 "You may simply call the '*{1}' method of this table.\n\n",
280 (this.augmentedTableRow.ToLowerInvariant().EndsWith(
"entry")) ? this.augmentedTableRow.Substring(0,
this.augmentedTableRow.Length-5) : this.augmentedTableRow,
281 LwipDefs.FnctSuffix_GetNextInstance);
284 getNextInstanceMethod.AddElement(
new Comment(String.Format(
285 "TODO: analyze '{0}->id'/'{0}->len' and return the subsequent row instance\n" +
286 "Be aware that '{0}->id'/'{0}->len' must not point to a valid instance or have correct instance length.\n" +
287 "If '{0}->len' is 0, return the first instance. If '{0}->len' is longer than expected, cut superfluous OID parts.\n" +
288 "If a valid next instance is found, store it in '{0}->id'/'{0}->len' and set '{1} = {2};'\n\n" +
289 "snmp_oid_* methods may be used for easier processing of oid\n\n" +
291 "In order to avoid decoding OID a second time in subsequent get_value/set_test/set_value methods,\n" +
292 "you may store an arbitrary value (like a pointer to target value object) in '{4}->reference'/'{4}->reference_len'.\n" +
293 "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" +
294 "You also may replace function pointers in '{4}' param for get/test/set methods which contain the default values from table definition,\n" +
295 "in order to provide special methods, for the currently processed cell. Changed pointers are only valid for current request.",
296 getNextInstanceMethod.Parameter[1].Name,
297 returnValue.Type.Name,
298 LwipDefs.Def_ErrorCode_Ok,
300 getNextInstanceMethod.Parameter[2].Name
303 getNextInstanceMethod.AddElement(
new Comment(String.Format(
304 "For easier processing and getting the next instance, you may use the 'snmp_next_oid_*' enumerator.\n" +
305 "Simply pass all known instance OID's to it and it returns the next valid one:\n\n" +
307 "{1} result_buf;\n" +
308 "snmp_next_oid_init(&state, {2}->id, {2}->len, result_buf, LWIP_SNMP_OBJ_ID_LEN);\n" +
309 "while ({{not all instances passed}}) {{\n" +
311 " {{fill test_oid to create instance oid for next instance}}\n" +
312 " snmp_next_oid_check(&state, test_oid->id, test_oid->len, {{target_data_ptr}});\n" +
314 "if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {{\n" +
315 " snmp_oid_assign(row_oid, result_buf->oid, result_buf->len);\n" +
316 " {3}->reference.ptr = state.reference; //==target_data_ptr, for usage in subsequent get/test/set\n" +
320 LwipDefs.Vt_StNextOidState,
321 LwipDefs.Vt_StObjectId,
322 getNextInstanceMethod.Parameter[1].Name,
323 getNextInstanceMethod.Parameter[2].Name,
324 returnValue.Type.Name,
325 LwipDefs.Def_ErrorCode_Ok
328 getNextInstanceMethod.AddCodeFormat(
"return {0};", returnValue.Type.Name);
Code AddCodeFormat(string codeFormat, params object[] args)
override string FullNodeName
virtual void GenerateGetNextInstanceMethodCode(Function getNextInstanceMethod)
virtual int OidRepresentationLen
If scalar is used as a table index its value becomes part of the OID. This value returns how many OID...
static Function FromDeclaration(FunctionDeclaration decl)
SnmpTableNode(SnmpTreeNode parentNode)
virtual void GenerateGetInstanceMethodCode(Function getInstanceMethod)
List< CodeElement > Implementation
List< CodeElement > Declarations
SnmpAccessMode AccessMode
override IEnumerable< SnmpScalarNode > AggregatedScalarNodes
void GenerateAggregatedCode(MibCFile mibFile, VariableType instanceType, string switchSelector, bool generateDeclarations=true, bool generateImplementations=true)
List< SnmpScalarNode > IndexNodes
override void GenerateCode(MibCFile mibFile)
List< VariableType > Parameter
CodeElement AddElement(CodeElement element)
List< CodeElement > Declarations
List< SnmpScalarNode > CellNodes
List< VariableType > Parameter