[457] | 1 | /*
|
---|
| 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
| 6 | * are permitted provided that the following conditions are met:
|
---|
| 7 | *
|
---|
| 8 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
| 9 | * this list of conditions and the following disclaimer.
|
---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
| 11 | * this list of conditions and the following disclaimer in the documentation
|
---|
| 12 | * and/or other materials provided with the distribution.
|
---|
| 13 | * 3. The name of the author may not be used to endorse or promote products
|
---|
| 14 | * derived from this software without specific prior written permission.
|
---|
| 15 | *
|
---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
---|
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
---|
| 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
---|
| 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
| 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
| 25 | * OF SUCH DAMAGE.
|
---|
| 26 | *
|
---|
| 27 | * This file is part of the lwIP TCP/IP stack.
|
---|
| 28 | *
|
---|
| 29 | * Author: Martin Hentschel <info@cl-soft.de>
|
---|
| 30 | *
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | using System;
|
---|
| 34 | using System.Text.RegularExpressions;
|
---|
| 35 | using CCodeGeneration;
|
---|
| 36 |
|
---|
| 37 | namespace LwipSnmpCodeGeneration
|
---|
| 38 | {
|
---|
| 39 | public abstract class SnmpNode
|
---|
| 40 | {
|
---|
| 41 | public static readonly Regex NameValidationRegex = new Regex(@"^\w+$");
|
---|
| 42 |
|
---|
| 43 | private string name;
|
---|
| 44 | private readonly SnmpTreeNode parentNode;
|
---|
| 45 |
|
---|
| 46 | protected SnmpNode(SnmpTreeNode parentNode)
|
---|
| 47 | {
|
---|
| 48 | this.parentNode = parentNode;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public SnmpTreeNode ParentNode
|
---|
| 52 | {
|
---|
| 53 | get { return this.parentNode; }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public virtual uint Oid { get; set; }
|
---|
| 57 |
|
---|
| 58 | public abstract string FullNodeName
|
---|
| 59 | {
|
---|
| 60 | get;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | public virtual string Name
|
---|
| 64 | {
|
---|
| 65 | get { return this.name; }
|
---|
| 66 | set
|
---|
| 67 | {
|
---|
| 68 | if (value != this.name)
|
---|
| 69 | {
|
---|
| 70 | // check for valid name
|
---|
| 71 | if (!NameValidationRegex.IsMatch(value))
|
---|
| 72 | {
|
---|
| 73 | throw new ArgumentOutOfRangeException("Name");
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | this.name = value;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public virtual void Generate(MibCFile generatedFile, MibHeaderFile generatedHeaderFile)
|
---|
| 82 | {
|
---|
| 83 | int declCount = generatedFile.Declarations.Count;
|
---|
| 84 | int implCount = generatedFile.Implementation.Count;
|
---|
| 85 |
|
---|
| 86 | this.GenerateHeaderCode(generatedHeaderFile);
|
---|
| 87 | this.GenerateCode(generatedFile);
|
---|
| 88 |
|
---|
| 89 | if (generatedFile.Declarations.Count != declCount)
|
---|
| 90 | {
|
---|
| 91 | generatedFile.Declarations.Add(EmptyLine.SingleLine);
|
---|
| 92 | }
|
---|
| 93 | if (generatedFile.Implementation.Count != implCount)
|
---|
| 94 | {
|
---|
| 95 | generatedFile.Implementation.Add(EmptyLine.SingleLine);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public abstract void GenerateCode(MibCFile mibFile);
|
---|
| 100 |
|
---|
| 101 | public virtual void GenerateHeaderCode(MibHeaderFile mibHeaderFile)
|
---|
| 102 | {
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | /// <summary>
|
---|
| 106 | /// Called after node structure creation is completed and before code is created.
|
---|
| 107 | /// Offers the possibility to perform operations depending on properties/subnodes.
|
---|
| 108 | /// If the node shall be transformed to another node(-type) than the own instance
|
---|
| 109 | /// may be replaced on parent node by the transformed instance.
|
---|
| 110 | /// Calling sequence is always from leafs up to root. So a tree node can assume
|
---|
| 111 | /// that the analyze method was already called on all child nodes.
|
---|
| 112 | /// E.g. a tree node only has scalar sub nodes -> it transforms itself to a scalar array node
|
---|
| 113 | /// </summary>
|
---|
| 114 | /// <returns>The transformed node or null if nothing shall be changed in parent structure.</returns>
|
---|
| 115 | public virtual void Analyze()
|
---|
| 116 | {
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|