Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
6.5 KiB

  1. //
  2. // Copyright (c) 1997-2002 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_OID_TREE_H
  5. #define SIMC_OID_TREE_H
  6. #include <autoptr.h>
  7. /*
  8. * This file contains the SIMCOidTree class, which is a class that
  9. * represents the OID tree of an SNMP MIB module, and the associated classes
  10. */
  11. // Forward references
  12. class SIMCOidTreeNode;
  13. class SIMCParseTree;
  14. class SIMCOidTree;
  15. // Helpful typedefs
  16. typedef CList<const SIMCSymbol **, const SIMCSymbol **> SIMCSymbolList;
  17. typedef CList<SIMCOidTreeNode *, SIMCOidTreeNode *> SIMCNodeList;
  18. // Each node in the OID tree
  19. class SIMCOidTreeNode
  20. {
  21. // The integer value of this node. Basically a component of the
  22. // OID value
  23. int _val;
  24. // A list of symbols that have an OID value represented by this node
  25. SIMCSymbolList _listOfSymbols;
  26. // A list of child nodes
  27. SIMCNodeList _listOfChildNodes;
  28. public:
  29. // You *have* to supply an integer value for this node
  30. SIMCOidTreeNode(int val)
  31. : _val(val)
  32. {}
  33. ~SIMCOidTreeNode();
  34. // Add a symbol to the list of symbols that have this oid value
  35. void AddSymbol(const SIMCSymbol ** s)
  36. {
  37. _listOfSymbols.AddTail(s);
  38. }
  39. int GetValue() const
  40. {
  41. return _val;
  42. }
  43. const SIMCSymbolList *GetSymbolList() const
  44. {
  45. return &_listOfSymbols;
  46. }
  47. // Check whether the specified symbol is in the list of symbols
  48. // of this node
  49. BOOL HasSymbol(SIMCSymbol *symbol)
  50. {
  51. POSITION p = _listOfSymbols.GetHeadPosition();
  52. const SIMCSymbol **next;
  53. const char * const symbolName = symbol->GetSymbolName();
  54. const char * const moduleName = (symbol->GetModule())->GetModuleName();
  55. while(p)
  56. {
  57. next = _listOfSymbols.GetNext(p);
  58. if(strcmp((*next)->GetSymbolName(), symbolName) == 0 &&
  59. strcmp( ((*next)->GetModule())->GetModuleName(), moduleName) == 0)
  60. return TRUE;
  61. }
  62. return FALSE;
  63. }
  64. // Add a child node
  65. BOOL AddChild(int val)
  66. {
  67. POSITION p = _listOfChildNodes.GetHeadPosition();
  68. SIMCOidTreeNode * next;
  69. while(p)
  70. {
  71. next = _listOfChildNodes.GetNext(p);
  72. if( next->GetValue() == val )
  73. return FALSE;
  74. }
  75. SIMCOidTreeNode * pTmp = new SIMCOidTreeNode(val) ;
  76. wmilib::auto_ptr<SIMCOidTreeNode> pTmp_Guard ( pTmp ) ;
  77. _listOfChildNodes.AddTail ( pTmp ) ;
  78. //
  79. // dismiss as we succeeded to add that node
  80. //
  81. pTmp_Guard.release () ;
  82. return TRUE;
  83. }
  84. const SIMCNodeList * GetListOfChildNodes() const
  85. {
  86. return &_listOfChildNodes;
  87. }
  88. // Get a child node that has the specified value
  89. SIMCOidTreeNode *GetChild(int val) const
  90. {
  91. POSITION p = _listOfChildNodes.GetHeadPosition();
  92. SIMCOidTreeNode * next;
  93. while(p)
  94. {
  95. next = _listOfChildNodes.GetNext(p);
  96. if( next->GetValue() == val )
  97. return next;
  98. }
  99. return NULL;
  100. }
  101. // Check whether the specified symbol is an any of the child
  102. // nodes
  103. BOOL HasChild(SIMCSymbol *child)
  104. {
  105. POSITION p = _listOfChildNodes.GetHeadPosition();
  106. SIMCOidTreeNode * next;
  107. while(p)
  108. {
  109. next = _listOfChildNodes.GetNext(p);
  110. if( next->HasSymbol(child))
  111. return TRUE;
  112. }
  113. return FALSE;
  114. }
  115. // These functions make semantic checks on a node
  116. BOOL CheckNode(BOOL local, SIMCParseTree *const parseTree,
  117. SIMCSymbol *parentSequence,
  118. SIMCSymbol *parentSequenceOf,
  119. SIMCSymbol *ancestor);
  120. BOOL CheckSequenceProperty(BOOL local, SIMCParseTree *const parseTree,
  121. SIMCSymbol *objectTypeSymbol,
  122. SIMCObjectTypeType *objectType,
  123. SIMCBuiltInTypeReference *seqTypeRef);
  124. BOOL CheckSequenceOfProperty(BOOL local, SIMCParseTree *const parseTree,
  125. SIMCSymbol *objectTypeSymbol,
  126. SIMCBuiltInTypeReference *seqOfTypeRef);
  127. // These functions are used in the implementation of
  128. // SIMCOidTree functions and should never be called by
  129. // the user. the user should always call the corresponding
  130. // SIMCOidTree functions
  131. BOOL GetOidValue(const char * const symbolName,
  132. const char * const moduleName,
  133. SIMCCleanOidValue& val) const;
  134. SIMCOidTreeNode *GetParentOf(const SIMCOidTreeNode * node);
  135. SIMCOidTreeNode *GetParentOf(SIMCSymbol *symbol);
  136. // Gets all the object groups, from this node, downwards.
  137. // Never called by the user. Use the corresponding SIMCOidTree
  138. // functions
  139. BOOL GetObjectGroups(SIMCOidTree *tree,
  140. SIMCGroupList *groupList);
  141. // These functions deal with fabrication
  142. // Never called by the user. Use the corresponding SIMCOidTree
  143. // functions
  144. BOOL FabricateGroup(SIMCOidTree *tree,
  145. SIMCSymbol *namedNode, SIMCGroupList *groupList);
  146. BOOL FabricateTable(SIMCOidTree *tree, SIMCTable *table);
  147. BOOL FabricateRow(SIMCOidTree *tree, SIMCTable *table);
  148. };
  149. /* And the OID tree */
  150. class SIMCOidTree
  151. {
  152. SIMCOidTreeNode _root;
  153. public:
  154. SIMCOidTree()
  155. : _root(0)
  156. {}
  157. // Gets the root of the OID tree
  158. const SIMCOidTreeNode * GetRoot() const
  159. {
  160. return &_root;
  161. }
  162. // Adds a symbol with the specified OID value to the OID tree
  163. BOOL AddSymbol(const SIMCSymbol ** s, const SIMCCleanOidValue& val);
  164. // Gets a list of symbols that have the specified OID value
  165. const SIMCSymbolList *GetSymbolList(const SIMCCleanOidValue& val);
  166. // Gets the OID value of a symbol, based on its name and its module name
  167. BOOL GetOidValue(const char * const symbolName,
  168. const char * const moduleName,
  169. SIMCCleanOidValue& val) const;
  170. // Gets the parent node of the specified node
  171. SIMCOidTreeNode *GetParentOf(const SIMCOidTreeNode * node);
  172. // Gets the parent node of the specified symbol
  173. SIMCOidTreeNode *GetParentOf(SIMCSymbol *symbol);
  174. // Gets all the OBJECT-GROUPS that can be fabricated from
  175. // this tree.
  176. BOOL GetObjectGroups(SIMCGroupList *groupList);
  177. // Checks the semantics of the OID tree
  178. BOOL CheckOidTree(BOOL local, SIMCParseTree * const parseTree);
  179. // Checks the semantics of single node
  180. BOOL CheckNode(BOOL local, SIMCParseTree * const parseTree);
  181. // Never called by the user
  182. static void SetAugmentedTable(SIMCTable *table,
  183. SIMCSymbol *augmentsSymbol,
  184. SIMCGroupList *groupList);
  185. // debugging functions
  186. friend ostream& operator<< (ostream& outStream, const SIMCOidTree& obj)
  187. {
  188. obj.WriteTree(outStream);
  189. return outStream;
  190. }
  191. void WriteTree(ostream& outStream) const;
  192. static void WriteSubTree(ostream& outStream,
  193. const SIMCOidTreeNode *subNode,
  194. SIMCCleanOidValue& realValue);
  195. };
  196. #endif